/*
 * Haveloc Metrics Console — Apple-style dark glass system (deliberate single look).
 *
 * Principles: flat translucent surfaces with real backdrop blur, hairline separators,
 * SF-style typography, pill segmented controls, no gradients on content — depth comes from
 * blur, hairlines and elevation, never from color ramps.
 */

:root {
    color-scheme: dark;

    /* ground */
    --surface-0: #0a0a0d;
    --surface-1: #16181d;                        /* chart surface (canvas needs a solid) */
    --surface-2: #232630;                        /* raised solid: inputs, thumbs */
    --glass: rgba(255, 255, 255, 0.045);          /* panel fill over the ground */
    --glass-strong: rgba(30, 32, 40, 0.72);       /* chrome: sidebar, topbar, tooltip */
    --hairline: rgba(255, 255, 255, 0.10);
    --separator: rgba(255, 255, 255, 0.065);
    --border: rgba(255, 255, 255, 0.10);
    --grid: rgba(255, 255, 255, 0.055);

    /* ink */
    --text-primary: #f5f5f7;
    --text-secondary: #b9bac2;
    --text-muted: #7d7f89;

    /* system colors (Apple dark palette) */
    --accent: #1ba202;                            /* Haveloc brand green (haveloc-frontend) */
    --good: #30d158;
    --warning: #ff9f0a;
    --critical: #ff453a;

    /* fixed categorical assignment — color follows the service, never its rank */
    --s-app-engine: #3987e5;
    --s-communication: #d95926;
    --s-crm: #199e70;
    --s-search: #c98500;
    --s-survey: #d55181;

    --fill-1: rgba(255, 255, 255, 0.055);         /* subtle control fill */
    --fill-2: rgba(255, 255, 255, 0.10);          /* hover fill */
    --chrome: rgba(26, 28, 34, 0.92);             /* sticky table header */
    --well: rgba(0, 0, 0, 0.30);                  /* recessed: logs, call graphs */
    --selection: rgba(27, 162, 2, 0.35);
    --shadow-1: 0 24px 70px rgba(0, 0, 0, 0.55);
    --is-light: 0;
    --scroll: rgba(255, 255, 255, 0.14);
    --scroll-hover: rgba(255, 255, 255, 0.24);
    --ambient: none;

    --r-panel: 16px;
    --r-control: 9px;
    --blur: saturate(180%) blur(20px);
    --font-mono: "SF Mono", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win, even over display:flex rules. */
[hidden] { display: none !important; }

html { height: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--surface-0);
    color: var(--text-primary);
    font: 14px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* Faint ambient washes the glass blurs over — depth, not decoration. */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: var(--ambient);
    z-index: 0;
}

#shell, .login-view { position: relative; z-index: 1; }

.mono { font-family: var(--font-mono); }
.muted { color: var(--text-muted); }
.error { color: var(--critical); font-size: 13px; }

::selection { background: var(--selection); }

/* Thin, quiet scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--scroll); border-radius: 5px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--scroll-hover); border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------------------------------------------------------- app frame */

#shell { display: flex; min-height: 100vh; }

.sidenav {
    width: 216px;
    flex: none;
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 18px 12px 16px;
    background: var(--glass-strong);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    border-right: 1px solid var(--separator);
}

.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 18px; }

.brand-mark {
    width: 34px;
    height: 34px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 9px;
    background: var(--accent);
    color: #fff;
    font-size: 19px;
    font-weight: 700;
}

.brand-name { font-size: 13px; font-weight: 700; line-height: 1.15; letter-spacing: -0.01em; }
.brand-name em { font-style: normal; color: var(--text-muted); font-weight: 600; }

.tabs { display: flex; flex-direction: column; gap: 2px; }

.tabs button {
    display: flex;
    align-items: center;
    gap: 11px;
    width: 100%;
    background: none;
    border: 0;
    color: var(--text-secondary);
    padding: 9px 12px;
    font: inherit;
    font-size: 13.5px;
    font-weight: 500;
    border-radius: 10px;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}

.tabs button svg {
    width: 17px;
    height: 17px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: .85;
}

.tabs button:hover { color: var(--text-primary); background: var(--fill-2); }

.tabs button.active {
    color: #fff;
    background: var(--accent);
    font-weight: 600;
}
.tabs button.active svg { opacity: 1; }

.side-spacer { flex: 1; }

.side-user {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 8px 0;
    border-top: 1px solid var(--separator);
}

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---------------------------------------------------------------- topbar */

header.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 24px;
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--glass-strong);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    border-bottom: 1px solid var(--separator);
}

.topbar h2 {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.spacer, .grow { flex: 1; }

.badge {
    font-size: 11px;
    font-weight: 600;
    padding: 4px 11px;
    border-radius: 20px;
    border: 1px solid var(--hairline);
    color: var(--text-secondary);
    background: var(--fill-1);
}

.badge.on { color: var(--good); border-color: rgba(48, 209, 88, 0.45); background: rgba(48, 209, 88, 0.10); }
.badge.off { color: var(--warning); border-color: rgba(255, 159, 10, 0.45); background: rgba(255, 159, 10, 0.10); }
.badge.alert { color: var(--critical); border-color: rgba(255, 69, 58, 0.5); background: rgba(255, 69, 58, 0.12); font-weight: 700; }

.icon-btn {
    background: var(--fill-1);
    border: 1px solid var(--hairline);
    color: var(--text-secondary);
    border-radius: var(--r-control);
    padding: 6px 12px;
    font: inherit;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}

.icon-btn:hover { color: var(--text-primary); background: var(--fill-2); }
.icon-btn.active { color: var(--good); border-color: rgba(48, 209, 88, 0.45); background: rgba(48, 209, 88, 0.10); }

main { padding: 22px 24px 48px; max-width: 1640px; width: 100%; margin: 0 auto; }

.view[hidden] { display: none; }

.hint { font-size: 12px; color: var(--text-muted); }

/* ---------------------------------------------------------------- login */

.login-view {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: 360px;
    background: var(--glass-strong);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    border: 1px solid var(--hairline);
    border-radius: 20px;
    padding: 32px 30px;
    box-shadow: var(--shadow-1);
}

.login-card h1 { margin: 0 0 4px; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.login-sub { margin: 0 0 20px; color: var(--text-secondary); font-size: 13px; }
.login-card label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin: 14px 0 5px; }
.login-note { font-size: 12px; margin-top: 14px; }

.login-card input, .toolbar select, .toolbar input {
    width: 100%;
    background: var(--fill-1);
    color: var(--text-primary);
    border: 1px solid var(--hairline);
    border-radius: var(--r-control);
    padding: 9px 12px;
    font: inherit;
    font-size: 13.5px;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.login-card input:focus, .toolbar select:focus, .toolbar input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3.5px rgba(10, 132, 255, 0.25);
}

.login-card button {
    width: 100%;
    margin-top: 22px;
    background: var(--accent);
    color: #fff;
    border: 0;
    border-radius: 10px;
    padding: 10px;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: filter .15s ease;
}

.login-card button:hover { filter: brightness(1.12); }

.qr-box { background: #fff; border-radius: 12px; padding: 10px; margin: 10px auto; width: 196px; }
.qr-box svg { display: block; width: 176px; height: 176px; }

/* ---------------------------------------------------------------- toolbar & segmented controls */

.toolbar { display: flex; gap: 10px; align-items: center; margin: 0 0 16px; flex-wrap: wrap; }
.toolbar select, .toolbar input { width: auto; font-size: 13px; padding: 7px 11px; }
.toolbar .hint { font-size: 12px; }

/* macOS-style segmented control: pill track, floating thumb */
.seg {
    display: inline-flex;
    background: var(--fill-1);
    border: 1px solid var(--separator);
    border-radius: 10px;
    padding: 2.5px;
    gap: 2px;
}

.seg button {
    background: none;
    border: 0;
    color: var(--text-secondary);
    padding: 5.5px 13px;
    font: inherit;
    font-size: 12.5px;
    font-weight: 500;
    border-radius: 7.5px;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}

.seg button:hover { color: var(--text-primary); }

.seg button.active {
    background: var(--surface-2);
    color: var(--text-primary);
    font-weight: 600;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4), inset 0 0 0 1px var(--hairline);
}

/* ---------------------------------------------------------------- panels & cards */

.panel, .card, .tile {
    background: var(--glass);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    border: 1px solid var(--separator);
    border-radius: var(--r-panel);
}

.panel { padding: 18px 20px; margin-bottom: 16px; }

.panel h3 { margin: 0 0 4px; font-size: 14px; font-weight: 650; letter-spacing: -0.012em; }
.panel .sub { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }

.panel canvas.chart { width: 100%; height: 220px; display: block; }
.panel canvas.chart.tall { height: 264px; }

#flowmap { width: 100%; height: 430px; display: block; }

.legend { display: flex; gap: 15px; flex-wrap: wrap; margin-top: 10px; font-size: 12px; color: var(--text-secondary); }
.legend .item { display: inline-flex; align-items: center; gap: 6px; }
.legend .chip { width: 9px; height: 9px; border-radius: 3px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 .panel { margin-bottom: 16px; }
@media (max-width: 1060px) { .grid2 { grid-template-columns: 1fr; } }

.drill { border-left: 3px solid var(--accent); }
.drill .close { float: right; }

.empty { padding: 28px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ---------------------------------------------------------------- overview cards */

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 16px; margin-bottom: 16px; }

.card { padding: 16px 18px; transition: border-color .18s ease, transform .18s ease; }
.card:hover { border-color: var(--hairline); transform: translateY(-1.5px); cursor: pointer; }

.card .card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--critical); flex: none; }
.dot.up { background: var(--good); box-shadow: 0 0 7px rgba(48, 209, 88, 0.6); }

.card .svc-name, .alert-row .svc-name { font-weight: 650; font-size: 13.5px; letter-spacing: -0.01em; }
.svc-name .chip { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 7px; }
.card .uptime { margin-left: auto; font-size: 11px; color: var(--text-muted); }

.stat-row { display: flex; gap: 14px; margin: 8px 0; }
.stat { flex: 1; }
.stat .v { font-size: 18px; font-weight: 700; font-family: var(--font-mono); letter-spacing: -0.02em; }
.stat .v.warn { color: var(--warning); }
.stat .v.crit { color: var(--critical); }
.stat .v.good { color: var(--good); }
.stat .k { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-top: 1px; }

.card canvas.spark { width: 100%; height: 30px; display: block; margin-top: 6px; }

.meter { height: 5px; border-radius: 3px; background: var(--grid); overflow: hidden; margin-top: 3px; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.meter i.warn { background: var(--warning); }
.meter i.crit { background: var(--critical); }

.gauges { display: flex; gap: 16px; align-items: center; margin-top: 12px; }
.gauges .g { text-align: center; font-size: 10px; color: var(--text-muted); }
.gauges canvas { width: 54px; height: 54px; display: block; margin: 0 auto 3px; }

/* ---------------------------------------------------------------- service dashboard */

.svc-head { display: flex; align-items: center; gap: 12px; margin: 0 0 16px; flex-wrap: wrap; }
.svc-title { font-size: 19px; font-weight: 700; letter-spacing: -0.02em; }

.pill {
    font-size: 11px;
    font-weight: 700;
    padding: 4px 11px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: .06em;
}
.pill.ok { color: var(--good); background: rgba(48, 209, 88, 0.12); border: 1px solid rgba(48, 209, 88, 0.4); }
.pill.warn { color: var(--warning); background: rgba(255, 159, 10, 0.12); border: 1px solid rgba(255, 159, 10, 0.4); }
.pill.crit { color: var(--critical); background: rgba(255, 69, 58, 0.12); border: 1px solid rgba(255, 69, 58, 0.4); }

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(142px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.tile { padding: 14px 16px; }
.tile .v { font-size: 23px; font-weight: 700; font-family: var(--font-mono); letter-spacing: -0.03em; }
.tile .v.warn { color: var(--warning); }
.tile .v.crit { color: var(--critical); }
.tile .v.good { color: var(--good); }
.tile .k { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-top: 3px; }

/* ---------------------------------------------------------------- tables */

.tbl-wrap { overflow-x: auto; border-radius: 10px; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }

table.data th {
    text-align: right;
    padding: 9px 11px;
    color: var(--text-muted);
    font-size: 10.5px;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: .06em;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    position: sticky;
    top: 0;
    background: var(--chrome);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    border-bottom: 1px solid var(--hairline);
}

table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th.sorted { color: var(--accent); }

table.data td {
    padding: 8px 11px;
    border-top: 1px solid var(--separator);
    text-align: right;
    font-family: var(--font-mono);
    font-size: 12px;
    white-space: nowrap;
}

table.data td:first-child { font-family: inherit; font-size: 13px; }
table.data tbody tr { transition: background .12s ease; }
table.data tbody tr:hover { background: var(--fill-1); cursor: pointer; }

.method {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    padding: 2.5px 7px;
    border-radius: 6px;
    margin-right: 8px;
    background: var(--fill-1);
    border: 1px solid var(--separator);
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.method.GET { color: var(--good); }
.method.POST { color: var(--accent); }
.method.PUT { color: var(--warning); }
.method.DELETE { color: var(--critical); }

td .err { color: var(--critical); }
td .warn-txt { color: var(--warning); }
td .lat-hi { color: var(--critical); font-weight: 700; }
td .lat-mid { color: var(--warning); }

/* Slow-calls table: not sortable; Endpoint column left-aligned. */
#slow-table th { cursor: default; }
#slow-table tbody tr:hover { cursor: default; }
#slow-table th:nth-child(2), #slow-table td:nth-child(2) { text-align: left; }
#slow-table td:nth-child(2) { font-family: inherit; font-size: 13px; }
#slow-table td:first-child { font-family: var(--font-mono); font-size: 12px; white-space: nowrap; }

#svc-endpoints td:first-child, #svc-slow td:nth-child(2) { font-family: inherit; font-size: 13px; }
#svc-slow td:first-child { font-family: var(--font-mono); font-size: 12px; white-space: nowrap; }
#svc-slow th:nth-child(2), #svc-slow td:nth-child(2) { text-align: left; }
#svc-traces td:first-child, #svc-traces td:nth-child(2) { text-align: left; }
#svc-traces td:first-child { font-family: var(--font-mono); font-size: 12px; }
#svc-traces td:nth-child(2) { font-family: inherit; font-size: 13px; }
#svc-exceptions td:first-child, #svc-exceptions td:nth-child(2) { text-align: left; font-family: inherit; font-size: 13px; }
#svc-exceptions tbody tr { cursor: pointer; }
#admin-table td:first-child { font-weight: 600; }
#admin-table .icon-btn { padding: 3px 9px; font-size: 11px; margin-left: 6px; }
#admin-table td:last-child { text-align: right; }

.role-tag { font-size: 10px; font-weight: 700; padding: 2.5px 8px; border-radius: 10px; border: 1px solid var(--separator); }
.role-tag.ADMIN { color: var(--accent); border-color: rgba(10, 132, 255, 0.5); background: rgba(10, 132, 255, 0.1); }

.kind-tag {
    font-size: 10px;
    font-weight: 700;
    padding: 2.5px 8px;
    border-radius: 10px;
    border: 1px solid var(--separator);
    color: var(--text-secondary);
    text-transform: uppercase;
    background: var(--fill-1);
}
.kind-tag.hot { color: var(--warning); border-color: rgba(255, 159, 10, 0.45); background: rgba(255, 159, 10, 0.1); }

/* ---------------------------------------------------------------- tooltip */

.chart-tooltip {
    position: fixed;
    z-index: 50;
    pointer-events: none;
    background: var(--glass-strong);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    border: 1px solid var(--hairline);
    border-radius: 11px;
    padding: 9px 12px;
    font-size: 12px;
    box-shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
    max-width: 320px;
}

.tt-time { color: var(--text-muted); font-size: 11px; margin-bottom: 6px; }
.tt-row { display: flex; align-items: center; gap: 7px; margin: 2.5px 0; }
.tt-chip { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.tt-name { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tt-val { margin-left: auto; font-family: var(--font-mono); font-weight: 600; }

/* ---------------------------------------------------------------- alerts, events, waterfall */

.alert-row { display: flex; align-items: center; gap: 10px; padding: 8px 2px; font-size: 13px; }
.alert-row + .alert-row, .alert-row + .wf-tree + .alert-row { border-top: 1px solid var(--separator); }
.alert-row .dot.sev-critical { background: var(--critical); box-shadow: 0 0 7px rgba(255, 69, 58, 0.55); }
.alert-row .dot.sev-warning { background: var(--warning); box-shadow: 0 0 7px rgba(255, 159, 10, 0.5); }
.alert-row .svc-name { white-space: nowrap; }
.alert-row .alert-msg { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alert-row .alert-when { margin-left: auto; flex: none; font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); }
.alert-row.resolved .dot { opacity: .4; box-shadow: none; }
.alert-row.resolved .svc-name { color: var(--text-muted); font-weight: 400; }
.alert-row.resolved .alert-msg { color: var(--text-muted); text-decoration: line-through; }

.event-row { cursor: pointer; }
.event-row .kind-tag { flex: none; }

.req-link {
    color: var(--accent);
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 11px;
    text-decoration: underline dotted;
}
.req-link:hover { filter: brightness(1.2); }

.wf-row { cursor: pointer; }
.wf-tree { border-left: 3px solid var(--separator); margin: 0 0 4px 10px; }

/* ---------------------------------------------------------------- call graph tree */

.cg-wrap { padding: 8px 12px 14px 26px; background: var(--well); border-radius: 10px; margin: 4px 0; }
.cg-row { display: flex; align-items: center; gap: 10px; padding: 3px 0; font-size: 12px; }
.cg-sig { font-family: var(--font-mono); color: var(--text-primary); white-space: nowrap; }
.cg-sig .cg-depth { color: var(--text-muted); }
.cg-times { margin-left: auto; flex: none; display: flex; align-items: center; gap: 10px; }
.cg-self, .cg-total { font-family: var(--font-mono); font-size: 11px; color: var(--text-secondary); width: 74px; text-align: right; }
.cg-bar { width: 160px; height: 6px; background: var(--grid); border-radius: 4px; overflow: hidden; flex: none; }
.cg-bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.cg-bar i.hotbar { background: var(--warning); }
.cg-head { font-size: 11px; color: var(--text-muted); display: flex; gap: 10px; padding: 4px 0 6px; }
.cg-head .cg-times { margin-left: auto; }

/* ---------------------------------------------------------------- log viewer */

.log-view {
    max-height: 640px;
    overflow-y: auto;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.55;
    background: var(--well);
    border: 1px solid var(--separator);
    border-radius: 12px;
    padding: 10px 12px;
}

.log-line { display: flex; gap: 10px; align-items: baseline; padding: 1.5px 4px; white-space: nowrap; border-radius: 6px; }
.log-line.has-stack { cursor: pointer; }
.log-line:hover { background: var(--fill-2); }
.log-ts { color: var(--text-muted); flex: none; }
.log-level { flex: none; width: 46px; font-weight: 700; font-size: 10px; }
.log-level.lv-error { color: var(--critical); }
.log-level.lv-warn { color: var(--warning); }
.log-level.lv-info { color: var(--accent); }
.log-level.lv-muted { color: var(--text-muted); }
.log-svc { flex: none; color: var(--text-secondary); }
.log-svc .chip { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }
.log-logger { flex: none; color: var(--text-secondary); }
.log-msg { color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; }
.log-line .req-link { flex: none; }

.log-stack {
    margin: 3px 0 8px 60px;
    padding: 7px 11px;
    border-left: 3px solid var(--critical);
    border-radius: 0 8px 8px 0;
    background: rgba(255, 69, 58, 0.06);
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 11px;
    white-space: pre-wrap;
}

/* ---------------------------------------------------------------- responsive */

@media (max-width: 940px) {
    .sidenav { width: 66px; padding: 18px 8px 16px; }
    .brand-name, .tabs button span, .side-user .hint { display: none; }
    .tabs button { justify-content: center; padding: 10px; }
    .brand { justify-content: center; padding-bottom: 16px; }
    main { padding: 16px 14px 40px; }
}

/* ================================================================ LIGHT THEME
   Selected, not inverted: Apple light-mode values. Applied when the user picks Light
   (data-theme="light") or picks Auto while the OS is light. */

:root[data-theme="light"] {
    color-scheme: light;
    --surface-0: #f5f5f7;
    --surface-1: #ffffff;
    --surface-2: #ffffff;
    --glass: rgba(255, 255, 255, 0.62);
    --glass-strong: rgba(248, 248, 250, 0.78);
    --hairline: rgba(0, 0, 0, 0.12);
    --separator: rgba(0, 0, 0, 0.075);
    --border: rgba(0, 0, 0, 0.12);
    --grid: rgba(0, 0, 0, 0.06);
    --text-primary: #1d1d1f;
    --text-secondary: #515154;
    --text-muted: #86868b;
    --accent: #1ba202;
    --good: #248a3d;
    --warning: #c93400;
    --critical: #d70015;
    --fill-1: rgba(0, 0, 0, 0.045);
    --fill-2: rgba(0, 0, 0, 0.08);
    --chrome: rgba(255, 255, 255, 0.92);
    --well: rgba(0, 0, 0, 0.035);
    --selection: rgba(27, 162, 2, 0.22);
    --shadow-1: 0 24px 70px rgba(0, 0, 0, 0.18);
    --scroll: rgba(0, 0, 0, 0.18);
    --scroll-hover: rgba(0, 0, 0, 0.30);
    --is-light: 1;
    --ambient: none;
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]):not([data-theme="light"]) {
        color-scheme: light;
        --surface-0: #f5f5f7;
        --surface-1: #ffffff;
        --surface-2: #ffffff;
        --glass: rgba(255, 255, 255, 0.62);
        --glass-strong: rgba(248, 248, 250, 0.78);
        --hairline: rgba(0, 0, 0, 0.12);
        --separator: rgba(0, 0, 0, 0.075);
        --border: rgba(0, 0, 0, 0.12);
        --grid: rgba(0, 0, 0, 0.06);
        --text-primary: #1d1d1f;
        --text-secondary: #515154;
        --text-muted: #86868b;
        --accent: #1ba202;
        --good: #248a3d;
        --warning: #c93400;
        --critical: #d70015;
        --fill-1: rgba(0, 0, 0, 0.045);
        --fill-2: rgba(0, 0, 0, 0.08);
        --chrome: rgba(255, 255, 255, 0.92);
        --well: rgba(0, 0, 0, 0.035);
        --selection: rgba(27, 162, 2, 0.22);
        --shadow-1: 0 24px 70px rgba(0, 0, 0, 0.18);
        --scroll: rgba(0, 0, 0, 0.18);
        --scroll-hover: rgba(0, 0, 0, 0.30);
        --is-light: 1;
        --ambient: none;
    }
}

/* Light-mode contrast fixes for elements tuned on dark */
:root[data-theme="light"] .tabs button.active { color: #fff; }
:root[data-theme="light"] .seg button.active { box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18), inset 0 0 0 1px var(--hairline); }

/* ================================================================ market-style live traffic */

.ticker {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 4px;
    margin-bottom: 14px;
}

.tick {
    flex: none;
    min-width: 190px;
    padding: 11px 14px;
    border-radius: 13px;
    background: var(--glass);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    border: 1px solid var(--separator);
    cursor: pointer;
    transition: border-color .15s ease;
}

.tick:hover { border-color: var(--hairline); }

.tick .t-head { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 650; }
.tick .t-head .chip { width: 9px; height: 9px; border-radius: 3px; }
.tick .t-main { display: flex; align-items: baseline; gap: 8px; margin-top: 5px; }
.tick .t-val { font-family: var(--font-mono); font-size: 19px; font-weight: 700; letter-spacing: -0.03em; }
.tick .t-delta { font-family: var(--font-mono); font-size: 12px; font-weight: 700; }
.tick .t-delta.up { color: var(--good); }
.tick .t-delta.down { color: var(--critical); }
.tick .t-delta.flat { color: var(--text-muted); }
.tick .t-sub { font-size: 10.5px; color: var(--text-muted); margin-top: 3px; font-family: var(--font-mono); }

#traffic-candles { width: 100%; height: 300px; display: block; }

/* insights + admin role picker */
.insight-row { cursor: pointer; padding: 10px 2px; }
.insight-row .alert-msg { white-space: normal; line-height: 1.45; }
.insight-row .alert-msg strong { color: var(--text-primary); }
.role-pick {
    background: var(--fill-1);
    color: var(--text-primary);
    border: 1px solid var(--hairline);
    border-radius: 7px;
    padding: 3px 6px;
    font-size: 11px;
}

/* single-icon theme toggle */
.theme-btn { display: inline-grid; place-items: center; width: 34px; height: 30px; padding: 0; }
.theme-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }

/* ================================================================ motion
   Short, physical, purposeful. Every rule here is disabled for reduced-motion users. */

@keyframes viewIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

@keyframes badgePulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 69, 58, 0.35); }
    50%      { box-shadow: 0 0 0 5px rgba(255, 69, 58, 0); }
}

@keyframes dotPulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.35); }
}

/* Tab switches glide in; display:none → block restarts the animation naturally. */
.view { animation: viewIn .28s cubic-bezier(.2, .7, .3, 1); }

/* Gentle stagger for the first few panels of a view. */
.view > .panel:nth-child(1), .view > .tiles:nth-child(1), .view > .ticker:nth-child(1) { animation: viewIn .28s cubic-bezier(.2,.7,.3,1) both; }
.view > *:nth-child(2) { animation: viewIn .32s cubic-bezier(.2,.7,.3,1) .04s both; }
.view > *:nth-child(3) { animation: viewIn .36s cubic-bezier(.2,.7,.3,1) .08s both; }

/* Interactive surfaces lift; theme switches cross-fade. */
.tile, .tick, .card { transition: transform .18s ease, border-color .18s ease, background-color .25s ease; }
.tile:hover, .tick:hover { transform: translateY(-1.5px); border-color: var(--hairline); }

body, .panel, .sidenav, header.topbar, .log-view, .login-card, table.data th {
    transition: background-color .25s ease, color .25s ease, border-color .25s ease;
}

/* The alerts badge breathes while anything is active; critical dots tick. */
.badge.alert { animation: badgePulse 2.2s ease-in-out infinite; }
.alert-row .dot.sev-critical, .dot:not(.up) { animation: dotPulse 2.4s ease-in-out infinite; }
.alert-row.resolved .dot { animation: none; }

/* Expanding call graphs / stacks unfold. */
.cg-wrap, .log-stack, .wf-tree > .cg-wrap { animation: viewIn .22s ease both; }

/* Sidebar active pill settles softly. */
.tabs button { transition: background .18s ease, color .18s ease, transform .12s ease; }
.tabs button:active { transform: scale(.985); }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }
}

/* data-driven arrivals: rows/lines that were not there at the previous render */
@keyframes rowNew {
    0%   { background: color-mix(in srgb, var(--accent) 22%, transparent); }
    100% { background: transparent; }
}
.row-new { animation: viewIn .25s ease both, rowNew 1.6s ease .1s both; }
.log-new { animation: rowNew 1.4s ease both; }
.tile .v.v-sm { font-size: 17px; }
