:root {
    color-scheme: dark;

    --sidebar-w: 257.5px;
    --topbar-h: 58px;
    --main-bg: #181818;
    --sidebar-bg: #2b2b2b;
    --surface: #1f1f1f;
    --surface-raised: #2d2d2d;
    --surface-hover: #252525;
    --border: #3c3c3c;
    --border-strong: #414141;
    --separator: #3e3e3e;

    --text-primary: #ffffff;
    --text-sidebar: #dedede;
    --text-secondary: #9a9a9a;
    --text-muted: #858585;
    --text-placeholder: #6a6a6a;

    --blue: #539af8;
    --purple: #a67df2;
    --green: #6bc67f;
    --orange: #ea733a;
    --red: #ed6a5e;
    --yellow: #f4bf4f;

    --red-dim: rgba(237, 106, 94, 0.11);
    --green-dim: rgba(107, 198, 127, 0.10);
    --yellow-dim: rgba(244, 191, 79, 0.10);
    --blue-dim: rgba(83, 154, 248, 0.10);

    --font-ui:
        -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
        "Helvetica Neue", Arial, sans-serif;

    --transition: 160ms ease;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--main-bg);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    text-rendering: geometricPrecision;
}

h1,
h2,
h3,
p {
    margin: 0;
}

ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

button:focus-visible,
input:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}

.hidden {
    display: none !important;
}

.app-shell {
    min-height: 100vh;
    background: var(--main-bg);
}

/* Sidebar */

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    min-height: 100vh;
    color: var(--text-sidebar);
    background:
        radial-gradient(
            95% 26% at 0% 100%,
            rgba(47, 55, 57, 0.34) 0%,
            rgba(39, 39, 39, 0) 70%
        ),
        linear-gradient(
            96deg,
            rgba(45, 45, 45, 1) 0%,
            rgba(44, 44, 44, 1) 48%,
            rgba(42, 42, 42, 1) 100%
        );
    border-right: 0.5px solid rgba(76, 76, 76, 0.92);
    overflow: hidden;
    transition: transform var(--transition);
    z-index: 20;
}

.sidebar::after {
    content: "";
    position: absolute;
    inset: var(--topbar-h) 0 0;
    pointer-events: none;
    background: linear-gradient(
        180deg,
        rgba(0, 0, 0, 0.02) 0%,
        rgba(0, 0, 0, 0.10) 28%,
        rgba(0, 0, 0, 0.10) 100%
    );
}

.sidebar-header,
.sidebar-footer,
.sidebar-body {
    position: relative;
    z-index: 1;
}

.sidebar-header {
    height: var(--topbar-h);
    padding: 13px 16px;
    border-bottom: 0.5px solid var(--separator);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.brand-icon {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    color: var(--text-sidebar);
    background: rgba(24, 24, 24, 0.34);
    border: 0.5px solid rgba(154, 154, 154, 0.38);
    border-radius: 10px;
}

.brand-copy,
.operator-copy,
.plant-card-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.brand-name {
    overflow: hidden;
    color: var(--text-sidebar);
    font-size: 14px;
    font-weight: 600;
    line-height: 20px;
    text-overflow: clip;
    white-space: nowrap;
}

.brand-subtitle {
    color: var(--text-muted);
    font-size: 11px;
    line-height: 16px;
}

.sidebar-body {
    height: calc(100vh - var(--topbar-h) - 54px);
    padding: 20px 12px;
    overflow-y: auto;
    scrollbar-width: none;
}

.sidebar-body::-webkit-scrollbar {
    display: none;
}

.sidebar-label {
    padding: 0 5px;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.06em;
    line-height: 20px;
    text-transform: uppercase;
}

.app-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 6px;
}

.nav-tab {
    width: 100%;
    min-height: 38px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    color: var(--text-secondary);
    background: transparent;
    border: 0.5px solid transparent;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 400;
    text-align: left;
    transition:
        color var(--transition),
        background var(--transition),
        border-color var(--transition);
}

.nav-tab svg {
    flex: 0 0 auto;
}

.nav-tab:hover {
    color: var(--text-sidebar);
    background: rgba(255, 255, 255, 0.035);
}

.nav-tab--active {
    color: var(--text-primary);
    background: rgba(24, 24, 24, 0.46);
    border-color: rgba(154, 154, 154, 0.28);
}

.nav-badge {
    margin-left: auto;
    color: var(--red);
    font-size: 10px;
    font-weight: 600;
    line-height: 16px;
    font-variant-numeric: tabular-nums;
}

.sidebar-section {
    margin-top: 28px;
}

.plant-card {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 7px;
    padding: 11px 10px;
    border: 0.5px solid rgba(154, 154, 154, 0.20);
    border-radius: 12px;
    background: rgba(24, 24, 24, 0.24);
}

.plant-card-icon {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    color: var(--purple);
    border: 0.5px solid rgba(166, 125, 242, 0.30);
    border-radius: 8px;
}

.plant-card-copy strong,
.operator-copy strong {
    overflow: hidden;
    color: var(--text-sidebar);
    font-size: 12px;
    font-weight: 500;
    line-height: 18px;
    text-overflow: clip;
    white-space: nowrap;
}

.plant-card-copy small,
.operator-copy small {
    overflow: hidden;
    color: var(--text-muted);
    font-size: 11px;
    line-height: 16px;
    text-overflow: clip;
    white-space: nowrap;
}

.sidebar-footer {
    position: absolute;
    inset: auto 0 0;
    height: 54px;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 0 16px;
    border-top: 0.5px solid var(--separator);
    background: rgba(42, 42, 42, 0.96);
}

.operator-avatar {
    width: 22px;
    height: 22px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    color: #ffffff;
    background: #7b878a;
    border-radius: 50%;
    font-size: 8px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.operator-copy {
    flex: 1;
}

.footer-pulse {
    width: 7px;
    height: 7px;
    flex: 0 0 auto;
    background: var(--green);
    border-radius: 50%;
}

/* Workspace */

.workspace {
    min-height: 100vh;
    margin-left: var(--sidebar-w);
    background: var(--main-bg);
    transition: margin-left var(--transition);
}

.app-shell.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
}

.app-shell.sidebar-collapsed .workspace {
    margin-left: 0;
}

.app-header {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 0 20px;
    border-bottom: 0.5px solid var(--separator);
}

.header-context,
.header-breadcrumb {
    min-width: 0;
    display: flex;
    align-items: center;
}

.header-context {
    gap: 11px;
}

.sidebar-toggle {
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    padding: 0;
    color: var(--text-secondary);
    background: transparent;
    border: 0;
    border-radius: 4px;
    transition:
        color var(--transition),
        background var(--transition);
}

.sidebar-toggle:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.055);
}

.sidebar-toggle-arrow {
    transform-origin: 14.5px 12px;
    transition: transform var(--transition);
}

.sidebar-toggle[aria-expanded="false"] .sidebar-toggle-arrow {
    transform: rotate(180deg);
}

.header-context-icon {
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    color: var(--text-secondary);
}

.header-breadcrumb {
    gap: 10px;
    white-space: nowrap;
}

.workspace-path {
    overflow: hidden;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0;
    line-height: 20px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-separator {
    flex: 0 0 auto;
    color: var(--border-strong);
    font-size: 14px;
    font-weight: 400;
    line-height: 20px;
}

.section-kicker {
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.095em;
    line-height: 16px;
    text-transform: uppercase;
}

.app-header h1 {
    overflow: hidden;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.08px;
    line-height: 20px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    flex: 0 0 auto;
    padding-left: 12px;
    color: var(--text-secondary);
    border-left: 0.5px solid var(--separator);
    font-size: 11px;
    font-weight: 500;
    line-height: 16px;
    transition: color var(--transition);
}

.status-dot {
    width: 6px;
    height: 6px;
    background: currentColor;
    border-radius: 50%;
}

.status--connected {
    color: var(--green);
}

.status--connecting {
    color: var(--yellow);
}

.status--disconnected {
    color: var(--red);
}

.app-main {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 28px 24px 64px;
}

.panel {
    display: none;
}

.panel--active {
    display: block;
}

.panel-heading,
.zones-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 28px;
    margin-bottom: 26px;
}

.panel-heading h2,
.zones-title {
    margin-top: 4px;
    color: var(--text-primary);
    font-size: 28px;
    font-weight: 400;
    letter-spacing: -0.35px;
    line-height: 34px;
}

.section-description,
.zones-subtitle {
    max-width: 620px;
    margin-top: 8px;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 20px;
}

.record-count,
.sync-badge {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    min-height: 18px;
    padding-left: 10px;
    color: var(--text-secondary);
    border-left: 0.5px solid var(--separator);
    font-size: 11px;
    font-weight: 500;
    line-height: 16px;
    font-variant-numeric: tabular-nums;
}

/* Incidents */

.incident-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    border-top: 0.5px solid var(--separator);
}

.incident-card {
    min-height: 136px;
    display: flex;
    align-items: stretch;
    gap: 18px;
    padding: 12px 0;
    background: transparent;
    border: 0;
    border-bottom: 0.5px solid var(--separator);
    border-radius: 0;
    overflow: hidden;
    animation: incident-in 220ms ease-out;
    transition: background var(--transition);
}

.incident-card:hover {
    background: rgba(255, 255, 255, 0.018);
}

@keyframes incident-in {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.incident-thumb-button {
    position: relative;
    width: 184px;
    align-self: center;
    flex: 0 0 auto;
    display: block;
    padding: 0;
    background: #141414;
    border: 0.5px solid #303030;
    border-radius: 7px;
    overflow: hidden;
    cursor: zoom-in;
}

.incident-thumb-button:hover {
    border-color: #4a4a4a;
}

.incident-thumb-button:focus-visible {
    outline: 1px solid var(--blue);
    outline-offset: 2px;
}

.incident-thumb-button:disabled {
    cursor: default;
}

.incident-thumb {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.incident-thumb--placeholder {
    display: grid;
    place-items: center;
    min-height: 104px;
    color: var(--text-placeholder);
    font-size: 10px;
    line-height: 14px;
    text-align: center;
}

.incident-thumb-overlay {
    pointer-events: none;
}

.incident-thumb-overlay .bounding-box {
    border-width: 1px;
}

.incident-thumb-overlay .bounding-label {
    max-width: 100%;
    padding: 1px 3px;
    font-size: 7px;
    line-height: 10px;
}

.incident-body {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 3px 0;
}

.incident-top {
    display: grid;
    grid-template-columns: minmax(120px, 1fr) auto auto;
    align-items: center;
    gap: 12px;
}

.incident-camera {
    overflow: hidden;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
    text-overflow: clip;
    white-space: nowrap;
}

.incident-zone {
    padding-left: 10px;
    color: var(--purple);
    border-left: 0.5px solid var(--separator);
    font-size: 10px;
    font-weight: 500;
    line-height: 14px;
    text-transform: capitalize;
}

.incident-time {
    color: var(--text-muted);
    font-size: 11px;
    line-height: 16px;
    white-space: nowrap;
}

.badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    margin-top: 14px;
}

.badge {
    display: inline-flex;
    align-items: center;
    color: var(--red);
    font-size: 11px;
    font-weight: 500;
    line-height: 15px;
}

.badge::before {
    content: "";
    width: 5px;
    height: 5px;
    flex: 0 0 auto;
    margin-right: 6px;
    background: currentColor;
}

.badge:not(:last-child)::after {
    content: "";
    width: 0.5px;
    height: 12px;
    margin: 0 10px;
    background: var(--separator);
}

.incident-pagination {
    min-height: 48px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 16px;
    padding-top: 12px;
}

.pagination-button {
    min-height: 30px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 8px;
    color: var(--text-secondary);
    background: transparent;
    border: 0.5px solid var(--border);
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    line-height: 16px;
}

.pagination-button:first-child {
    justify-self: start;
}

.pagination-button:last-child {
    justify-self: end;
}

.pagination-button:hover:not(:disabled) {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.045);
}

.pagination-button:disabled {
    color: var(--text-placeholder);
    opacity: 0.5;
    cursor: default;
}

.pagination-label {
    color: var(--text-muted);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    line-height: 16px;
}

/* Live cameras */

.camera-heading {
    align-items: flex-start;
}

.camera-heading-actions {
    display: flex;
    align-items: center;
    gap: 9px;
    flex: 0 0 auto;
}

.overlay-toggle {
    min-height: 28px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    color: var(--text-secondary);
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: 7px;
    font-size: 11px;
    font-weight: 500;
    line-height: 16px;
    transition:
        color var(--transition),
        border-color var(--transition),
        background var(--transition);
}

.overlay-toggle:hover {
    color: var(--text-primary);
    border-color: #4a4a4a;
}

.overlay-toggle-switch {
    position: relative;
    width: 14px;
    height: 14px;
    flex: 0 0 auto;
    background: var(--main-bg);
    border: 1px solid #565656;
    border-radius: 3px;
    transition:
        background var(--transition),
        border-color var(--transition);
}

.overlay-toggle-switch::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 4px;
    width: 4px;
    height: 7px;
    border: solid #ffffff;
    border-width: 0 1.5px 1.5px 0;
    opacity: 0;
    transform: rotate(45deg);
    transition:
        opacity var(--transition);
}

.overlay-toggle[aria-pressed="true"] {
    color: var(--blue);
    background: var(--surface-hover);
    border-color: rgba(83, 154, 248, 0.30);
}

.overlay-toggle[aria-pressed="true"] .overlay-toggle-switch {
    background: var(--blue);
    border-color: var(--blue);
}

.overlay-toggle[aria-pressed="true"] .overlay-toggle-switch::after {
    opacity: 1;
}

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

.camera-card {
    min-width: 0;
    overflow: hidden;
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: 16px;
    cursor: pointer;
    transition:
        transform var(--transition),
        background var(--transition),
        border-color var(--transition);
}

.camera-card:hover {
    background: var(--surface-hover);
    border-color: #4a4a4a;
    transform: translateY(-1px);
}

.camera-card:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}

.camera-viewport {
    position: relative;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.018), transparent 45%),
        #101010;
    border-bottom: 0.5px solid var(--separator);
}

.camera-frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.camera-hud {
    position: absolute;
    inset: 0 0 auto;
    z-index: 3;
    min-height: 56px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 12px;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.68), transparent);
    pointer-events: none;
}

.camera-name {
    min-width: 0;
    overflow: hidden;
    color: #ffffff;
    font-size: 12px;
    font-weight: 500;
    line-height: 18px;
    text-overflow: clip;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.75);
    white-space: nowrap;
}

.camera-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    padding: 0;
    color: #ffffff;
    font-size: 9px;
    font-weight: 600;
    line-height: 13px;
    letter-spacing: 0.035em;
    text-transform: uppercase;
}

.camera-status > span {
    width: 5px;
    height: 5px;
    background: currentColor;
    border-radius: 50%;
}

.camera-status--live {
    color: var(--green);
}

.camera-status--stale {
    color: var(--red);
}

.bounding-layer {
    position: absolute;
    inset: 0;
    z-index: 2;
    opacity: 1;
    pointer-events: none;
    transition: opacity var(--transition);
}

.camera-grid--boxes-hidden .bounding-layer {
    opacity: 0;
}

.bounding-box {
    --box-color: var(--green);

    position: absolute;
    min-width: 12px;
    min-height: 12px;
    border: 1.5px solid var(--box-color);
    border-radius: 2px;
}

.bounding-box--violation {
    --box-color: var(--red);

    background: rgba(237, 106, 94, 0.035);
}

.bounding-box--compliant {
    --box-color: var(--green);

    background: rgba(107, 198, 127, 0.025);
}

.bounding-label {
    position: absolute;
    top: 2px;
    left: 2px;
    max-width: calc(100% - 4px);
    overflow: hidden;
    padding: 2px 5px;
    color: #ffffff;
    background: var(--box-color);
    border-radius: 2px;
    font-size: 8px;
    font-weight: 600;
    line-height: 11px;
    text-overflow: clip;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);
    white-space: nowrap;
}

.camera-meta {
    min-height: 46px;
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    color: var(--text-muted);
    font-size: 10px;
    line-height: 15px;
}

.camera-zone {
    overflow: hidden;
    color: var(--purple);
    font-weight: 500;
    text-overflow: clip;
    text-transform: capitalize;
    white-space: nowrap;
}

.camera-detection-count {
    color: var(--text-secondary);
}

.camera-time {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.camera-cooldown {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 5px auto 34px 14px;
    align-items: center;
    gap: 7px;
    min-width: 0;
    justify-content: start;
    font-variant-numeric: tabular-nums;
}

.camera-cooldown-dot {
    width: 5px;
    height: 5px;
    background: var(--green);
}

.camera-cooldown-label {
    color: var(--text-secondary);
    font-size: 9px;
    font-weight: 500;
    line-height: 13px;
}

.camera-cooldown strong {
    color: var(--green);
    font-size: 9px;
    font-weight: 600;
    line-height: 13px;
    text-align: right;
}

.camera-cooldown-ring {
    --cooldown-progress: 0;

    position: relative;
    width: 14px;
    height: 14px;
    background: var(--green);
    border-radius: 50%;
}

.camera-cooldown-ring::after {
    content: "";
    position: absolute;
    inset: 3px;
    background: var(--surface);
    border-radius: 50%;
}

.camera-cooldown--active .camera-cooldown-dot {
    background: var(--red);
}

.camera-cooldown--active .camera-cooldown-ring {
    background: conic-gradient(
        var(--red) calc(var(--cooldown-progress) * 1turn),
        var(--separator) 0
    );
}

.camera-cooldown--active strong {
    color: var(--red);
}

.camera-open-indicator {
    width: 18px;
    height: 18px;
    display: grid;
    place-items: center;
    color: var(--text-muted);
    transition:
        color var(--transition),
        transform var(--transition);
}

.camera-card:hover .camera-open-indicator {
    color: var(--text-primary);
    transform: translateX(2px);
}

/* Zone incident drawer */

body.drawer-open {
    overflow: hidden;
}

.drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(0, 0, 0, 0.42);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
}

.drawer-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
}

.zone-incidents-drawer {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 50;
    width: min(540px, 100vw);
    display: flex;
    flex-direction: column;
    color: var(--text-primary);
    background: #1c1c1c;
    border-left: 0.5px solid var(--border-strong);
    box-shadow: -24px 0 70px rgba(0, 0, 0, 0.28);
    transform: translateX(100%);
    transition: transform 220ms ease;
}

.zone-incidents-drawer.is-open {
    transform: translateX(0);
}

.drawer-header {
    min-height: 92px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    padding: 18px;
    border-bottom: 0.5px solid var(--separator);
}

.drawer-heading {
    min-width: 0;
}

.drawer-heading h2 {
    margin-top: 3px;
    font-size: 20px;
    font-weight: 500;
    letter-spacing: -0.22px;
    line-height: 27px;
    text-transform: capitalize;
}

.drawer-camera-context {
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 11px;
    line-height: 16px;
}

.drawer-close {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    padding: 0;
    color: var(--text-secondary);
    background: transparent;
    border: 0;
    border-radius: 5px;
}

.drawer-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.055);
}

.drawer-summary {
    min-height: 40px;
    display: flex;
    align-items: center;
    padding: 10px 18px;
    color: var(--text-secondary);
    border-bottom: 0.5px solid var(--separator);
    font-size: 11px;
    line-height: 16px;
    font-variant-numeric: tabular-nums;
}

.drawer-content {
    min-height: 0;
    flex: 1;
    overflow-y: auto;
}

.hand-inspection {
    padding: 16px 18px 18px;
    border-bottom: 0.5px solid var(--separator);
}

.hand-inspection-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
}

.hand-inspection-heading h3 {
    margin-top: 3px;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
}

.hand-inspection-heading time {
    flex: 0 0 auto;
    color: var(--text-muted);
    font-size: 9px;
    line-height: 14px;
    font-variant-numeric: tabular-nums;
}

.hand-inspection-status {
    margin-top: 9px;
    color: var(--text-muted);
    font-size: 10px;
    line-height: 15px;
}

.hand-inspection-status--ready {
    color: var(--green);
}

.hand-crop-gallery {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
    margin-top: 12px;
}

.hand-crop-card {
    min-width: 0;
    margin: 0;
    overflow: hidden;
    background: #141414;
    border: 0.5px solid var(--border);
    border-radius: 8px;
}

.hand-crop-media {
    position: relative;
    min-height: 96px;
    overflow: hidden;
    background: #0d0d0d;
}

.hand-crop-media img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
}

.hand-crop-card figcaption {
    padding: 7px 8px;
    color: var(--text-muted);
    border-top: 0.5px solid var(--separator);
    font-size: 9px;
    line-height: 14px;
}

.drawer-state {
    min-height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 28px;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 18px;
    text-align: center;
}

.drawer-state--error {
    color: var(--red);
}

.zone-incidents-list {
    display: flex;
    flex-direction: column;
}

.zone-incident-item {
    display: grid;
    grid-template-columns: 98px minmax(0, 1fr);
    gap: 14px;
    padding: 16px 18px;
    border-bottom: 0.5px solid var(--separator);
}

.zone-incident-image-button,
.zone-incident-image,
.zone-incident-image--empty {
    width: 98px;
}

.zone-incident-image-button {
    position: relative;
    align-self: start;
    display: block;
    padding: 0;
    background: #141414;
    border: 0.5px solid #303030;
    border-radius: 7px;
    overflow: hidden;
    cursor: zoom-in;
}

.zone-incident-image-button:focus-visible {
    outline: 1px solid var(--blue);
    outline-offset: 2px;
}

.zone-incident-image-button:disabled {
    cursor: default;
}

.zone-incident-image,
.zone-incident-image--empty {
    height: 100%;
    display: block;
    object-fit: cover;
}

.zone-incident-image--empty {
    display: grid;
    place-items: center;
    color: var(--text-placeholder);
    font-size: 9px;
    line-height: 13px;
}

.zone-incident-image-overlay {
    pointer-events: none;
}

.zone-incident-image-overlay .bounding-label {
    display: none;
}

.zone-incident-body {
    min-width: 0;
}

.zone-incident-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}

.zone-incident-head strong {
    overflow: hidden;
    font-size: 12px;
    font-weight: 500;
    line-height: 18px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.zone-incident-head time {
    flex: 0 0 auto;
    color: var(--text-muted);
    font-size: 9px;
    line-height: 14px;
    font-variant-numeric: tabular-nums;
}

.zone-incident-violations {
    margin-top: 9px;
    color: var(--red);
    font-size: 11px;
    font-weight: 500;
    line-height: 16px;
}

.zone-incident-detail {
    margin-top: 7px;
    color: var(--text-muted);
    font-size: 9px;
    line-height: 14px;
}

/* Incident evidence preview */

body.incident-preview-open {
    overflow: hidden;
}

.incident-preview {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: grid;
    place-items: center;
    padding: 28px;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease, visibility 160ms ease;
}

.incident-preview.is-open {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}

.incident-preview-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
}

.incident-preview-dialog {
    position: relative;
    z-index: 1;
    width: min(1040px, 100%);
    max-height: calc(100vh - 56px);
    display: flex;
    flex-direction: column;
    color: var(--text-primary);
    background: #1c1c1c;
    border: 0.5px solid var(--border-strong);
    border-radius: 10px;
    box-shadow: 0 26px 90px rgba(0, 0, 0, 0.48);
    overflow: hidden;
}

.incident-preview-header {
    min-height: 76px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 14px 16px;
    border-bottom: 0.5px solid var(--separator);
}

.incident-preview-header h2 {
    margin-top: 2px;
    font-size: 17px;
    font-weight: 500;
    line-height: 23px;
}

.incident-preview-context {
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 11px;
    line-height: 16px;
    text-transform: capitalize;
}

.incident-preview-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.incident-preview-content {
    min-height: 0;
    display: grid;
    place-items: center;
    padding: 18px;
    overflow: auto;
    background: #111;
}

.incident-preview-media {
    position: relative;
    width: 100%;
    max-height: calc(100vh - 150px);
    background: #0d0d0d;
    overflow: hidden;
}

.incident-preview-media img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
}

.incident-preview-media--boxes-hidden .bounding-layer {
    display: none;
}

/* Empty state */

.empty-state {
    min-height: 410px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    text-align: center;
}

.empty-mark {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    color: #5d5d5d;
    border: 0.5px solid var(--border);
    border-radius: 16px;
}

.empty-state h3 {
    margin-top: 24px;
    color: var(--text-primary);
    font-size: 22px;
    font-weight: 400;
    letter-spacing: -0.25px;
    line-height: 30px;
}

.empty-state p {
    max-width: 340px;
    margin-top: 8px;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 20px;
}

/* Zone rules */

.zones-header {
    align-items: flex-start;
}

.zones-header-actions {
    display: flex;
    align-items: center;
    gap: 9px;
    flex: 0 0 auto;
}

.sync-badge--idle {
    color: var(--text-muted);
}

.sync-badge--dirty {
    color: var(--yellow);
}

.sync-badge--saving {
    color: var(--blue);
}

.sync-badge--saved {
    color: var(--green);
}

.sync-badge--error {
    color: var(--red);
}

.btn {
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 7px 12px;
    border: 0.5px solid transparent;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 500;
    line-height: 18px;
    transition:
        color var(--transition),
        background var(--transition),
        border-color var(--transition),
        transform var(--transition);
}

.btn--primary {
    color: #181818;
    background: var(--text-sidebar);
    border-color: var(--text-sidebar);
}

.btn--primary:hover:not(:disabled) {
    background: #ffffff;
    border-color: #ffffff;
    transform: translateY(-1px);
}

.btn--primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn:disabled {
    color: var(--text-placeholder);
    background: var(--surface);
    border-color: var(--border);
    cursor: not-allowed;
}

.zones-loading {
    min-height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--text-secondary);
    font-size: 12px;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 1.5px solid var(--border);
    border-top-color: var(--text-secondary);
    border-radius: 50%;
    animation: spin 700ms linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.zones-error {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 18px;
    padding: 12px 14px;
    color: var(--red);
    background: var(--red-dim);
    border: 0.5px solid rgba(237, 106, 94, 0.30);
    border-radius: 12px;
    font-size: 12px;
}

.zones-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(288px, 1fr));
    gap: 11px;
}

.zone-card {
    position: relative;
    padding: 18px;
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: 16px;
    transition:
        background var(--transition),
        border-color var(--transition);
}

.zone-card:hover {
    background: var(--surface-hover);
    border-color: #4a4a4a;
}

.zone-card--dirty {
    border-color: rgba(244, 191, 79, 0.58);
}

.zone-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 14px;
    border-bottom: 0.5px solid var(--separator);
}

.zone-name {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 9px;
    overflow: hidden;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
    text-overflow: clip;
    text-transform: capitalize;
    white-space: nowrap;
}

.zone-name-dot {
    width: 7px;
    height: 7px;
    flex: 0 0 auto;
    background: var(--green);
    border-radius: 50%;
}

.zone-dirty-label {
    opacity: 0;
    color: var(--yellow);
    font-size: 10px;
    font-weight: 500;
    line-height: 14px;
    transition: opacity var(--transition);
}

.zone-card--dirty .zone-dirty-label {
    opacity: 1;
}

.zone-epp-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 12px;
}

.epp-item {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 34px;
    padding: 7px 8px;
    border-radius: 9px;
    cursor: pointer;
    user-select: none;
    transition: background var(--transition);
}

.epp-item:hover {
    background: rgba(255, 255, 255, 0.035);
}

.epp-checkbox {
    position: relative;
    width: 15px;
    height: 15px;
    flex: 0 0 auto;
    appearance: none;
    -webkit-appearance: none;
    background: var(--main-bg);
    border: 1px solid #505050;
    border-radius: 4px;
    cursor: pointer;
    transition:
        background var(--transition),
        border-color var(--transition);
}

.epp-checkbox:checked {
    background: var(--blue);
    border-color: var(--blue);
}

.epp-checkbox:checked::after {
    content: "";
    position: absolute;
    left: 4px;
    top: 1px;
    width: 4px;
    height: 8px;
    border: solid #ffffff;
    border-width: 0 1.5px 1.5px 0;
    transform: rotate(45deg);
}

.epp-label {
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 18px;
    transition: color var(--transition);
}

.epp-item:has(.epp-checkbox:checked) .epp-label {
    color: var(--text-primary);
}

/* Toast */

.toast {
    position: fixed;
    right: 22px;
    bottom: 20px;
    z-index: 100;
    max-width: 340px;
    padding: 11px 14px;
    color: var(--text-primary);
    background: var(--surface-raised);
    border: 0.5px solid var(--border-strong);
    border-radius: 14px;
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.30);
    font-size: 12px;
    line-height: 18px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(7px);
    transition:
        opacity 220ms ease,
        transform 220ms ease;
}

.toast--visible {
    opacity: 1;
    transform: translateY(0);
}

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

.toast--error {
    color: var(--red);
}

.toast--info {
    color: var(--blue);
}

/* Responsive */

@media (max-width: 900px) {
    :root {
        --sidebar-w: 218px;
    }

    .app-main {
        width: 100%;
        padding: 28px 24px 64px;
    }

    .incident-top {
        grid-template-columns: minmax(120px, 1fr) auto;
    }

    .incident-time {
        grid-column: 1 / -1;
    }

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

@media (max-width: 720px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        position: relative;
        width: 100%;
        min-height: 0;
        border-right: 0;
        border-bottom: 0.5px solid var(--separator);
    }

    .sidebar::after,
    .sidebar-section,
    .sidebar-footer {
        display: none;
    }

    .sidebar-header {
        height: var(--topbar-h);
        padding: 13px 18px;
    }

    .sidebar-body {
        height: auto;
        padding: 8px 12px 12px;
    }

    .app-nav {
        flex-direction: row;
        margin: 0;
    }

    .sidebar-label {
        display: none;
    }

    .nav-tab {
        flex: 1;
        justify-content: center;
    }

    .workspace {
        margin-left: 0;
    }

    .app-shell.sidebar-collapsed .sidebar {
        display: none;
        transform: none;
    }

    .app-header {
        height: var(--topbar-h);
        padding: 0 14px;
    }

    .app-header h1 {
        font-size: 13px;
        line-height: 20px;
    }

    .header-context-icon,
    .workspace-path,
    .header-separator {
        display: none;
    }

    .app-main {
        width: 100%;
        padding: 24px 14px 48px;
    }

    .panel-heading,
    .zones-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 14px;
    }

    .panel-heading h2,
    .zones-title {
        font-size: 24px;
        line-height: 30px;
    }

    .zones-header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .camera-heading-actions {
        width: 100%;
        justify-content: space-between;
    }

    .incident-card {
        align-items: flex-start;
    }

    .incident-thumb-button {
        width: 84px;
    }

    .incident-top {
        grid-template-columns: 1fr;
        gap: 5px;
    }

    .incident-zone {
        width: fit-content;
    }

    .incident-time {
        grid-column: auto;
    }
}

@media (max-width: 480px) {
    .brand-subtitle {
        display: none;
    }

    .status {
        padding: 5px 8px;
    }

    .incident-card {
        flex-direction: column;
    }

    .incident-thumb-button {
        width: 100%;
    }

    .incident-pagination {
        gap: 8px;
    }

    .pagination-button {
        font-size: 0;
    }

    .pagination-button svg {
        margin: 0;
    }

    .zones-grid {
        grid-template-columns: 1fr;
    }

    .zone-incidents-drawer {
        width: 100vw;
    }

    .hand-crop-gallery {
        grid-template-columns: 1fr;
    }

    .zone-incident-item {
        grid-template-columns: 84px minmax(0, 1fr);
        padding: 14px;
    }

    .zone-incident-image-button,
    .zone-incident-image,
    .zone-incident-image--empty {
        width: 84px;
    }

    .incident-preview {
        padding: 0;
    }

    .incident-preview-dialog {
        width: 100%;
        max-height: 100vh;
        border-right: 0;
        border-left: 0;
        border-radius: 0;
    }

    .incident-preview-header {
        align-items: flex-start;
        padding: 12px;
    }

    .incident-preview-actions {
        flex: 0 0 auto;
    }

    .incident-preview-content {
        padding: 0;
    }

    .toast {
        right: 14px;
        bottom: 14px;
        left: 14px;
        max-width: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
