:root {
    --bg: #101216;
    --panel: #181b21;
    --panel-2: #1f242c;
    --line: #2a3038;
    --text: #e6e8ec;
    --muted: #9aa3af;
    --accent: #4f9dff;
    --bad: #e0574c;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* the hidden attribute always wins over a class's display */

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 5;
}

header h1 {
    font-size: 16px;
    letter-spacing: .14em;
    text-transform: uppercase;
    margin: 0;
    font-weight: 600;
}

.spacer { flex: 1; }
.who { color: var(--muted); }

header nav {
    display: flex;
    gap: 4px;
    margin-left: 8px;
}

header nav a {
    color: var(--muted);
    text-decoration: none;
    padding: 5px 10px;
    border-radius: 7px;
    font-size: 14px;
}
header nav a:hover { color: var(--text); background: var(--panel-2); }
header nav a.current { color: var(--text); background: var(--panel-2); }

.button {
    color: var(--text);
    text-decoration: none;
    border: 1px solid var(--line);
    background: var(--panel-2);
    border-radius: 7px;
    padding: 6px 12px;
    font-size: 13px;
}
.button:hover { border-color: var(--accent); }

/* ---------------------------------------------------------------- camera grid */

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 12px;
    padding: 12px;
}

.tile {
    margin: 0;
    background: #000;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    cursor: pointer;
}

.tile video {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: contain;
    background: #000;
}

.tile figcaption {
    display: flex;
    gap: 10px;
    align-items: baseline;
    padding: 7px 10px;
    background: var(--panel);
    border-top: 1px solid var(--line);
    font-size: 13px;
}

.tile .label { font-weight: 600; }
.tile .meta { color: var(--muted); font-size: 12px; margin-left: auto; font-variant-numeric: tabular-nums; }

.overlay {
    position: absolute;
    inset: 0 0 34px 0;
    display: grid;
    place-items: center;
    pointer-events: none;
}

.state {
    font-size: 13px;
    color: var(--muted);
    background: rgba(0, 0, 0, .6);
    padding: 5px 12px;
    border-radius: 999px;
}
.state:empty { display: none; }

.tile[data-state="error"] .state { color: var(--bad); }

/* clicking a tile blows it up; the others shrink out of the way */
body.has-focus .grid { grid-template-columns: 1fr; }
body.has-focus .tile:not(.focused) { display: none; }
body.has-focus .tile.focused video { aspect-ratio: auto; max-height: calc(100vh - 110px); }

.empty {
    color: var(--muted);
    padding: 24px;
    text-align: center;
}

/* ----------------------------------------------------------------- recordings */

.viewer {
    background: #000;
    border-bottom: 1px solid var(--line);
}

.viewer video {
    display: block;
    width: 100%;
    min-height: 240px;
    max-height: min(70vh, 720px);
    background: #000;
}

/* speed / direction bar: rewind on the left, fast-forward on the right */
.speeds {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    padding: 8px 12px;
    background: var(--panel);
    border-top: 1px solid var(--line);
}

.speeds button.speed {
    cursor: pointer;
    font-family: inherit;
    color: var(--muted);
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 5px 9px;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    min-width: 42px;
}
.speeds button.speed:hover { color: var(--text); border-color: var(--accent); }
.speeds button.speed.current {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

.viewer-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--panel);
    border-top: 1px solid var(--line);
    font-size: 14px;
}

.state-inline { color: var(--muted); font-size: 13px; }

.clock {
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    font-size: 13px;
}

.viewer-bar button.button { cursor: pointer; font-family: inherit; }

.recordings {
    padding: 12px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
    gap: 12px;
    align-items: start;
}

.rec-camera {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px 14px 14px;
}

.rec-camera h2 {
    margin: 0 0 10px;
    font-size: 15px;
}

.muted { color: var(--muted); font-size: 13px; margin: 0; }

ul.days {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 480px;
    overflow-y: auto;
}

ul.days button {
    width: 100%;
    display: flex;
    align-items: baseline;
    gap: 10px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--text);
    padding: 8px 10px;
    font: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}
ul.days button:hover { border-color: var(--accent); }
ul.days .d { white-space: nowrap; }
ul.days .m { color: var(--muted); font-size: 12px; margin-left: auto; white-space: nowrap; }

/* -------------------------------------------------------------------- sign in */

.login-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
}

.login {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 28px;
    width: min(340px, calc(100vw - 32px));
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login h1 {
    margin: 0 0 6px;
    font-size: 18px;
    letter-spacing: .16em;
    text-transform: uppercase;
    text-align: center;
}

.login label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 13px;
    color: var(--muted);
}

.login input {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--text);
    padding: 9px 11px;
    font-size: 15px;
}
.login input:focus { outline: none; border-color: var(--accent); }

.login button {
    margin-top: 4px;
    background: var(--accent);
    color: #06101d;
    border: 0;
    border-radius: 7px;
    padding: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.error {
    margin: 0;
    color: var(--bad);
    font-size: 13px;
    text-align: center;
}

/* a camera whose recordings are replicated from another server */
.rec-camera h2 .via {
    margin-left: 8px;
    font-size: 12px;
    font-weight: 400;
    color: var(--muted);
}

/* ------------------------------------------------------------------- send page */

.send {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(280px, 2fr);
    gap: 16px;
    padding: 16px;
    max-width: 1400px;
    margin: 0 auto;
}
@media (max-width: 800px) {
    .send { grid-template-columns: 1fr; padding: 12px; }
}

.send-preview {
    position: relative;
    background: #000;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    align-self: start;
}
.send-preview video {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: contain;
    background: #000;
}
.send-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    background: var(--bad);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .08em;
    padding: 3px 8px;
    border-radius: 4px;
}

.send-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-self: start;
}
.send-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}
.send-grid label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--muted);
}
.send-grid select {
    font: inherit;
    font-size: 14px;
    color: var(--text);
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 6px 8px;
}
.send-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.send-actions .button { cursor: pointer; font-family: inherit; font-size: 14px; padding: 8px 14px; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button:disabled { opacity: .5; cursor: not-allowed; }
.send-support, .send-hint { font-size: 12px; color: var(--muted); margin: 0; }
.send-status { margin: 0; font-size: 14px; }
.send-status.problem { color: var(--bad); }
.send-stats { margin: 0; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.send-warning {
    margin: 0;
    padding: 10px 12px;
    border: 1px solid var(--bad);
    border-radius: 7px;
    color: var(--text);
    font-size: 13px;
}

/* narrow phones: three nav links, the user name and "Sign out" must fit in one row */
header .button { white-space: nowrap; }
@media (max-width: 480px) {
    header { gap: 6px; padding: 8px 10px; }
    header h1 { font-size: 14px; letter-spacing: .08em; }
    header nav { margin-left: 0; gap: 0; }
    header nav a { padding: 5px 7px; }
    .who { display: none; }
}

/* "Dim screen" while sending: the screen stays on (so the camera keeps
   running) but shows black - saves battery on OLED phones and is less
   conspicuous. A tap brings the page back. */
.send-dimmer {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: #000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 24px;
}
.send-dimmer span { color: #333; font-size: 13px; }
.send-dimmer[hidden] { display: none; }            /* display:flex above would otherwise override hidden */

/* bottom of the recordings page: disk use */
.storage {
    max-width: 640px;
    margin: 8px auto 0;
    padding: 0 16px;
}
.storage-bar {
    display: flex;
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    background: var(--panel-2);           /* the free part */
    border: 1px solid var(--line);
}
.storage-bar .seg { display: block; height: 100%; }
.storage-bar .rec { background: var(--accent); }
.storage-bar .other { background: var(--muted); opacity: .45; }
.storage-text {
    margin: 6px 0 0;
    text-align: center;
    font-size: 13px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}
.storage-text .key {
    display: inline-block;
    width: 9px;
    height: 9px;
    margin-right: 6px;
    border-radius: 2px;
    background: var(--accent);
}
.storage.low .storage-text { color: var(--bad); }
.storage.low .storage-bar { border-color: var(--bad); }

/* live tile: sound on/off, only for cameras that send sound (all start muted) */
.tile .sound {
    font: inherit;
    font-size: 12px;
    color: var(--muted);
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 1px 8px;
    cursor: pointer;
}
.tile .sound:hover { color: var(--text); border-color: var(--accent); }
.tile .sound.on { color: #fff; background: var(--accent); border-color: var(--accent); }

/* thermal cameras: the temperature view drawn over the picture */
.thermal-layer {
    position: absolute;
    pointer-events: none;
    z-index: 2;
}
.viewer { position: relative; }
.tile .thermal {
    font: inherit;
    font-size: 12px;
    color: var(--muted);
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 1px 8px;
    cursor: pointer;
}
.tile .thermal:hover { color: var(--text); border-color: var(--accent); }
.tile .thermal.on { color: #fff; background: var(--accent); border-color: var(--accent); }

/* a live camera of another server (arrives with the backup) */
.tile .label .via {
    white-space: nowrap;
    margin-left: 6px;
    font-size: 12px;
    font-weight: 400;
    color: var(--muted);
}
