:root {
    --bg: #edf2f4;
    --panel: #ffffff;
    --panel-alt: #dce7f4;
    --text: #18212a;
    --muted: #5e6b78;
    --line: #c9d4dc;
    --accent: #2563eb;
    --accent-soft: #dbeafe;
    --danger: #c2410c;
    --danger-soft: #fce7d6;
    --nav: #10233f;
    --shadow: 0 18px 48px rgba(15, 23, 35, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, 0.15), transparent 28%),
        linear-gradient(180deg, #f7fbfc 0%, var(--bg) 100%);
    color: var(--text);
    font-family: "Segoe UI", "Helvetica Neue", sans-serif;
}

body.has-modal {
    overflow: hidden;
}

a {
    color: inherit;
    text-decoration: none;
}

.shell {
    min-height: 100vh;
    padding: 24px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    padding: 18px 22px;
    background: var(--nav);
    color: #f8fafc;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-link {
    border-radius: 8px;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.brand-link:hover {
    opacity: 0.96;
}

.brand-link:focus-visible {
    outline: 2px solid rgba(191, 219, 254, 0.95);
    outline-offset: 4px;
}

.brand strong {
    display: block;
    font-size: 18px;
}

.brand p {
    margin: 2px 0 0;
    color: rgba(248, 250, 252, 0.7);
    font-size: 14px;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 8px;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: #fff;
    font-weight: 700;
    letter-spacing: 0;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.brand-mark--image {
    display: block;
    object-fit: cover;
    padding: 0;
    background: transparent;
    box-shadow: none;
}

.nav {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.nav-toggle {
    display: none;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid rgba(248, 250, 252, 0.16);
    border-radius: 8px;
    background: rgba(248, 250, 252, 0.08);
    color: #f8fafc;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
}

.nav-toggle span {
    display: block;
    width: 18px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
}

.nav-link {
    padding: 10px 14px;
    border-radius: 8px;
    color: rgba(248, 250, 252, 0.75);
    border: 1px solid rgba(248, 250, 252, 0.14);
}

.nav-link.is-active {
    color: #fff;
    background: rgba(248, 250, 252, 0.12);
}

.content {
    margin-top: 24px;
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 20px;
    margin-bottom: 18px;
}

.page-head h1 {
    margin: 0 0 8px;
    font-size: 34px;
    line-height: 1.05;
}

.page-head p {
    margin: 0;
    color: var(--muted);
    max-width: 720px;
}

.page-stamp {
    min-width: 220px;
    padding: 14px 16px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.page-stamp span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.page-stamp strong {
    display: block;
    margin-top: 6px;
    font-size: 18px;
}

.page-stamp small {
    display: block;
    margin-top: 8px;
    color: var(--muted);
    font-size: 13px;
}

.page-stamp small.sync-error {
    color: var(--danger);
}

.list-grid {
    display: grid;
    gap: 16px;
}

.sync-health {
    margin-bottom: 16px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    font-size: 14px;
    line-height: 1.35;
}

.sync-health--ok {
    background: #eef8f5;
    color: #166534;
}

.sync-health--warn {
    background: #fff7e6;
    color: #92400e;
    border-color: #f4c35a;
}

.sync-health--alert {
    background: #fff1f2;
    color: #9f1239;
    border-color: #fda4af;
}

.status-overview {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.status-overview__item {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 72px;
    padding: 14px 16px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.status-overview__summary {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
}

.status-overview__text {
    min-width: 0;
}

.status-overview__name {
    display: block;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
}

.status-overview__stats {
    flex: 1 1 auto;
    min-width: 0;
}

.status-overview__stats-title {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.2;
}

.status-overview__stats small {
    display: block;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.35;
}

.status-overview__stats small span {
    font-weight: 400;
}

.status-overview__stats small + small {
    margin-top: 6px;
}

.status-overview__stats .next-change--unknown {
    color: var(--muted);
}

.status-overview__stats .next-change--low {
    color: #15803d;
}

.status-overview__stats .next-change--low-mid {
    color: #65a30d;
}

.status-overview__stats .next-change--mid {
    color: #ca8a04;
}

.status-overview__stats .next-change--mid-high {
    color: #ea580c;
}

.status-overview__stats .next-change--high-mid {
    color: #f97316;
}

.status-overview__stats .next-change--high {
    color: #dc2626;
}

.status-overview__status {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex: 0 0 auto;
}

.status-overview__since {
    display: block;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.2;
}

.status-overview__duration {
    display: block;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.2;
}

.status-overview__footer {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}

.camera-button--overview {
    flex: 0 0 auto;
    min-height: 34px;
    padding: 8px 12px;
    font-size: 12px;
}

.crossing-row,
.archive-panel,
.tabs-band,
.empty-state {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.crossing-row {
    padding: 20px 22px;
}

.crossing-main {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 16px;
}

.crossing-title-wrap h2 {
    margin: 0;
    font-size: 24px;
}

.crossing-title-wrap p {
    margin: 6px 0 0;
    color: var(--muted);
}

.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 110px;
    min-height: 40px;
    padding: 0 14px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 14px;
}

.status-pill--compact {
    min-width: 88px;
    min-height: 34px;
    font-size: 13px;
}

.status-pill.status-open,
.status-dot.status-open {
    background: var(--accent-soft);
    color: var(--accent);
}

.status-pill.status-closed,
.status-dot.status-closed {
    background: var(--danger-soft);
    color: var(--danger);
}

.crossing-meta {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin: 18px 0 0;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.crossing-meta div {
    min-width: 0;
}

.crossing-meta dt {
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.crossing-meta dd {
    margin: 0;
    font-size: 16px;
}

.crossing-media {
    margin-top: 18px;
}

.crossing-camera-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: linear-gradient(135deg, #fff7e6 0%, #fff 100%);
}

.crossing-camera-preview {
    min-width: 0;
}

.crossing-camera-preview strong {
    display: block;
    font-size: 18px;
}

.crossing-camera-preview p {
    margin: 6px 0 0;
    color: var(--muted);
}

.camera-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 54px;
    min-height: 26px;
    margin-bottom: 10px;
    padding: 0 10px;
    border-radius: 999px;
    background: #fee2e2;
    color: #b91c1c;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.camera-button {
    flex: 0 0 auto;
    min-width: 150px;
    min-height: 44px;
    padding: 0 16px;
    border: 0;
    border-radius: 8px;
    background: var(--nav);
    color: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.camera-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.camera-modal[hidden] {
    display: none !important;
}

.camera-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(11, 23, 35, 0.72);
}

.camera-modal__dialog {
    position: relative;
    z-index: 1;
    width: min(960px, 100%);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}

.camera-modal__header {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--line);
}

.camera-modal__header strong {
    display: block;
    font-size: 20px;
}

.camera-modal__header p {
    margin: 6px 0 0;
    color: var(--muted);
}

.camera-modal__close {
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 8px;
    background: #eef3f6;
    color: var(--text);
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
}

.camera-modal__body {
    padding: 0;
}

.crossing-video {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    border: 0;
}

.crossing-video-frame {
    min-height: 540px;
}

.tabs-band {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    padding: 12px;
    margin-bottom: 16px;
}

.tab-link {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 190px;
    padding: 12px 14px;
    border-radius: 8px;
    background: #f4f8fa;
    border: 1px solid transparent;
}

.tab-link span {
    font-weight: 700;
}

.tab-link small {
    color: var(--muted);
    font-size: 13px;
}

.tab-link.is-active {
    background: #fff8e6;
    border-color: #f4c35a;
}

.archive-panel {
    padding: 18px;
}

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

table {
    width: 100%;
    border-collapse: collapse;
}

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

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.archive-row--closed td {
    background: #fff2ec;
}

.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.pagination-meta {
    color: var(--muted);
    font-size: 14px;
}

.pagination-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pagination-link {
    min-width: 40px;
    padding: 9px 12px;
    text-align: center;
    background: #f6fafb;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
}

.pagination-link.is-active {
    background: var(--nav);
    border-color: var(--nav);
    color: #fff;
}

.pagination-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    color: var(--muted);
    font-size: 14px;
}

.status-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 8px;
    border-radius: 999px;
    vertical-align: middle;
}

.empty-state {
    padding: 44px 24px;
    text-align: center;
}

.empty-state.compact {
    padding: 18px;
}

.empty-state h1,
.empty-state h2,
.empty-state p {
    margin: 0;
}

.empty-state p {
    margin-top: 8px;
    color: var(--muted);
}

@media (max-width: 860px) {
    .shell {
        padding: 12px;
    }

    .page-head,
    .crossing-main {
        flex-direction: column;
        align-items: stretch;
    }

    .topbar {
        position: relative;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }

    .brand {
        min-width: 0;
        flex: 1;
    }

    .brand strong {
        font-size: 16px;
    }

    .brand p {
        font-size: 13px;
    }

    .nav-toggle {
        display: inline-flex;
        flex: 0 0 auto;
    }

    .nav {
        position: absolute;
        top: calc(100% + 10px);
        right: 0;
        left: 0;
        display: none;
        flex-direction: column;
        gap: 8px;
        padding: 12px;
        background: rgba(16, 35, 63, 0.98);
        border: 1px solid rgba(248, 250, 252, 0.12);
        border-radius: 8px;
        box-shadow: var(--shadow);
        z-index: 20;
    }

    .nav.is-open {
        display: flex;
    }

    .nav-link {
        width: 100%;
        text-align: left;
    }

    .page-head h1 {
        font-size: 24px;
    }

    .page-head {
        gap: 12px;
        margin-bottom: 12px;
    }

    .page-head p {
        font-size: 14px;
    }

    .crossing-meta {
        grid-template-columns: 1fr;
        gap: 10px;
        margin-top: 14px;
        padding-top: 14px;
    }

    .status-pill {
        width: 100%;
    }

    .status-overview {
        position: sticky;
        top: 8px;
        z-index: 10;
        grid-template-columns: 1fr;
        gap: 8px;
        margin-bottom: 12px;
    }

    .status-overview__item {
        min-height: 64px;
        padding: 12px;
        justify-content: space-between;
    }

    .status-overview__summary {
        flex-direction: column;
        align-items: stretch;
    }

    .status-overview__name {
        font-size: 14px;
    }

    .status-overview__stats {
        margin-top: 8px;
        padding-top: 8px;
    }

    .status-overview__footer {
        flex-direction: column;
        align-items: stretch;
    }

    .camera-button--overview {
        align-self: flex-start;
        margin-top: 2px;
    }

    .status-overview__status {
        align-items: center;
    }

    .status-overview__since {
        font-size: 11px;
    }

    .status-overview__duration {
        font-size: 11px;
    }

    .status-pill--compact {
        width: 100%;
    }

    .crossing-row {
        padding: 14px;
    }

    .crossing-title-wrap h2 {
        font-size: 19px;
        line-height: 1.15;
    }

    .crossing-title-wrap p,
    .crossing-meta dd {
        font-size: 14px;
    }

    .crossing-meta dt {
        font-size: 11px;
    }

    .crossing-camera-card {
        flex-direction: column;
        align-items: stretch;
        padding: 14px;
    }

    .camera-button {
        width: 100%;
    }

    .camera-modal {
        padding: 12px;
    }

    .crossing-video-frame {
        min-height: 240px;
    }

    .tab-link {
        min-width: 100%;
    }

    .pagination {
        flex-direction: column;
        align-items: stretch;
    }

    .pagination-links {
        justify-content: flex-start;
    }
}
