/* ========================================
   AlertAxis V2 - Design System
   Dark-first theme with CSS variables
   ======================================== */

/* === Theme Variables === */
[data-theme="dark"], :root {
    --bg: #0f1117;
    --surface-1: #161b22;
    --surface-2: #21262d;
    --surface-3: #30363d;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --text-ghost: #484f58;
    --main: #3b82f6;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;

    /* Semantic colours */
    --success: #00c98e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --purple: #8b5cf6;

    /* Status colours */
    --alarm: #ffe746;
    --alert: #ef4444;
    --prealert: #3b82f6;
    --parked: #8b949e;
    --closed: #00c98e;
    --stooddown: #f59e0b;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
}

[data-theme="light"] {
    --bg: #f6f8fa;
    --surface-1: #ffffff;
    --surface-2: #f0f2f5;
    --surface-3: #e1e4e8;
    --border: #d0d7de;
    --text: #1f2937;
    --text-muted: #57606a;
    --text-ghost: #8b949e;
    --main: #3b82f6;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;

    --success: #00c98e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --purple: #8b5cf6;

    --alarm: #d4a017;
    --alert: #dc2626;
    --prealert: #2563eb;
    --parked: #6b7280;
    --closed: #059669;
    --stooddown: #d97706;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);
}

/* === Base Reset === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--main); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Typography === */
h1 { font-size: 24px; font-weight: 600; color: var(--text); }
h2 { font-size: 20px; font-weight: 600; color: var(--text); }
h3 { font-size: 16px; font-weight: 600; color: var(--text); }
h4 { font-size: 14px; font-weight: 600; color: var(--text); }
.text-muted { color: var(--text-muted); }
.text-ghost { color: var(--text-ghost); }
.text-sm { font-size: 11px; }
.text-mono { font-family: 'Cascadia Code', Consolas, monospace; }

/* === Layout === */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.app-sidebar {
    width: 220px;
    background: var(--surface-1);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
    transition: width 0.2s;
}

.app-sidebar.collapsed {
    width: 52px;
}

.app-sidebar.collapsed .nav-label,
.app-sidebar.collapsed .nav-section-title,
.app-sidebar.collapsed .sidebar-brand-text {
    display: none;
}

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.app-topbar {
    height: 48px;
    background: var(--surface-1);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    flex-shrink: 0;
}

.app-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

/* === Sidebar Navigation === */
.sidebar-brand {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border);
    min-height: 48px;
}

.sidebar-brand img {
    height: 28px;
}

.sidebar-brand-text {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
}

.nav-section-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-ghost);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 16px 16px 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 16px;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
    border-radius: 0;
    text-decoration: none;
    position: relative;
}

.nav-item:hover {
    background: var(--surface-2);
    color: var(--text);
    text-decoration: none;
}

.nav-item.active {
    color: var(--main);
    background: color-mix(in srgb, var(--main), transparent 90%);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 4px;
    bottom: 4px;
    width: 3px;
    background: var(--main);
    border-radius: 0 2px 2px 0;
}

.nav-item i, .nav-item .nav-icon {
    width: 20px;
    text-align: center;
    font-size: 14px;
    flex-shrink: 0;
}

.nav-badge {
    margin-left: auto;
    background: var(--danger);
    color: white;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.nav-divider {
    height: 1px;
    background: var(--border);
    margin: 8px 16px;
}

/* === Topbar === */
.topbar-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
    font-size: 12px;
    font-weight: 600;
}

.topbar-badge:hover {
    background: var(--surface-2);
}

.topbar-badge .count {
    min-width: 20px;
    text-align: center;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-muted);
    font-size: 12px;
}

.topbar-user:hover {
    background: var(--surface-2);
    color: var(--text);
}

/* === Cards === */
.v3-card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    transition: background 0.15s;
}

.v3-card:hover {
    background: var(--surface-2);
}

.v3-card.clickable {
    cursor: pointer;
}

.v3-card-header {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

/* === Stat Cards (Dashboard) === */
.stat-card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
    border-left: 3px solid var(--state-color, var(--border));
}

.stat-card:hover {
    background: var(--surface-2);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

.stat-card .stat-icon {
    font-size: 24px;
    margin-bottom: 8px;
}

/* === Tables === */
.v3-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.v3-table thead th {
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1;
}

.v3-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

.v3-table tbody tr:hover {
    background: var(--surface-2);
}

.v3-table tbody tr.clickable {
    cursor: pointer;
}

.v3-table tbody td {
    padding: 8px 12px;
    color: var(--text);
}

.v3-table tbody tr.selected {
    background: color-mix(in srgb, var(--main), transparent 85%);
}

/* === Badges/Chips === */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-alarm { background: color-mix(in srgb, var(--alarm), transparent 80%); color: var(--alarm); }
.badge-alert { background: color-mix(in srgb, var(--alert), transparent 80%); color: var(--alert); }
.badge-prealert { background: color-mix(in srgb, var(--prealert), transparent 80%); color: var(--prealert); }
.badge-parked { background: color-mix(in srgb, var(--parked), transparent 80%); color: var(--parked); }
.badge-closed { background: color-mix(in srgb, var(--closed), transparent 80%); color: var(--closed); }
.badge-stooddown { background: color-mix(in srgb, var(--stooddown), transparent 80%); color: var(--stooddown); }
.badge-success { background: color-mix(in srgb, var(--success), transparent 80%); color: var(--success); }
.badge-warning { background: color-mix(in srgb, var(--warning), transparent 80%); color: var(--warning); }
.badge-danger { background: color-mix(in srgb, var(--danger), transparent 80%); color: var(--danger); }
.badge-info { background: color-mix(in srgb, var(--info), transparent 80%); color: var(--info); }
.badge-primary { background: color-mix(in srgb, var(--main), transparent 80%); color: var(--main); }
.badge-muted { background: var(--surface-2); color: var(--text-muted); }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-1);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    text-decoration: none;
}

.btn:hover {
    background: var(--surface-2);
    text-decoration: none;
}

.btn-primary {
    background: var(--main);
    border-color: var(--main);
    color: white;
}

.btn-primary:hover {
    background: color-mix(in srgb, var(--main), black 15%);
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: color-mix(in srgb, var(--danger), black 15%);
}

.btn-success {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

.btn-warning {
    background: var(--warning);
    border-color: var(--warning);
    color: white;
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-muted);
}

.btn-ghost:hover {
    background: var(--surface-2);
    color: var(--text);
}

.btn-sm {
    padding: 3px 10px;
    font-size: 12px;
}

.btn-lg {
    padding: 10px 20px;
    font-size: 14px;
}

.btn-block {
    width: 100%;
    justify-content: center;
}

.btn:disabled, .btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn i, .btn svg {
    font-size: 14px;
}

/* === Form Inputs === */
.form-input, input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="search"], textarea, select {
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-1);
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    width: 100%;
    transition: border-color 0.15s;
}

.form-input:focus, input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--main);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--main), transparent 80%);
}

.form-input::placeholder, input::placeholder, textarea::placeholder {
    color: var(--text-ghost);
}

.form-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-group {
    margin-bottom: 12px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
}

/* === Modals/Dialogs === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    max-width: 520px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    font-size: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-body {
    padding: 16px;
}

.modal-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* === Tabs === */
.v3-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    gap: 0;
}

.v3-tab {
    padding: 8px 16px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
}

.v3-tab:hover {
    color: var(--text);
    background: var(--surface-2);
}

.v3-tab.active {
    color: var(--main);
    border-bottom-color: var(--main);
}

.v3-tab-content {
    padding: 16px 0;
}

/* === Alerts/Notifications === */
.v3-alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 12px;
}

.v3-alert-info { background: color-mix(in srgb, var(--info), transparent 90%); border: 1px solid color-mix(in srgb, var(--info), transparent 70%); color: var(--info); }
.v3-alert-success { background: color-mix(in srgb, var(--success), transparent 90%); border: 1px solid color-mix(in srgb, var(--success), transparent 70%); color: var(--success); }
.v3-alert-warning { background: color-mix(in srgb, var(--warning), transparent 90%); border: 1px solid color-mix(in srgb, var(--warning), transparent 70%); color: var(--warning); }
.v3-alert-danger { background: color-mix(in srgb, var(--danger), transparent 90%); border: 1px solid color-mix(in srgb, var(--danger), transparent 70%); color: var(--danger); }

/* === Pagination === */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 12px;
    background: var(--surface-1);
    border-top: 1px solid var(--border);
}

.pagination-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-1);
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
}

.pagination-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}

.pagination-btn.active {
    background: var(--main);
    border-color: var(--main);
    color: white;
}

.pagination-info {
    font-size: 12px;
    color: var(--text-ghost);
    margin-left: 12px;
}

/* === Search === */
.search-bar {
    position: relative;
}

.search-bar input {
    padding-left: 32px;
}

.search-bar i, .search-bar .search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-ghost);
    font-size: 14px;
}

/* === Toggle/Switch === */
.toggle {
    width: 36px;
    height: 20px;
    background: var(--surface-3);
    border-radius: 10px;
    cursor: pointer;
    position: relative;
    transition: background 0.2s;
}

.toggle.active {
    background: var(--main);
}

.toggle::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    top: 2px;
    left: 2px;
    transition: transform 0.2s;
}

.toggle.active::after {
    transform: translateX(16px);
}

/* === Checkbox === */
.v3-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
}

.v3-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--main);
}

/* === Progress Bar === */
.progress-bar {
    height: 6px;
    background: var(--surface-3);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--main);
    border-radius: 3px;
    transition: width 0.3s;
}

.progress-bar-fill.danger {
    background: var(--danger);
}

/* === Tooltip === */
[data-tooltip] {
    position: relative;
}

[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    font-size: 11px;
    white-space: nowrap;
    z-index: 100;
    box-shadow: var(--shadow-md);
    margin-bottom: 4px;
}

/* === Context Menu === */
.context-menu {
    position: absolute;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    min-width: 180px;
    z-index: 500;
    padding: 4px 0;
}

.context-item {
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}

.context-item:hover {
    background: var(--surface-2);
}

.context-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

/* === Toast Notifications === */
.toast-container {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    min-width: 300px;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.2s ease;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.toast-success { border-left: 3px solid var(--success); }
.toast-warning { border-left: 3px solid var(--warning); }
.toast-danger { border-left: 3px solid var(--danger); }
.toast-info { border-left: 3px solid var(--info); }

.toast-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.toast-message {
    font-size: 12px;
    color: var(--text-muted);
}

.toast-close {
    margin-left: auto;
    cursor: pointer;
    color: var(--text-ghost);
    font-size: 14px;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* === Dropdown === */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    min-width: 180px;
    z-index: 100;
    padding: 4px 0;
    margin-top: 4px;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    transition: background 0.1s;
}

.dropdown-item:hover {
    background: var(--surface-2);
}

/* === Grid Helpers === */
.grid { display: grid; }
.grid-2 { grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.grid-4 { grid-template-columns: 1fr 1fr 1fr 1fr; gap: 12px; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }
.w-full { width: 100%; }

/* Spacing */
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }
.ml-auto { margin-left: auto; }
.p-2 { padding: 8px; } .p-3 { padding: 12px; } .p-4 { padding: 16px; }
.px-3 { padding-left: 12px; padding-right: 12px; }
.py-2 { padding-top: 8px; padding-bottom: 8px; }

/* === Scrollbar === */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: var(--surface-3);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-ghost);
}

/* === Mobile Responsive === */
@media (max-width: 768px) {
    .app-sidebar {
        position: fixed;
        left: -220px;
        top: 0;
        bottom: 0;
        z-index: 100;
        transition: left 0.2s;
    }

    .app-sidebar.mobile-open {
        left: 0;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }

    .hide-mobile {
        display: none !important;
    }
}

/* === Loading Spinner === */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--surface-3);
    border-top-color: var(--main);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-ghost);
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 12px;
}

/* === Selection === */
::selection {
    background: color-mix(in srgb, var(--main), transparent 70%);
    color: var(--text);
}

/* === User Select === */
.selectable { user-select: all; }
.cursor-pointer { cursor: pointer; }
