/* Tunnel Command — enterprise security control plane design system.
   One coherent dark theme. States never rely on color alone (dot + label). */
:root {
  --bg: #0b0e14; --bg-raised: #11151f; --bg-panel: #141926; --bg-hover: #1a2030;
  --ink: #e6eaf2; --ink-dim: #9aa4b8; --ink-faint: #6b7488; --ink-ghost: #4a5266;
  --rule: #1e2534; --rule-strong: #2a3346;
  --accent: #4c8dff; --accent-dim: #2b4a80; --accent-ghost: #16233d;
  --ok: #3fb968; --ok-bg: #10241a; --warn: #d99a2b; --warn-bg: #251c0e;
  --danger: #e5484d; --danger-bg: #2a1214; --info: #56b6c2; --neutral: #8891a4;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --sb-w: 244px; --radius: 8px; --radius-sm: 5px;
  --shadow: 0 8px 30px rgba(0,0,0,.45); --shadow-lg: 0 24px 60px rgba(0,0,0,.6);
}
* { box-sizing: border-box; }
svg.ico { width: 16px; height: 16px; flex: 0 0 16px; }
html, body { margin: 0; padding: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--sans);
  font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
.mono { font-family: var(--mono); font-size: .8125rem; letter-spacing: -.01em; }
.trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── App shell ── */
.shell { display: grid; grid-template-columns: var(--sb-w) 1fr; min-height: 100vh; }
.sidebar { background: var(--bg-raised); border-right: 1px solid var(--rule);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 20px 20px 16px; border-bottom: 1px solid var(--rule); }
.brand .logo { display: flex; align-items: center; gap: 10px; }
.brand .mark { width: 26px; height: 26px; border-radius: 6px; background:
  linear-gradient(135deg, var(--accent), #7db0ff); display: grid; place-items: center;
  color: #071019; font-weight: 800; font-size: 15px; }
.brand h1 { font-size: 14px; margin: 0; font-weight: 650; letter-spacing: .02em; }
.brand .sub { font-size: 11px; color: var(--ink-faint); letter-spacing: .14em; text-transform: uppercase; margin-top: 2px; }
.nav { padding: 10px 10px; overflow-y: auto; flex: 1; }
.nav-group { margin: 6px 0 14px; }
.nav-group .label { font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink-ghost); padding: 8px 12px 6px; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 8px 12px; border-radius: var(--radius-sm);
  color: var(--ink-dim); cursor: pointer; font-weight: 500; font-size: 13.5px; position: relative; }
.nav-item:hover { background: var(--bg-hover); color: var(--ink); }
.nav-item.active { background: var(--accent-ghost); color: var(--ink); }
.nav-item.active::before { content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px;
  border-radius: 2px; background: var(--accent); }
.nav-item .ico { width: 17px; height: 17px; flex: 0 0 17px; opacity: .85; }
.nav-item.disabled { opacity: .38; cursor: not-allowed; }
.nav-item .tag { margin-left: auto; font-size: 9.5px; letter-spacing: .1em; color: var(--ink-ghost);
  border: 1px solid var(--rule-strong); border-radius: 4px; padding: 1px 5px; text-transform: uppercase; }
.sidebar-foot { border-top: 1px solid var(--rule); padding: 12px 14px; font-size: 11px; color: var(--ink-faint); }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 56px; border-bottom: 1px solid var(--rule); display: flex; align-items: center;
  gap: 16px; padding: 0 26px; background: var(--bg-raised); position: sticky; top: 0; z-index: 20; }
.topbar .org { display: flex; align-items: center; gap: 9px; font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .admin { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--ink-dim); }
.topbar .admin .who { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.topbar .admin .who b { color: var(--ink); font-weight: 600; font-size: 13px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-ghost);
  color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 12px; border: 1px solid var(--accent-dim); }
.content { padding: 26px; max-width: 1280px; width: 100%; }

/* ── Page header ── */
.page-head { display: flex; align-items: flex-start; gap: 20px; margin-bottom: 22px; }
.page-head .eyebrow { font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 6px; }
.page-head h2 { font-size: 22px; margin: 0; font-weight: 660; letter-spacing: -.01em; }
.page-head p { color: var(--ink-dim); margin: 7px 0 0; max-width: 62ch; font-size: 13.5px; }
.page-head .actions { margin-left: auto; display: flex; gap: 10px; align-items: center; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--rule-strong); background: var(--bg-panel);
  color: var(--ink); font: inherit; font-size: 13px; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--bg-hover); border-color: #37425a; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06101f; font-weight: 650; }
.btn.primary:hover { background: #5f9bff; }
.btn.danger { background: var(--danger-bg); border-color: #5a2327; color: #ff9a9d; }
.btn.danger:hover { background: #3a181b; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-dim); }
.btn.ghost:hover { background: var(--bg-hover); color: var(--ink); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Metrics ── */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 14px; margin-bottom: 22px; }
.metric { background: var(--bg-raised); border: 1px solid var(--rule); border-radius: var(--radius); padding: 16px 18px; }
.metric .k { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-faint); }
.metric .v { font-size: 28px; font-weight: 680; margin-top: 8px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.metric .v small { font-size: 13px; color: var(--ink-faint); font-weight: 500; margin-left: 4px; }
.metric .foot { margin-top: 8px; font-size: 12px; color: var(--ink-dim); display: flex; align-items: center; gap: 6px; }
.metric.alert { border-color: #4a2327; } .metric.alert .v { color: #ff8f92; }
.metric.warn { border-color: #4a3a18; }

/* ── Cards / sections ── */
.section { margin-bottom: 26px; }
.section > .head { display: flex; align-items: center; margin-bottom: 12px; gap: 12px; }
.section > .head h3 { font-size: 14px; margin: 0; font-weight: 620; letter-spacing: .01em; }
.section > .head .count { color: var(--ink-faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.card { background: var(--bg-raised); border: 1px solid var(--rule); border-radius: var(--radius); }
.card.pad { padding: 18px 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 1000px){ .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ── Status badge (never color-only: dot + text) ── */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 7px;
  border-radius: 100px; font-size: 11.5px; font-weight: 600; letter-spacing: .02em;
  border: 1px solid var(--rule-strong); color: var(--ink-dim); background: var(--bg-panel); white-space: nowrap; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--neutral); flex: 0 0 6px; }
.badge.ok { color: #7fe0a0; border-color: #1f4630; background: var(--ok-bg); } .badge.ok .dot { background: var(--ok); }
.badge.warn { color: #f0c674; border-color: #4a3a18; background: var(--warn-bg); } .badge.warn .dot { background: var(--warn); }
.badge.danger { color: #ff9a9d; border-color: #5a2327; background: var(--danger-bg); } .badge.danger .dot { background: var(--danger); }
.badge.info { color: #86d3dd; border-color: #1d3d42; background: #0e2124; } .badge.info .dot { background: var(--info); }
.badge.accent { color: #9dc0ff; border-color: var(--accent-dim); background: var(--accent-ghost); } .badge.accent .dot { background: var(--accent); }
.badge.pulse .dot { box-shadow: 0 0 0 0 currentColor; animation: pulse 2s infinite; }
@keyframes pulse { 0%{ box-shadow: 0 0 0 0 rgba(63,185,104,.5);} 70%{ box-shadow: 0 0 0 5px rgba(63,185,104,0);} 100%{ box-shadow: 0 0 0 0 rgba(63,185,104,0);} }

/* ── Data table ── */
.table-wrap { border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; background: var(--bg-raised); }
.table-scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-weight: 600; font-size: 11px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--ink-faint); padding: 11px 16px; border-bottom: 1px solid var(--rule); background: var(--bg-panel); white-space: nowrap; }
table.data td { padding: 12px 16px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr { cursor: default; }
table.data tbody tr.click { cursor: pointer; }
table.data tbody tr.click:hover { background: var(--bg-hover); }
table.data td.num { font-variant-numeric: tabular-nums; text-align: right; }
.cell-id { font-family: var(--mono); font-size: 11.5px; color: var(--ink-faint); }
.cell-primary { font-weight: 600; }
.cell-sub { color: var(--ink-faint); font-size: 12px; }

/* ── Filter bar ── */
.filter-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.chip { padding: 5px 12px; border-radius: 100px; border: 1px solid var(--rule-strong); background: var(--bg-panel);
  color: var(--ink-dim); font-size: 12.5px; cursor: pointer; font-weight: 500; }
.chip:hover { color: var(--ink); border-color: #37425a; }
.chip.on { background: var(--accent-ghost); border-color: var(--accent-dim); color: #9dc0ff; }
.input, select.input { height: 34px; padding: 0 12px; border-radius: var(--radius-sm); border: 1px solid var(--rule-strong);
  background: var(--bg); color: var(--ink); font: inherit; font-size: 13px; min-width: 180px; }
.input:focus, select.input:focus { outline: none; border-color: var(--accent-dim); box-shadow: 0 0 0 3px var(--accent-ghost); }
label.fld { display: block; margin-bottom: 14px; }
label.fld .lab { font-size: 12px; color: var(--ink-dim); margin-bottom: 6px; font-weight: 550; }
label.fld .input, label.fld select.input { width: 100%; }

/* ── Relationship direction visual ── */
.rel-view { display: flex; align-items: center; gap: 16px; padding: 18px 20px; }
.rel-node { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 96px; }
.rel-node .av { width: 42px; height: 42px; border-radius: 50%; background: var(--bg-panel); border: 1px solid var(--rule-strong);
  display: grid; place-items: center; font-weight: 700; color: var(--ink); }
.rel-node .nm { font-weight: 600; font-size: 13px; } .rel-node .rl { font-size: 11px; color: var(--ink-faint); }
.rel-arrow { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--accent); }
.rel-arrow svg { width: 100%; height: 22px; }
.rel-arrow .dir-label { font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); }
.cap-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px; border-top: 1px solid var(--rule); }
.cap-row .name { font-weight: 550; }

/* ── Detail panel (side sheet) ── */
.sheet-overlay { position: fixed; inset: 0; background: rgba(4,6,10,.6); backdrop-filter: blur(2px); z-index: 60;
  opacity: 0; animation: fade .16s forwards; }
.sheet { position: fixed; top: 0; right: 0; height: 100vh; width: 520px; max-width: 92vw; background: var(--bg-raised);
  border-left: 1px solid var(--rule-strong); box-shadow: var(--shadow-lg); z-index: 61; display: flex; flex-direction: column;
  transform: translateX(20px); opacity: 0; animation: slidein .2s forwards; }
@keyframes slidein { to { transform: translateX(0); opacity: 1; } }
@keyframes fade { to { opacity: 1; } }
.sheet .sh-head { padding: 20px 22px; border-bottom: 1px solid var(--rule); display: flex; align-items: flex-start; gap: 12px; }
.sheet .sh-head h3 { margin: 0; font-size: 17px; font-weight: 640; }
.sheet .sh-body { padding: 8px 22px 24px; overflow-y: auto; flex: 1; }
.sheet .tabs { display: flex; gap: 4px; padding: 0 22px; border-bottom: 1px solid var(--rule); }
.sheet .tab { padding: 11px 12px; font-size: 12.5px; color: var(--ink-dim); cursor: pointer; border-bottom: 2px solid transparent; font-weight: 550; }
.sheet .tab.on { color: var(--ink); border-bottom-color: var(--accent); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 4px 12px; padding: 14px 0; border-bottom: 1px solid var(--rule); }
.kv .k { color: var(--ink-faint); font-size: 12px; letter-spacing: .04em; }
.kv .v { font-size: 13px; word-break: break-word; }
.adv { margin-top: 16px; }
.adv summary { cursor: pointer; color: var(--ink-faint); font-size: 12px; padding: 8px 0; }
.adv .mono { display: block; background: var(--bg); border: 1px solid var(--rule); border-radius: 6px; padding: 12px;
  color: var(--ink-dim); font-size: 11px; word-break: break-all; margin-top: 8px; }

/* ── Dialog ── */
.dlg-overlay { position: fixed; inset: 0; background: rgba(4,6,10,.66); backdrop-filter: blur(3px); z-index: 80;
  display: grid; place-items: center; opacity: 0; animation: fade .14s forwards; padding: 24px; }
.dlg { background: var(--bg-raised); border: 1px solid var(--rule-strong); border-radius: 12px; box-shadow: var(--shadow-lg);
  width: 520px; max-width: 100%; transform: translateY(8px); opacity: 0; animation: slideup .18s forwards; max-height: 90vh; overflow-y: auto; }
@keyframes slideup { to { transform: translateY(0); opacity: 1; } }
.dlg .dh { padding: 20px 24px 4px; } .dlg .dh h3 { margin: 0; font-size: 17px; font-weight: 640; }
.dlg .dh .eyebrow { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 8px; }
.dlg .db { padding: 12px 24px 4px; }
.dlg .df { padding: 18px 24px 22px; display: flex; gap: 10px; justify-content: flex-end; border-top: 1px solid var(--rule); margin-top: 14px; }
.consequence { background: var(--danger-bg); border: 1px solid #4a2327; border-radius: 8px; padding: 14px 16px; margin: 6px 0 4px; }
.consequence .t { font-weight: 620; color: #ff9a9d; margin-bottom: 6px; font-size: 13px; }
.consequence p { margin: 4px 0; font-size: 13px; color: #f0c9ca; }
.consequence .safe { color: #86d3dd; font-size: 12.5px; margin-top: 8px; }
.stepup-note { display: flex; align-items: center; gap: 9px; font-size: 12.5px; color: var(--ink-dim);
  background: var(--accent-ghost); border: 1px solid var(--accent-dim); border-radius: 7px; padding: 10px 13px; margin-top: 6px; }

/* ── Empty / loading / error ── */
.empty, .errstate { text-align: center; padding: 54px 20px; color: var(--ink-faint); }
.empty .ico, .errstate .ico { font-size: 26px; margin-bottom: 12px; opacity: .7; }
.empty h4 { color: var(--ink-dim); margin: 0 0 6px; font-weight: 600; font-size: 15px; }
.empty p { margin: 0; font-size: 13px; max-width: 42ch; margin-inline: auto; }
.skeleton { background: linear-gradient(90deg, var(--bg-panel) 25%, var(--bg-hover) 50%, var(--bg-panel) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 6px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.sk-row { height: 44px; margin: 8px 0; }

/* ── Login ── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #12203a 0%, var(--bg) 55%); }
.login { width: 420px; max-width: 100%; background: var(--bg-raised); border: 1px solid var(--rule-strong);
  border-radius: 14px; padding: 34px; box-shadow: var(--shadow-lg); }
.login .mark { width: 44px; height: 44px; border-radius: 10px; background: linear-gradient(135deg, var(--accent), #7db0ff);
  display: grid; place-items: center; color: #071019; font-weight: 800; font-size: 22px; margin-bottom: 20px; }
.login h1 { font-size: 20px; margin: 0 0 6px; } .login p { color: var(--ink-dim); margin: 0 0 24px; font-size: 13.5px; }
.login .btn { width: 100%; justify-content: center; height: 42px; font-size: 14px; }
.login .hint { margin-top: 16px; font-size: 12px; color: var(--ink-faint); text-align: center; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100;
  background: var(--bg-panel); border: 1px solid var(--rule-strong); border-radius: 9px; padding: 12px 18px;
  box-shadow: var(--shadow); font-size: 13px; display: flex; align-items: center; gap: 10px; }
.toast.ok { border-color: #1f4630; } .toast.err { border-color: #5a2327; }
#toast-root { position: fixed; bottom: 0; left: 0; right: 0; }

@media (max-width: 860px){
  .shell { grid-template-columns: 1fr; } .sidebar { display: none; }
  .content { padding: 18px; } .metric-grid { grid-template-columns: 1fr 1fr; }
}
