@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

:root {
    --bg-body: #0b1120;
    --bg-panel: #111a2e;
    --bg-surface: #15213a;
    --bg-surface-alt: #1b2945;
    --border-color: rgba(148, 163, 184, 0.12);
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #6366f1;
    --accent-hover: #7c81ff;
    --danger: #f87171;
    --success: #34d399;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-glow: 0 24px 48px rgba(15, 23, 42, 0.35);
}

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

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    background: radial-gradient(circle at top left, rgba(99, 102, 241, 0.25), transparent 45%),
                radial-gradient(circle at bottom right, rgba(59, 130, 246, 0.2), transparent 40%),
                var(--bg-body);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    min-height: 100vh;
}

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

.app-shell {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(18px);
    border-right: 1px solid var(--border-color);
    padding: 28px 24px;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 32px;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 18px;
    letter-spacing: 0.04em;
}

.logo-mark {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    background: linear-gradient(135deg, #6366f1, #22d3ee);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 14px;
}

.logo-text {
    opacity: 0.92;
}

.sidebar-nav {
    display: grid;
    gap: 6px;
    color: var(--text-secondary);
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.nav-link .nav-icon {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: rgba(148, 163, 184, 0.14);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.nav-link:hover {
    background: rgba(99, 102, 241, 0.18);
    color: var(--text-primary);
    transform: translateX(4px);
}

.nav-link.active {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.4), rgba(59, 130, 246, 0.35));
    color: var(--text-primary);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.nav-link.active .nav-icon {
    background: rgba(226, 232, 240, 0.16);
    color: var(--text-primary);
}

.nav-link.muted {
    opacity: 0.8;
}

.sidebar-divider {
    border-bottom: 1px solid var(--border-color);
    margin: 18px 0 12px;
}

.sidebar-label {
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.main-panel {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.top-bar {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 28px 36px 16px;
    flex-wrap: wrap;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1 1 auto;
    min-width: 0;
}

.context-control {
    margin-top: 0;
    flex: 0 0 auto;
}

.context-switcher {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.context-switcher select {
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(15, 23, 42, 0.5);
    color: var(--text-primary);
}

.context-display {
    display: flex;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
}

.context-name {
    color: var(--text-primary);
    font-weight: 500;
}

.menu-toggle {
    display: none;
    background: rgba(148, 163, 184, 0.12);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: var(--radius-sm);
    padding: 8px;
    width: 42px;
    height: 38px;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    margin-right: 16px;
}

.menu-toggle span {
    display: block;
    height: 2px;
    background: var(--text-secondary);
    border-radius: 2px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.menu-toggle.active span:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
}

.menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.menu-toggle.active span:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
}

.sidebar-overlay {
    display: none;
}

.top-bar .page-title {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.top-bar-user {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-left: auto;
}

.user-meta {
    text-align: right;
}

.user-name {
    display: block;
    font-weight: 500;
}

.user-role {
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.page-content {
    padding: 0 36px 48px;
    flex: 1;
    margin: 0;
}

.page-content > *:first-child {
    margin-top: 0;
}

.guest-content {
    max-width: 420px;
    margin: 120px auto 40px;
    padding: 0 24px;
}

.card {
    background: rgba(21, 33, 58, 0.9);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.03);
    box-shadow: var(--shadow-glow);
    backdrop-filter: blur(14px);
    display: flex;
    flex-direction: column;
}

.card-header {
    padding: 20px 24px 12px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.08);
}

.card-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.card-body {
    padding: 20px 24px 24px;
    color: var(--text-secondary);
}

.card-body--table {
    padding: 0;
}

.polygon-settings .card-subtitle {
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 14px;
}

.polygon-rows {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.polygon-row {
    display: grid;
    grid-template-columns: minmax(240px, 2fr) 130px 160px 120px;
    gap: 16px;
    align-items: end;
    padding: 16px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: var(--radius-md);
    background: rgba(15, 23, 42, 0.35);
}

.polygon-row label {
    font-size: 13px;
    color: var(--text-muted);
    display: block;
    margin-bottom: 4px;
}

.polygon-row input[type="text"],
.polygon-row input[type="number"] {
    width: 100%;
}

.polygon-required {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
    font-size: 13px;
    color: var(--text-muted);
}

.toggle {
    position: relative;
    width: 46px;
    height: 24px;
    display: inline-flex;
    align-items: center;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle span {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(148, 163, 184, 0.4);
    border-radius: 999px;
    transition: background 0.2s ease;
}

.toggle span::after {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s ease;
}

.toggle input:checked + span {
    background: linear-gradient(135deg, #6366f1, #22d3ee);
}

.toggle input:checked + span::after {
    transform: translateX(22px);
}

.polygon-row-actions {
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
}

.polygon-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 24px;
}

.polygon-actions-spacer {
    flex: 1 1 auto;
}

.polygon-footer {
    margin-top: 18px;
}

.polygon-editor-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    margin-top: 20px;
}

.polygon-canvas-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.polygon-image-wrapper {
    position: relative;
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: rgba(15, 23, 42, 0.75);
}

.polygon-image-wrapper img {
    width: 100%;
    display: block;
}

.polygon-image-wrapper canvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: auto;
    width: 100%;
    height: 100%;
}

.polygon-image-wrapper.is-loading img,
.polygon-image-wrapper.is-loading canvas {
    opacity: 0.15;
    filter: grayscale(1);
}

.polygon-loader {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 8px;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.78), rgba(15, 23, 42, 0.65));
    color: var(--text-primary);
    font-weight: 600;
}

.polygon-loader[hidden] {
    display: none !important;
}

.loader-spinner {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid rgba(226, 232, 240, 0.25);
    border-top-color: var(--accent);
    animation: spin 1s linear infinite;
}

.polygon-placeholder {
    padding: 24px;
    border-radius: var(--radius-md);
    background: rgba(148, 163, 184, 0.12);
    color: var(--text-muted);
    text-align: center;
}

.polygon-rules-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.polygon-rule {
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: var(--radius-md);
    padding: 14px;
    background: rgba(15, 23, 42, 0.4);
}

.polygon-rule-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    gap: 8px;
}

.polygon-rule .rule-name {
    font-weight: 600;
}

.polygon-rule .rule-subtitle {
    font-size: 12px;
    color: var(--text-muted);
}

.rule-count {
    font-weight: 600;
    color: var(--primary);
}

.polygon-shape-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 12px;
}

.polygon-shape-card {
    border: 1px dashed rgba(148, 163, 184, 0.35);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.polygon-shape-card .shape-label {
    font-size: 13px;
    color: var(--text-secondary);
}

.polygon-draw-controls {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.polygon-draw-status {
    font-size: 13px;
    color: var(--text-muted);
}

.polygon-error {
    color: var(--danger);
}

.status-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}

.status-ok {
    background: #34d399;
    box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.15);
}

.status-down {
    background: #f87171;
    box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.15);
}

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

.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
}

.map-container {
    height: 420px;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    overflow: hidden;
}

.camera-balloon {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 13px;
    max-width: 240px;
}

.camera-balloon strong {
    font-size: 14px;
}

.balloon-address {
    color: var(--text-muted);
}

.balloon-image {
    width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(148, 163, 184, 0.3);
}

.balloon-placeholder {
    padding: 12px;
    background: rgba(15, 23, 42, 0.05);
    border-radius: var(--radius-sm);
    text-align: center;
}

.balloon-meta {
    font-size: 12px;
    color: var(--text-muted);
}

.balloon-link {
    font-size: 13px;
    color: var(--primary);
    text-decoration: none;
}

.balloon-link:hover {
    text-decoration: underline;
}

.events-card .card-body {
    padding: 0;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table thead {
    background: rgba(15, 23, 42, 0.65);
}

.data-table th,
.data-table td {
    padding: 14px 16px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.08);
    color: var(--text-secondary);
}

.data-table tbody tr:hover {
    background: rgba(99, 102, 241, 0.12);
}

.alert {
    border-radius: var(--radius-md);
    padding: 14px 18px;
    font-size: 14px;
    margin-bottom: 20px;
}

.alert-error {
    background: rgba(248, 113, 113, 0.12);
    color: #fca5a5;
    border: 1px solid rgba(248, 113, 113, 0.2);
}

.alert-success {
    background: rgba(52, 211, 153, 0.12);
    color: #6ee7b7;
    border: 1px solid rgba(52, 211, 153, 0.2);
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.button-primary {
    background: linear-gradient(135deg, #6366f1, #22d3ee);
    color: #0b1120;
    box-shadow: 0 14px 30px rgba(99, 102, 241, 0.25);
}

.button-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 18px 36px rgba(99, 102, 241, 0.35);
}

.button-ghost {
    background: rgba(148, 163, 184, 0.08);
    color: var(--text-secondary);
    border: 1px solid rgba(148, 163, 184, 0.15);
}

.button-ghost:hover {
    background: rgba(148, 163, 184, 0.18);
}

.link-underline {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.link-underline:hover {
    text-decoration: underline;
}

.button-small {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: var(--radius-sm);
    background: rgba(148, 163, 184, 0.12);
    color: var(--text-secondary);
    border: 1px solid rgba(148, 163, 184, 0.15);
}

label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--text-secondary);
}

input[type="text"],
input[type="password"],
input[type="email"],
textarea,
select {
    width: 100%;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(148, 163, 184, 0.15);
    background: rgba(15, 23, 42, 0.65);
    color: var(--text-primary);
    margin-bottom: 16px;
    transition: border 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
textarea:focus,
select:focus {
    border-color: rgba(99, 102, 241, 0.6);
    outline: none;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

textarea {
    resize: vertical;
}

.stacked-form {
    display: flex;
    flex-direction: column;
}

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

.flex-row {
    display: flex;
    gap: 24px;
}

.flex-grow {
    flex: 1;
}

.card-fixed {
    width: 360px;
}

.hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: -8px;
    margin-bottom: 16px;
}

.camera-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    margin-top: 0;
    margin-bottom: 28px;
}

.camera-meta dl {
    display: grid;
    grid-template-columns: minmax(120px, 1fr) 2fr;
    gap: 10px 18px;
    margin: 0;
    color: var(--text-secondary);
}

.camera-meta dt {
    color: var(--text-muted);
    font-weight: 500;
}

.camera-meta dd {
    margin: 0;
}

.stream-player {
    width: 100%;
    border-radius: var(--radius-md);
    background: #000;
    min-height: 240px;
}

.camera-map {
    height: 240px;
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-top: 16px;
}

.card-body--filters {
    padding: 20px 24px 8px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.08);
}

.filter-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px 18px;
}

.filter-field label {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.filter-field input,
.filter-field select {
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(15, 23, 42, 0.55);
    color: var(--text-primary);
}

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

.schedule-config {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

[data-schedule-form].is-loading {
    opacity: 0.6;
    pointer-events: none;
}

.schedule-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 12px;
}

.schedule-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.schedule-row input[type="time"] {
    flex: 1;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(15, 23, 42, 0.55);
    color: var(--text-primary);
}

.schedule-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 8px;
}

.schedule-feedback {
    min-height: 18px;
    font-size: 13px;
    color: var(--text-secondary);
}

.schedule-feedback[data-status="success"] {
    color: var(--success);
}

.schedule-feedback[data-status="error"] {
    color: var(--danger);
}

.readonly-field {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px dashed rgba(148, 163, 184, 0.25);
    background: rgba(15, 23, 42, 0.3);
    color: var(--text-secondary);
    min-height: 42px;
    display: flex;
    align-items: center;
}

.model-stats-card {
    margin-top: 24px;
}

.model-stats-body {
    display: flex;
    gap: 32px;
    align-items: center;
    flex-wrap: wrap;
}

.model-chart {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.4);
    position: relative;
}

.model-chart-inner {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: var(--bg-panel);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-align: center;
}

.model-chart-value {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.model-chart-label {
    font-size: 12px;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    text-transform: uppercase;
}

.model-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px 24px;
    flex: 1;
}

.model-metric {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.08);
}

.model-metric:last-child {
    border-bottom: none;
}

.metric-label {
    font-size: 12px;
    color: var(--text-muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.metric-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.text-success {
    color: var(--success);
}

.text-danger {
    color: var(--danger);
}

.pagination-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 12px 18px;
    padding: 16px 24px 20px;
    border-top: 1px solid rgba(148, 163, 184, 0.08);
}

.pagination-info {
    font-size: 13px;
    color: var(--text-muted);
}

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

.pagination-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(15, 23, 42, 0.5);
    color: var(--text-secondary);
    font-size: 13px;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.pagination-link:hover {
    background: rgba(99, 102, 241, 0.22);
    border-color: rgba(99, 102, 241, 0.35);
    color: var(--text-primary);
}

.pagination-link.active {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.5), rgba(59, 130, 246, 0.45));
    border-color: transparent;
    color: var(--text-primary);
    box-shadow: 0 12px 24px rgba(99, 102, 241, 0.25);
}

.pagination-link.disabled {
    opacity: 0.5;
    cursor: default;
    pointer-events: none;
}

.pagination-ellipsis {
    color: var(--text-muted);
    padding: 0 4px;
}

.neural-card-header {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
}

.neural-tab-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tab-button {
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(148, 163, 184, 0.16);
    background: rgba(15, 23, 42, 0.35);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.tab-button:hover {
    background: rgba(99, 102, 241, 0.18);
    border-color: rgba(99, 102, 241, 0.35);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.tab-button.active {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.45), rgba(59, 130, 246, 0.42));
    color: var(--text-primary);
    border-color: transparent;
    box-shadow: 0 12px 24px rgba(99, 102, 241, 0.18);
}

.neural-card-body {
    padding-top: 16px;
}

.neural-card .tab-content {
    display: none;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.neural-card .tab-content.active {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.neural-card .tab-content[hidden] {
    display: none !important;
}

.tab-description {
    margin-bottom: 18px;
}

.neural-section + .neural-section {
    margin-top: 28px;
}

.neural-section h3 {
    margin-top: 0;
    margin-bottom: 14px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.table-scroll {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid rgba(148, 163, 184, 0.1);
}

.table-scroll table {
    min-width: 100%;
}

.table-scroll::-webkit-scrollbar {
    height: 8px;
}

.table-scroll::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.4);
}

.table-scroll::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.45);
    border-radius: 999px;
}

.pollution-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 14px;
}

.pollution-item {
    padding: 16px 18px;
    border-radius: var(--radius-md);
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid rgba(148, 163, 184, 0.12);
}

.pollution-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.pollution-metrics {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 18px;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.pollution-description {
    font-size: 13px;
    color: var(--text-secondary);
}

.level-tag {
    background: rgba(99, 102, 241, 0.2);
}

.pollution-item.level-critical {
    border-color: rgba(248, 113, 113, 0.45);
}

.pollution-item.level-critical .level-tag {
    background: rgba(248, 113, 113, 0.2);
    color: #fca5a5;
}

.pollution-item.level-medium .level-tag {
    background: rgba(234, 179, 8, 0.2);
    color: #fde68a;
}

.pollution-item.level-low .level-tag {
    background: rgba(34, 211, 238, 0.2);
    color: #67e8f9;
}

.pollution-item.level-none .level-tag {
    background: rgba(148, 163, 184, 0.2);
    color: var(--text-muted);
}

.media-preview {
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(15, 23, 42, 0.45);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.media-preview:hover {
    background: rgba(99, 102, 241, 0.25);
    border-color: rgba(99, 102, 241, 0.4);
    transform: translateY(-1px);
}

.media-modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1400;
}

.media-modal.active {
    display: flex;
}

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

.media-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.72);
    backdrop-filter: blur(6px);
}

.media-modal-dialog {
    position: relative;
    background: rgba(15, 23, 42, 0.95);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(99, 102, 241, 0.25);
    padding: 16px 18px 18px;
    max-width: min(90vw, 900px);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.6);
    z-index: 1;
}

.media-modal-close {
    position: absolute;
    top: 10px;
    right: 12px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(99, 102, 241, 0.15);
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.media-modal-close:hover {
    background: rgba(99, 102, 241, 0.35);
    transform: rotate(90deg);
}

.media-modal-body {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.media-player {
    max-width: 80vw;
    max-height: 70vh;
    width: auto;
    height: auto;
    border-radius: var(--radius-md);
    box-shadow: 0 18px 32px rgba(15, 23, 42, 0.5);
    display: block;
    object-fit: contain;
    background: #000;
}

.checkbox-group {
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: var(--radius-md);
    padding: 16px 18px;
    background: rgba(15, 23, 42, 0.55);
}

.checkbox-group legend {
    padding: 0 4px;
    color: var(--text-secondary);
    font-size: 12px;
    letter-spacing: 0.04em;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.checkbox-item input {
    accent-color: #6366f1;
    width: 16px;
    height: 16px;
}

.event-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.event-list li {
    padding: 12px 0;
    border-bottom: 1px solid rgba(148, 163, 184, 0.08);
}

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

.app-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 36px;
    color: var(--text-muted);
    font-size: 13px;
    border-top: 1px solid rgba(148, 163, 184, 0.08);
}

.app-footer.guest {
    justify-content: center;
    padding: 32px 0 48px;
    border-top: none;
}

.auth-card {
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(148, 163, 184, 0.16);
    border-radius: var(--radius-lg);
    padding: 38px;
    box-shadow: var(--shadow-glow);
}

.auth-card h1 {
    margin-top: 0;
    margin-bottom: 24px;
    font-size: 24px;
    font-weight: 600;
}

.widget-title {
    font-size: 14px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(99, 102, 241, 0.16);
    color: var(--text-primary);
    font-size: 12px;
}

.map-widget {
    height: 220px;
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-top: 16px;
}

.tag-list {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag {
    padding: 4px 10px;
    background: rgba(99, 102, 241, 0.2);
    border-radius: 999px;
    font-size: 12px;
    color: var(--text-primary);
    border: 1px solid rgba(99, 102, 241, 0.25);
}

.tag-link {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.tag-link:hover {
    background: rgba(99, 102, 241, 0.35);
}

.neural-assignment-form {
    position: relative;
}

.neural-toolbar {
    position: sticky;
    top: 20px;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 18px;
    margin: 0 0 16px;
    background: rgba(17, 26, 46, 0.95);
    border: 1px solid rgba(99, 102, 241, 0.28);
    border-radius: var(--radius-md);
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.25);
    backdrop-filter: blur(12px);
}

.neural-toolbar.active {
    border-color: rgba(99, 102, 241, 0.6);
    box-shadow: 0 16px 32px rgba(99, 102, 241, 0.25);
}

.assign-toggle {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    color: var(--text-secondary);
}

.assign-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #6366f1;
}

.neural-controls {
    display: none;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.neural-toolbar.active .neural-controls {
    display: flex;
}

.camera-table {
    width: 100%;
}

.camera-table thead {
    background: rgba(15, 23, 42, 0.65);
}

.camera-table th,
.camera-table td {
    padding: 14px 16px;
}

.neural-view {
    display: block;
}

.neural-edit {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.neural-assignment-form.editing .neural-view {
    display: none;
}

.neural-assignment-form.editing .neural-edit {
    display: flex;
}

.neural-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: rgba(148, 163, 184, 0.12);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(148, 163, 184, 0.18);
    color: var(--text-secondary);
}

.neural-checkbox input {
    margin: 0;
    accent-color: #6366f1;
}

.status-view {
    color: var(--text-secondary);
}

.status-edit {
    display: none;
    align-items: center;
    gap: 10px;
}

.neural-assignment-form.editing .status-view {
    display: none;
}

.neural-assignment-form.editing .status-edit {
    display: inline-flex;
}

.status-switch {
    position: relative;
    display: inline-flex;
    width: 46px;
    height: 24px;
    cursor: pointer;
}

.status-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.status-slider {
    position: absolute;
    inset: 0;
    background: rgba(148, 163, 184, 0.4);
    border-radius: 999px;
    transition: background 0.2s ease;
}

.status-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    top: 3px;
    border-radius: 50%;
    background: #ffffff;
    transition: transform 0.2s ease;
}

.status-switch input:checked + .status-slider {
    background: rgba(99, 102, 241, 0.9);
}

.status-switch input:checked + .status-slider::before {
    transform: translateX(22px);
}

.status-switch input:focus-visible + .status-slider {
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.35);
}

.devices-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
}

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

.device-meta {
    display: grid;
    gap: 10px;
}

.device-meta-item {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-secondary);
    padding: 12px 16px;
    background: rgba(17, 26, 46, 0.9);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(148, 163, 184, 0.08);
}

select[multiple] {
    height: 150px;
    background: rgba(15, 23, 42, 0.75);
}

@media (max-width: 1200px) {
    .app-shell {
        grid-template-columns: 220px 1fr;
    }

    .dashboard-grid,
    .camera-layout,
    .devices-grid {
        grid-template-columns: 1fr;
    }

    .card-fixed {
        width: 100%;
    }
}

@media (max-width: 920px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: 220px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 100;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .menu-toggle {
        display: inline-flex;
    }

    .side-stack {
        width: 100%;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.72);
        backdrop-filter: blur(6px);
        z-index: 90;
    }

    body.sidebar-open .sidebar-overlay {
        display: block;
    }

    body.sidebar-open {
        overflow: hidden;
    }

    .main-panel {
        margin-left: 0;
    }

    .top-bar {
        gap: 16px;
    }

    .top-bar-left {
        width: 100%;
    }

    .context-control {
        width: 100%;
    }

    .top-bar-user {
        width: 100%;
        justify-content: space-between;
    }

    .polygon-row {
        grid-template-columns: 1fr;
    }

    .polygon-row-actions {
        justify-content: flex-start;
    }

    .polygon-editor-layout {
        grid-template-columns: 1fr;
    }

}

@media (max-width: 640px) {
    .guest-content {
        margin-top: 60px;
    }

    .card {
        border-radius: var(--radius-md);
    }

    .data-table th,
    .data-table td {
        padding: 10px 12px;
    }

    .card-fixed {
        width: 100%;
    }

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

    .neural-controls {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .neural-checkbox {
        width: 100%;
        justify-content: space-between;
    }
}
