:root {
    /* tokens — overridden by tweaks at runtime */
    --accent: oklch(48% 0.13 250);
    --accent-soft: oklch(96% 0.025 250);
    --accent-ink: oklch(38% 0.14 250);

    --bg: oklch(98.5% 0.003 250);
    --surface: #ffffff;
    --surface-2: oklch(97% 0.004 250);
    --border: oklch(92% 0.006 250);
    --border-strong: oklch(86% 0.008 250);

    --ink: oklch(22% 0.015 255);
    --ink-2: oklch(38% 0.012 255);
    --ink-3: oklch(56% 0.012 255);
    --ink-4: oklch(72% 0.008 255);

    --success: oklch(58% 0.11 155);
    --success-soft: oklch(96% 0.03 155);
    --warning: oklch(68% 0.13 75);
    --warning-soft: oklch(96% 0.04 80);
    --danger: oklch(58% 0.17 25);
    --danger-soft: oklch(96% 0.03 25);

    --side-bg: oklch(22% 0.012 255);
    --side-ink: oklch(72% 0.01 255);
    --side-ink-active: #ffffff;
    --side-hover: oklch(28% 0.014 255);
    --side-active: oklch(32% 0.016 255);

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

    --shadow-sm: 0 1px 0 oklch(0% 0 0 / 0.02), 0 1px 2px oklch(0% 0 0 / 0.04);
    --shadow: 0 1px 0 oklch(0% 0 0 / 0.02), 0 4px 10px -2px oklch(0% 0 0 / 0.06);

    --row-h: 44px;
    --pad: 16px;
  }

  * { box-sizing: border-box; }
  html, body { margin: 0; padding: 0; }
  body {
    font-family: 'Pretendard Variable', Pretendard, -apple-system, system-ui, sans-serif;
    font-size: 14px;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }
  button { font-family: inherit; }
  input, select, textarea { font-family: inherit; font-size: 14px; color: var(--ink); }
  .mono { font-family: 'JetBrains Mono', ui-monospace, monospace; font-feature-settings: 'tnum'; }
  .tnum { font-variant-numeric: tabular-nums; }

  /* layout */
  .app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
  .app.collapsed { grid-template-columns: 64px 1fr; }

  /* sidebar */
  .side {
    background: var(--side-bg);
    color: var(--side-ink);
    padding: 18px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: sticky;
    top: 0;
    height: 100vh;
  }
  .side-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 10px 18px;
    color: #fff;
    font-weight: 700;
    letter-spacing: -0.01em;
  }
  .side-brand .logo {
    width: 28px; height: 28px; border-radius: 8px;
    background: linear-gradient(135deg, var(--accent), oklch(60% 0.14 290));
    display: grid; place-items: center;
    color: #fff; font-size: 13px; font-weight: 800;
    box-shadow: inset 0 0 0 1px oklch(100% 0 0 / 0.1);
  }
  .side-section {
    color: oklch(50% 0.012 255);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 14px 10px 6px;
  }
  .nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px;
    border-radius: 8px;
    color: var(--side-ink);
    cursor: pointer;
    user-select: none;
    font-weight: 500;
    transition: background 0.12s, color 0.12s;
  }
  .nav-item:hover { background: var(--side-hover); color: #fff; }
  .nav-item.active { background: var(--side-active); color: var(--side-ink-active); }
  .nav-item .ic { width: 18px; height: 18px; flex: none; opacity: 0.85; }
  .nav-item.active .ic { opacity: 1; }
  .nav-item .badge-mini {
    margin-left: auto;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 999px;
  }
  .side-foot {
    margin-top: auto;
    padding: 10px;
    border-top: 1px solid oklch(28% 0.012 255);
    display: flex; align-items: center; gap: 10px;
  }
  .avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), oklch(60% 0.14 290));
    color: #fff; font-weight: 700; font-size: 12px;
    display: grid; place-items: center;
    flex: none;
  }
  .side-foot .who { display: flex; flex-direction: column; min-width: 0; }
  .side-foot .who b { color: #fff; font-size: 13px; }
  .side-foot .who span { font-size: 11px; color: oklch(55% 0.012 255); }

  /* main */
  .main { display: flex; flex-direction: column; min-width: 0; }
  .topbar {
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 16px;
    padding: 0 24px;
    position: sticky; top: 0; z-index: 10;
  }
  .crumbs { display: flex; align-items: center; gap: 8px; color: var(--ink-3); font-size: 13px; }
  .crumbs b { color: var(--ink); font-weight: 600; }
  .crumbs .sep { color: var(--ink-4); }
  .search {
    margin-left: auto;
    display: flex; align-items: center; gap: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    width: 280px;
    color: var(--ink-3);
  }
  .search input { flex: 1; border: 0; background: transparent; outline: none; padding: 2px 0; }
  .search kbd {
    font-family: inherit; font-size: 11px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 4px; padding: 1px 5px; color: var(--ink-3);
  }
  .icon-btn {
    width: 32px; height: 32px;
    display: grid; place-items: center;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 8px;
    cursor: pointer;
    color: var(--ink-2);
  }
  .icon-btn:hover { background: var(--surface-2); color: var(--ink); }

  .content { padding: 24px 28px 80px; max-width: 1280px; width: 100%; }
  .page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
  .page-head h1 { font-size: 22px; font-weight: 700; margin: 0 0 4px; letter-spacing: -0.015em; }
  .page-head .sub { color: var(--ink-3); font-size: 13px; }

  /* card */
  .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
  }
  .card-h {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 8px;
    font-weight: 600;
  }
  .card-h .count { color: var(--ink-3); font-weight: 500; }
  .card-h .right { margin-left: auto; }
  .card-b { padding: 18px; }
  .card-b.flush { padding: 0; }

  /* stats */
  .stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
  .stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
    display: flex; flex-direction: column; gap: 6px;
    position: relative; overflow: hidden;
  }
  .stat .label { font-size: 12px; color: var(--ink-3); font-weight: 500; display: flex; align-items: center; gap: 6px; }
  .stat .val { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; color: var(--ink); }
  .stat .val .unit { font-size: 14px; font-weight: 500; color: var(--ink-3); margin-left: 2px; }
  .stat .delta { font-size: 12px; display: flex; align-items: center; gap: 4px; }
  .delta.up { color: var(--success); }
  .delta.down { color: var(--danger); }
  .delta.flat { color: var(--ink-3); }
  .stat .spark { position: absolute; right: 12px; bottom: 12px; opacity: 0.7; }

  /* buttons */
  .btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 12px;
    border-radius: 7px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--ink);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.12s, border 0.12s;
    white-space: nowrap;
  }
  .btn:hover { background: var(--surface-2); }
  .btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
  .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
  .btn.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
  .btn.ghost { border-color: transparent; background: transparent; }
  .btn.ghost:hover { background: var(--surface-2); }
  .btn.danger { color: var(--danger); border-color: var(--border-strong); }
  .btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
  .btn.icon-only { padding: 6px; }

  /* inputs */
  .input, .select {
    width: 100%;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    border-radius: 7px;
    padding: 7px 10px;
    outline: none;
    transition: border 0.12s, box-shadow 0.12s;
  }
  .input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px oklch(from var(--accent) l c h / 0.15); }
  .input.sm, .select.sm { padding: 5px 9px; font-size: 13px; border-radius: 6px; }
  .label { display: block; font-size: 12px; font-weight: 500; color: var(--ink-2); margin-bottom: 5px; }
  .field { margin-bottom: 14px; }
  .field .hint { font-size: 11px; color: var(--ink-3); margin-top: 4px; }

  /* table */
  .table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
  .table thead th {
    text-align: left;
    font-weight: 500;
    color: var(--ink-3);
    font-size: 12px;
    padding: 10px 14px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
  }
  .table thead th:first-child { padding-left: 18px; }
  .table thead th:last-child { padding-right: 18px; }
  .table tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
  }
  .table tbody td:first-child { padding-left: 18px; }
  .table tbody td:last-child { padding-right: 18px; }
  .table tbody tr:last-child td { border-bottom: 0; }
  .table tbody tr { transition: background 0.1s; }
  .table tbody tr:hover { background: var(--surface-2); }
  .table tbody tr.clickable { cursor: pointer; }
  .table.compact tbody td { padding: 7px 12px; }
  .table.compact thead th { padding: 7px 12px; }

  /* badge */
  .badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 500;
    line-height: 1.6;
    border: 1px solid transparent;
  }
  .badge .dot { width: 6px; height: 6px; border-radius: 50%; }
  .badge.neutral { background: var(--surface-2); color: var(--ink-2); border-color: var(--border); }
  .badge.neutral .dot { background: var(--ink-3); }
  .badge.success { background: var(--success-soft); color: var(--success); }
  .badge.success .dot { background: var(--success); }
  .badge.warning { background: var(--warning-soft); color: oklch(45% 0.13 70); }
  .badge.warning .dot { background: var(--warning); }
  .badge.danger { background: var(--danger-soft); color: var(--danger); }
  .badge.danger .dot { background: var(--danger); }
  .badge.accent { background: var(--accent-soft); color: var(--accent-ink); }
  .badge.accent .dot { background: var(--accent); }

  /* user cell */
  .user-cell { display: flex; align-items: center; gap: 10px; }
  .user-cell .avatar { width: 28px; height: 28px; font-size: 11px; }
  .user-cell .info { display: flex; flex-direction: column; line-height: 1.2; }
  .user-cell .info b { font-weight: 600; color: var(--ink); font-size: 13px; }
  .user-cell .info span { font-size: 11.5px; color: var(--ink-3); }

  /* alerts */
  .alert {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid;
    font-size: 13px;
    margin-bottom: 18px;
  }
  .alert.success { background: var(--success-soft); border-color: oklch(85% 0.06 155); color: oklch(35% 0.1 155); }
  .alert.danger { background: var(--danger-soft); border-color: oklch(85% 0.08 25); color: oklch(38% 0.14 25); }
  .alert.info { background: var(--accent-soft); border-color: oklch(85% 0.06 250); color: var(--accent-ink); }

  /* timeline */
  .timeline { display: flex; flex-direction: column; gap: 2px; padding: 8px 0; }
  .tl-row {
    display: grid; grid-template-columns: 18px 1fr auto; gap: 12px;
    align-items: center;
    padding: 10px 18px;
    position: relative;
  }
  .tl-row .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-left: 5px; position: relative; z-index: 1; }
  .tl-row .dot.muted { background: var(--ink-4); }
  .tl-row .dot.success { background: var(--success); }
  .tl-row::before {
    content: '';
    position: absolute; left: 27px; top: 0; bottom: 0;
    width: 1px; background: var(--border);
  }
  .tl-row:first-child::before { top: 50%; }
  .tl-row:last-child::before { bottom: 50%; }
  .tl-row .what { font-size: 13px; }
  .tl-row .when { font-size: 12px; color: var(--ink-3); }

  /* login */
  .login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background:
      radial-gradient(800px 400px at 20% 10%, oklch(from var(--accent) l c h / 0.08), transparent),
      radial-gradient(700px 500px at 90% 90%, oklch(60% 0.14 290 / 0.06), transparent),
      var(--bg);
  }
  .login-card {
    width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 20px 60px -20px oklch(0% 0 0 / 0.15), 0 2px 6px -2px oklch(0% 0 0 / 0.06);
    padding: 32px;
  }

  /* misc */
  .row { display: flex; align-items: center; gap: 10px; }
  .row.between { justify-content: space-between; }
  .row.wrap { flex-wrap: wrap; }
  .grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
  .grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
  .gap-2 { gap: 8px; }
  .gap-3 { gap: 12px; }
  .muted { color: var(--ink-3); }
  .strong { font-weight: 600; }
  .small { font-size: 12px; }
  .tag-id {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11.5px;
    color: var(--ink-3);
    background: var(--surface-2);
    padding: 1px 6px;
    border-radius: 4px;
    border: 1px solid var(--border);
  }

  /* density */
  .density-compact .table tbody td { padding: 8px 12px; }
  .density-compact .stat { padding: 12px 14px; }
  .density-compact .stat .val { font-size: 24px; }

  /* tabs */
  .tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
  .tab {
    padding: 8px 14px;
    font-size: 13px;
    color: var(--ink-3);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    font-weight: 500;
  }
  .tab:hover { color: var(--ink); }
  .tab.active { color: var(--accent); border-bottom-color: var(--accent); }

  /* ---------- screen readiness gate ----------
     The body (.main) is revealed all at once only "once everything is ready".
     Ready = DOM parsing + web font loading + layout (table column width) calculation complete.
     Showing it earlier makes the columns recompute as the font swaps and the screen shakes.

     WARNING: the left sidebar is never covered - an earlier full-screen white overlay made the
     dark sidebar flash white. The loading indicator stays inside the body area only. */
  .main { visibility: hidden; }
  html.ready .main { visibility: visible; }

  #pageLoading {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    left: 240px;                 /* to the right of the sidebar (240px) = covers the body area only */
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    background: var(--bg, #f7f8fa);
    z-index: 500;
  }
  .app.collapsed ~ #pageLoading { left: 64px; }
  html.ready #pageLoading { display: none; }
  #pageLoading .spin {
    width: 38px; height: 38px;
    border: 4px solid rgba(0,0,0,0.10);
    border-top-color: var(--accent, #6366f1);
    border-radius: 50%;
    animation: pageSpin 0.7s linear infinite;
  }
  #pageLoading .txt { font-size: 13px; color: var(--ink-3, #94a3b8); }
  @keyframes pageSpin { to { transform: rotate(360deg); } }

  /* On narrow screens where the sidebar folds to the top, it covers everything. */
  @media (max-width: 860px) {
    #pageLoading { left: 0; }
  }
