:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --brand-50:  oklch(0.97 0.01 255);
  --brand-100: oklch(0.93 0.03 255);
  --brand-200: oklch(0.85 0.06 255);
  --brand-300: oklch(0.74 0.10 255);
  --brand-400: oklch(0.60 0.13 255);
  --brand-500: oklch(0.50 0.15 255);
  --brand-600: oklch(0.42 0.14 255);
  --brand-700: oklch(0.34 0.12 255);
  --brand-800: oklch(0.26 0.09 255);
  --brand-900: oklch(0.18 0.05 255);

  --ok-500:   oklch(0.65 0.15 155);
  --warn-500: oklch(0.75 0.15 80);
  --err-500:  oklch(0.60 0.20 25);

  --bg:        oklch(0.985 0.003 255);
  --bg-soft:   oklch(0.965 0.005 255);
  --bg-elev:   oklch(1.00 0 0);
  --border:    oklch(0.90 0.008 255);
  --border-strong: oklch(0.82 0.012 255);
  --text:      oklch(0.20 0.02 255);
  --text-muted: oklch(0.45 0.02 255);
  --text-faint: oklch(0.62 0.02 255);
  --primary: var(--brand-600);
  --primary-hover: var(--brand-700);
  --on-primary: #fff;

  --radius-sm: 4px;
  --radius:    6px;
  --radius-lg: 10px;
  --radius-xl: 14px;

  --shadow-sm: 0 1px 2px rgba(15,23,42,.04);
  --shadow:    0 1px 2px rgba(15,23,42,.05), 0 4px 12px rgba(15,23,42,.04);
  --shadow-lg: 0 4px 8px rgba(15,23,42,.06), 0 16px 40px rgba(15,23,42,.08);

  --sidebar-w: 248px;
  --header-h: 56px;
  --density-row: 44px;
}

[data-theme="dark"] {
  --bg:        oklch(0.16 0.015 255);
  --bg-soft:   oklch(0.20 0.018 255);
  --bg-elev:   oklch(0.23 0.020 255);
  --border:    oklch(0.30 0.020 255);
  --border-strong: oklch(0.38 0.025 255);
  --text:      oklch(0.96 0.005 255);
  --text-muted: oklch(0.72 0.015 255);
  --text-faint: oklch(0.55 0.015 255);
  --primary: var(--brand-400);
  --primary-hover: var(--brand-300);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow:    0 1px 2px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 4px 8px rgba(0,0,0,.4), 0 16px 40px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
a { color: inherit; text-decoration: none; }
.mono { font-family: var(--font-mono); }
.tnum { font-variant-numeric: tabular-nums; }

/* ── App shell ── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  overflow: hidden;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
  flex: none;
}
.sidebar-mark {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  border-radius: 7px;
  display: grid; place-items: center;
  color: white; font-weight: 700; font-size: 12px;
  letter-spacing: -0.02em; flex: none;
  box-shadow: 0 1px 2px rgba(0,0,0,.15), inset 0 1px 0 rgba(255,255,255,.2);
}
.sidebar-brand-text { display: flex; flex-direction: column; line-height: 1.15; overflow: hidden; }
.sidebar-brand-text strong { font-size: 13px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.sidebar-brand-text small { font-size: 10.5px; color: var(--text-muted); letter-spacing: 0.06em; text-transform: uppercase; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 8px; display: flex; flex-direction: column; gap: 1px; }
.sidebar-section { font-size: 10px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); padding: 14px 12px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 12px; min-height: 36px;
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer; font-size: 13px; font-weight: 500;
  border: 0; background: transparent; width: 100%; text-align: left;
  position: relative;
}
.nav-item:hover { background: var(--bg-elev); color: var(--text); }
.nav-item.active {
  background: color-mix(in oklch, var(--primary) 12%, transparent);
  color: var(--primary);
}
.nav-item.active::before {
  content: ''; position: absolute; left: -8px; top: 8px; bottom: 8px;
  width: 2.5px; border-radius: 0 2px 2px 0; background: var(--primary);
}
.nav-item svg { flex: none; }
.nav-item-label { flex: 1; white-space: nowrap; }

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 10px;
  display: flex; align-items: center; gap: 10px;
  flex: none;
}
.avatar {
  width: 32px; height: 32px; flex: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-400), var(--brand-600));
  color: white; display: grid; place-items: center;
  font-size: 11.5px; font-weight: 600;
}
.sidebar-foot-name { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.sidebar-foot-name strong { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-foot-name span { font-size: 11px; color: var(--text-faint); }

/* ── Main / Topbar ── */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px; gap: 16px;
  background: var(--bg);
  position: sticky; top: 0; z-index: 10; flex: none;
}
.topbar-trail { flex: 1; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); }
.topbar-trail strong { color: var(--text); font-weight: 600; }
.topbar-trail .sep { color: var(--text-faint); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ── Page ── */
.page { padding: 28px 32px; max-width: 1320px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; margin: 0 0 4px; }
.page-sub { color: var(--text-muted); font-size: 13.5px; margin: 0; max-width: 640px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px;
  border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-soft); color: var(--text);
  transition: background .12s, border-color .12s;
  white-space: nowrap; cursor: pointer;
}
.btn:hover { background: var(--bg-elev); }
.btn-primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--bg-soft); }
.btn-danger { background: color-mix(in oklch, var(--err-500) 12%, transparent); color: var(--err-500); border-color: color-mix(in oklch, var(--err-500) 30%, var(--border)); }
.btn-danger:hover { background: color-mix(in oklch, var(--err-500) 20%, transparent); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn[disabled], .btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn {
  width: 32px; height: 32px;
  border: 1px solid transparent;
  background: transparent; border-radius: var(--radius);
  display: grid; place-items: center; color: var(--text-muted); cursor: pointer;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); border-color: var(--border); }

/* ── Cards ── */
.card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-pad { padding: 20px; }
.card-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-title { font-size: 14px; font-weight: 600; margin: 0; letter-spacing: -0.005em; }
.card-sub { font-size: 12.5px; color: var(--text-muted); margin: 2px 0 0; }

/* ── KPI Row ── */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 24px; }
.kpi { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; }
.kpi-label { font-size: 11.5px; color: var(--text-muted); letter-spacing: 0.04em; text-transform: uppercase; font-weight: 500; }
.kpi-value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 11.5px; margin-top: 4px; color: var(--text-faint); }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 500;
  padding: 2px 8px; border-radius: 999px;
  background: var(--bg-soft); color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge.ok    { color: var(--ok-500);   border-color: color-mix(in oklch, var(--ok-500)   30%, var(--border)); background: color-mix(in oklch, var(--ok-500)   8%, transparent); }
.badge.warn  { color: var(--warn-500); border-color: color-mix(in oklch, var(--warn-500) 30%, var(--border)); background: color-mix(in oklch, var(--warn-500) 8%, transparent); }
.badge.err   { color: var(--err-500);  border-color: color-mix(in oklch, var(--err-500)  30%, var(--border)); background: color-mix(in oklch, var(--err-500)  8%, transparent); }
.badge.brand { color: var(--primary);  border-color: color-mix(in oklch, var(--primary)  30%, var(--border)); background: color-mix(in oklch, var(--primary)  8%, transparent); }

/* ── Table ── */
.table-wrap { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 0 16px; height: var(--density-row); text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-faint); background: var(--bg-soft); height: 38px; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--bg-soft); }
.table .num { text-align: right; }
.table .actions { width: 1%; white-space: nowrap; text-align: right; }
.table .pri { font-weight: 600; }

/* ── Filters bar ── */
.filters {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  padding: 16px 20px; border-bottom: 1px solid var(--border); background: var(--bg-soft);
}
.filters .field { min-width: 160px; flex: 1; }

/* ── Forms ── */
.form-grid { display: grid; gap: 18px; }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 500; color: var(--text-muted); }
.input, .select {
  height: 38px; padding: 0 12px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev); color: var(--text);
  border-radius: var(--radius); font-size: 13.5px; outline: none;
  transition: border-color .12s, box-shadow .12s; width: 100%;
}
.input:focus, .select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--primary) 18%, transparent);
}
.input::placeholder { color: var(--text-faint); }
.input-icon { position: relative; }
.input-icon .input { padding-left: 36px; }
.input-icon svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-faint); pointer-events: none; }
.select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'><path d='M1 1l4 4 4-4' stroke='%23788' stroke-width='1.5' stroke-linecap='round'/></svg>"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
.field-hint { font-size: 11.5px; color: var(--text-faint); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; padding-top: 8px; border-top: 1px solid var(--border); margin-top: 8px; }

/* ── Upload zone ── */
.upload-zone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  background: var(--bg-soft);
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary);
  background: color-mix(in oklch, var(--primary) 5%, var(--bg-soft));
}
.upload-zone input[type="file"] { display: none; }
.upload-zone p { color: var(--text-muted); font-size: 13px; margin: 8px 0 0; }

/* ── Invite highlight ── */
.invite-highlight {
  background: color-mix(in oklch, var(--ok-500) 8%, var(--bg-elev));
  border: 1px solid color-mix(in oklch, var(--ok-500) 28%, var(--border));
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex; flex-direction: column; gap: 10px;
}
.invite-link-row { display: flex; align-items: center; gap: 8px; }
.invite-link-row .input { font-family: var(--font-mono); font-size: 12.5px; }

/* ── Modal ── */
.modal-back {
  position: fixed; inset: 0; z-index: 40;
  background: oklch(0.15 0.02 255 / .55);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  padding: 24px;
}
.modal {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 440px;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 15px; font-weight: 600; margin: 0; }
.modal-body { padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: var(--bg-soft); }

/* ── Login ── */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 0.95fr; }
@media (max-width: 800px) { .login-wrap { grid-template-columns: 1fr; } .login-hero { display: none; } }
.login-hero {
  position: relative;
  background:
    radial-gradient(ellipse at 30% 20%, color-mix(in oklch, var(--brand-400) 50%, transparent) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 80%, color-mix(in oklch, var(--brand-500) 35%, transparent) 0%, transparent 60%),
    linear-gradient(135deg, var(--brand-800), var(--brand-900));
  color: white; padding: 48px;
  display: flex; flex-direction: column; justify-content: space-between;
}
.login-hero::after {
  content: ''; position: absolute; inset: 0;
  background-image: linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: linear-gradient(180deg, black 0%, transparent 80%);
  pointer-events: none;
}
.login-hero-mark { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; }
.login-hero-mark strong { font-size: 16px; font-weight: 600; }
.login-hero-mark small { font-size: 11px; color: rgba(255,255,255,.65); letter-spacing: 0.08em; text-transform: uppercase; }
.login-hero-content { position: relative; z-index: 1; max-width: 460px; }
.login-hero-content h1 { font-size: 30px; font-weight: 600; letter-spacing: -0.025em; line-height: 1.2; margin: 0 0 14px; }
.login-hero-content p { color: rgba(255,255,255,.75); font-size: 14.5px; line-height: 1.6; margin: 0; }
.login-hero-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; position: relative; z-index: 1; }
.login-hero-stats .stat strong { display: block; font-size: 22px; font-weight: 600; }
.login-hero-stats .stat span { font-size: 11.5px; color: rgba(255,255,255,.6); text-transform: uppercase; letter-spacing: 0.04em; }
.login-panel { display: grid; place-items: center; padding: 48px 32px; }
.login-form { width: 100%; max-width: 380px; }
.login-form h2 { font-size: 22px; font-weight: 600; margin: 0 0 4px; letter-spacing: -0.02em; }
.login-form p.lead { color: var(--text-muted); margin: 0 0 28px; font-size: 13.5px; }
.login-form .field + .field { margin-top: 14px; }
.login-form .btn { width: 100%; height: 42px; margin-top: 22px; font-size: 13.5px; }
.login-foot { margin-top: 36px; font-size: 11.5px; color: var(--text-faint); text-align: center; }
.input-pw-wrap { position: relative; }
.input-pw-wrap .input { padding-right: 40px; }
.btn-pw-toggle { position: absolute; right: 4px; top: 4px; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow-lg); z-index: 60;
  animation: popIn .2s ease;
  white-space: nowrap;
}
.toast.error { background: var(--err-500); color: white; }
.toast.warning { background: var(--warn-500); color: white; }

/* ── Empty state ── */
.empty { text-align: center; padding: 48px 24px; color: var(--text-muted); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty-icon { width: 44px; height: 44px; border-radius: 50%; background: var(--bg-soft); display: grid; place-items: center; color: var(--text-faint); }
.empty strong { font-size: 14px; color: var(--text); font-weight: 600; }

/* ── Alert ── */
.alert { padding: 14px 16px; border-radius: var(--radius); font-size: 13px; display: flex; align-items: flex-start; gap: 10px; }
.alert.error { background: color-mix(in oklch, var(--err-500) 10%, transparent); border: 1px solid color-mix(in oklch, var(--err-500) 30%, var(--border)); color: var(--err-500); }
.alert.success { background: color-mix(in oklch, var(--ok-500) 10%, transparent); border: 1px solid color-mix(in oklch, var(--ok-500) 30%, var(--border)); color: var(--ok-500); }

/* ── Pagination ── */
.pagination { display: flex; align-items: center; gap: 6px; justify-content: center; padding: 16px; }
.pagination .btn { min-width: 36px; }
.pagination .current { font-size: 13px; color: var(--text-muted); padding: 0 8px; }

/* ── Separator ── */
.sep-h { border: none; border-top: 1px solid var(--border); margin: 0; }

/* ── Role badge ── */
.role-developer { color: var(--brand-600); background: color-mix(in oklch, var(--brand-600) 10%, transparent); border-color: color-mix(in oklch, var(--brand-600) 30%, var(--border)); }

@keyframes popIn { from { opacity: 0; transform: translateX(-50%) translateY(8px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

/* ── Help / Manual ── */
.help-body { max-width: 720px; display: flex; flex-direction: column; gap: 40px; padding: 4px 0 32px; }
.help-section {}
.help-h2 { font-size: 14px; font-weight: 700; color: var(--text); padding-bottom: 10px; border-bottom: 1px solid var(--border); margin-bottom: 16px; letter-spacing: -0.1px; }
.help-h3 { font-size: 13px; font-weight: 600; color: var(--text); margin: 18px 0 8px; }
.help-body p { font-size: 13.5px; color: var(--text-muted); margin-bottom: 8px; }
.help-ol { list-style: none; padding: 0; counter-reset: help-steps; display: flex; flex-direction: column; gap: 8px; }
.help-ol li { counter-increment: help-steps; display: flex; align-items: flex-start; gap: 10px; font-size: 13.5px; color: var(--text-muted); }
.help-ol li::before { content: counter(help-steps); min-width: 20px; height: 20px; background: var(--text); color: var(--bg); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; flex-shrink: 0; margin-top: 1px; }
.help-callout { background: color-mix(in oklch, var(--brand-600) 8%, transparent); border: 1px solid color-mix(in oklch, var(--brand-600) 25%, var(--border)); border-radius: var(--radius); padding: 10px 14px; font-size: 13px; color: var(--text-muted); margin: 12px 0; }
.faq-list { display: flex; flex-direction: column; gap: 6px; }
.faq-item { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.faq-q { width: 100%; background: none; border: none; padding: 13px 16px; text-align: left; font-size: 13.5px; font-weight: 600; color: var(--text); cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.faq-q:hover { background: var(--bg); }
.faq-arrow { color: var(--text-faint); flex-shrink: 0; transition: transform 0.2s; }
.faq-item.open .faq-arrow { transform: rotate(180deg); }
.faq-a { display: none; padding: 0 16px 13px; font-size: 13.5px; color: var(--text-muted); border-top: 1px solid var(--border); padding-top: 10px; }
.faq-item.open .faq-a { display: block; }
