/* detcham — control-plane UI. A dark instrument panel, committed single-theme:
   every color is painted explicitly so it holds on any host. */
:root {
    --bg:        #0e141b;   /* deep blue-slate, not pure github-black */
    --surface:   #151d27;
    --surface-2: #1b2532;
    --inset:     #10171f;
    --border:    #253140;
    --border-2:  #2f3d4e;
    --text:      #e8eef4;
    --muted:     #93a3b4;
    --faint:     #6b7b8c;

    --accent:    #37b6ad;   /* teal — the instrument accent */
    --accent-ink:#04120f;
    --critical:  #f0645a;
    --warning:   #e0a63c;
    --success:   #46b98a;
    --info:      #5aa9e6;

    --font-mono: ui-monospace, "JetBrains Mono", "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.22);
    --radius: 10px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    font-size: 14px;
}
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ── Auth gating ─────────────────────────────────────────────
   The app shell is hidden until authenticated; only #login-view shows.
   JS flips body.authed. */
#app-view { display: none; }
#login-view { display: flex; }
body.authed #app-view { display: flex; }
body.authed #login-view { display: none; }

/* ── App shell ───────────────────────────────────────────── */
#app-view { min-height: 100vh; }

.sidebar {
    width: 232px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand { display: flex; align-items: baseline; gap: 8px; padding: 0 6px 2px; }
.brand .logo {
    font-family: var(--font-mono);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.02em;
}
.brand .logo::before {
    content: "";
    display: inline-block;
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--accent);
    margin-right: 8px;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.brand .tag { font-size: .68rem; color: var(--faint); letter-spacing: .04em; text-transform: uppercase; }

.sidebar nav { margin-top: 22px; display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px;
    color: var(--muted);
    text-decoration: none;
    border-radius: 7px;
    font-size: .875rem;
    font-weight: 500;
    transition: background .12s, color .12s;
}
.sidebar nav a:hover { background: var(--surface-2); color: var(--text); }
.sidebar nav a.active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--text); }
.sidebar nav a.active::before,
.sidebar nav a::before {
    content: ""; width: 3px; height: 15px; border-radius: 2px; background: transparent;
    margin-left: -10px;
}
.sidebar nav a.active::before { background: var(--accent); }

.side-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.tenant-chip { display: flex; align-items: center; gap: 8px; padding: 4px 6px; }
.tenant-chip .avatar {
    width: 26px; height: 26px; border-radius: 6px; flex-shrink: 0;
    background: color-mix(in srgb, var(--accent) 22%, var(--surface-2));
    color: var(--accent); font-family: var(--font-mono); font-weight: 700; font-size: .8rem;
    display: flex; align-items: center; justify-content: center;
}
.tenant-chip .who { min-width: 0; }
.tenant-chip .who b { display: block; font-size: .82rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tenant-chip .who small { color: var(--faint); font-size: .68rem; }
.logout { margin-top: 8px; width: 100%; }

.main { flex: 1; min-width: 0; padding: 28px 32px 60px; overflow-x: hidden; }

/* ── Page header ─────────────────────────────────────────── */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-head h1 { font-size: 1.45rem; font-weight: 640; letter-spacing: -.02em; }
.page-head .sub { color: var(--muted); font-size: .85rem; margin-top: 3px; }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── Stat cards ──────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 26px; }
.stat-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
}
.stat-card .label { font-size: .68rem; color: var(--faint); text-transform: uppercase; letter-spacing: .07em; font-weight: 600; }
.stat-card .value { font-size: 2rem; font-weight: 700; font-family: var(--font-mono); margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat-card .value.critical { color: var(--critical); }
.stat-card .value.warning  { color: var(--warning); }
.stat-card .value.success  { color: var(--success); }
.stat-card .value.zero     { color: var(--faint); }
.stat-card .sub { font-size: .72rem; color: var(--muted); margin-top: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Panels / tables ─────────────────────────────────────── */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 22px; box-shadow: var(--shadow); }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.panel-head h2 { font-size: .92rem; font-weight: 620; }
.panel-body { padding: 18px; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
    text-align: left; padding: 10px 18px;
    font-size: .68rem; font-weight: 600; color: var(--faint);
    text-transform: uppercase; letter-spacing: .06em;
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 11px 18px; font-size: .87rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
td.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.link { color: var(--accent); text-decoration: none; font-weight: 500; }
.link:hover { text-decoration: underline; }
.mono { font-family: var(--font-mono); }
.dim { color: var(--muted); }

.empty { padding: 40px 18px; text-align: center; color: var(--muted); }
.empty .big { font-size: 1.05rem; color: var(--text); margin-bottom: 4px; font-weight: 560; }

/* ── Dependency graph ────────────────────────────────────── */
.graphlegend { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; margin: 0 0 14px; font-size: .82rem; color: var(--muted); }
.graphbar { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin: 0 0 12px; padding: 10px 14px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.graphbar label { display: inline-flex; align-items: center; gap: 7px; font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.graphbar input[type=range] { width: 96px; accent-color: var(--accent); }
.graphbar select { background: var(--surface-2); color: var(--text); border: 1px solid var(--border-2); border-radius: 6px; padding: 4px 8px; font-size: .82rem; max-width: 220px; }
.graphbar .gc-proj { margin-right: auto; }
.graphlegend .gdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.graphlegend .gdot-t { background: var(--surface) !important; box-shadow: inset 0 0 0 2px var(--info); }
.graphlegend .dim { margin-left: auto; opacity: .8; }
#graph-canvas { cursor: grab; background: var(--surface); }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 9px; border-radius: 999px;
    font-size: .68rem; font-weight: 650; text-transform: uppercase; letter-spacing: .03em;
    border: 1px solid transparent;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.critical { color: var(--critical); background: color-mix(in srgb, var(--critical) 14%, transparent); border-color: color-mix(in srgb, var(--critical) 30%, transparent); }
.badge.warning  { color: var(--warning);  background: color-mix(in srgb, var(--warning) 14%, transparent); border-color: color-mix(in srgb, var(--warning) 30%, transparent); }
.badge.info     { color: var(--info);     background: color-mix(in srgb, var(--info) 14%, transparent); border-color: color-mix(in srgb, var(--info) 30%, transparent); }
.badge.success  { color: var(--success);  background: color-mix(in srgb, var(--success) 14%, transparent); border-color: color-mix(in srgb, var(--success) 30%, transparent); }
.badge.neutral  { color: var(--muted);    background: var(--surface-2); border-color: var(--border-2); }

/* ── Buttons / inputs ────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 13px; border-radius: 7px;
    font-size: .8rem; font-weight: 560; cursor: pointer;
    border: 1px solid var(--border-2); background: var(--surface-2); color: var(--text);
    transition: background .12s, border-color .12s, opacity .12s;
    white-space: nowrap;
}
.btn:hover { background: var(--border); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 640; }
.btn.primary:hover { opacity: .9; background: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 45%, transparent); background: transparent; }
.btn.danger:hover { background: color-mix(in srgb, var(--critical) 12%, transparent); }
.btn.sm { padding: 4px 9px; font-size: .74rem; }
.btn:disabled { opacity: .5; cursor: default; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: .72rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; letter-spacing: .02em; }
input, select, textarea {
    width: 100%; padding: 9px 11px;
    background: var(--inset); border: 1px solid var(--border-2); border-radius: 7px;
    color: var(--text); font-size: .87rem; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
input::placeholder { color: var(--faint); }
.row { display: flex; gap: 8px; align-items: center; }
.row > input, .row > select { width: auto; }
.row > input.grow { flex: 1; }

/* ── Login ───────────────────────────────────────────────── */
#login-view { min-height: 100vh; align-items: center; justify-content: center; padding: 24px; background:
    radial-gradient(1200px 600px at 50% -10%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 70%), var(--bg); }
.login-card { width: 100%; max-width: 400px; }
.login-brand { text-align: center; margin-bottom: 26px; }
.login-brand .logo { font-family: var(--font-mono); font-size: 2rem; font-weight: 700; letter-spacing: -.03em; }
.login-brand .logo b { color: var(--accent); }
.login-brand p { color: var(--muted); margin-top: 6px; font-size: .9rem; }
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px; box-shadow: var(--shadow); }
.login-box h2 { font-size: .95rem; font-weight: 620; margin-bottom: 4px; }
.login-box .hint { color: var(--muted); font-size: .82rem; margin-bottom: 16px; }
.login-box .btn { width: 100%; justify-content: center; }
.disclosure { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 16px; }
.disclosure summary { cursor: pointer; color: var(--muted); font-size: .82rem; list-style: none; display: flex; align-items: center; gap: 6px; }
.disclosure summary::-webkit-details-marker { display: none; }
.disclosure summary::before { content: "▸"; color: var(--faint); transition: transform .15s; }
.disclosure[open] summary::before { transform: rotate(90deg); }
.disclosure .body { margin-top: 14px; }
.form-msg { font-size: .82rem; margin-top: 12px; min-height: 1em; }
.form-msg.err { color: var(--critical); }
.form-msg.ok  { color: var(--success); }

/* ── Fingerprint / run detail ────────────────────────────── */
.fp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; margin-top: 14px; }
.fp-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.fp-card h3 { font-size: .78rem; font-weight: 640; margin-bottom: 10px; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }
pre { font-family: var(--font-mono); font-size: .76rem; color: var(--muted); white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto; }
.logbox { background: var(--inset); border-radius: var(--radius); padding: 14px; max-height: 440px; overflow: auto; margin: 0; }
.form-msg .spinner { display: inline-block; width: 11px; height: 11px; vertical-align: -1px; margin-right: 4px; }

/* ── Matrix cell ─────────────────────────────────────────── */
.mcell { min-width: 46px; padding: 5px 0; border-radius: 6px; text-align: center; font-family: var(--font-mono); font-size: .74rem; font-weight: 660; font-variant-numeric: tabular-nums; }
.mcell.score-0 { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.mcell.score-1 { background: color-mix(in srgb, var(--warning) 16%, transparent); color: var(--warning); }
.mcell.score-2 { background: color-mix(in srgb, var(--critical) 16%, transparent); color: var(--critical); }
.mcell.score-3 { background: color-mix(in srgb, var(--critical) 32%, transparent); color: var(--critical); }

/* ── Loading ─────────────────────────────────────────────── */
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 30px 4px; font-size: .9rem; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

/* ── Toasts ──────────────────────────────────────────────── */
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 50; max-width: 380px; }
.toast {
    background: var(--surface-2); border: 1px solid var(--border-2); border-left-width: 3px;
    border-radius: 9px; padding: 11px 14px; box-shadow: var(--shadow); font-size: .85rem;
    animation: toast-in .18s ease-out;
}
.toast.ok  { border-left-color: var(--success); }
.toast.err { border-left-color: var(--critical); }
.toast.info{ border-left-color: var(--accent); }
.toast b { display: block; font-weight: 620; margin-bottom: 2px; }
.toast span { color: var(--muted); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 860px) {
    #app-view { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 6px; }
    .sidebar nav { flex-direction: row; flex-wrap: wrap; margin-top: 0; }
    .sidebar nav a::before { display: none; }
    .side-foot { margin: 0 0 0 auto; padding: 0; border: none; }
    .logout { display: none; }
    .main { padding: 20px; }
}

/* ── Inventory: search, chips, version-strip heatmap ─────────── */
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.search { max-width: 340px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
    padding: 4px 11px; border-radius: 999px; cursor: pointer;
    border: 1px solid var(--border-2); background: var(--surface-2);
    color: var(--muted); font-size: .75rem; font-family: var(--font-mono);
}
.chip:hover { color: var(--text); }
.chip.on { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--text); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.chip b { color: var(--faint); font-weight: 600; }
.chip.on b { color: var(--accent); }

.pkgcell { display: inline-flex; align-items: center; gap: 8px; }
.badge.eco-docker { color: var(--info); background: color-mix(in srgb, var(--info) 14%, transparent); border-color: color-mix(in srgb, var(--info) 30%, transparent); }

.vstrip { display: inline-flex; gap: 2px; align-items: center; flex-wrap: nowrap; }
.vsq { width: 13px; height: 13px; border-radius: 3px; background: var(--border-2); display: inline-block; flex: 0 0 auto; }
.vsq-clean { background: var(--success); }
.vsq-low   { background: color-mix(in srgb, var(--success) 65%, var(--warning)); }
.vsq-warn  { background: var(--warning); }
.vsq-crit  { background: var(--critical); }
.vsq-err   { background: color-mix(in srgb, var(--critical) 38%, var(--surface-2)); }  /* attempted / failed */
.vsq-none  { background: var(--border-2); }
.vsq.inuse { box-shadow: 0 0 0 2px var(--accent); }   /* ring = a version we actually use */
/* reachable-by-version-less: a SUBTLE amber underline, not a shouty full inset ring */
.vsq.cand { box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--warning) 50%, transparent); }
.vsq.cand.inuse { box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--warning) 50%, transparent), 0 0 0 2px var(--accent); }
/* known CVE on this version: a hard red outline (layers over the in-use ring) */
.vsq.vuln { outline: 2px solid var(--critical); outline-offset: -1px; }
.risk-banner { display: flex; flex-direction: column; gap: 3px; padding: 12px 16px; margin: 0 0 20px;
    border-radius: var(--radius); background: color-mix(in srgb, var(--critical) 12%, var(--surface));
    border: 1px solid color-mix(in srgb, var(--critical) 45%, var(--border)); }
.risk-banner b { color: var(--text); }
.risk-banner > span { font-size: .84rem; color: var(--muted); line-height: 1.5; }
/* a version GUESS — visually distinct from a real pin (never mono-numeric like a pin) */
.guess { font-size: .8rem; color: var(--warning); font-style: italic; margin-left: 6px; }
.guess-as { color: var(--muted); font-style: normal; opacity: .85; }
tr.former td { opacity: .6; }   /* historical usage — de-emphasised */

/* ── Version grid ──────────────────────────────────────────────────────────── */
.vg { display: flex; flex-direction: column; gap: 3px; overflow-x: auto; }
.vg-row { display: flex; align-items: center; gap: 10px; min-height: 17px; }
.vg-name { flex: 0 0 auto; font-size: .82rem; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.vg-use { margin-left: auto; font-size: .7rem; color: var(--muted); font-variant-numeric: tabular-nums;
    background: var(--surface-2); border-radius: 8px; padding: 0 6px; }
/* grid mode: uniform squares, right-aligned so the newest column lines up across rows */
.vg-track.grid { display: flex; gap: 2px; justify-content: flex-end; flex: 1 1 auto; flex-wrap: nowrap; }
/* timeline mode: squares absolutely placed by release date on a shared axis */
.vg-track.timeline { position: relative; flex: 1 1 auto; height: 15px; min-width: 320px; }
.vg-track.timeline .vsq.tl { position: absolute; top: 1px; transform: translateX(-50%); }
.vg-axis { display: flex; justify-content: space-between; font-size: .7rem; color: var(--muted);
    margin-bottom: 6px; padding-right: 4px; }
.seg { display: inline-flex; border: 1px solid var(--border-2); border-radius: 8px; overflow: hidden; }
.seg-btn { background: var(--surface); color: var(--muted); border: none; padding: 5px 12px;
    font-size: .8rem; cursor: pointer; font-family: inherit; }
.seg-btn.on { background: color-mix(in srgb, var(--accent) 20%, var(--surface-2)); color: var(--text); }
.graphlegend .vsq { width: 12px; height: 12px; }
.vmore { font-size: .68rem; color: var(--faint); font-family: var(--font-mono); margin-right: 3px; }

.vlegend { display: flex; gap: 16px; margin: 0 0 16px; font-size: .72rem; color: var(--muted); flex-wrap: wrap; }
.vlegend span { display: inline-flex; align-items: center; gap: 6px; }
.vlegend .vsq { width: 12px; height: 12px; }

.pager { display: flex; gap: 14px; align-items: center; justify-content: center; font-size: .82rem; margin-top: 4px; }
.tl-ends { display: flex; justify-content: space-between; margin-top: 8px; font-size: .7rem; color: var(--faint); font-family: var(--font-mono); }
/* ── Sortable columns ────────────────────────────────────────── */
th:not(.nosort) { cursor: pointer; user-select: none; }
th:not(.nosort):hover { color: var(--muted); }
th.sorted-asc::after  { content: " ▲"; color: var(--accent); font-size: .8em; }
th.sorted-desc::after { content: " ▼"; color: var(--accent); font-size: .8em; }

/* ── Accordion (collapsible manifest groups) ─────────────────── */
.accordion .panel-head { cursor: pointer; user-select: none; }
.accordion .chev { color: var(--faint); display: inline-block; transition: transform .15s; flex: 0 0 auto; }
.accordion .chev::before { content: "▾"; }
.accordion.collapsed .chev { transform: rotate(-90deg); }
.accordion.collapsed .table-scroll { display: none; }
@media (prefers-reduced-motion: reduce) { .accordion .chev { transition: none; } }
.chip.risk { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 35%, transparent); }
.chip.risk.on { background: color-mix(in srgb, var(--critical) 16%, transparent); color: var(--critical); border-color: color-mix(in srgb, var(--critical) 50%, transparent); }
