:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --border: #e2e6ec;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --sidebar-bg: #111827;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #2563eb;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 16px 0;
}
.sidebar .brand {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  padding: 0 20px 16px 20px;
  border-bottom: 1px solid #1f2937;
  margin-bottom: 8px;
}
.sidebar .brand small { display: block; font-weight: 400; color: #94a3b8; font-size: 11px; margin-top: 2px; }
.sidebar nav { flex: 1; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: #1f2937; color: #fff; }
.sidebar nav a.active { background: #1f2937; color: #fff; border-left-color: var(--sidebar-active); font-weight: 600; }
.sidebar .lan-box {
  margin: 8px 14px;
  padding: 10px 12px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 6px;
  font-size: 11px;
}
.sidebar .lan-box-label { color: #94a3b8; margin-bottom: 4px; }
.sidebar .lan-box-url { color: #e5e7eb; font-family: Consolas, monospace; word-break: break-all; line-height: 1.5; }
.sidebar .user-box {
  padding: 12px 20px;
  border-top: 1px solid #1f2937;
  font-size: 12.5px;
}
.sidebar .user-box .name { color: #fff; font-weight: 600; }
.sidebar .user-box .role { color: #94a3b8; }
.sidebar .user-box form { margin-top: 8px; }
.sidebar .user-box button {
  background: transparent;
  border: 1px solid #374151;
  color: #cbd5e1;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  width: 100%;
}
.sidebar .user-box button:hover { background: #1f2937; color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: flex-start;
}
.topbar h1 { font-size: 18px; margin: 0; }
.content { padding: 24px; flex: 1; }

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 40;
}
.sidebar-overlay.show { display: block; }
body.no-scroll { overflow: hidden; }

.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13.5px; }
.flash.success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

.cards-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  min-width: 180px;
  flex: 1;
}
.stat-card .label { color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
.stat-card .value { font-size: 26px; font-weight: 700; }
.stat-card .value.warn { color: var(--warning); }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.panel h2 { font-size: 15px; margin: 0 0 14px 0; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.toolbar .search-form { display: flex; gap: 8px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: #fafbfc; }
.table-wrap { overflow-x: auto; }
.empty-row td { text-align: center; color: var(--muted); padding: 24px; }

.btn {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  text-decoration: none;
  line-height: 1.2;
}
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: #fff; color: var(--danger); border-color: #fca5a5; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-row { display: flex; gap: 8px; }

form.inline { display: inline; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; }
.form-grid.one-col { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field .hint { font-size: 11.5px; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], input[type=email], input[type=tel], select, textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  min-width: 0;
  max-width: 100%;
}
.field > input, .field > select, .field > textarea { width: 100%; }
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
.form-actions { margin-top: 18px; display: flex; gap: 10px; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-red { background: #fee2e2; color: #991b1b; }

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #111827, #1e3a8a);
}
.login-box {
  background: #fff;
  border-radius: 12px;
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.login-box h1 { font-size: 19px; margin: 0 0 4px 0; }
.login-box p.sub { color: var(--muted); margin: 0 0 22px 0; font-size: 13px; }
.login-box .field { margin-bottom: 14px; }
.login-box button { width: 100%; padding: 10px; font-size: 14px; margin-top: 6px; }

.help-text { color: var(--muted); font-size: 12.5px; margin-top: -8px; margin-bottom: 14px; }

.kanban { display: flex; gap: 16px; align-items: flex-start; }
.kanban-col { flex: 1; min-width: 0; background: #f8fafc; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.kanban-col h3 { font-size: 13px; margin: 0 0 10px 0; display: flex; justify-content: space-between; color: var(--muted); }
.kanban-card { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 10px; margin-bottom: 10px; font-size: 13px; }
.kanban-card .title { font-weight: 600; margin-bottom: 6px; }
.kanban-card .meta { color: var(--muted); font-size: 11.5px; display: flex; justify-content: space-between; align-items: center; gap: 6px; flex-wrap: wrap;}

.pagetabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.pagetabs a { padding: 9px 14px; font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent; }
.pagetabs a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.pagetabs a:hover { text-decoration: none; color: var(--primary); }

.text-muted { color: var(--muted); }
.text-danger { color: var(--danger); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }

.split-row { display: flex; gap: 20px; align-items: flex-start; }
.split-row > .panel { flex: 1; min-width: 0; margin-bottom: 0; }

.viz-legend { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; }
.viz-legend-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.viz-swatch { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.viz-legend-label { flex: 1; color: var(--text); }
.viz-legend-value { color: var(--muted); font-variant-numeric: tabular-nums; }

.viz-hbar-chart { display: flex; flex-direction: column; gap: 10px; }
.viz-hbar-row { display: flex; align-items: center; gap: 10px; }
.viz-hbar-label { width: 110px; flex-shrink: 0; font-size: 12px; color: var(--text); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viz-hbar-track { flex: 1; height: 18px; background: #f1f5f9; border-radius: 4px; overflow: hidden; }
.viz-hbar-fill { height: 100%; border-radius: 0 4px 4px 0; }
.viz-hbar-value { width: 48px; flex-shrink: 0; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

@media (max-width: 800px) {
  .app-shell { flex-direction: column; }
  .nav-toggle { display: inline-flex; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    max-width: 82vw;
    z-index: 50;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 28px rgba(0,0,0,0.3); }
  .content { padding: 14px; }
  .topbar { padding: 10px 14px; }
  .topbar h1 { font-size: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .kanban { flex-direction: column; }
  .kanban-col { width: 100%; }
  .split-row { flex-direction: column; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .search-form { width: 100%; }
  .toolbar .search-form input[type=search] { flex: 1; min-width: 0 !important; }
  input[type=search] { min-width: 0 !important; }
  .btn-row { flex-wrap: wrap; }
}

@media (max-width: 1100px) {
  .split-row { flex-direction: column; }
}

@media (max-width: 480px) {
  input[type=text], input[type=password], input[type=number], input[type=date],
  input[type=search], input[type=email], input[type=tel], select, textarea {
    font-size: 16px;
  }
  .btn { padding: 10px 14px; }
  th, td { padding: 8px 7px; font-size: 12.5px; }
  .content { padding: 12px; }
  .panel { padding: 14px; }
  .stat-card { min-width: 46%; padding: 12px 14px; }
  .cards-row { gap: 10px; }
  .login-page { padding: 16px; }
  .login-box { padding: 26px 22px; }
}
