:root {
    /* Base theme tokens (needed on standalone pages like login/offline) */
    --bg-body: 
        linear-gradient(180deg, #eef4fb 0%, #e5eef8 52%, #dde8f4 100%),
        linear-gradient(rgba(37, 99, 235, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(37, 99, 235, 0.03) 1px, transparent 1px);
    --bg-card: #fff;
    --bg-input: #fff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.12);
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --success-bg: #dcfce7;
    --success-text: #166534;
    --danger-bg: #fee2e2;
    --danger-text: #991b1b;
}

.dark {
    --bg-body:
        linear-gradient(180deg, #0f172a 0%, #172235 56%, #1e2a3f 100%),
        linear-gradient(rgba(96, 165, 250, 0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(96, 165, 250, 0.035) 1px, transparent 1px);
    --bg-card: #1e293b;
    --bg-input: #334155;
    --border: #475569;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --accent: #60a5fa;
    --accent-hover: #93c5fd;
}

.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
}

.btn-secondary {
    background: color-mix(in srgb, var(--bg-card) 86%, var(--border));
}

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

.flash {
    border-radius: var(--radius-sm);
}

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

.flash-error {
    background: var(--danger-bg);
    color: var(--danger-text);
}

.header-spacer {
    height: 86px;
}

.header-bar {
    padding: 0.9rem 1.5rem;
}

header.header-cameras {
    border-radius: var(--radius-lg);
    padding: 0.7rem 1rem;
}

.header-section-tabs .btn {
    min-height: 2.2rem;
}

.header-menu-btn {
    min-height: 2.2rem;
}

.breadcrumbs {
    margin-bottom: var(--space-5);
}

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

/* Login */
.login-page {
    font-family: "Inter", "Segoe UI", system-ui, sans-serif;
    background: linear-gradient(180deg, #e8efff 0%, #dbeafe 45%, #ecfeff 100%);
    color: #1e293b;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: var(--radius-lg);
    border: 1px solid #e2e8f0;
    box-shadow: var(--shadow-md);
    padding: 2rem;
}

/* Camera section password login */
.camera-login-card {
    max-width: 400px;
    padding: 1.75rem;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-5);
}

.login-logo {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    object-fit: contain;
    background: #eff6ff;
    border: 1px solid #dbeafe;
}

.login-title {
    font-size: 1.45rem;
    font-weight: 700;
    margin: 0;
}

.login-form .form-group {
    margin-bottom: var(--space-4);
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
}

.camera-login-form .form-group {
    max-width: 280px;
}

.camera-login-form {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.camera-login-form .form-group {
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

.login-card .form-group label {
    display: block;
    margin-bottom: 0.4rem;
    color: #64748b;
    font-size: 0.9rem;
    font-weight: 500;
}

.login-form input,
.camera-login-form input {
    box-sizing: border-box;
    width: 100%;
    padding: 0.65rem 0.9rem;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-sm);
    background: #fff;
    color: #1e293b;
    font-size: 0.95rem;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.login-form input:focus,
.camera-login-form input:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.16);
}

.login-form .btn,
.camera-login-form .btn {
    box-sizing: border-box;
    border-radius: var(--radius-sm);
    width: 100%;
    margin-top: var(--space-2);
    padding: 0.72rem;
    border: none;
    color: #fff;
    font-size: 0.98rem;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.login-form .btn,
.camera-login-form .btn {
    max-width: 320px;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.camera-login-form .btn {
    max-width: 280px;
}

.login-form .btn:hover,
.camera-login-form .btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(79, 70, 229, 0.22);
}

.login-2fa-hint {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0 0 1rem;
}
.login-2fa-back {
    margin-top: 1rem;
    font-size: 0.9rem;
}
.login-2fa-back a { color: var(--accent); }

.login-card .flash {
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.3;
    display: flex;
    align-items: flex-start;
    gap: 0.55rem;
    border: 1px solid transparent;
}

.login-card .flash-success { border-color: color-mix(in srgb, var(--success-text) 18%, transparent); }
.login-card .flash-error { border-color: color-mix(in srgb, var(--danger-text) 18%, transparent); }
.login-card .flash-success::before,
.login-card .flash-error::before {
    content: "!";
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    font-weight: 800;
    line-height: 1;
    margin-top: 1px;
}
.login-card .flash-success::before {
    content: "✓";
    background: color-mix(in srgb, var(--success-bg) 65%, #fff);
    color: var(--success-text);
}
.login-card .flash-error::before {
    background: color-mix(in srgb, var(--danger-bg) 65%, #fff);
    color: var(--danger-text);
}

.login-toast-stack {
    position: fixed;
    left: 50%;
    bottom: 1rem;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 9999;
    width: auto;
    max-width: 92vw;
    pointer-events: none;
}

.login-toast {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.75rem;
    border-radius: 12px;
    padding: 0.65rem 0.8rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    background: var(--bg-card);
    color: var(--text);
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.login-toast.is-hiding {
    opacity: 0;
    transform: translateY(8px);
}

.login-toast-error {
    background: transparent;
    border-color: transparent;
    box-shadow: none;
    color: #b91c1c;
    padding: 0.2rem 0.15rem;
}

.login-toast-success {
    background: #ecfdf5;
    border-color: #86efac;
    color: #166534;
}

.login-toast-text {
    font-size: 0.92rem;
    line-height: 1.25;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
}

.login-toast-error .login-toast-text::before {
    content: "!";
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.78rem;
    border: 1px solid color-mix(in srgb, currentColor 38%, transparent);
    background: color-mix(in srgb, currentColor 8%, #fff);
}

.login-toast-close {
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0.1rem 0.25rem;
    border-radius: 6px;
    margin-left: 0.25rem;
}

.login-toast-close:hover {
    background: color-mix(in srgb, currentColor 10%, transparent);
}

/* Error and offline pages */
.status-page {
    min-height: 100vh;
    padding: var(--space-4);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-body);
    color: var(--text);
    font-family: "Inter", "Segoe UI", system-ui, sans-serif;
}

.status-card {
    width: 100%;
    max-width: 720px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 1.25rem;
}

.status-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

/* Cameras dashboard */
.cameras-dashboard .cameras-stat-card {
    border-radius: var(--radius-md);
}

.cameras-dashboard .cameras-dashboard-card {
    min-height: 280px;
}

.cameras-dashboard .chart-wrap {
    padding: 0.25rem;
}

/* Cameras list tree */
.camera-page .table-wrap {
    border-radius: var(--radius-md);
}

.object-tree .tree-object-row,
.object-tree .tree-sector-row,
.object-tree .tree-camera-row {
    transition: background-color 0.18s ease, border-color 0.18s ease;
}

.object-tree .tree-object-row.expanded {
    box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.15);
}

.status-badge {
    border-radius: 999px;
    font-weight: 700;
    padding: 0.24rem 0.62rem;
}

.status-working {
    background: #dcfce7;
    color: #166534;
}

.status-not_working {
    background: #fee2e2;
    color: #b91c1c;
}

/* Map */
/* На широких экранах карта не остаётся «квадратом» в колонке 1280px — тянем на всю ширину вьюпорта */
@media (min-width: 1280px) {
    .camera-map-page {
        width: 100vw;
        max-width: 100vw;
        margin-left: calc(50% - 50vw);
        padding-left: max(2rem, env(safe-area-inset-left, 0px));
        padding-right: max(2rem, env(safe-area-inset-right, 0px));
        box-sizing: border-box;
    }
}

.camera-map-page .camera-map-filters {
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.camera-map-page .map-frame {
    border-radius: var(--radius-md);
}

.camera-map-page .map-fullscreen-btn {
    border-radius: 10px;
}

/* Forms and view pages */
.camera-form-page .form-card-header {
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.card-view .card-header {
    gap: var(--space-3);
}

.card-view .actions {
    row-gap: var(--space-2);
}

.attachment-list {
    margin: 0;
    padding-left: 1rem;
}

@media (max-width: 768px) {
    .header-spacer {
        height: 108px;
    }

    .header-bar {
        padding: 0.55rem 0.8rem;
    }

    header.header-cameras {
        padding: 0.55rem 0.7rem;
    }

    .login-card {
        padding: 1.25rem;
    }
}
