:root {
    --sd-red: #b51f1f;
    --sd-red-dark: #8f1818;
    --sd-black: #1a2327;
    --sd-ink: #263238;
    --sd-muted: #6d7a80;
    --sd-line: #d8dee2;
    --sd-soft: #f4f6f7;
    --sd-paper: #ffffff;
    --sd-gold: #aa7936;
    --sd-gold-soft: #ffdc88;
    --shadow: 0 20px 50px rgba(26, 35, 39, 0.12);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100%;
    margin: 0;
    background: var(--sd-soft);
    color: var(--sd-black);
    font-family: "Open Sans", Arial, Helvetica, sans-serif;
    line-height: 1.5;
}

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

a:hover {
    color: var(--sd-red-dark);
}

code {
    display: inline-block;
    max-width: 100%;
    padding: 3px 6px;
    overflow-wrap: anywhere;
    border-radius: 4px;
    background: var(--sd-soft);
}

img {
    max-width: 100%;
    display: block;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 28px;
    align-items: center;
    padding: 14px clamp(18px, 3vw, 44px);
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid rgba(26, 35, 39, 0.08);
    backdrop-filter: blur(18px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    color: var(--sd-black);
    font-weight: 800;
    letter-spacing: 0;
}

.brand img {
    width: 150px;
    height: 48px;
    object-fit: contain;
}

.brand span {
    padding-left: 14px;
    border-left: 3px solid var(--sd-red);
}

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

.nav-link {
    color: var(--sd-ink);
    padding: 10px 12px;
    border-radius: var(--radius);
    font-size: 0.94rem;
    font-weight: 700;
}

.nav-link:hover,
.nav-link.is-active {
    background: rgba(181, 31, 31, 0.08);
    color: var(--sd-red);
}

.session-box {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--sd-muted);
    font-size: 0.92rem;
}

.page-shell {
    width: min(1480px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 52px;
}

.auth-page,
.setup-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px;
    background:
        linear-gradient(135deg, rgba(26, 35, 39, 0.96), rgba(26, 35, 39, 0.84)),
        linear-gradient(90deg, transparent 0 68%, rgba(181, 31, 31, 0.38) 68% 72%, transparent 72%),
        var(--sd-black);
}

.auth-panel,
.setup-panel {
    width: min(980px, 100%);
    display: grid;
    grid-template-columns: minmax(260px, 0.9fr) minmax(320px, 1fr);
    background: var(--sd-paper);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.auth-brand,
.setup-brand {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 32px;
    padding: 34px;
    background: var(--sd-black);
    color: #fff;
}

.auth-brand img,
.setup-brand img {
    width: 220px;
    filter: brightness(0) invert(1);
}

.auth-brand h1,
.setup-brand h1,
.page-title h1,
.camera-title h1 {
    margin: 0;
    font-size: clamp(2rem, 4vw, 3.6rem);
    line-height: 1.02;
    letter-spacing: 0;
}

.auth-brand p,
.setup-brand p {
    margin: 0;
    color: rgba(255, 255, 255, 0.78);
    max-width: 34rem;
    font-family: "PT Serif", Georgia, serif;
}

.auth-form,
.setup-form {
    padding: 34px;
}

.setup-panel {
    grid-template-columns: minmax(260px, 0.6fr) minmax(420px, 1fr);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.field {
    display: grid;
    gap: 7px;
    margin-bottom: 16px;
}

.field-full {
    grid-column: 1 / -1;
}

label {
    color: var(--sd-ink);
    font-weight: 800;
    font-size: 0.88rem;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--sd-line);
    background: #fff;
    color: var(--sd-black);
    border-radius: var(--radius);
    padding: 12px 13px;
    font: inherit;
    outline: none;
}

input[type="checkbox"] {
    width: auto;
    accent-color: var(--sd-red);
}

textarea {
    min-height: 110px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--sd-red);
    box-shadow: 0 0 0 4px rgba(181, 31, 31, 0.12);
}

.hint,
.muted {
    color: var(--sd-muted);
    font-size: 0.9rem;
}

.page-title,
.camera-title {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 24px;
    margin-bottom: 24px;
}

.page-title p,
.camera-title p {
    max-width: 720px;
    margin: 8px 0 0;
    color: var(--sd-muted);
    font-family: "PT Serif", Georgia, serif;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.button,
button,
input[type="submit"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 10px 15px;
    background: var(--sd-red);
    color: #fff;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.button:hover,
button:hover,
input[type="submit"]:hover {
    background: var(--sd-red-dark);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(181, 31, 31, 0.18);
}

.button-secondary {
    background: var(--sd-black);
}

.button-secondary:hover {
    background: #0f171a;
}

.button-light {
    background: #fff;
    color: var(--sd-black);
    border-color: var(--sd-line);
}

.button-light:hover {
    background: var(--sd-soft);
    color: var(--sd-black);
    box-shadow: none;
}

.button-ghost {
    background: transparent;
    color: var(--sd-red);
    border-color: rgba(181, 31, 31, 0.28);
}

.button-ghost:hover {
    background: rgba(181, 31, 31, 0.08);
    color: var(--sd-red);
    box-shadow: none;
}

.button-danger {
    background: #922222;
}

.button-small {
    min-height: 34px;
    padding: 7px 10px;
    font-size: 0.86rem;
}

button:disabled,
.button[aria-disabled="true"] {
    opacity: 0.58;
    cursor: progress;
    transform: none;
}

.notice {
    margin-bottom: 18px;
    border-radius: var(--radius);
    padding: 14px 16px;
    background: #fff;
    border-left: 5px solid var(--sd-red);
    box-shadow: 0 8px 24px rgba(26, 35, 39, 0.06);
}

.notice-success {
    border-left-color: #1f8b4c;
}

.notice-danger {
    border-left-color: #b51f1f;
}

.notice-info {
    border-left-color: var(--sd-gold);
}

.metric-grid,
.camera-grid,
.admin-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
}

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

.panel,
.camera-card,
.metric,
.table-panel,
.timeline-day,
.job-card {
    background: var(--sd-paper);
    border: 1px solid rgba(26, 35, 39, 0.08);
    border-radius: var(--radius);
    box-shadow: 0 12px 34px rgba(26, 35, 39, 0.07);
}

.panel {
    padding: 22px;
}

.metric {
    padding: 20px;
}

.metric span {
    display: block;
    color: var(--sd-muted);
    font-size: 0.88rem;
    font-weight: 800;
}

.metric strong {
    display: block;
    margin-top: 6px;
    font-size: 2rem;
    line-height: 1;
}

.metric small {
    display: block;
    margin-top: 8px;
    color: var(--sd-muted);
}

.camera-card {
    overflow: hidden;
}

.camera-thumb {
    display: block;
    position: relative;
    aspect-ratio: 16 / 9;
    background: var(--sd-black);
    overflow: hidden;
}

.camera-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.camera-card:hover .camera-thumb img {
    transform: scale(1.025);
}

.camera-body {
    padding: 18px;
}

.camera-body h2 {
    margin: 0;
    font-size: 1.35rem;
}

.camera-body p {
    min-height: 2.8rem;
    margin: 8px 0 14px;
    color: var(--sd-muted);
}

.camera-meta,
.badge-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border-radius: 999px;
    padding: 6px 9px;
    background: var(--sd-soft);
    color: var(--sd-ink);
    font-size: 0.82rem;
    font-weight: 800;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--sd-muted);
}

.status-online .status-dot {
    background: #1f8b4c;
}

.status-delayed .status-dot {
    background: var(--sd-gold);
}

.status-offline .status-dot {
    background: var(--sd-red);
}

.hero-image {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius);
    background: var(--sd-black);
    box-shadow: var(--shadow);
}

.hero-image img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
}

.hero-overlay {
    position: absolute;
    left: 18px;
    bottom: 18px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.hero-overlay .badge {
    background: rgba(255, 255, 255, 0.92);
}

.camera-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.7fr) minmax(320px, 0.8fr);
    gap: 20px;
    align-items: start;
}

.side-stack {
    display: grid;
    gap: 18px;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: end;
}

.toolbar .field {
    min-width: 180px;
    margin-bottom: 0;
}

.progress {
    width: 100%;
    height: 12px;
    border-radius: 999px;
    overflow: hidden;
    background: #e9eef1;
}

.progress-bar {
    width: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--sd-red), var(--sd-gold));
    transition: width 0.25s ease;
}

.timeline {
    display: grid;
    gap: 16px;
    margin-top: 22px;
}

.timeline-day {
    overflow: hidden;
}

.timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 15px 18px;
    background: #fff;
    border-bottom: 1px solid var(--sd-line);
}

.timeline-header h2 {
    margin: 0;
    font-size: 1.08rem;
}

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

.image-tile {
    display: grid;
    gap: 8px;
    color: var(--sd-black);
}

.image-tile img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: var(--radius);
    background: var(--sd-black);
}

.image-tile small {
    color: var(--sd-muted);
}

.pagination {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 24px;
}

.pagination a,
.pagination span {
    min-width: 38px;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    background: #fff;
    border: 1px solid var(--sd-line);
    color: var(--sd-ink);
    font-weight: 800;
}

.pagination .active {
    background: var(--sd-red);
    border-color: var(--sd-red);
    color: #fff;
}

.table-panel {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

th,
td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--sd-line);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--sd-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0;
}

tr:last-child td {
    border-bottom: 0;
}

.empty-state {
    padding: 36px;
    text-align: center;
    color: var(--sd-muted);
    background: #fff;
    border: 1px dashed var(--sd-line);
    border-radius: var(--radius);
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 28px;
    background: rgba(7, 12, 14, 0.88);
}

.lightbox[hidden] {
    display: none;
}

.lightbox img {
    max-height: calc(100vh - 60px);
    max-width: calc(100vw - 60px);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.icon-button {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    padding: 0;
}

.lightbox-close {
    position: absolute;
    top: 18px;
    right: 18px;
    background: #fff;
    color: var(--sd-black);
    font-size: 1.6rem;
}

.job-card {
    padding: 18px;
}

.job-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 10px 0;
}

.live-panel {
    border-top: 4px solid var(--sd-red);
}

.video-frame {
    width: 100%;
    aspect-ratio: 16 / 9;
    border: 0;
    border-radius: var(--radius);
    background: var(--sd-black);
}

.near-live-image[data-stale="true"] {
    filter: saturate(0.8);
}

@media (max-width: 980px) {
    .topbar {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .session-box {
        justify-content: space-between;
    }

    .auth-panel,
    .setup-panel,
    .camera-layout,
    .metric-grid,
    .admin-grid {
        grid-template-columns: 1fr;
    }

    .page-title,
    .camera-title {
        align-items: start;
        flex-direction: column;
    }
}

@media (max-width: 620px) {
    .page-shell {
        width: min(100% - 22px, 1480px);
        padding-top: 18px;
    }

    .brand img {
        width: 124px;
        height: 40px;
    }

    .brand span {
        font-size: 0.9rem;
    }

    .main-nav,
    .actions,
    .toolbar {
        width: 100%;
    }

    .nav-link,
    .button,
    button {
        flex: 1 1 auto;
    }

    .form-grid,
    .camera-grid {
        grid-template-columns: 1fr;
    }

    .auth-page,
    .setup-page {
        padding: 12px;
    }

    .auth-brand,
    .setup-brand,
    .auth-form,
    .setup-form {
        padding: 24px;
    }
}
