:root {
    --bg: #0b0f17;
    --panel: #121826;
    --panel-2: #0e1422;
    --line: #1f2937;
    --line-soft: #1a2233;
    --text: #e6edf6;
    --muted: #8696ad;
    --accent: #4dd0c4;      /* signal teal */
    --accent-dim: #1f3a3a;
    --warn: #f4a259;
    --crit: #ef5d68;
    --ok: #5fd38d;
    --focus: #6ea8ff;
    --mono: 'SFMono-Regular', ui-monospace, 'JetBrains Mono', Menlo, Consolas, monospace;
    --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; height: 100%; }
  body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
  }
  a { color: var(--accent); }
  button {
    font-family: var(--sans);
    cursor: pointer;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 13px;
    transition: border-color .15s, background .15s;
  }
  button:hover { border-color: var(--accent); }
  button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
  button.primary { background: var(--accent); color: #04201d; border-color: var(--accent); font-weight: 600; }
  button.primary:hover { filter: brightness(1.08); }
  button.ghost { background: transparent; }
  button.danger { border-color: #3a1d22; color: var(--crit); }
  button.danger:hover { border-color: var(--crit); }
  button:disabled { opacity: .5; cursor: not-allowed; }
  input, select {
    font-family: var(--sans);
    background: var(--panel-2);
    border: 1px solid var(--line);
    color: var(--text);
    padding: 9px 11px;
    border-radius: 6px;
    font-size: 13px;
    width: 100%;
  }
  input:focus, select:focus { outline: none; border-color: var(--focus); }
  label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; letter-spacing: .02em; }
  .field { margin-bottom: 14px; }
  .mono { font-family: var(--mono); }
  .hidden { display: none !important; }

  /* ---------- Login ---------- */
  .auth-wrap {
    min-height: 100%;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
      radial-gradient(1200px 600px at 80% -10%, #11202b 0%, transparent 55%),
      radial-gradient(900px 500px at -10% 110%, #161226 0%, transparent 50%),
      var(--bg);
  }
  .auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 30px 28px;
    box-shadow: 0 24px 60px rgba(0,0,0,.45);
  }
  .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
  .brand-mark {
    width: 28px; height: 28px; border-radius: 7px;
    background: linear-gradient(135deg, var(--accent), #2a8f87);
    display: grid; place-items: center; color: #04201d; font-weight: 800; font-size: 15px;
  }
  .brand-name { font-weight: 700; letter-spacing: .04em; }
  .auth-sub { color: var(--muted); font-size: 12.5px; margin: 6px 0 22px; }
  .err {
    background: #2a1418; border: 1px solid #4a2027; color: #f3a3aa;
    padding: 9px 12px; border-radius: 6px; font-size: 12.5px; margin-bottom: 14px;
  }

  /* ---------- App shell ---------- */
  .shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
  .side {
    background: var(--panel-2);
    border-right: 1px solid var(--line);
    padding: 18px 14px;
    display: flex; flex-direction: column;
  }
  .nav { margin-top: 22px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
  .nav button {
    text-align: left; border: none; background: transparent; color: var(--muted);
    padding: 9px 11px; border-radius: 7px; width: 100%;
  }
  .nav button:hover { background: var(--panel); color: var(--text); }
  .nav button.active { background: var(--accent-dim); color: var(--accent); }
  .side-foot { border-top: 1px solid var(--line); padding-top: 14px; font-size: 12px; color: var(--muted); }
  .side-foot .who { color: var(--text); font-weight: 600; }
  .role-tag {
    display: inline-block; font-size: 10px; text-transform: uppercase; letter-spacing: .08em;
    background: var(--accent-dim); color: var(--accent); padding: 2px 7px; border-radius: 99px; margin-top: 6px;
  }

  .main { padding: 26px 30px; overflow: auto; }
  .page-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
  .page-head h1 { font-size: 19px; margin: 0; letter-spacing: -.01em; }
  .page-head .desc { color: var(--muted); font-size: 12.5px; }
  .toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

  /* ---------- Cards / grid ---------- */
  .cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
  .card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; }
  .card .k { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
  .card .v { font-family: var(--mono); font-size: 26px; margin-top: 6px; font-weight: 600; }
  .card .v.small { font-size: 15px; }

  .panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
  .panel-head { padding: 13px 16px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 13px; display:flex; justify-content:space-between; align-items:center;}

  /* ---------- Tables ---------- */
  table { width: 100%; border-collapse: collapse; font-size: 13px; }
  thead th {
    text-align: left; font-weight: 600; color: var(--muted); font-size: 11px;
    text-transform: uppercase; letter-spacing: .06em; padding: 11px 14px;
    border-bottom: 1px solid var(--line); background: var(--panel-2);
    position: sticky; top: 0;
  }
  tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
  tbody tr:hover { background: #0f1626; }
  tbody tr { cursor: default; }
  .row-click { cursor: pointer; }
  td.mono, th.mono { font-family: var(--mono); font-size: 12px; }
  .truncate { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .pill { font-size: 11px; padding: 2px 9px; border-radius: 99px; font-weight: 600; display:inline-block; }
  .pill.crit { background: #2a1418; color: var(--crit); }
  .pill.warn { background: #2a2113; color: var(--warn); }
  .pill.ok   { background: #122a1c; color: var(--ok); }
  .pill.info { background: #14202e; color: #6ea8ff; }
  .pill.muted{ background: #1a2130; color: var(--muted); }

  .filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px,1fr)); gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
  .pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding: 12px 16px; color: var(--muted); font-size: 12px; }

  /* ---------- Drawer ---------- */
  .drawer-bg { position: fixed; inset: 0; background: rgba(2,6,14,.6); display: grid; justify-items: end; }
  .drawer { width: min(560px, 92vw); height: 100%; background: var(--panel); border-left: 1px solid var(--line); padding: 20px 22px; overflow: auto; }
  .drawer h2 { font-size: 15px; margin: 0 0 4px; }
  pre.json { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 14px; overflow: auto; font-family: var(--mono); font-size: 12px; color: #cdd9ea; }
  .kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 14px 0; font-size: 13px; }
  .kv .key { color: var(--muted); }

  /* ---------- Modal ---------- */
  .modal-bg { position: fixed; inset: 0; background: rgba(2,6,14,.6); display: grid; place-items: center; padding: 20px; }
  .modal { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; }
  .modal h2 { margin: 0 0 16px; font-size: 16px; }
  .modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
  .qr { display: block; margin: 14px auto; width: 180px; height: 180px; background: #fff; border-radius: 8px; padding: 8px; }
  .codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; font-family: var(--mono); font-size: 13px; margin: 14px 0; }
  .codes div { background: var(--panel-2); border: 1px solid var(--line); padding: 6px 10px; border-radius: 6px; }
  .note { color: var(--muted); font-size: 12px; }
  .empty { padding: 40px; text-align: center; color: var(--muted); }
  .spin { display:inline-block; width:14px; height:14px; border:2px solid var(--line); border-top-color: var(--accent); border-radius:50%; animation: spin .7s linear infinite; vertical-align:-2px;}
  @keyframes spin { to { transform: rotate(360deg); } }
  @media (prefers-reduced-motion: reduce) { .spin { animation: none; } }
  @media (max-width: 720px) { .shell { grid-template-columns: 1fr; } .side { flex-direction: row; align-items:center; } .nav { flex-direction: row; margin: 0 0 0 12px; } .side-foot { display:none; } }
