/* CAMeníček 2.0 */

:root {
    --bg: #f3f4f9;
    --surface: #ffffff;
    --surface-2: #f6f7fb;
    --border: #e3e5ef;
    --text: #1b1d2a;
    --muted: #6b6f85;
    --faint: #9a9db0;
    --brand-1: #280d6e;
    --brand-2: #72acf2;
    --accent: #4b5bdc;
    --cold: #2f7fe0;
    --ok: #17915a;
    --hot: #e2620f;
    --warn: #b7791f;
    --danger: #d23b3b;
    --comfort: rgba(23, 145, 90, 0.07);
    --grid: rgba(27, 29, 42, 0.07);
    --shadow: 0 1px 2px rgba(20, 22, 40, .05), 0 4px 16px rgba(20, 22, 40, .06);
    --radius: 14px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0d0f1c;
        --surface: #161a2c;
        --surface-2: #1c2136;
        --border: #272c45;
        --text: #e8eaf5;
        --muted: #a0a5c0;
        --faint: #6f7491;
        --accent: #8b97ff;
        --cold: #5ea4ff;
        --ok: #3cc985;
        --hot: #ff8a3d;
        --warn: #f0b44c;
        --danger: #ff6b6b;
        --comfort: rgba(60, 201, 133, 0.08);
        --grid: rgba(232, 234, 245, 0.08);
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --bg: #0d0f1c;
    --surface: #161a2c;
    --surface-2: #1c2136;
    --border: #272c45;
    --text: #e8eaf5;
    --muted: #a0a5c0;
    --faint: #6f7491;
    --accent: #8b97ff;
    --cold: #5ea4ff;
    --ok: #3cc985;
    --hot: #ff8a3d;
    --warn: #f0b44c;
    --danger: #ff6b6b;
    --comfort: rgba(60, 201, 133, 0.08);
    --grid: rgba(232, 234, 245, 0.08);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}
h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- horní lišta ---------- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    background: linear-gradient(110deg, var(--brand-1) 0%, #3f2a9b 45%, var(--brand-2) 130%);
    color: #fff;
    padding-top: env(safe-area-inset-top);
}
.topbar-in {
    max-width: 1200px; margin: 0 auto; padding: 12px 16px;
    display: flex; align-items: center; gap: 16px;
}
.brand { display: inline-flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; }
.brand-mark {
    display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
    background: rgba(255, 255, 255, .16);
}
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: -0.02em; }
.brand-ver {
    font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px;
    background: rgba(255, 255, 255, .2);
}
.topbar-status { flex: 1; font-size: 13px; opacity: .9; display: flex; gap: 14px; flex-wrap: wrap; }
.topbar-status .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #5ff0a8; margin-right: 6px; vertical-align: 1px; }
.topbar-status .dot.bad { background: #ffb4a8; }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
    display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
    border: 0; background: transparent; cursor: pointer; color: inherit;
}
.icon-btn svg { width: 20px; height: 20px; }
.topbar .icon-btn:hover { background: rgba(255, 255, 255, .15); }
#tema-btn svg { display: none; }
#tema-btn[data-tema="auto"] .ico-auto, #tema-btn[data-tema="light"] .ico-light, #tema-btn[data-tema="dark"] .ico-dark { display: block; }

/* ---------- stránka ---------- */
.page { max-width: 1200px; margin: 0 auto; padding: 20px 16px calc(32px + env(safe-area-inset-bottom)); }
.section { margin-bottom: 32px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.section-head h2 { font-size: 18px; }
.hint { color: var(--faint); font-size: 13px; }
.grid { display: grid; gap: 14px; }
.cards { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.cams { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 14px 8px; box-shadow: var(--shadow); }
.foot { text-align: center; color: var(--faint); font-size: 12px; padding-top: 8px; }

.offline-banner {
    background: var(--danger); color: #fff; border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; font-weight: 500;
}
.alerts {
    --alert: var(--warn);
    margin: 0 0 20px; background: var(--surface); border: 1px solid var(--border);
    border-left: 4px solid var(--alert); border-radius: 10px; font-size: 14px;
}
.alerts.danger { --alert: var(--danger); }
.alerts summary {
    display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer;
    list-style: none; user-select: none;
}
.alerts summary::-webkit-details-marker { display: none; }
.alerts-ico {
    flex: none; display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%;
    background: var(--alert); color: #fff; font-size: 12px; font-weight: 700;
}
.alerts-text { flex: 1; min-width: 0; display: flex; gap: 8px; white-space: nowrap; }
.alerts-text b { font-weight: 600; }
.alerts-names { overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.alerts-chev { flex: none; width: 18px; height: 18px; color: var(--muted); transition: transform .15s ease; }
.alerts[open] .alerts-chev { transform: rotate(180deg); }
.alerts[open] .alerts-names { visibility: hidden; }
.alerts ul { list-style: none; margin: 0; padding: 0 12px 8px 40px; display: grid; gap: 4px; }
.alerts li { display: flex; gap: 8px; font-size: 13px; color: var(--muted); line-height: 1.4; }
.alerts li::before { content: ""; flex: none; width: 6px; height: 6px; margin-top: 6px; border-radius: 50%; background: var(--warn); }
.alerts li.danger::before { background: var(--danger); }
.alerts li strong { color: var(--text); font-weight: 600; white-space: nowrap; }

/* ---------- karta čidla ---------- */
.card {
    position: relative; text-align: left; cursor: pointer;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 14px 16px 12px; box-shadow: var(--shadow);
    transition: transform .15s ease, border-color .15s ease;
    display: flex; flex-direction: column; gap: 6px; width: 100%;
}
.card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-name { font-weight: 600; font-size: 15px; }
.card-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.status { display: inline-flex; align-items: center; gap: 5px; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.status.off::before { background: var(--danger); }
.card-temp { display: flex; align-items: baseline; gap: 10px; margin-top: 2px; }
.card-temp .val { font-size: 40px; font-weight: 600; letter-spacing: -0.03em; line-height: 1.05; }
.card-temp .val small { font-size: 18px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.card.offline .card-temp .val { color: var(--faint); }
.pill { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.pill.zima { color: var(--cold); background: color-mix(in srgb, var(--cold) 12%, transparent); }
.pill.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.pill.hic { color: var(--hot); background: color-mix(in srgb, var(--hot) 13%, transparent); }
.trend { font-size: 13px; color: var(--muted); white-space: nowrap; }
.trend.up { color: var(--hot); }
.trend.down { color: var(--cold); }
.spark { width: 100%; height: 44px; display: block; margin: 2px 0; }
.card-bottom { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); }
.card-bottom b { color: var(--text); font-weight: 600; }

.batt { display: inline-flex; align-items: center; gap: 4px; }
.batt-ico { position: relative; width: 20px; height: 10px; border: 1.5px solid currentColor; border-radius: 2.5px; }
.batt-ico::after { content: ""; position: absolute; right: -4px; top: 2px; width: 2px; height: 3px; background: currentColor; border-radius: 0 1px 1px 0; }
.batt-ico i { position: absolute; left: 1px; top: 1px; bottom: 1px; border-radius: 1px; background: var(--ok); }
.batt.ctvrt .batt-ico i, .batt.pul .batt-ico i { background: var(--warn); }
.batt.prazdna .batt-ico i { background: var(--danger); }
.batt.prazdna, .batt.ctvrt { color: var(--danger); }

/* ---------- přepínač rozsahu ---------- */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

/* ---------- grafy ---------- */
.chart { position: relative; min-height: 280px; }
.chart-lg { min-height: 320px; }
.chart-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--faint); font-size: 14px; }
.chart-hint { color: var(--faint); font-size: 12px; margin: 6px 2px 4px; }
.uplot { font-family: inherit; }
.uplot .u-legend { font-size: 13px; color: var(--muted); margin-top: 4px; }
.uplot .u-legend .u-marker { border-radius: 3px; }
.uplot .u-select { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.tt {
    position: absolute; z-index: 5; pointer-events: none; white-space: nowrap;
    background: var(--surface); color: var(--text); border: 1px solid var(--border);
    border-radius: 8px; padding: 6px 9px; font-size: 12px; box-shadow: var(--shadow);
}
.tt b { font-weight: 600; }
.tt .row { display: flex; align-items: center; gap: 6px; }
.tt .sw { width: 8px; height: 8px; border-radius: 2px; }

/* ---------- kamery ---------- */
.cam {
    position: relative; overflow: hidden; cursor: zoom-in; padding: 0; text-align: left;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.cam img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--surface-2); }
.cam-bar { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; }
.cam-bar .card-name { font-size: 14px; }
.live {
    position: absolute; top: 10px; left: 10px; font-size: 11px; font-weight: 700; letter-spacing: .04em;
    color: #fff; background: rgba(210, 40, 40, .9); padding: 3px 8px; border-radius: 6px;
}
.live.off { background: rgba(30, 30, 40, .75); font-weight: 600; letter-spacing: 0; }
.live::before { content: "● "; }
.live.off::before { content: ""; }
.cam.loading .live::before { animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }

/* ---------- modální okna ---------- */
.modal {
    border: 0; padding: 0; background: transparent; color: var(--text);
    width: min(980px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
}
.modal::backdrop { background: rgba(8, 10, 24, .55); backdrop-filter: blur(3px); }
.modal-in {
    background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
    padding: 18px 20px 14px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.modal-head h3 { font-size: 20px; }
.modal .icon-btn:hover { background: var(--surface-2); }
.detail-now { color: var(--muted); font-size: 14px; margin-top: 2px; }
.detail-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.day-pick { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.day-pick input {
    font: inherit; font-size: 13px; color: var(--text); background: var(--surface-2);
    border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px;
}
.day-pick.on input { border-color: var(--accent); }
.btn-ghost {
    display: inline-flex; align-items: center; gap: 6px; margin-left: auto;
    border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px;
    padding: 5px 10px; font-size: 13px; font-weight: 500; cursor: pointer;
}
.btn-ghost:hover { border-color: var(--accent); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 10px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 8px 12px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 20px; font-weight: 600; }
.stat .s { font-size: 12px; color: var(--faint); }
.stat.min .v { color: var(--cold); }
.stat.max .v { color: var(--hot); }
.modal-cam { width: min(1200px, calc(100vw - 24px)); }
.modal-cam img { display: block; width: 100%; max-height: calc(100dvh - 130px); object-fit: contain; border-radius: 10px; background: #000; }
.modal-cam iframe { display: block; width: 100%; aspect-ratio: 16 / 9; max-height: calc(100dvh - 130px); border: 0; border-radius: 10px; background: #000; }
.modal-actions { display: flex; align-items: center; gap: 8px; }
.live-chip {
    display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600;
    color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent);
    padding: 2px 8px; border-radius: 99px; margin-left: 8px;
}
.live-chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: blink 1.4s infinite; }

/* ---------- přihlášení ---------- */
.login-page {
    min-height: 100dvh; display: grid; place-items: center; padding: 16px;
    background: linear-gradient(45deg, var(--brand-1) 0%, var(--brand-2) 100%);
}
.login-card {
    width: 100%; max-width: 380px; background: var(--surface); border-radius: 20px;
    padding: 28px 24px 24px; box-shadow: 0 24px 60px rgba(10, 8, 40, .35);
}
.login-card .brand { color: var(--brand-1); }
:root[data-theme="dark"] .login-card .brand { color: var(--text); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .login-card .brand { color: var(--text); } }
.login-card .brand-mark { background: color-mix(in srgb, var(--brand-2) 22%, transparent); }
.login-card .brand-ver { background: color-mix(in srgb, var(--brand-2) 25%, transparent); }
.brand-lg .brand-name { font-size: 22px; }
.login-sub { color: var(--muted); margin: 8px 0 20px; font-size: 14px; }
.login-card form { display: grid; gap: 14px; }
.login-card label { display: grid; gap: 5px; font-size: 13px; font-weight: 500; color: var(--muted); }
.login-card input[type=text], .login-card input[type=password] {
    font: inherit; color: var(--text); background: var(--surface-2);
    border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px;
}
.login-card input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); border-color: var(--accent); }
.btn-primary {
    margin-top: 4px; border: 0; border-radius: 10px; padding: 12px; cursor: pointer;
    font-weight: 600; color: #fff; background: linear-gradient(110deg, var(--brand-1), #4a36b8);
}
.btn-primary:hover { filter: brightness(1.12); }
.login-error {
    background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger);
    border-radius: 10px; padding: 9px 12px; font-size: 14px; margin-bottom: 14px; font-weight: 500;
}

/* ---------- mobil ---------- */
@media (max-width: 640px) {
    .topbar-in { flex-wrap: wrap; gap: 6px 10px; padding: 10px 16px; }
    .topbar-status { order: 3; flex-basis: 100%; font-size: 12px; gap: 10px; }
    .brand { flex: 1; }
    .cams { grid-template-columns: 1fr; }
    .card-temp .val { font-size: 36px; }
    .hint { display: none; }
    .modal { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; margin: 0; }
    .modal-in { border-radius: 0; min-height: 100%; padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); }
    .chart, .chart-lg { min-height: 240px; }
    .stats .stat { padding: 7px 9px; }
    .stat .v { font-size: 17px; }
    .btn-ghost { margin-left: 0; }
}
