:root {
    color-scheme: light;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-strong: #eef1f5;
    --surface-muted: #f8fafc;
    --text: #16202a;
    --muted: #647081;
    --border: #d9e0ea;
    --accent: #0f766e;
    --accent-strong: #0b5f59;
    --accent-soft: #d9f2ee;
    --danger: #c2410c;
    --danger-soft: #fff1e8;
    --warning: #b7791f;
    --shadow: 0 18px 55px rgba(22, 32, 42, 0.12);
    --shadow-soft: 0 10px 26px rgba(22, 32, 42, 0.08);
    --radius: 8px;
    --header-height: 76px;
    --focus-bg: #f6f7f9;
    --control-height: 42px;
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #111417;
    --surface: #181d22;
    --surface-strong: #232a31;
    --surface-muted: #15191e;
    --text: #edf2f7;
    --muted: #a3adba;
    --border: #303944;
    --accent: #2dd4bf;
    --accent-strong: #5eead4;
    --accent-soft: rgba(45, 212, 191, 0.14);
    --danger: #fb923c;
    --danger-soft: rgba(251, 146, 60, 0.13);
    --warning: #fbbf24;
    --shadow: 0 20px 70px rgba(0, 0, 0, 0.35);
    --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.24);
    --focus-bg: #111417;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    min-height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
    transition: background-color 180ms ease, color 180ms ease;
}

body.panel-open,
body.focus-open {
    overflow: hidden;
}

button,
input,
select {
    font: inherit;
}

button {
    color: inherit;
}

img {
    max-width: 100%;
}

.app-shell {
    width: min(1760px, 100%);
    min-height: 100vh;
    margin: 0 auto;
    padding: 18px;
}

.app-shell:fullscreen,
.app-shell:-webkit-full-screen,
.app-shell.is-fullscreen-shell {
    width: 100%;
    height: 100%;
    max-width: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    background: var(--bg);
}

.focus-view:fullscreen,
.focus-view:-webkit-full-screen,
.focus-view.is-fullscreen-focus {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--focus-bg);
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--header-height);
    gap: 16px;
    padding: 12px 14px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(16px);
}

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

.brand-icon {
    display: grid;
    place-items: center;
    flex: 0 0 46px;
    width: 46px;
    height: 46px;
    border-radius: var(--radius);
    color: var(--accent-strong);
    background: var(--accent-soft);
    font-size: 20px;
}

.eyebrow {
    margin: 0 0 2px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1,
h2,
h3,
p {
    overflow-wrap: anywhere;
}

h1 {
    margin: 0;
    font-size: clamp(20px, 2.2vw, 30px);
    line-height: 1.1;
}

h2 {
    margin: 0;
    font-size: 22px;
    line-height: 1.2;
}

h3 {
    margin: 0;
    font-size: 15px;
    line-height: 1.25;
}

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

.toolbar,
.focus-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.icon-button,
.chip,
.secondary-button,
.danger-button,
.widget-header {
    min-height: var(--control-height);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    transition: transform 160ms ease, border-color 160ms ease, background-color 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.icon-button {
    display: inline-grid;
    place-items: center;
    width: var(--control-height);
    height: var(--control-height);
    padding: 0;
    color: var(--muted);
}

.icon-button:hover,
.chip:hover,
.secondary-button:hover,
.widget-header:hover {
    color: var(--text);
    border-color: color-mix(in srgb, var(--accent) 48%, var(--border));
    transform: translateY(-1px);
}

.icon-button.is-active,
.chip.is-active {
    color: var(--accent-strong);
    border-color: color-mix(in srgb, var(--accent) 52%, var(--border));
    background: var(--accent-soft);
}

.icon-button.is-danger {
    color: var(--danger);
    border-color: color-mix(in srgb, var(--danger) 38%, var(--border));
    background: var(--danger-soft);
}

.dashboard-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    align-items: start;
}

.camera-section,
.info-panel,
.widget,
.settings-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-soft);
}

.camera-section {
    padding: 16px;
    min-width: 0;
}

.section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.status-strip {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 32px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    background: var(--surface-muted);
    font-size: 13px;
    white-space: nowrap;
}

.status-pill i {
    color: var(--accent);
    font-size: 9px;
}

.status-pill.is-paused i {
    color: var(--warning);
}

.quick-filters {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    color: var(--muted);
    background: var(--surface-muted);
}

.camera-grid {
    display: grid;
    gap: 12px;
}

.camera-grid.density-comfortable {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.camera-grid.density-compact {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.camera-grid.density-large {
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
}

.camera-card {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-muted);
    box-shadow: none;
    transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.camera-card:hover {
    border-color: color-mix(in srgb, var(--accent) 38%, var(--border));
    box-shadow: var(--shadow-soft);
    transform: translateY(-2px);
}

.camera-card.is-hidden-card {
    opacity: 0.6;
}

.camera-media-button {
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    background: #0e1216;
    cursor: pointer;
}

.camera-card img {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: contain;
    background: #05070a;
}

.camera-offline img {
    filter: grayscale(1);
    opacity: 0.7;
}

.camera-card-footer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 10px;
}

.camera-title {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    font-weight: 700;
}

.camera-title span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.camera-title i {
    color: var(--accent);
}

.camera-meta {
    margin-top: 2px;
    color: var(--muted);
    font-size: 12px;
}

.camera-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.camera-actions .icon-button {
    --control-height: 34px;
    font-size: 13px;
}

.empty-state {
    display: grid;
    place-items: center;
    gap: 8px;
    min-height: 240px;
    padding: 24px;
    color: var(--muted);
    text-align: center;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: var(--surface-muted);
}

.empty-state[hidden] {
    display: none;
}

.empty-state i {
    color: var(--accent);
    font-size: 28px;
}

.empty-state p {
    margin: 0;
}

.info-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 12px;
    padding: 0;
    position: static;
    background: transparent;
    border: 0;
    box-shadow: none;
}

.widget {
    overflow: hidden;
}

.widget.is-hidden {
    display: none;
}

.widget.is-collapsed .widget-body {
    display: none;
}

.widget.is-collapsed .widget-header > i {
    transform: rotate(180deg);
}

.widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0 12px;
    border: 0;
    border-radius: 0;
    background: var(--surface);
    color: var(--text);
}

.widget-header span {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.widget-header > i {
    color: var(--muted);
    transition: transform 160ms ease;
}

.widget-body {
    padding: 0 12px 12px;
}

.widget-body img {
    display: block;
    width: 100%;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-muted);
}

.widget-fallback {
    display: grid;
    justify-items: center;
    gap: 10px;
    min-height: 180px;
    padding: 22px 14px;
    color: var(--muted);
    text-align: center;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: var(--surface-muted);
}

.widget-fallback[hidden] {
    display: none;
}

.widget-fallback i {
    color: var(--accent);
    font-size: 28px;
}

.widget-fallback p {
    margin: 0;
}

.widget-fallback a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--accent-strong);
    background: var(--surface);
    font-weight: 700;
    text-decoration: none;
}

.focus-view {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
    padding: 10px;
    background: var(--focus-bg);
}

.focus-view[hidden] {
    display: none;
}

.focus-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 58px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-soft);
}

.focus-topbar > div:nth-child(2) {
    min-width: 0;
    flex: 1 1 auto;
}

.focus-frame {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 0;
    margin: 0;
    overflow: hidden;
    border-radius: var(--radius);
    background: #05070a;
}

.focus-grid {
    position: absolute;
    inset: 0;
    display: grid;
    gap: 8px;
    min-width: 0;
    min-height: 0;
    padding: 8px;
}

.focus-grid.layout-1 {
    grid-template-columns: minmax(0, 1fr);
}

.focus-grid.layout-2,
.focus-grid.layout-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.focus-tile {
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #05070a;
    box-shadow: var(--shadow);
}

.focus-tile img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #0e1216;
}

.focus-tile-label {
    position: absolute;
    left: 8px;
    top: 8px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: calc(100% - 16px);
    padding: 5px 8px;
    border-radius: 999px;
    color: #f8fafc;
    background: rgba(5, 7, 10, 0.7);
    font-size: 12px;
    font-weight: 700;
    pointer-events: none;
}

.focus-frame figcaption {
    position: absolute;
    right: 10px;
    bottom: 10px;
    max-width: min(420px, calc(100% - 20px));
    padding: 6px 10px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    color: #f8fafc;
    background: rgba(5, 7, 10, 0.72);
    font-size: 13px;
    text-align: center;
    pointer-events: none;
}

.settings-panel {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: transparent;
    border: 0;
    box-shadow: none;
}

.settings-panel[hidden] {
    display: none;
}

.settings-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.48);
}

.settings-card {
    position: absolute;
    top: 12px;
    right: 12px;
    bottom: 12px;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    width: min(460px, calc(100vw - 24px));
    overflow: hidden;
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.settings-content {
    display: grid;
    align-content: start;
    gap: 14px;
    min-height: 0;
    padding: 16px;
    overflow: auto;
}

.settings-group {
    display: grid;
    gap: 10px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-muted);
}

.field,
.toggle-row,
.camera-preference-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(126px, 180px);
    gap: 12px;
    align-items: center;
}

.field > span,
.toggle-row > span,
.camera-preference-row > span {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    color: var(--muted);
}

.field select,
.field input {
    width: 100%;
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    background: var(--surface);
}

.toggle-row input,
.camera-preference-row input {
    justify-self: end;
    width: 20px;
    height: 20px;
    accent-color: var(--accent);
}

.camera-preferences {
    display: grid;
    gap: 8px;
    max-height: 280px;
    overflow: auto;
    padding-right: 4px;
}

.camera-preference-row {
    grid-template-columns: minmax(0, 1fr) auto;
    min-height: 34px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}

.camera-preference-row:last-child {
    border-bottom: 0;
}

.secondary-button,
.danger-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 0 12px;
}

.secondary-button {
    color: var(--text);
    background: var(--surface);
}

.danger-button {
    color: var(--danger);
    background: var(--danger-soft);
    border-color: color-mix(in srgb, var(--danger) 36%, var(--border));
}

.danger-button:hover {
    transform: translateY(-1px);
    border-color: var(--danger);
}

@media (max-width: 1180px) {
    .dashboard-layout {
        grid-template-columns: 1fr;
    }

    .info-panel {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    }
}

@media (max-width: 760px) {
    :root {
        --header-height: 68px;
        --control-height: 36px;
    }

    .app-shell {
        padding: 8px;
    }

    .app-header,
    .section-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .focus-view {
        gap: 6px;
        padding: 6px;
    }

    .focus-topbar {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto;
        align-items: center;
        min-height: 46px;
        padding: 5px;
        gap: 6px;
    }

    .focus-topbar .eyebrow {
        display: none;
    }

    .toolbar,
    .focus-actions,
    .status-strip {
        justify-content: flex-start;
    }

    .brand-icon {
        flex-basis: 42px;
        width: 42px;
        height: 42px;
    }

    h1 {
        font-size: 21px;
    }

    h2 {
        font-size: 19px;
    }

    .focus-topbar h2 {
        font-size: 16px;
    }

    .focus-actions {
        gap: 5px;
    }

    .focus-topbar .icon-button {
        width: 34px;
        height: 34px;
        min-height: 34px;
    }

    .focus-frame figcaption {
        right: 6px;
        bottom: 6px;
        padding: 4px 8px;
        font-size: 11px;
    }

    .focus-grid {
        gap: 4px;
        padding: 4px;
    }

    .focus-grid.layout-2 {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: repeat(2, minmax(0, 1fr));
    }

    .focus-grid.layout-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-rows: repeat(2, minmax(0, 1fr));
    }

    .focus-tile-label {
        left: 5px;
        top: 5px;
        padding: 3px 6px;
        font-size: 11px;
    }

    .camera-section {
        padding: 12px;
    }

    .camera-grid,
    .camera-grid.density-comfortable,
    .camera-grid.density-compact,
    .camera-grid.density-large {
        grid-template-columns: 1fr;
    }

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

    .camera-actions {
        justify-content: flex-start;
    }

    .info-panel {
        grid-template-columns: 1fr;
    }

    .settings-card {
        top: auto;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        max-height: 92vh;
        border-radius: var(--radius) var(--radius) 0 0;
    }

    .field,
    .toggle-row,
    .camera-preference-row {
        grid-template-columns: 1fr;
    }

    .toggle-row input,
    .camera-preference-row input {
        justify-self: start;
    }
}

@media (max-width: 420px) {
    .toolbar,
    .focus-actions,
    .quick-filters {
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        width: 100%;
    }

    .quick-filters {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .quick-filters .chip span {
        display: none;
    }

    .focus-topbar .focus-actions {
        display: flex;
        width: auto;
        gap: 4px;
    }

    .focus-topbar .icon-button {
        width: 32px;
        height: 32px;
        min-height: 32px;
    }

    .icon-button,
    .chip {
        width: 100%;
    }

    .chip {
        min-height: 36px;
        padding: 0;
        justify-content: center;
    }

    .status-pill {
        width: 100%;
        justify-content: center;
    }
}

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