:root {
    color-scheme: light;
    --bg: #f4f3f0;
    --surface-1: #fcfcfb;
    --surface-2: #f0efec;
    --border: #e2e0da;
    --text-primary: #0b0b0b;
    --text-secondary: #52514e;
    --text-muted: #7a7974;
    --accent: #2a78d6;
    --accent-soft: #e3eefb;
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --series-3: #1baf7a;
    --good: #0ca30c;
    --good-text: #006300;
    --warning: #fab219;
    --warning-text: #8a5a00;
    --critical: #d03b3b;
    --grid: #e7e5e0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
    --radius: 10px;
}
@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme="light"])) {
        color-scheme: dark;
        --bg: #121211;
        --surface-1: #1a1a19;
        --surface-2: #232321;
        --border: #33332f;
        --text-primary: #f0efec;
        --text-secondary: #c3c2b7;
        --text-muted: #8f8e86;
        --accent: #3987e5;
        --accent-soft: #1d2b3d;
        --series-1: #3987e5;
        --series-2: #d95926;
        --series-3: #199e70;
        --good-text: #4fcf4f;
        --warning-text: #fab219;
        --grid: #2c2c29;
        --shadow: none;
    }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #121211;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --border: #33332f;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --accent: #3987e5;
    --accent-soft: #1d2b3d;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --good-text: #4fcf4f;
    --warning-text: #fab219;
    --grid: #2c2c29;
    --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    background: var(--bg);
    color: var(--text-primary);
    font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.loading { padding: 48px; text-align: center; color: var(--text-muted); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* Layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
    background: var(--surface-1);
    border-right: 1px solid var(--border);
    padding: 18px 12px;
    position: sticky; top: 0; height: 100vh;
    display: flex; flex-direction: column; gap: 4px;
}
.brand { font-weight: 700; font-size: 16px; padding: 4px 10px 18px; display: flex; align-items: center; gap: 8px; }
.brand span { color: var(--accent); }
.nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; border-radius: 8px; color: var(--text-secondary); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav .count { margin-left: auto; font-size: 11px; background: var(--critical); color: #fff; border-radius: 10px; padding: 0 6px; }
.sidebar .user { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 10px; font-size: 12px; color: var(--text-secondary); }
.sidebar .user img { width: 26px; height: 26px; border-radius: 50%; }
.sidebar .user button { margin-left: auto; }
main { padding: 24px 28px 48px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }

/* Cards & tiles */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.tile .label { font-size: 12px; color: var(--text-secondary); }
.tile .value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.01em; margin-top: 2px; }
.tile .sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.bar-meter { height: 6px; background: var(--surface-2); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.bar-meter > div { height: 100%; background: var(--series-1); border-radius: 3px; }
.mb { margin-bottom: 16px; }

/* Jobs */
.job { display: flex; flex-direction: column; gap: 6px; }
.job .title { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.job dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 4px 0 0; font-size: 13px; }
.job dt { color: var(--text-muted); }
.job dd { margin: 0; }

/* Status badges: always icon + label, never color alone */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 10px; background: var(--surface-2); color: var(--text-secondary); white-space: nowrap; }
.badge.good { color: var(--good-text); background: color-mix(in srgb, var(--good) 14%, transparent); }
.badge.warn { color: var(--warning-text); background: color-mix(in srgb, var(--warning) 20%, transparent); }
.badge.bad { color: var(--critical); background: color-mix(in srgb, var(--critical) 13%, transparent); }
.badge.info { color: var(--accent); background: var(--accent-soft); }
.pill { font-size: 11px; padding: 0 6px; border-radius: 8px; background: var(--surface-2); color: var(--text-secondary); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--text-secondary); white-space: nowrap; background: var(--surface-1); position: sticky; top: 0; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text-primary); }
tbody tr:hover { background: var(--surface-2); }
td .sub { font-size: 12px; color: var(--text-muted); }
tr.inactive td { opacity: .55; }

/* Notifications */
.notes { list-style: none; margin: 0; padding: 0; }
.notes li { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.notes li:last-child { border-bottom: 0; }
.notes .icon { font-size: 14px; line-height: 20px; text-align: center; }
.notes .t { font-weight: 550; }
.notes .m { color: var(--text-secondary); font-size: 13px; }
.notes .when { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.lvl-success .icon { color: var(--good-text); }
.lvl-warn .icon { color: var(--warning-text); }
.lvl-error .icon { color: var(--critical); }
.lvl-info .icon { color: var(--accent); }

/* Forms */
input, select, button, textarea { font: inherit; color: inherit; }
input[type=text], input[type=search], input[type=number], select {
    background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; cursor: pointer; font-weight: 500; }
button:hover { border-color: var(--text-muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.filters label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs a { padding: 8px 14px; color: var(--text-secondary); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text-primary); border-bottom-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--text-primary); }

/* Charts */
.chart-box { position: relative; height: 240px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-secondary); margin: -4px 0 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* Gallery */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.ad { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; cursor: pointer; box-shadow: var(--shadow); }
.ad:hover { border-color: var(--accent); }
.ad .shot { background: #fff; height: 170px; display: flex; align-items: center; justify-content: center; overflow: hidden; border-bottom: 1px solid var(--border); }
.ad .shot img { max-width: 100%; max-height: 100%; object-fit: contain; }
.ad .shot.empty { background: var(--surface-2); color: var(--text-muted); font-size: 12px; }
.ad .body { padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.ad .ttl { font-weight: 600; font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ad .dom { font-size: 12px; color: var(--good-text); }
.ad .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: auto; padding-top: 6px; font-size: 12px; color: var(--text-muted); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 18px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 50; }
.modal[hidden] { display: none; }
.modal .dialog { background: var(--surface-1); border-radius: 14px; width: min(1000px, 100%); padding: 20px 22px; box-shadow: 0 10px 40px rgba(0, 0, 0, .3); }
.modal .dialog.narrow { width: min(460px, 100%); }
.modal .head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.versions { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.version { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.version img { width: 100%; display: block; background: #fff; }
.version .txt { padding: 10px 12px; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.form-row label { font-size: 12px; color: var(--text-secondary); font-weight: 600; }
.error-text { color: var(--critical); font-size: 13px; }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login .card { width: 360px; text-align: center; padding: 32px 28px; }
.login .brand { justify-content: center; font-size: 20px; padding-bottom: 6px; }
.login p { color: var(--text-secondary); margin: 0 0 22px; }
.login #gbtn { display: flex; justify-content: center; min-height: 44px; }

@media (max-width: 900px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; }
    .brand { padding: 0 8px 0 0; }
    .nav { display: flex; gap: 2px; }
    .sidebar .user { margin-top: 0; margin-left: auto; padding: 0; }
    .sidebar .user .email { display: none; }
    main { padding: 16px; }
    .g2, .g3 { grid-template-columns: 1fr; }
}
