/**
 * SOPVI Web — Design System v2.0
 * Single source of truth for all styles.
 * Theme controlled by: <html data-theme="light|dark">
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,300..800;1,14..32,300..800&display=swap');

/* ============================================================
   1. DESIGN TOKENS — Color Themes
   ============================================================ */

/* DEFAULT: Light Theme */
:root,
[data-theme="light"] {
    --bg-base:       #f6f8fa;
    --bg-surface:    #ffffff;
    --bg-elevated:   #f0f3f6;
    --bg-overlay:    #ffffff;
    --border:        #d0d7de;
    --border-subtle: #e8ecf0;

    /* Aliases used across components */
    --bg-card:       #ffffff;
    --bg-input:      #ffffff;
    --bg-hover:      #f0f3f6;
    --border-color:  #d0d7de;
    --text-muted:    #656d76;
    --text-dim:      #9da7b0;
    --primary:       #0969da;
    --primary-hover: #0752b0;

    --text-primary:   #1f2328;
    --text-secondary: #656d76;
    --text-disabled:  #9da7b0;

    --accent:         #0969da;
    --accent-hover:   #0752b0;
    --accent-subtle:  rgba(9, 105, 218, 0.08);
    --accent-muted:   rgba(9, 105, 218, 0.15);

    --success:        #1a7f37;
    --success-bg:     rgba(26, 127, 55, 0.08);
    --warning:        #9a6700;
    --warning-bg:     rgba(154, 103, 0, 0.08);
    --danger:         #d1242f;
    --danger-bg:      rgba(209, 36, 47, 0.08);

    --shadow-sm:  0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md:  0 4px 12px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
    --shadow-lg:  0 12px 28px rgba(0,0,0,0.12), 0 4px 8px rgba(0,0,0,0.06);
    --shadow-xl:  0 24px 48px rgba(0,0,0,0.16);

    /* Border radius */
    --radius-sm:  4px;
    --radius-md:  8px;
    --radius-lg:  12px;
    --radius-xl:  16px;

    --sidebar-width: 240px;
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);

    /* ── Legacy aliases (ventas_v2, config, etc.) ── */
    --primary-color:  #0969da;
    --accent-color:   #0969da;
    --success-color:  #1a7f37;
    --danger-color:   #d1242f;
    --dark-text:      #1f2328;
    --text-light:     #1f2328;
    --bg-dark:        #f6f8fa;
    --gradient-main:  linear-gradient(135deg, #0969da 0%, #2563eb 100%);

    /* Custom color variables used in older pages */
    --color-border:         var(--border);
    --color-text-secondary: var(--text-secondary);
    --color-success:        var(--success);
    --color-primary:        var(--primary);
    --color-warning:        var(--warning);
    --color-surface:        var(--bg-surface);
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-base:       #0d1117;
    --bg-surface:    #161b22;
    --bg-elevated:   #21262d;
    --bg-overlay:    #2d333b;
    --border:        #30363d;
    --border-subtle: #21262d;

    /* Aliases */
    --bg-card:       #161b22;
    --bg-input:      #21262d;
    --bg-hover:      #21262d;
    --border-color:  #30363d;
    --text-muted:    #8b949e;
    --text-dim:      #484f58;
    --primary:       #2f81f7;
    --primary-hover: #58a6ff;

    --text-primary:   #e6edf3;
    --text-secondary: #8b949e;
    --text-disabled:  #484f58;

    --accent:         #2f81f7;
    --accent-hover:   #58a6ff;
    --accent-subtle:  rgba(47, 129, 247, 0.10);
    --accent-muted:   rgba(47, 129, 247, 0.20);

    --success:        #3fb950;
    --success-bg:     rgba(63, 185, 80, 0.10);
    --warning:        #d29922;
    --warning-bg:     rgba(210, 153, 34, 0.10);
    --danger:         #f85149;
    --danger-bg:      rgba(248, 81, 73, 0.10);

    --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 12px 28px rgba(0,0,0,0.5);
    --shadow-xl:  0 24px 48px rgba(0,0,0,0.6);

    /* Border radius (same as light) */
    --radius-sm:  4px;
    --radius-md:  8px;
    --radius-lg:  12px;
    --radius-xl:  16px;

    /* ── Legacy aliases (ventas_v2, config, etc.) ── */
    --primary-color:  #2f81f7;
    --accent-color:   #2f81f7;
    --success-color:  #3fb950;
    --danger-color:   #f85149;
    --dark-text:      #e6edf3;
    --text-light:     #e6edf3;
    --bg-dark:        #0d1117;
    --gradient-main:  linear-gradient(135deg, #2f81f7 0%, #58a6ff 100%);

    /* Custom color variables used in older pages */
    --color-border:         var(--border);
    --color-text-secondary: var(--text-secondary);
    --color-success:        var(--success);
    --color-primary:        var(--primary);
    --color-warning:        var(--warning);
    --color-surface:        var(--bg-surface);
}

/* ============================================================
   2. RESET & BASE
   ============================================================ */

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

html { font-size: 16px; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.25s ease, color 0.25s ease;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 700;
    line-height: 1.3;
    color: var(--text-primary);
}

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

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-disabled); }

/* ============================================================
   3. APP LAYOUT
   ============================================================ */

.app-layout {
    display: flex;
    min-height: 100vh;
    background: var(--bg-base);
}

/* ============================================================
   4. SIDEBAR
   ============================================================ */

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    height: 100vh;
    position: sticky;
    top: 0;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 100;
    transition: var(--transition);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--border-subtle);
    text-decoration: none;
}

.sidebar-brand-logo {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    object-fit: contain;
    flex-shrink: 0;
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
}

.sidebar-brand-name {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.3px;
    line-height: 1.1;
}

.sidebar-brand-sub {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 8px;
}

.sidebar-section-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-disabled);
    padding: 8px 10px 4px;
    margin-top: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    margin-bottom: 1px;
    white-space: nowrap;
}

.nav-item i {
    font-size: 0.95rem;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
    opacity: 0.8;
}

.nav-item:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}
.nav-item:hover i { opacity: 1; }

.nav-item.active {
    background: var(--accent-subtle);
    color: var(--accent);
    font-weight: 600;
}
.nav-item.active i { opacity: 1; }

.sidebar-divider {
    height: 1px;
    background: var(--border-subtle);
    margin: 8px 0;
}

/* Sidebar Footer: Theme Toggle + User */
.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 12px 8px;
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-radius: 8px;
    background: var(--bg-elevated);
    margin-bottom: 6px;
}

.theme-toggle-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 7px;
}

/* The switch */
.toggle-switch {
    position: relative;
    width: 40px;
    height: 22px;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--border);
    border-radius: 99px;
    transition: 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
}

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

/* User info row */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.sidebar-user:hover { background: var(--bg-elevated); }

.sidebar-user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent);
    flex-shrink: 0;
}

.sidebar-user-info { flex: 1; overflow: hidden; }

.sidebar-user-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.sidebar-logout-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 4px 6px;
    border-radius: 6px;
    transition: var(--transition);
}

.sidebar-logout-btn:hover {
    color: var(--danger);
    background: var(--danger-bg);
}

/* ============================================================
   5. MAIN CONTENT AREA
   ============================================================ */

.main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-base);
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 28px 32px 0;
    gap: 16px;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.page-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 3px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.page-body {
    padding: 24px 32px 32px;
    flex: 1;
}

/* ============================================================
   6. CARDS
   ============================================================ */

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

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

/* Metric cards */
.metric-card {
    padding: 20px 24px;
}

.metric-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    margin-bottom: 16px;
    background: var(--accent-subtle);
    color: var(--accent);
}

.metric-label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.metric-value {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -1px;
    line-height: 1;
}

.metric-trend {
    font-size: 0.8rem;
    font-weight: 600;
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.trend-up   { color: var(--success); }
.trend-down { color: var(--danger); }
.trend-flat { color: var(--text-secondary); }

/* ============================================================
   7. BUTTONS
   ============================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
    font-family: inherit;
    line-height: 1.4;
}

.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 2px 8px var(--accent-muted);
}
.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px var(--accent-muted);
    color: #fff;
}

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border);
}
.btn-secondary:hover {
    background: var(--bg-overlay);
    border-color: var(--text-disabled);
    color: var(--text-primary);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}
.btn-ghost:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.btn-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: transparent;
}
.btn-danger:hover {
    background: var(--danger);
    color: #fff;
}

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-icon { padding: 8px; gap: 0; }

/* ============================================================
   8. FORMS
   ============================================================ */

.form-label {
    display: block;
    font-size: 0.83rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    letter-spacing: 0.01em;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 9px 13px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    transition: var(--transition);
    appearance: none;
    line-height: 1.4;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
    outline: none;
}

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

.form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    padding-right: 36px;
    cursor: pointer;
}

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

.form-group { margin-bottom: 16px; }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.input-group {
    position: relative;
}

.input-group .input-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-disabled);
    font-size: 0.9rem;
    pointer-events: none;
}

.input-group .form-input { padding-left: 36px; }

/* ============================================================
   9. TABLES
   ============================================================ */

.table-wrapper {
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    background: var(--bg-surface);
    box-shadow: var(--shadow-sm);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table thead {
    background: var(--bg-elevated);
}

.data-table th {
    padding: 11px 16px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 13px 16px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
}

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

.data-table tbody tr {
    transition: background 0.12s ease;
}

.data-table tbody tr:hover {
    background: var(--bg-elevated);
}

/* Product thumbnail */
.product-thumb {
    width: 40px;
    height: 40px;
    object-fit: contain;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    padding: 2px;
    display: block;
}

.product-thumb-fallback {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-disabled);
    font-size: 1rem;
}

.product-desc-cell {
    display: flex;
    align-items: center;
    gap: 12px;
}

.product-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.85rem;
}

.clave-link {
    font-weight: 700;
    color: var(--accent);
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 0.82rem;
}
.clave-link:hover { color: var(--accent-hover); text-decoration: underline; }

/* Action select */
.action-select {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 6px 10px;
    border-radius: 7px;
    font-size: 0.82rem;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    min-width: 130px;
    transition: var(--transition);
}

.action-select:focus {
    border-color: var(--accent);
    outline: none;
}

/* ============================================================
   10. BADGES
   ============================================================ */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 99px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger); }
.badge-info    { background: var(--accent-subtle); color: var(--accent); }
.badge-neutral { background: var(--bg-elevated); color: var(--text-secondary); }

/* Stock badge */
.stock-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 99px;
    font-size: 0.78rem;
    font-weight: 700;
}

.stock-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Balance badges */
.balance-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 700;
}

.balance-debt { background: var(--danger-bg); color: var(--danger); }
.balance-ok   { background: var(--success-bg); color: var(--success); }

/* ============================================================
   11. PAGINATION
   ============================================================ */

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

.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
    border-radius: 7px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-secondary);
    transition: var(--transition);
    font-family: inherit;
}

.page-btn:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--text-disabled);
}

.page-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 2px 8px var(--accent-muted);
}

.page-btn:disabled,
.page-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.pagination-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ============================================================
   12. MODALS — legacy & modal-form
   ============================================================ */

/* Legacy overlay modals (productos, clientes, etc.) */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 9000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.15s ease;
}
.modal[style*="display:block"],
.modal[style*="display: block"] {
    display: flex !important;
}
.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-xl);
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.2s ease;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}
.modal-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: background 0.15s, color 0.15s;
}
.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.modal-body {
    padding: 1.5rem;
}
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
}

.modal-form-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeOverlay 0.2s ease;
}

@keyframes fadeOverlay {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.modal-form-container {
    background: var(--bg-surface);
    width: 100%;
    max-width: 1050px;
    height: 90vh;
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalSlideIn 0.3s cubic-bezier(0.34, 1.2, 0.64, 1);
}

@keyframes modalSlideIn {
    from { transform: translateY(20px) scale(0.97); opacity: 0; }
    to   { transform: translateY(0) scale(1);       opacity: 1; }
}

.modal-form-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
    flex-shrink: 0;
}

.modal-form-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-form-close {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.modal-form-close:hover {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
    transform: rotate(90deg);
}

.modal-form-iframe {
    flex: 1;
    width: 100%;
    border: none;
    background: var(--bg-surface);
}

/* ============================================================
   13. SEARCH / FILTER BAR
   ============================================================ */

.search-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 24px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

.search-input-wrapper {
    position: relative;
    flex: 1;
}

.search-input-wrapper i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-disabled);
    font-size: 0.9rem;
    pointer-events: none;
}

.search-input-wrapper .form-input {
    padding-left: 36px;
}

/* ============================================================
   14. EXPIRATION BANNER
   ============================================================ */

.expiration-banner {
    background: var(--warning-bg);
    border: 1px solid var(--warning);
    color: var(--warning);
    padding: 10px 32px;
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ============================================================
   15. LOGIN PAGE
   ============================================================ */

.login-layout {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-base);
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px;
    box-shadow: var(--shadow-lg);
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo img {
    width: 56px;
    height: 56px;
    border-radius: 14px;
}

.login-title {
    font-size: 1.4rem;
    font-weight: 800;
    text-align: center;
    margin-bottom: 8px;
}

.login-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 32px;
}

/* ============================================================
   16. MISC UTILITIES
   ============================================================ */

.flex          { display: flex; }
.flex-col      { flex-direction: column; }
.items-center  { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-4  { margin-top: 16px; }
.mb-4  { margin-bottom: 16px; }
.p-4   { padding: 16px; }
.p-6   { padding: 24px; }
.w-full { width: 100%; }
.text-sm { font-size: 0.875rem; }
.text-muted { color: var(--text-secondary); }
.font-bold { font-weight: 700; }
.font-mono { font-family: 'SFMono-Regular', Consolas, monospace; }

/* Status indicator */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 2px var(--success-bg);
}

/* Section divider */
.section-heading {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-disabled);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-heading::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-subtle);
}

/* Dashboard grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

/* Department badge colors */
.dept-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 99px;
    font-size: 0.72rem;
    font-weight: 600;
}

/* Responsive Mobile Navigation */
@media (max-width: 768px) {
    .app-layout {
        flex-direction: column !important;
    }

    .mobile-navbar {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        padding: 10px 16px;
        background: var(--bg-surface, #ffffff);
        border-bottom: 1px solid var(--border, #d0d7de);
        position: sticky;
        top: 0;
        z-index: 9999;
        width: 100%;
        box-shadow: var(--shadow-sm);
    }

    .mobile-navbar-brand {
        display: flex;
        align-items: center;
        gap: 8px;
        font-weight: 800;
        font-size: 1rem;
        color: var(--text-primary, #0f172a);
        text-decoration: none;
    }

    .mobile-menu-btn {
        background: transparent;
        border: 1px solid var(--border, #d0d7de);
        color: var(--text-primary, #0f172a);
        font-size: 1.15rem;
        width: 40px;
        height: 40px;
        border-radius: 8px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: background 0.15s;
    }

    .mobile-menu-btn:active {
        background: var(--bg-elevated, #f0f3f6);
    }

    /* Off-Canvas Sidebar Drawer for Mobile */
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        height: 100vh !important;
        height: 100dvh !important;
        width: 280px !important;
        max-width: 85vw !important;
        z-index: 100001 !important;
        transform: translateX(-100%) !important;
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1) !important;
        box-shadow: var(--shadow-xl) !important;
        background: var(--bg-surface, #ffffff) !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .sidebar.mobile-open {
        transform: translateX(0) !important;
    }

    /* Force mobile open state to display all elements clearly regardless of collapsed flag */
    .sidebar.mobile-open .sidebar-section-label,
    .sidebar.mobile-open .nav-item > span,
    .sidebar.mobile-open .sidebar-brand-name,
    .sidebar.mobile-open .sidebar-user-info,
    .sidebar.mobile-open .js-theme-label,
    .sidebar.mobile-open .toggle-switch,
    .sidebar.mobile-open #sopvi-notice-sivetel {
        display: block !important;
    }

    .sidebar.mobile-open .sidebar-user-avatar {
        display: flex !important;
    }

    .sidebar.mobile-open .sidebar-logout-btn {
        display: inline-block !important;
    }

    .sidebar.mobile-open .nav-item {
        justify-content: flex-start !important;
        padding: 10px 14px !important;
    }

    .sidebar.mobile-open .nav-item i {
        margin-right: 10px !important;
    }

    .sidebar.mobile-open .sidebar-brand {
        justify-content: flex-start !important;
        padding: 16px !important;
    }

    .sidebar-toggle-btn {
        display: none !important;
    }

    /* Dark Overlay Backdrop */
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
        z-index: 100000;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }

    .sidebar-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }

    .page-body { padding: 16px; }
    .page-header { padding: 16px 16px 0; }
}

@media (min-width: 769px) {
    .mobile-navbar {
        display: none !important;
    }
    .sidebar-overlay {
        display: none !important;
    }
}


/* ============================================================
   17. FORM PAGES (inside modals)
   ============================================================ */

.form-page-layout {
    min-height: 100%;
    background: var(--bg-base);
    padding: 24px;
}

.form-section-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

.form-section-title {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-section-title i {
    color: var(--accent);
    font-size: 1rem;
}

/* Tab strip for forms */
.tab-strip {
    display: flex;
    gap: 4px;
    background: var(--bg-elevated);
    padding: 4px;
    border-radius: 10px;
    margin-bottom: 24px;
    border: 1px solid var(--border);
    width: fit-content;
}

.tab-btn {
    padding: 8px 20px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 7px;
    font-family: inherit;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.5);
}

.tab-btn.active {
    background: var(--bg-surface);
    color: var(--accent);
    box-shadow: var(--shadow-sm);
}

/* Form actions bar */
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding-top: 16px;
    border-top: 1px solid var(--border-subtle);
    margin-top: 8px;
}

/* Image upload cards */
.image-upload-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.image-upload-card {
    aspect-ratio: 1;
    border: 2px dashed var(--border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    background: var(--bg-elevated);
    color: var(--text-secondary);
}

.image-upload-card:hover {
    border-color: var(--accent);
    background: var(--accent-subtle);
    color: var(--accent);
}

.image-upload-card .upload-label {
    font-size: 0.78rem;
    font-weight: 600;
}

.image-upload-card .upload-preview {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}

/* Splash Screen */
.splash-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    flex-direction: column;
    gap: 24px;
    transition: opacity 0.5s ease;
}

.splash-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}
