:root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c2330;
    --border: #2a3140;
    --border-strong: #3a4354;
    --text: #e6ebf2;
    --text-muted: #8b98a9;
    --text-faint: #5b6675;
    --accent: #4f8cff;
    --accent-hover: #6da0ff;
    --red: #ef4444;
    --orange: #f59e0b;
    --green: #10b981;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
    --mono: ui-monospace, 'SF Mono', 'Cascadia Mono', Menlo, Consolas, monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.45;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

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

a:hover {
    color: var(--accent-hover);
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

::selection {
    background: rgba(79, 140, 255, 0.35);
}

.topbar {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 10px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--text);
}

.brand img {
    width: 22px;
    height: 22px;
    display: block;
}

.brand:hover {
    color: var(--text);
}

.nav-tabs {
    display: flex;
    gap: 4px;
}

.nav-tabs a {
    padding: 6px 14px;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.92rem;
    transition: background 0.15s, color 0.15s;
}

.nav-tabs a:hover {
    background: var(--surface-2);
    color: var(--text);
}

.nav-tabs a.active {
    background: var(--surface-2);
    color: var(--text);
    font-weight: 600;
}

.topbar-spacer {
    flex: 1;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    color: var(--text);
    font: inherit;
    font-size: 0.88rem;
    padding: 7px 16px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.btn:hover {
    background: #232c3b;
    border-color: var(--border-strong);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-muted);
}

.btn-ghost:hover {
    background: var(--surface-2);
    color: var(--text);
}

.page {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.page-pad {
    padding: 18px 20px;
}

.pillbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(22, 27, 34, 0.6);
    flex-shrink: 0;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 11px;
    font-family: var(--mono);
    font-size: 0.72rem;
    color: var(--text-faint);
    white-space: nowrap;
}

.pillbar-spacer {
    flex: 1;
}

.layout-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 10px;
    font-family: var(--mono);
    font-size: 0.72rem;
    color: var(--text-faint);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.layout-btn:hover {
    background: var(--surface-2);
    color: var(--text-muted);
}

.layout-btn.active {
    background: var(--surface-2);
    border-color: var(--accent);
    color: var(--text);
}

.badge-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #333c49;
    flex-shrink: 0;
    transition: background 0.3s, box-shadow 0.3s;
}

.badge-dot.motion {
    background: var(--red);
    box-shadow: 0 0 6px rgba(239, 68, 68, 0.7);
}

.badge-dot.pending {
    background: var(--orange);
}

.badge-dot.stale {
    background: #444d5a;
    outline: 2px dotted var(--red);
    outline-offset: 1px;
}

.object-chip {
    padding: 1px 7px;
    border-radius: 4px;
    background: var(--green);
    color: #fff;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    display: none;
}

.object-chip.active {
    display: inline-block;
}

.timing-text {
    color: var(--text-faint);
    font-family: var(--mono);
    font-size: 0.7rem;
}

.tile-grid {
    display: grid;
    gap: 14px;
    padding: 16px 20px;
}

.tile-grid.layout-grid {
    grid-template-columns: repeat(var(--cols, 1), 1fr);
    grid-template-rows: repeat(var(--rows, 1), var(--row-h, auto));
    justify-items: stretch;
    align-items: stretch;
}

.tile-grid.layout-stack {
    grid-template-columns: 1fr;
    max-width: 960px;
    margin-left: auto;
    margin-right: auto;
}

.tile-grid.layout-row {
    grid-template-columns: repeat(var(--cam-count, 1), 1fr);
    grid-template-rows: auto;
    overflow-x: auto;
    padding-bottom: 8px;
    align-items: start;
}

.tile {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: border-color 0.15s, transform 0.15s, opacity 0.3s;
    display: flex;
    flex-direction: column;
}

.tile:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.tile.offline {
    opacity: 0.55;
}

.tile-link {
    display: block;
    aspect-ratio: 16 / 9;
    background: #000;
    flex: 1;
    min-height: 0;
}

.layout-grid .tile-link {
    aspect-ratio: unset;
    width: 100%;
    height: 100%;
}

.tile-link img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.tile-overlay {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 8px;
    padding: 22px 12px 9px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
    pointer-events: none;
}

.tile-name {
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.tile-badges {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 20px;
}

.cam-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 5px 14px;
    color: var(--text-muted);
    font-size: 0.85rem;
    transition: border-color 0.15s, color 0.15s;
}

.cam-chip:hover {
    border-color: var(--accent);
    color: var(--text);
}

.cam-chip.current {
    border-color: var(--accent);
    color: var(--text);
    font-weight: 600;
}

.feed-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    background: #000;
    position: relative;
}

.feed-wrap img {
    max-width: 100%;
    max-height: 100%;
    display: block;
    object-fit: contain;
}

.placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    color: var(--text-faint);
    font-size: 1.05rem;
    z-index: 1;
    transition: opacity 0.4s;
}

.placeholder.hidden {
    opacity: 0;
    pointer-events: none;
}

.motion-badge {
    position: absolute;
    top: 12px;
    left: 12px;
    padding: 4px 11px;
    border-radius: 5px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    z-index: 2;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.motion-badge.active {
    opacity: 1;
}

.motion-badge.motion {
    background: var(--red);
    color: #fff;
}

.motion-badge.pending {
    background: var(--orange);
    color: #fff;
}

.object-badge {
    position: absolute;
    top: 46px;
    left: 12px;
    padding: 4px 11px;
    border-radius: 5px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    z-index: 2;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    background: var(--green);
    color: #fff;
}

.object-badge.active {
    opacity: 1;
}

.timing-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    padding: 4px 9px;
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.65);
    color: var(--text-muted);
    font-family: var(--mono);
    font-size: 0.73rem;
    z-index: 2;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.timing-badge.active {
    opacity: 1;
}

.camera-stats {
    width: 100%;
    padding: 6px 20px;
    font-family: var(--mono);
    font-size: 0.72rem;
    color: var(--text-faint);
    flex-shrink: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.camera-stats .warn {
    color: var(--orange);
}

.camera-stats .err {
    color: var(--red);
}

.camera-stats .ok {
    color: var(--green);
}

.player-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 10px 14px;
    gap: 8px;
    min-height: 0;
    width: 100%;
}

.video-container {
    flex: 1;
    min-height: 0;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-container video {
    max-width: 100%;
    max-height: 100%;
    display: block;
    object-fit: contain;
}

.controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.controls button {
    min-width: 90px;
    text-align: center;
}

.controls .spacer {
    flex: 1;
}

.controls .time-display {
    font-family: var(--mono);
    font-size: 0.88rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.timeline-wrap {
    position: relative;
    width: 100%;
    flex-shrink: 0;
}

.timeline-wrap canvas {
    width: 100%;
    display: block;
    cursor: grab;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    touch-action: none;
}

.timeline-wrap canvas:active {
    cursor: grabbing;
}

.tooltip {
    position: absolute;
    background: rgba(13, 17, 23, 0.95);
    color: var(--text);
    padding: 4px 9px;
    border-radius: 5px;
    font-size: 0.8rem;
    pointer-events: none;
    white-space: nowrap;
    display: none;
    z-index: 10;
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow);
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
}

.legend-item.selected {
    outline: 2px solid #fff;
    outline-offset: 1px;
}

.legend-item.deselected {
    opacity: 0.4;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}

.loading,
.error,
.no-data,
.no-files {
    padding: 40px;
    text-align: center;
    color: var(--text-faint);
}

.selector-bar {
    padding: 12px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.selector-bar select {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border-strong);
    padding: 7px 10px;
    border-radius: var(--radius);
    font: inherit;
    font-size: 0.9rem;
    width: 100%;
    max-width: 420px;
}

.video-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
}

.video-center video {
    max-width: 100%;
    max-height: 100%;
    display: block;
    background: #000;
    border-radius: var(--radius);
}

.date-nav {
    display: flex;
    align-items: center;
    gap: 6px;
}

.header-select {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border-strong);
    padding: 6px 10px;
    border-radius: var(--radius);
    font: inherit;
    font-size: 0.9rem;
    cursor: pointer;
}

.date-nav input[type="date"] {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border-strong);
    padding: 6px 10px;
    border-radius: var(--radius);
    font: inherit;
    font-size: 0.9rem;
    color-scheme: dark;
}

.icon-btn {
    background: var(--surface-2);
    color: var(--text-muted);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    font: inherit;
    font-size: 0.9rem;
    padding: 6px 12px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
    background: #232c3b;
    color: var(--text);
}

.footer {
    padding: 10px 20px;
    color: var(--text-faint);
    font-size: 0.75rem;
    text-align: center;
    flex-shrink: 0;
}

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background:
        radial-gradient(ellipse 80% 50% at 50% -10%, rgba(79, 140, 255, 0.12), transparent),
        var(--bg);
}

.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 36px 32px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-bottom: 26px;
}

.login-brand img {
    width: 44px;
    height: 44px;
}

.login-brand h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.03em;
}

.login-subtitle {
    color: var(--text-faint);
    font-size: 0.82rem;
    margin-top: -4px;
}

.form-field {
    margin-bottom: 16px;
}

.form-field label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.form-field input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    color: var(--text);
    font: inherit;
    padding: 10px 12px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-field input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.25);
}

.login-error {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.45);
    color: #fca5a5;
    border-radius: var(--radius);
    padding: 9px 13px;
    font-size: 0.84rem;
    margin-bottom: 16px;
}

.login-submit {
    width: 100%;
    padding: 11px;
    font-size: 0.95rem;
    margin-top: 6px;
}

@media (max-width: 640px) {
    .topbar {
        padding: 10px 12px;
        gap: 10px;
    }

    .nav-tabs a {
        padding: 6px 9px;
        font-size: 0.85rem;
    }

    .tile-grid {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto !important;
        padding: 12px;
        gap: 10px;
    }

    .tile-grid.layout-grid {
        --cols: 1;
        --rows: auto;
    }

    .layout-btn {
        display: none;
    }

    .pillbar {
        padding: 8px 12px;
        gap: 6px;
    }

.toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.toolbar .spacer {
    flex: 1;
}

.player-wrap {
        padding: 8px 10px;
    }
}
