﻿/* Server Monitor - mobile first, dark by default */
:root {
    --bg: #0b1220;
    --bg-soft: #121c2f;
    --card: #16233a;
    --card-2: #1c2b45;
    --line: #26375a;
    --text: #e7eefc;
    --muted: #93a4c4;
    --ok: #2fbf71;
    --warn: #f2b134;
    --crit: #ef4d5a;
    --down: #b23bd1;
    --off: #5c6b88;
    --accent: #4aa8ff;
    --track: rgba(255, 255, 255, .10);    /* empty part of a dial */
    --radius: 14px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", "Sarabun", "Noto Sans Thai", Tahoma, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

/* uses the whole screen; only the settings form keeps a readable width */
main { padding: 10px 10px calc(28px + var(--safe-bottom)); margin: 0 auto; }
#viewConfig { max-width: 1100px; margin: 0 auto; }

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

/* ---------------------------------------------------------------- topbar */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: calc(10px + var(--safe-top)) 12px 10px;
    background: rgba(11, 18, 32, .95);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(6px);
}

.topbar-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-text { display: flex; flex-direction: column; min-width: 0; }
.topbar-text strong { font-size: 15px; letter-spacing: .2px; }
.topbar-sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 6px; flex: none; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--text);
    font-size: 17px;
    text-decoration: none;
    cursor: pointer;
}
.icon-btn:active { background: var(--card-2); }
.icon-btn.off { opacity: .4; }

.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--off); flex: none; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.crit { background: var(--crit); animation: pulse 1.1s infinite; }
.dot.down { background: var(--down); animation: pulse 1.1s infinite; }

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(239, 77, 90, .6); }
    70% { box-shadow: 0 0 0 9px rgba(239, 77, 90, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 77, 90, 0); }
}

/* ------------------------------------------------------------------ tabs */
.tabs {
    display: flex;
    gap: 6px;
    padding: 10px 10px 0;
    margin: 0 auto;
}
.tab {
    flex: 1;
    padding: 9px 4px;
    border-radius: 10px 10px 0 0;
    border: 1px solid var(--line);
    border-bottom: none;
    background: var(--bg-soft);
    color: var(--muted);
    font-size: 13px;
    cursor: pointer;
}
.tab.active { background: var(--card); color: var(--text); font-weight: 600; }

/* -------------------------------------------------------------- headline */
.headline {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: var(--card);
    margin: 10px 0 12px;
}
.headline strong { display: block; font-size: 17px; }
.headline span { display: block; font-size: 12.5px; color: var(--muted); }
.hl-icon {
    width: 34px; height: 34px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: 700; flex: none;
}
/* ".headline span" above is more specific than ".hl-icon" and would undo its centring */
.headline .hl-icon { display: flex; font-size: 18px; }
.headline.ok { border-color: rgba(47, 191, 113, .45); }
.headline.ok .hl-icon { background: rgba(47, 191, 113, .16); color: var(--ok); }
.headline.warn { border-color: rgba(242, 177, 52, .5); }
.headline.warn .hl-icon { background: rgba(242, 177, 52, .16); color: var(--warn); }
.headline.crit { border-color: rgba(239, 77, 90, .55); }
.headline.crit .hl-icon { background: rgba(239, 77, 90, .16); color: var(--crit); }
.headline.down { border-color: rgba(178, 59, 209, .55); }
.headline.down .hl-icon { background: rgba(178, 59, 209, .16); color: var(--down); }

.sys-warn {
    background: rgba(242, 177, 52, .12);
    border: 1px solid rgba(242, 177, 52, .35);
    color: #ffe6b3;
    border-radius: 10px;
    padding: 9px 11px;
    font-size: 12.5px;
    margin-bottom: 10px;
}

/* ----------------------------------------------------------------- cards */
/* one machine -> one card across the whole width; more machines share the row */
.cards { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 800px) { .cards { grid-template-columns: repeat(auto-fit, minmax(560px, 1fr)); } }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-left: 4px solid var(--off);
    border-radius: var(--radius);
    overflow: hidden;
}
.card.ok { border-left-color: var(--ok); }
.card.warn { border-left-color: var(--warn); }
.card.crit { border-left-color: var(--crit); }
.card.down { border-left-color: var(--down); }
.card.off { opacity: .55; }

.card-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 13px 12px;
    cursor: pointer;
    user-select: none;
}
.card-title { flex: 1; min-width: 0; }
.card-title strong { display: block; font-size: 15.5px; }
.card-title span { display: block; font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-state { font-size: 11.5px; padding: 3px 9px; border-radius: 999px; background: var(--card-2); color: var(--muted); }
.card-state.ok { color: var(--ok); }
.card-state.warn { color: var(--warn); }
.card-state.crit { color: var(--crit); }
.card-state.down { color: var(--down); }
.caret { color: var(--muted); font-size: 12px; }
.card-note { padding: 0 12px 12px; font-size: 12px; color: var(--muted); }

/* alerts inside a card: what + numbers + what to do */
.alerts-inline { padding: 0 12px 10px; display: flex; flex-direction: column; gap: 7px; }
.alert-pill {
    font-size: 12.5px;
    padding: 9px 11px;
    border-radius: 10px;
    background: rgba(239, 77, 90, .14);
    border: 1px solid rgba(239, 77, 90, .35);
    color: #ffd7da;
}
.alert-pill b { display: block; font-size: 13.5px; }
.alert-pill span { display: block; opacity: .85; }
.alert-pill em { display: block; font-style: normal; opacity: .7; margin-top: 3px; font-size: 11.5px; }
.alert-pill.warn { background: rgba(242, 177, 52, .14); border-color: rgba(242, 177, 52, .35); color: #ffe6b3; }
.alert-pill.down { background: rgba(178, 59, 209, .16); border-color: rgba(178, 59, 209, .4); color: #f0d2ff; }

/* dials: the whole point is answering "ok?" without reading numbers */
.card-body { padding: 2px 12px 12px; }
.gauges { display: flex; gap: 10px; padding-bottom: 12px; }
.gauge { flex: 1; text-align: center; min-width: 0; }
.gauge .ring {
    width: 82px; height: 82px; margin: 0 auto; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; position: relative; flex: none;
    background: conic-gradient(var(--g) calc(var(--p) * 1%), var(--track) 0);
}
.gauge .ring::before {
    content: ''; position: absolute; top: 9px; right: 9px; bottom: 9px; left: 9px;
    border-radius: 50%; background: var(--card);
}
.gauge .val { position: relative; font-size: 19px; font-weight: 700; }
.g-text { min-width: 0; }
.gauge .cap { font-size: 12px; margin-top: 5px; }
.gauge .sub {
    font-size: 10.5px; color: var(--muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* the card measures itself: a card can be wide on a phone in landscape or narrow next to another card */
.card { container: card / inline-size; }

/* wide card: dials as 2 x 2 boxes on the left, category tiles 3 x 2 on the right - every box the same size */
@container card (min-width: 940px) {
    .card .card-body {
        display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 10px;
        padding: 4px 14px 14px;
    }
    .card .gauges {
        display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: 1fr;
        gap: 10px; padding: 0;
    }
    .card .gauge {
        display: flex; align-items: center; gap: 14px; text-align: left;
        background: var(--bg-soft); border: 1px solid var(--line); border-left: 4px solid var(--ok);
        border-radius: 10px; padding: 10px 14px;
    }
    .card .gauge.warn { border-left-color: var(--warn); }
    .card .gauge.crit { border-left-color: var(--crit); }
    .card .gauge .ring { width: 66px; height: 66px; margin: 0; }
    .card .gauge .ring::before { top: 7px; right: 7px; bottom: 7px; left: 7px; background: var(--bg-soft); }
    .card .gauge .val { font-size: 16px; }
    .card .gauge .cap { font-size: 14px; font-weight: 600; margin-top: 0; }
    .card .gauge .sub { font-size: 12px; white-space: normal; }
    .card .cats { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: 1fr; gap: 10px; padding: 0; }
    .card .cat-tile { padding: 10px 12px; gap: 5px; }
    .card .ct-name { font-size: 14px; }
    .card .ct-state { font-size: 11.5px; }
    .card .ct-vals { font-size: 12.5px; }
}
/* in between (two cards side by side, a tablet): dials in a row, tiles three across */
@container card (min-width: 560px) and (max-width: 939.98px) {
    .card .cats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* compact number strip: everything else worth a glance */
.mchips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 12px; }
.mchip {
    font-size: 11.5px; color: var(--muted);
    background: var(--card-2); border: 1px solid var(--line);
    border-radius: 999px; padding: 4px 9px;
}
.mchip b { color: var(--text); font-weight: 600; }
.mchip.warn { border-color: rgba(242, 177, 52, .5); }
.mchip.warn b { color: var(--warn); }
.mchip.crit { border-color: rgba(239, 77, 90, .55); }
.mchip.crit b { color: var(--crit); }

/* details that must stay visible without expanding */
.urgent {
    margin: 0 12px 12px; padding: 9px 11px;
    background: rgba(239, 77, 90, .09);
    border: 1px solid rgba(239, 77, 90, .3);
    border-radius: 10px;
}
.urgent-head { font-size: 12px; font-weight: 600; color: var(--crit); margin-bottom: 5px; }
.urgent-row {
    display: flex; justify-content: space-between; gap: 10px;
    font-size: 11.5px; padding: 3px 0; border-top: 1px solid rgba(255, 255, 255, .06);
}
.urgent-row span { color: var(--text); white-space: nowrap; }
.urgent-row em {
    font-style: normal; color: var(--muted); text-align: right;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%;
}
.urgent-more { font-size: 11px; color: var(--muted); margin-top: 5px; }

/* metric groups: one row per metric, value right, limit spelled out */
.grp { padding: 0 12px 10px; }
.grp-head {
    display: flex; justify-content: space-between; align-items: baseline;
    font-size: 11.5px; color: var(--accent);
    text-transform: none; letter-spacing: .3px;
    margin: 6px 0 6px;
    border-top: 1px solid var(--line);
    padding-top: 9px;
}
.grp-note { color: var(--muted); font-size: 10.5px; }

.mrow { padding: 7px 0; border-bottom: 1px dashed rgba(255, 255, 255, .06); }
.mrow:last-child { border-bottom: none; }
.mrow-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.m-label { font-size: 13px; color: var(--text); }
.m-label .slow {
    font-style: normal; font-size: 9.5px; color: var(--muted);
    border: 1px solid var(--line); border-radius: 4px; padding: 0 3px; margin-left: 3px;
}
.m-value { font-size: 15px; font-weight: 700; white-space: nowrap; }
.mrow.warn .m-value { color: var(--warn); }
.mrow.crit .m-value { color: var(--crit); }

.bar {
    position: relative;
    height: 5px; border-radius: 3px;
    background: rgba(255, 255, 255, .09);
    margin-top: 6px; overflow: hidden;
}
.bar > i { display: block; height: 100%; background: var(--ok); }
.mrow.warn .bar > i { background: var(--warn); }
.mrow.crit .bar > i { background: var(--crit); }
.bar > u {
    position: absolute; top: -2px; width: 2px; height: 9px;
    background: var(--muted); opacity: .8;
}

.mrow-foot {
    display: flex; justify-content: space-between; gap: 8px;
    font-size: 10.5px; color: var(--muted); margin-top: 4px;
}
.mrow.warn .mrow-foot span:first-child { color: var(--warn); }
.mrow.crit .mrow-foot span:first-child { color: var(--crit); }

.card-body { border-top: 1px solid var(--line); padding: 10px 12px 14px; background: var(--bg-soft); }
.info-line { font-size: 11.5px; color: var(--muted); margin-bottom: 8px; word-break: break-word; }
.info-line.warn { color: var(--warn); }

.tbl-title { font-size: 12px; font-weight: 600; margin: 12px 0 5px; color: var(--accent); }
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 11.5px; }
th, td { padding: 6px 8px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { background: var(--card-2); color: var(--muted); font-weight: 600; position: sticky; top: 0; }
td:last-child { white-space: normal; min-width: 220px; word-break: break-word; }
tr:last-child td { border-bottom: none; }

/* ------------------------------------------------------------ alert list */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; align-items: center; }
select, input[type=text], input[type=number], input[type=password] {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 9px 10px;
    font-size: 14px;
    font-family: inherit;
}
select { min-width: 130px; }
.chk { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

.alert-list { display: flex; flex-direction: column; gap: 8px; }
.alert-row {
    background: var(--card);
    border: 1px solid var(--line);
    border-left: 4px solid var(--warn);
    border-radius: 11px;
    padding: 11px 12px;
}
.alert-row.crit { border-left-color: var(--crit); }
.alert-row.down { border-left-color: var(--down); }
.alert-row.resolved { opacity: .62; }
.alert-row .ar-head { display: flex; justify-content: space-between; gap: 8px; font-size: 11.5px; color: var(--muted); }
.alert-row .ar-msg { margin: 3px 0 1px; font-size: 14.5px; font-weight: 600; }
.alert-row .ar-sub { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.alert-row .ar-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); }
.tag { padding: 2px 7px; border-radius: 999px; background: var(--card-2); font-size: 10.5px; }
.tag.open { color: var(--crit); }
.tag.closed { color: var(--ok); }
.btn-ack {
    border: 1px solid var(--line);
    background: var(--card-2);
    color: var(--accent);
    border-radius: 8px;
    padding: 5px 10px;
    font-size: 11.5px;
    cursor: pointer;
}

/* ----------------------------------------------------------------- chart */
.chart-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
canvas { width: 100%; display: block; }

/* -------------------------------------------------------------- settings */
.cfg-block {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 12px;
}
.cfg-block-head {
    display: flex; align-items: center; gap: 8px;
    font-size: 15px; font-weight: 700;
    padding-bottom: 10px; margin-bottom: 6px;
    border-bottom: 1px solid var(--line);
}
.badge {
    font-size: 10.5px; font-weight: 600; color: var(--accent);
    background: var(--card-2); border-radius: 999px; padding: 2px 8px;
}
.btn-del {
    margin-left: auto; border: 1px solid var(--line); background: transparent;
    color: var(--crit); border-radius: 8px; padding: 4px 10px; font-size: 11.5px; cursor: pointer;
}
.cfg-sub {
    font-size: 12px; color: var(--accent); margin: 14px 0 4px;
    border-top: 1px solid var(--line); padding-top: 10px;
}

.fld { display: block; margin: 9px 0; }
.fld > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.fld input[type=text], .fld input[type=number], .fld input[type=password] { width: 100%; }
.fld em { display: block; font-style: normal; font-size: 11px; color: var(--muted); opacity: .8; margin-top: 3px; }
.chkfld { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chkfld > span { margin: 0; color: var(--text); font-size: 13.5px; }
.chkfld input { width: 18px; height: 18px; }
.chkfld em { width: 100%; }

.adv { margin: 12px 0 2px; border-top: 1px solid var(--line); padding-top: 8px; }
.adv > summary {
    cursor: pointer; list-style: none;
    font-size: 12.5px; color: var(--accent); padding: 4px 0;
}
.adv > summary::-webkit-details-marker { display: none; }
.adv > summary::before { content: '▸ '; }
.adv[open] > summary::before { content: '▾ '; }

.cfg-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.btn-ghost {
    border: 1px solid var(--line); background: var(--card-2); color: var(--accent);
    border-radius: 9px; padding: 9px 12px; font-size: 13px; cursor: pointer;
}
.test-result { font-size: 12px; color: var(--muted); }
.test-result.ok { color: var(--ok); }
.test-result.bad { color: var(--crit); }
.cfg-save { margin: 16px 0 8px; }
.cfg-save .btn-primary { max-width: 420px; }

/* ----------------------------------------------------------------- toast */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(18px + var(--safe-bottom));
    transform: translateX(-50%);
    background: #000c;
    border: 1px solid var(--line);
    color: var(--text);
    padding: 10px 15px;
    border-radius: 999px;
    font-size: 12.5px;
    z-index: 40;
    max-width: 92vw;
    text-align: center;
}

/* ----------------------------------------------------------------- login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card {
    width: 100%;
    max-width: 340px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 26px 22px;
    text-align: center;
}
.login-logo { font-size: 34px; color: var(--accent); }
.login-card h1 { font-size: 19px; margin: 6px 0 2px; }
.login-sub { font-size: 12px; color: var(--muted); margin: 0 0 18px; }
.login-card label { display: block; text-align: left; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.login-card input[type=password] {
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--bg-soft);
    color: var(--text);
    font-size: 16px;
    margin-bottom: 12px;
}
.login-remember { display: flex !important; align-items: center; gap: 7px; font-size: 12px; margin-bottom: 16px; }
.login-remember input { width: auto; }
.btn-primary {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: #04203c;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
}
.login-error {
    background: rgba(239, 77, 90, .15);
    border: 1px solid rgba(239, 77, 90, .4);
    color: #ffd7da;
    border-radius: 9px;
    padding: 9px;
    font-size: 12.5px;
    margin-bottom: 14px;
}

/* ------------------------------------------------------------ categories */
.ctag {
    display: inline-block; margin-right: 6px; padding: 1px 7px; border-radius: 999px;
    background: var(--card-2); border: 1px solid var(--line);
    color: var(--muted); font-style: normal; font-weight: 500; font-size: 10.5px; vertical-align: 1px;
}
.alert-pill .ctag { background: rgba(0, 0, 0, .18); border-color: transparent; color: inherit; }

/* two per row on a phone (wider cards: see the @container rules) */
.cats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.cat-tile {
    display: flex; flex-direction: column; gap: 3px; text-align: left;
    background: var(--bg-soft); color: var(--text);
    border: 1px solid var(--line); border-left: 4px solid var(--ok); border-radius: 10px;
    padding: 8px 10px; font: inherit; cursor: pointer; min-width: 0;
}
.cat-tile.warn { border-left-color: var(--warn); }
.cat-tile.crit { border-left-color: var(--crit); }
.cat-tile.open { background: var(--card-2); border-color: var(--accent); border-left-color: inherit; }
.cat-tile.open.ok { border-left-color: var(--ok); }
.cat-tile.open.warn { border-left-color: var(--warn); }
.cat-tile.open.crit { border-left-color: var(--crit); }
.ct-head { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.ct-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ct-state { font-size: 10.5px; color: var(--ok); white-space: nowrap; }
.cat-tile.warn .ct-state { color: var(--warn); }
.cat-tile.crit .ct-state { color: var(--crit); }
.ct-vals { font-size: 11.5px; color: var(--muted); line-height: 1.45; }
.ct-vals b { color: var(--text); font-weight: 600; }
.ct-vals b.warn { color: var(--warn); }
.ct-vals b.crit { color: var(--crit); }
.ct-prob { font-size: 11px; color: var(--crit); line-height: 1.35; }
.cat-tile.warn .ct-prob { color: var(--warn); }

.cat-panel { border-top: 1px solid var(--line); padding: 10px 12px 12px; background: var(--bg-soft); }
.cat-panel .grp-head { margin-bottom: 4px; }
.cat-panel .info-line { margin-top: 8px; }

/* -------------------------------------------------- problem history / cause */
.cat-sum { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.sum-chip {
    border: 1px solid var(--line); background: var(--card); color: var(--muted);
    border-radius: 999px; padding: 5px 10px; font: inherit; font-size: 12px; cursor: pointer;
}
.sum-chip b { color: var(--text); }
.sum-chip.on { border-color: var(--accent); color: var(--text); background: var(--card-2); }

.day-head {
    display: flex; justify-content: space-between; align-items: baseline;
    margin: 6px 2px 0; font-size: 12.5px; font-weight: 600; color: var(--muted);
}
.day-head span { font-weight: 400; font-size: 11.5px; }
.alert-row .ar-head .ctag { margin-right: 6px; }
.alert-row.cause-open { opacity: 1; }
.alert-row.flash { box-shadow: 0 0 0 2px var(--accent); }
.inc-num {
    display: inline-block; min-width: 18px; margin-right: 6px; padding: 0 5px; border-radius: 5px;
    background: var(--text); color: var(--bg); font-style: normal; font-weight: 700; font-size: 10.5px; text-align: center;
}

.cause { margin-top: 10px; padding: 10px; border-radius: 9px; background: var(--bg-soft); border: 1px solid var(--line); }
.cause-fix { font-size: 12.5px; margin-bottom: 8px; }
.cause-fix b { color: var(--accent); margin-right: 4px; }
.cause-at { font-size: 11.5px; color: var(--muted); margin-bottom: 6px; }
.facts { list-style: none; margin: 0 0 8px; padding: 0; font-size: 12px; }
.facts li { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.facts li span { color: var(--muted); }
.facts li b { text-align: right; word-break: break-word; }
.readings { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.cause-slow { font-size: 12px; margin: 8px 0; }
.cause .tbl-title { margin-top: 10px; }

/* -------------------------------------------------------------- slow SQL */
.tab-badge {
    display: inline-block; min-width: 17px; margin-left: 5px; padding: 1px 5px;
    border-radius: 999px; background: var(--crit); color: #fff;
    font-size: 10.5px; font-weight: 700; line-height: 15px; vertical-align: 1px;
}
.tab-badge[hidden] { display: none; }
.sec-title { margin: 16px 0 8px; font-size: 14px; font-weight: 600; }
.sec-title span { color: var(--crit); }
.slow-list { display: flex; flex-direction: column; gap: 8px; }
.slow-none {
    margin: 0; padding: 12px; border: 1px dashed var(--line); border-radius: 11px;
    color: var(--ok); font-size: 13px;
}
.slow-row {
    background: var(--card);
    border: 1px solid var(--line);
    border-left: 4px solid var(--warn);
    border-radius: 11px;
    padding: 11px 12px;
}
.slow-row.running { border-left-color: var(--crit); }
.sq-top { display: flex; gap: 12px; align-items: center; }
.sq-time { flex: none; min-width: 96px; }
.sq-time b { display: block; font-size: 19px; line-height: 1.15; color: var(--warn); }
.slow-row.running .sq-time b { color: var(--crit); }
.sq-time span { font-size: 11px; color: var(--muted); }
.sq-who { min-width: 0; }
.sq-who strong { display: block; font-size: 14px; word-break: break-word; }
.sq-who span { display: block; font-size: 12px; color: var(--muted); word-break: break-word; }
.sq-reason { margin-top: 8px; font-size: 12.5px; }
.sq-reason.crit { color: var(--crit); font-weight: 600; }
.sq-facts { margin-top: 3px; font-size: 11.5px; color: var(--muted); }
/* the padding sits on the box: on the clamped element itself the next line would show through it */
.sq-box {
    margin-top: 8px; padding: 8px 10px;
    background: var(--bg-soft); border: 1px solid var(--line); border-radius: 8px;
}
.sq-sql {
    margin: 0; overflow: hidden;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4;   /* four lines, then "..." */
    font: 12px/1.45 Consolas, "SFMono-Regular", Menlo, monospace;
    white-space: pre-wrap; word-break: break-word; color: var(--text);
    -webkit-user-select: text; user-select: text;
}
.sq-sql.open { display: block; }
.sq-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; }
.slow-link { cursor: pointer; }
.slow-row.cancel { border-left-color: var(--down); }
.slow-row.cancel.err { border-left-color: var(--crit); }
.slow-row.cancel.err .sq-time b { color: var(--crit); }
.err-code {
    display: inline-block; padding: 0 6px; border-radius: 5px; margin-right: 4px;
    background: var(--card-2); border: 1px solid var(--line); font-size: 11.5px;
}
.err-link {
    background: none; border: none; padding: 0; font: inherit; color: var(--accent);
    text-decoration: underline; cursor: pointer;
}
.slow-row.cancel .sq-time b { color: var(--down); }
.slow-row.top { border-left-color: var(--accent); }
.slow-row.top .sq-time b { color: var(--accent); }
.sq-trend-box { margin-top: 8px; max-height: 340px; overflow-y: auto; overflow-x: hidden; }
.trend { display: grid; gap: 1px; font-size: 12px; }
.tr-row {
    display: grid; grid-template-columns: 76px 62px minmax(24px, 1fr) 54px 34px;
    gap: 6px; align-items: center; padding: 2px 4px; font-variant-numeric: tabular-nums;
}
.tr-row > span { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tr-row:nth-child(even) { background: var(--bg-soft); border-radius: 4px; }
.tr-head { color: var(--muted); font-size: 11px; }
.tr-bar { height: 8px; background: var(--card-2); border-radius: 4px; overflow: hidden; }
.tr-bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.top-link { font-size: 12px; margin-left: 6px; }
.sec-title small { font-weight: 400; font-size: 11.5px; }
/* five tabs have to fit a phone */
@media (max-width: 430px) { .tab { flex: 1 1 auto; font-size: 12px; padding: 9px 5px; white-space: nowrap; } }

/* --------------------------------------------------------- light devices */
@media (prefers-color-scheme: light) {
    :root {
        --bg: #f2f5fa;
        --bg-soft: #e9eef7;
        --card: #ffffff;
        --card-2: #f1f4fa;
        --line: #d6dcea;
        --text: #16213a;
        --muted: #5c6b88;
        --track: rgba(22, 33, 58, .10);
    }
    .topbar { background: rgba(255, 255, 255, .95); }
    .btn-primary { color: #fff; }
    .alert-pill { color: #8a1a24; }
    .alert-pill.warn { color: #7a5407; }
    .alert-pill.down { color: #6b1683; }
    .sys-warn { color: #7a5407; }
    .mrow { border-bottom-color: rgba(0, 0, 0, .07); }
    .bar { background: rgba(0, 0, 0, .08); }
}
