/* Midgard Monitor - app styles. Follows the OS/browser light/dark preference. */

:root {
    color-scheme: light dark;
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #f7f8fa;
    --text: #1d2330;
    --muted: #5d6778;
    --border: #d7dce4;
    --input-bg: #ffffff;
    --accent: #1f6feb;
    --accent-hover: #1a5fcc;
    --accent-text: #ffffff;
    --danger: #c62828;
    --danger-bg: #fdecea;
    --ok: #1b7f3b;
    --ok-bg: #e7f5ec;
    --shadow: 0 10px 30px rgba(20, 30, 50, .08), 0 1px 3px rgba(20, 30, 50, .06);
    --radius: 10px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1216;
        --surface: #181c22;
        --surface-2: #1e232a;
        --text: #e4e8ee;
        --muted: #98a2b3;
        --border: #2f3640;
        --input-bg: #11151a;
        --accent: #4c8dff;
        --accent-hover: #6aa0ff;
        --accent-text: #0b0e12;
        --danger: #ff6b6b;
        --danger-bg: #3a1d1f;
        --ok: #5fd08a;
        --ok-bg: #16301f;
        --shadow: 0 10px 30px rgba(0, 0, 0, .45);
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
}

/* One font everywhere, including w2ui (which sets OpenSans / Verdana on its widgets).
   w2ui icons are drawn in ::before pseudo-elements with their own icon font, which this does not touch. */
body *, input, button, select, textarea {
    font-family: var(--font) !important;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------------------------------------------ auth pages */

.auth-wrap {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 20px;
}

.card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
}
.card.wide { max-width: 760px; }

.card h1 {
    font-size: 20px;
    margin: 0 0 6px;
}
.card .sub {
    color: var(--muted);
    margin: 0 0 20px;
}

fieldset {
    border: 0;
    margin: 0 0 12px;
    padding: 0;
    min-width: 0;
}
legend {
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    padding: 0;
    margin-bottom: 10px;
}

legend .legend-link {
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
    margin-left: 8px;
}

.grid2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 16px;
}
.grid2 .span2 { grid-column: 1 / -1; }
@media (max-width: 640px) {
    .grid2 { grid-template-columns: 1fr; }
}

.field { margin-bottom: 14px; }
.field label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 5px;
}
.field input, .field textarea {
    width: 100%;
    padding: 9px 11px;
    font: inherit;
    color: var(--text);
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 7px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; min-height: 64px; }
.field input:focus, .field textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
.field input.invalid, .field textarea.invalid { border-color: var(--danger); }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }

.row-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    font-size: 13px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    font: inherit;
    font-weight: 600;
    color: var(--accent-text);
    background: var(--accent);
    border: 0;
    border-radius: 7px;
    cursor: pointer;
    transition: background .15s;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .6; cursor: default; }
.btn .spin {
    width: 14px; height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.alert {
    display: none;
    padding: 10px 12px;
    border-radius: 7px;
    margin-bottom: 16px;
    font-size: 13px;
    line-height: 1.45;
}
.alert.show { display: block; }
.alert.error { background: var(--danger-bg); color: var(--danger); }
.alert.success { background: var(--ok-bg); color: var(--ok); }

.foot {
    margin-top: 18px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
}

.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

/* ------------------------------------------------------------ main app (w2ui) */

body.app { height: 100vh; overflow: hidden; }
#app-layout { position: absolute; inset: 0; }

.topbar {
    display: flex;
    align-items: center;
    height: 100%;
    padding: 0 14px;
    gap: 12px;
    background: var(--surface);
    color: var(--text);
    border-bottom: 1px solid var(--border);
}
.topbar .brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.topbar .spacer { flex: 1; }
.topbar .who { text-align: right; line-height: 1.25; font-size: 12px; }
.topbar .who b { font-size: 13px; }
.topbar .who span { color: var(--muted); }
.topbar a.logout {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
}
.topbar a.logout:hover { background: var(--surface-2); text-decoration: none; }

.welcome { padding: 24px; max-width: 800px; }
.welcome h2 { margin-top: 0; }
.welcome p { color: var(--muted); line-height: 1.5; }

/* w2ui panels follow our tokens */
#app-layout .w2ui-panel-content { background: var(--bg); color: var(--text); }
#app-layout #layout_app-layout_panel_top .w2ui-panel-content { background: var(--surface); }
.w2ui-sidebar { background: var(--surface) !important; }

@media (prefers-color-scheme: dark) {
    .w2ui-sidebar .w2ui-sidebar-body .w2ui-node .w2ui-node-text { color: var(--text); }
    .w2ui-popup, .w2ui-popup .w2ui-popup-body, .w2ui-form, .w2ui-form .w2ui-page { color: var(--text); }
    .w2ui-grid .w2ui-grid-body table { color: var(--text); }
    .w2ui-field > label { color: var(--muted); }
}

/* release upload dialog */
.up-table th, .up-table td { padding: 4px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.up-table th { font-weight: 600; }

/* dashboard */
.dash { padding: 18px 22px 0; height: 100%; display: flex; flex-direction: column; overflow: hidden; box-sizing: border-box; }
.dash-head { flex: none; }
/* the device list scrolls on its own; the header (title, filters, search) stays in place */
#dash-body { flex: 1; min-height: 0; overflow: auto; padding-bottom: 18px; }
.dash-head h2 { margin: 0 0 12px; font-size: 20px; }
.dash-summary { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.dash-chip {
    display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; font: inherit; font-size: 13px;
    color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 18px; cursor: pointer;
}
.dash-chip:hover { border-color: var(--accent); }
.dash-chip.active { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.dash-legend { font-size: 12px; margin-left: 6px; }
#dash-search {
    width: 100%; max-width: 420px; padding: 8px 11px; margin-bottom: 16px; font: inherit; color: var(--text);
    background: var(--input-bg); border: 1px solid var(--border); border-radius: 7px; outline: none;
}
#dash-search:focus { border-color: var(--accent); }
.dash-muted { color: var(--muted); }
.dash-group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden; }
.dash-group h3 { display: flex; align-items: center; gap: 8px; margin: 0; padding: 10px 14px; font-size: 15px;
    background: var(--surface-2); border-bottom: 1px solid var(--border); }
.dash-group-counts { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 400; }
.dash-group-counts .dot { margin-left: 8px; }
.dash-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.dash-table th { text-align: left; font-weight: 600; color: var(--muted); padding: 7px 10px; border-bottom: 1px solid var(--border); }
.dash-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); }
.dash-table tr:last-child td { border-bottom: 0; }
.dash-table th:first-child, .dash-table td:first-child { width: 22px; padding-right: 0; }
.dash-name { font-weight: 600; }
.dash-table tr.is-disabled td { opacity: .55; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; vertical-align: middle; flex: none; }
.dot.green { background: #2e9d57; box-shadow: 0 0 0 3px color-mix(in srgb, #2e9d57 22%, transparent); }
.dot.yellow { background: #e0a800; box-shadow: 0 0 0 3px color-mix(in srgb, #e0a800 22%, transparent); }
.dot.red { background: #d93025; box-shadow: 0 0 0 3px color-mix(in srgb, #d93025 22%, transparent); }
.dot.disabled { background: #9aa0a6; }
/* same column widths in every client table */
.dash-table { table-layout: fixed; }
.dash-table td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-table th:nth-child(1) { width: 28px; }
.dash-table th:nth-child(2) { width: 19%; }
.dash-table th:nth-child(3) { width: 11%; }
.dash-table th:nth-child(4) { width: 14%; }
.dash-table th:nth-child(5) { width: 11%; }
.dash-table th:nth-child(6) { width: 24%; }
.dash-table th:nth-child(7) { width: 8%; }
.dash-table th:nth-child(8) { width: 11%; }

/* dashboard rows: clickable, hover cue, flash after returning from a device */
.dash-table tbody tr[data-id] { cursor: pointer; }
.dash-table tbody tr[data-id]:hover td { background: var(--surface-2); }
.dash-table tbody tr[data-id]:hover .dash-name { color: var(--accent); }
.dash-table tbody tr.flash td { animation: dash-flash 2.7s ease-out; }
@keyframes dash-flash {
    0%, 74% { background: color-mix(in srgb, var(--accent) 24%, var(--surface)); }
    100% { background: transparent; }
}

/* chart palette (dataviz reference palette, light and dark steps) */
:root { --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
        --series-5: #e87ba4; --series-6: #008300; --series-7: #4a3aa7; --series-8: #e34948; }
@media (prefers-color-scheme: dark) {
    :root { --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
            --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767; }
}

/* device detail */
.dev { padding: 16px 22px 24px; height: 100%; overflow: auto; box-sizing: border-box; }
.dev-back { display: inline-block; margin-bottom: 8px; font-size: 13px; }
.dev-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.dev-title h2 { margin: 0; font-size: 21px; }
.dev-sub { margin: 4px 0 12px; font-size: 13px; }
.dev-tabs { display: flex; gap: 2px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.dev-tabs button { font: inherit; font-size: 13px; padding: 8px 14px; color: var(--muted); background: none; border: 0;
    border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; }
.dev-tabs button:hover { color: var(--text); }
.dev-tabs button.active { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.dev-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.dev-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px 14px; margin-bottom: 14px; min-width: 0; }
.dev-grid .dev-card { margin-bottom: 0; }
.dev-grid + .dev-card { margin-top: 14px; }
.dev-card h3 { margin: 0 0 10px; font-size: 14px; font-weight: 600; }
.kv { border-collapse: collapse; font-size: 13px; width: 100%; }
.kv th { text-align: left; font-weight: 500; color: var(--muted); padding: 4px 12px 4px 0; width: 38%; vertical-align: top; }
.kv td { padding: 4px 0; word-break: break-word; }
.dt-wrap { overflow-x: auto; }
.dt { width: 100%; border-collapse: collapse; font-size: 13px; }
.dt th { text-align: left; font-weight: 600; color: var(--muted); padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.dt td { padding: 6px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.dt tr:last-child td { border-bottom: 0; }
.dt code, .kv code { font-family: ui-monospace, Consolas, monospace !important; font-size: 12px; }
.nowrap { white-space: nowrap; }
.dev-select { font: inherit; font-size: 13px; padding: 5px 8px; margin-bottom: 10px; color: var(--text); background: var(--input-bg);
    border: 1px solid var(--border); border-radius: 6px; }
.bar { display: inline-block; vertical-align: middle; width: 120px; height: 8px; border-radius: 4px; background: var(--surface-2);
    border: 1px solid var(--border); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 4px; }
.bar .green { background: #2e9d57; } .bar .yellow { background: #e0a800; } .bar .red { background: #d93025; }

/* line charts */
.chart { width: 100%; }
.chart-note { margin: 6px 0 0; font-size: 12px; }
.lc-wrap { position: relative; }
.lc { display: block; overflow: visible; }
.lc-grid { stroke: var(--border); stroke-width: 1; }
.lc-tick { stroke: var(--border); }
.lc-axis { fill: var(--muted); font-size: 11px; }
.lc-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.lc-cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.lc-hit { fill: transparent; cursor: crosshair; }
.lc-tip { position: absolute; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border);
    border-radius: 6px; padding: 6px 9px; font-size: 12px; box-shadow: var(--shadow); white-space: nowrap; z-index: 2; }
.lc-tip-time { color: var(--muted); margin-bottom: 3px; }
.lc-tip i, .lc-legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.lc-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text); margin-bottom: 6px; }

/* service history (Services tab) */
.svc-table tbody tr.svc-row { cursor: pointer; }
.svc-table tbody tr.svc-row:hover td { background: var(--surface-2); }
.svc-caret { display: inline-block; width: 14px; color: var(--muted); transition: transform .15s; }
.svc-row.open .svc-caret { transform: rotate(90deg); }
.svc-table tr.svc-history > td { background: var(--surface-2); padding: 10px 14px 14px; }
.svc-hist-title { font-size: 12px; margin-bottom: 6px; }
.svc-bar { display: flex; height: 14px; border-radius: 4px; overflow: hidden; background: var(--border); gap: 1px; }
.svc-bar span { display: block; height: 100%; min-width: 1px; }
.svc-bar .green { background: #2e9d57; } .svc-bar .red { background: #d93025; } .svc-bar .disabled { background: var(--border); }
.svc-bar-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin: 3px 0 10px; }
.svc-changes { max-width: 560px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; }
