/* ============================================
   SAVIA FINOFO-INSPIRED UI SYSTEM
   Modern, Clean, Minimal Design
   ============================================ */

/* ===== CSS VARIABLES ===== */
:root,
[data-theme="savia"] {
    /* Primary Brand Colors */
    --accent-primary: #2563EB;
    --accent-secondary: #3B82F6;
}

/* ===== LIGHT MODE PRESET ===== */
[data-theme="light"] {
    /* Backgrounds */
    --bg-base: #F1F5F9;
    --bg-elevated: #FFFFFF;
    --bg-surface: #F8FAFC;
    --bg-card: rgba(255, 255, 255, 0.85);
    --bg-card-solid: #FFFFFF;
    --bg-card-hover: #F1F5F9;
    --bg-input: rgba(0, 0, 0, 0.04);
    --bg-input-focus: rgba(59, 130, 246, 0.08);

    /* Text */
    --text-primary: #F1F5F9;
    --text-secondary: #475569;
    --text-muted: #94A3B8;

    /* Borders */
    --border-subtle: rgba(0, 0, 0, 0.06);
    --border-default: rgba(0, 0, 0, 0.1);
    --border-strong: rgba(0, 0, 0, 0.15);
}

/* Fix Dropdown Visibility on all themes */
select option {
    background-color: #FFFFFF;
    color: #1e293b;
}

:root,
[data-theme="savia"] {
    /* Primary Brand Colors */
    --accent-primary: #2563EB;
    --accent-secondary: #3B82F6;
    --accent-gradient: linear-gradient(135deg, #2563EB 0%, #3B82F6 100%);
    --accent-blue: #3B82F6;
    --accent-glow: rgba(37, 99, 235, 0.15);

    /* Background System - Clean Light */
    --bg-base: #FFFFFF;
    --bg-elevated: #F8FAFC;
    --bg-surface: #F1F5F9;
    --bg-card: #FFFFFF;
    --bg-card-solid: #FFFFFF;
    --bg-card-hover: #F1F5F9;
    --bg-input: #F8FAFC;
    --bg-input-focus: rgba(37, 99, 235, 0.06);

    /* Text System */
    --text-primary: #1E293B;
    --text-secondary: #64748B;
    --text-muted: #94A3B8;
    --text-accent: #2563EB;

    /* Border System */
    --border-subtle: #E2E8F0;
    --border-default: #CBD5E1;
    --border-strong: #94A3B8;
    --border-accent: rgba(37, 99, 235, 0.3);
    --border-focus: rgba(37, 99, 235, 0.5);

    /* Shadow System - Light */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.12);
    --shadow-glow: 0 0 40px var(--accent-glow);

    /* Status Colors */
    --success: #10B981;
    --success-bg: rgba(16, 185, 129, 0.1);
    --warning: #F59E0B;
    --warning-bg: rgba(245, 158, 11, 0.1);
    --danger: #EF4444;
    --danger-bg: rgba(239, 68, 68, 0.1);
    --info: #3B82F6;
    --info-bg: rgba(59, 130, 246, 0.1);
    --maintenance: #8B5CF6;
    --maintenance-bg: rgba(139, 92, 246, 0.1);

    /* Spacing Scale */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
    --space-16: 4rem;

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-2xl: 28px;
    --radius-full: 9999px;

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;
    --transition-slow: 0.3s ease;

    /* Z-Index Hierarchy — Single Source of Truth */
    --z-content: 1;
    --z-sticky: 100;
    --z-nav: 1000;
    --z-mobile-nav: 9999;
    --z-modal-backdrop: 10000;
    --z-modal: 10010;
    --z-toast: 11000;

    /* Legacy Support */
    --primary-blue: #2563EB;
    --primary-green: #3B82F6;
    --dark-bg: #FFFFFF;
    --darker-bg: #030508;
    --card-bg: rgba(241, 245, 249, 0.6);
    --sidebar-bg: #F8FAFC;
    --sidebar-hover: rgba(241, 245, 249, 0.8);
    --text-primary-old: #F8FAFC;
    --border-color: rgba(255, 255, 255, 0.08);
}

/* Theme Variants */
[data-theme="ocean"] {
    --accent-primary: #0EA5E9;
    --accent-secondary: #06B6D4;
    --accent-gradient: linear-gradient(135deg, #0EA5E9 0%, #06B6D4 100%);
    --accent-glow: rgba(14, 165, 233, 0.15);
    --primary-blue: #0EA5E9;
    --primary-green: #06B6D4;
}

[data-theme="emerald"] {
    --accent-primary: #10B981;
    --accent-secondary: #34D399;
    --accent-gradient: linear-gradient(135deg, #10B981 0%, #34D399 100%);
    --accent-glow: rgba(16, 185, 129, 0.15);
    --primary-blue: #10B981;
    --primary-green: #34D399;
}

[data-theme="violet"] {
    --accent-primary: #8B5CF6;
    --accent-secondary: #A78BFA;
    --accent-gradient: linear-gradient(135deg, #8B5CF6 0%, #A78BFA 100%);
    --accent-glow: rgba(139, 92, 246, 0.15);
    --primary-blue: #8B5CF6;
    --primary-green: #A78BFA;
}

[data-theme="sunset"] {
    --accent-primary: #F97316;
    --accent-secondary: #FB923C;
    --accent-gradient: linear-gradient(135deg, #F97316 0%, #FB923C 100%);
    --accent-glow: rgba(249, 115, 22, 0.15);
    --primary-blue: #F97316;
    --primary-green: #FB923C;
}

[data-theme="rose"] {
    --accent-primary: #F43F5E;
    --accent-secondary: #FB7185;
    --accent-gradient: linear-gradient(135deg, #F43F5E 0%, #FB7185 100%);
    --accent-glow: rgba(244, 63, 94, 0.15);
    --primary-blue: #F43F5E;
    --primary-green: #FB7185;
}

/* ===== BASE RESET ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
    position: relative;
}

/* ANTI-JEBOL: Force all children to respect width */
*,
*::before,
*::after {
    max-width: 100vw;
    box-sizing: border-box;
}

/* ===== TYPOGRAPHY ===== */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

h1 {
    font-size: 2.5rem;
    font-weight: 700;
}

h2 {
    font-size: 2rem;
}

h3 {
    font-size: 1.5rem;
}

h4 {
    font-size: 1.25rem;
}

h5 {
    font-size: 1rem;
}

h6 {
    font-size: 0.875rem;
}

p {
    color: var(--text-secondary);
    line-height: 1.7;
}

a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--text-primary);
}

/* ===== CARDS - FINOFO STYLE ===== */
.card,
.savia-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    transition: all var(--transition-base);
}

.card:hover,
.savia-card:hover {
    border-color: var(--border-default);
    background: var(--bg-card-hover);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-5);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.card-title i {
    color: var(--accent-primary);
    font-size: 1.1rem;
}

.card-body {
    position: relative;
}

/* Stat Cards */
.stat-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--accent-gradient);
    opacity: 0;
    transition: opacity var(--transition-base);
}

.stat-card:hover {
    border-color: var(--border-default);
    transform: translateY(-2px);
}

.stat-card:hover::before {
    opacity: 1;
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    margin-bottom: var(--space-4);
}

.stat-icon.blue {
    background: var(--info-bg);
    color: var(--info);
}

.stat-icon.green {
    background: var(--success-bg);
    color: var(--success);
}

.stat-icon.orange {
    background: var(--warning-bg);
    color: var(--warning);
}

.stat-icon.red {
    background: var(--danger-bg);
    color: var(--danger);
}

.stat-icon.purple {
    background: var(--maintenance-bg);
    color: var(--maintenance);
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-2);
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
    letter-spacing: -0.02em;
}

.stat-unit {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-left: var(--space-1);
}

.stat-change {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: var(--space-2);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
}

.stat-change.up {
    background: var(--success-bg);
    color: var(--success);
}

.stat-change.down {
    background: var(--danger-bg);
    color: var(--danger);
}

/* ===== BUTTONS ===== */
.btn,
button.savia-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    border: none;
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-default);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-strong);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: none;
}

.btn-ghost:hover {
    color: var(--text-primary);
    background: var(--bg-input);
}

.btn-outline {
    background: transparent;
    color: var(--accent-primary);
    border: 1px solid var(--accent-primary);
}

.btn-outline:hover {
    background: var(--accent-primary);
    color: white;
}

.btn-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
    background: var(--danger);
    color: white;
}

.btn-sm {
    padding: var(--space-2) var(--space-3);
    font-size: 0.75rem;
}

.btn-lg {
    padding: var(--space-4) var(--space-8);
    font-size: 1rem;
}

/* ===== FORM ELEMENTS ===== */
.form-group {
    margin-bottom: var(--space-5);
}

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    background: var(--bg-input-focus);
    border-color: var(--border-accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

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

.form-textarea {
    min-height: 100px;
    resize: vertical;
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394A3B8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* ===== BADGES ===== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-3);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-radius: var(--radius-full);
    border: 1px solid transparent;
}

.badge-success {
    background: var(--success-bg);
    color: var(--success);
    border-color: rgba(16, 185, 129, 0.2);
}

.badge-warning {
    background: var(--warning-bg);
    color: var(--warning);
    border-color: rgba(245, 158, 11, 0.2);
}

.badge-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.2);
}

.badge-info {
    background: var(--info-bg);
    color: var(--info);
    border-color: rgba(59, 130, 246, 0.2);
}

.badge-maintenance {
    background: var(--maintenance-bg);
    color: var(--maintenance);
    border-color: rgba(139, 92, 246, 0.2);
}

/* ===== TABLES ===== */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
}

.savia-table {
    width: 100%;
    border-collapse: collapse;
}

.savia-table thead {
    background: var(--bg-surface);
}

.savia-table th {
    padding: var(--space-4);
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-subtle);
}

.savia-table td {
    padding: var(--space-4);
    font-size: 0.875rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-subtle);
}

.savia-table tbody tr {
    transition: background var(--transition-fast);
}

.savia-table tbody tr:hover {
    background: var(--bg-card-hover);
}

.savia-table tbody tr:last-child td {
    border-bottom: none;
}

/* ===== SYSTEM STATUS BADGE ===== */
.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    transition: all 0.3s ease;
    border: 1px solid transparent;
}

.status-indicator.online {
    background: rgba(16, 185, 129, 0.15);
    color: #10B981;
    border-color: rgba(16, 185, 129, 0.3);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.2);
}

.status-indicator.offline {
    background: rgba(100, 116, 139, 0.15);
    color: #94A3B8;
    border-color: rgba(100, 116, 139, 0.3);
}

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

.status-dot.pulse-green {
    animation: statusPulse 2s infinite;
}

@keyframes statusPulse {
    0% {
        transform: scale(1);
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }

    70% {
        transform: scale(1);
        opacity: 1;
        box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
    }

    100% {
        transform: scale(1);
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

/* ===== MOBILE PERFORMANCE OPTIMIZATION ===== */
/* Disable heavy GPU effects on small screens */
@media (max-width: 768px) {

    .topbar,
    .sidebar,
    .card,
    .savia-card,
    .stat-card,
    .storage-panel-premium,
    .chart-panel-premium,
    .smart-tile,
    .quality-card-premium,
    .glass-panel {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background: var(--bg-elevated) !important;
        /* Force solid background */
    }

    /* Optional: Hardware accel for smooth scrolling if needed */
    .content,
    .sidebar {
        -webkit-overflow-scrolling: touch;
    }

    /* Hide Sidebar on Mobile */
    .sidebar {
        display: none !important;
    }

    /* Adjust Content Padding for Bottom Nav */
    .content,
    .main-content {
        padding-bottom: 90px !important;
        /* Space for bottom nav */
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    /* Input Zoom Prevention */
    input,
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* ===== MOBILE BOTTOM NAVIGATION ===== */
.bottom-nav {
    display: none;
    /* Hidden on desktop */
}

/* ===== GLOBAL BUG FIXES FOR MOBILE ===== */
html, body {
    max-width: 100vw !important;
    overflow-x: hidden !important;
    position: relative;
}

.row {
    max-width: 100%;
    margin-right: 0 !important;
    margin-left: 0 !important;
}

@media (max-width: 768px) {
    .bottom-nav {
        display: flex;
        justify-content: space-around;
        align-items: center;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 70px;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 1px solid #E2E8F0;
        z-index: var(--z-mobile-nav);
        padding-bottom: env(safe-area-inset-bottom);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
    }

    .bn-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        color: var(--text-secondary);
        font-size: 0.7rem;
        font-weight: 500;
        text-decoration: none;
        width: 100%;
        height: 100%;
        gap: 4px;
        transition: all 0.2s ease;
    }

    .bn-item i {
        font-size: 1.4rem;
        margin-bottom: 2px;
        transition: all 0.2s ease;
    }

    .bn-item.active {
        color: var(--accent-primary);
    }

    .bn-item.active i {
        transform: translateY(-2px);
        filter: drop-shadow(0 0 8px var(--accent-glow));
    }

    .bn-item:active {
        transform: scale(0.95);
    }

    /* Touch Target Fixes */
    .btn,
    .nav-link,
    .qa-btn {
        min-height: 44px;
        min-width: 44px;
    }

    /* Modal/Slider Visibility Fixes */
    .modal-content,
    .offcanvas-bottom {
        max-height: 85vh;
        overflow-y: auto;
        padding-bottom: 80px;
        /* Ensure content isn't covered */
    }

    /* Data Table Card View */
    .table-container table,
    .table-container thead,
    .table-container tbody,
    .table-container th,
    .table-container td,
    .table-container tr {
        display: block;
    }

    .table-container thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    .table-container tr {
        margin-bottom: 1rem;
        background: var(--bg-card);
        border: 1px solid var(--border-subtle);
        border-radius: 12px;
        padding: 1rem;
    }

    .table-container td {
        border: none;
        position: relative;
        padding-left: 50%;
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
        text-align: right;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .table-container td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--text-muted);
        text-transform: uppercase;
        font-size: 0.75rem;
        text-align: left;
    }
}

/* ===== NAVIGATION ===== */
.topbar {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid #E2E8F0;
    padding: var(--space-3) var(--space-6);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.sidebar {
    background: var(--bg-elevated);
    border-right: 1px solid var(--border-subtle);
    height: calc(100vh - 60px);
    position: sticky;
    top: 60px;
    overflow-y: auto;
    padding: var(--space-4) var(--space-3);
}

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    font-size: 0.875rem;
    font-weight: 500;
}

.nav-link:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.nav-link.active {
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent-primary);
}

.nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--accent-primary);
    border-radius: 0 2px 2px 0;
}

/* ===== GAUGE COMPONENTS ===== */
.gauge-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-4);
}

.gauge-svg {
    width: 140px;
    height: 70px;
    overflow: visible;
}

.gauge-bg {
    fill: none;
    stroke: var(--bg-surface);
    stroke-width: 12;
    stroke-linecap: round;
}

.gauge-fill {
    fill: none;
    stroke-width: 12;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.8s ease;
}

.gauge-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
    margin-top: var(--space-2);
}

.gauge-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===== CHARTS ===== */
.chart-container {
    position: relative;
    height: 350px;
    width: 100%;
    overflow: hidden;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: var(--space-5);
}

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-5);
}

.chart-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chart-legend {
    display: flex;
    gap: var(--space-4);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

/* ===== ALERTS/NOTIFICATIONS ===== */
.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    margin-bottom: var(--space-4);
}

.alert-success {
    background: var(--success-bg);
    border-color: rgba(16, 185, 129, 0.2);
    color: var(--success);
}

.alert-warning {
    background: var(--warning-bg);
    border-color: rgba(245, 158, 11, 0.2);
    color: var(--warning);
}

.alert-danger {
    background: var(--danger-bg);
    border-color: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.alert-info {
    background: var(--info-bg);
    border-color: rgba(59, 130, 246, 0.2);
    color: var(--info);
}

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal-backdrop, 1060);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--bg-card-solid);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.95);
    transition: transform var(--transition-base);
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-5);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-close {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    background: var(--bg-input, rgba(255, 255, 255, 0.03));
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.25rem;
    transition: all var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.modal-close:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

/* ===== TABS ===== */
.tabs {
    display: flex;
    gap: var(--space-1);
    background: var(--bg-input);
    padding: var(--space-1);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-5);
}

.tab {
    flex: 1;
    padding: var(--space-3) var(--space-4);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.tab:hover {
    color: var(--text-secondary);
}

.tab.active {
    background: var(--bg-card-solid);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: var(--space-12) var(--space-6);
    color: var(--text-muted);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: var(--space-4);
    opacity: 0.3;
}

.empty-state h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
}

.empty-state p {
    font-size: 0.875rem;
    max-width: 300px;
    margin: 0 auto;
}

/* ===== LOADING STATES ===== */
.skeleton {
    background: linear-gradient(90deg, var(--bg-surface) 25%, var(--bg-card-hover) 50%, var(--bg-surface) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: var(--radius-sm);
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-default);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-base);
}

::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-strong);
}

/* ===== SELECTION ===== */
::selection {
    background: var(--accent-primary);
    color: white;
}

/* ===== UTILITY CLASSES ===== */
.text-primary {
    color: var(--text-primary) !important;
}

.text-secondary {
    color: var(--text-secondary) !important;
}

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

.text-accent {
    color: var(--accent-primary) !important;
}

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

.text-warning {
    color: var(--warning) !important;
}

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

.bg-base {
    background: var(--bg-base) !important;
}

.bg-elevated {
    background: var(--bg-elevated) !important;
}

.bg-surface {
    background: var(--bg-surface) !important;
}

.bg-card {
    background: var(--bg-card) !important;
}

.border-subtle {
    border-color: var(--border-subtle) !important;
}

.border-default {
    border-color: var(--border-default) !important;
}

.rounded-sm {
    border-radius: var(--radius-sm) !important;
}

.rounded-md {
    border-radius: var(--radius-md) !important;
}

.rounded-lg {
    border-radius: var(--radius-lg) !important;
}

.rounded-xl {
    border-radius: var(--radius-xl) !important;
}

.rounded-full {
    border-radius: var(--radius-full) !important;
}

.shadow-sm {
    box-shadow: var(--shadow-sm) !important;
}

.shadow-md {
    box-shadow: var(--shadow-md) !important;
}

.shadow-lg {
    box-shadow: var(--shadow-lg) !important;
}

/* Grid System */
.grid {
    display: grid;
}

.grid-cols-1 {
    grid-template-columns: repeat(1, 1fr);
}

.grid-cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-cols-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-cols-4 {
    grid-template-columns: repeat(4, 1fr);
}

.gap-4 {
    gap: var(--space-4);
}

.gap-5 {
    gap: var(--space-5);
}

.gap-6 {
    gap: var(--space-6);
}

/* Flex */
.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.justify-center {
    justify-content: center;
}

/* Spacing */
.p-4 {
    padding: var(--space-4);
}

.p-5 {
    padding: var(--space-5);
}

.p-6 {
    padding: var(--space-6);
}

.mb-4 {
    margin-bottom: var(--space-4);
}

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

.mb-6 {
    margin-bottom: var(--space-6);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1200px) {
    .grid-cols-4 {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 992px) {

    .grid-cols-4,
    .grid-cols-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {

    .grid-cols-4,
    .grid-cols-3,
    .grid-cols-2 {
        grid-template-columns: 1fr;
    }

    .topbar {
        padding: var(--space-3) var(--space-4);
    }

    .sidebar {
        display: none;
    }

    .content {
        margin-left: 0 !important;
        max-width: 100% !important;
    }

    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    h3 {
        font-size: 1.25rem;
    }
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fadeIn {
    animation: fadeIn 0.4s ease forwards;
}

.animate-slideUp {
    animation: slideUp 0.5s ease forwards;
}

.animate-slideDown {
    animation: slideDown 0.5s ease forwards;
}

/* Stagger delays */
.delay-1 {
    animation-delay: 0.1s;
}

.delay-2 {
    animation-delay: 0.2s;
}

.delay-3 {
    animation-delay: 0.3s;
}

.delay-4 {
    animation-delay: 0.4s;
}

.delay-5 {
    animation-delay: 0.5s;
}

/* ===== MOBILE: Anti Auto-Zoom on iOS ===== */
@media (max-width: 767px) {

    input,
    select,
    textarea,
    .form-input,
    .form-select,
    .form-textarea,
    .chat-textarea,
    [contenteditable] {
        font-size: 16px !important;
    }
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */
.village-card::before,
.village-card::after,
.stat-badge::before,
.empty-state i {
    will-change: transform, opacity;
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}