/* Afrita – Material Design 3 Token System */

:root {
    /* ── M3 Color Tokens (Light) ─────────────────────────────── */
    --md-sys-color-primary: #1a65d1;
    --md-sys-color-on-primary: #ffffff;
    --md-sys-color-primary-container: #d6e3ff;
    --md-sys-color-on-primary-container: #001b3d;
    --md-sys-color-secondary: #555f71;
    --md-sys-color-on-secondary: #ffffff;
    --md-sys-color-secondary-container: #d9e3f8;
    --md-sys-color-on-secondary-container: #121c2b;
    --md-sys-color-tertiary: #6e5676;
    --md-sys-color-on-tertiary: #ffffff;
    --md-sys-color-tertiary-container: #f8d8ff;
    --md-sys-color-on-tertiary-container: #271430;
    --md-sys-color-error: #ba1a1a;
    --md-sys-color-on-error: #ffffff;
    --md-sys-color-error-container: #ffdad6;
    --md-sys-color-on-error-container: #410002;
    --md-sys-color-surface: #f9f9ff;
    --md-sys-color-on-surface: #1a1c20;
    --md-sys-color-surface-variant: #dee2eb;
    --md-sys-color-on-surface-variant: #42474e;
    --md-sys-color-surface-container-lowest: #ffffff;
    --md-sys-color-surface-container-low: #f3f3fa;
    --md-sys-color-surface-container: #edeff6;
    --md-sys-color-surface-container-high: #e7e8ef;
    --md-sys-color-surface-container-highest: #e1e2e9;
    --md-sys-color-outline: #73777f;
    --md-sys-color-outline-variant: #c3c6cf;
    --md-sys-color-inverse-surface: #2f3036;
    --md-sys-color-inverse-on-surface: #f0f0f7;
    --md-sys-color-success: #1b6e2d;
    --md-sys-color-on-success: #ffffff;
    --md-sys-color-success-container: #a4f7a5;
    --md-sys-color-on-success-container: #002107;
    --md-sys-color-warning: #7e5700;
    --md-sys-color-on-warning: #ffffff;
    --md-sys-color-warning-container: #ffdea6;
    --md-sys-color-on-warning-container: #271900;

    /* ── M3 Elevation (shadow) ───────────────────────────────── */
    --md-sys-elevation-0: none;
    --md-sys-elevation-1: 0 1px 2px rgba(0,0,0,.1), 0 1px 3px rgba(0,0,0,.08);
    --md-sys-elevation-2: 0 1px 2px rgba(0,0,0,.1), 0 2px 6px rgba(0,0,0,.08);
    --md-sys-elevation-3: 0 1px 3px rgba(0,0,0,.12), 0 4px 8px rgba(0,0,0,.08);
    --md-sys-elevation-4: 0 2px 4px rgba(0,0,0,.12), 0 6px 12px rgba(0,0,0,.08);
    --md-sys-elevation-5: 0 4px 6px rgba(0,0,0,.14), 0 8px 16px rgba(0,0,0,.1);

    /* ── M3 Shape (corner radius) ────────────────────────────── */
    --md-sys-shape-none: 0;
    --md-sys-shape-xs: 4px;
    --md-sys-shape-sm: 8px;
    --md-sys-shape-md: 12px;
    --md-sys-shape-lg: 16px;
    --md-sys-shape-xl: 28px;
    --md-sys-shape-full: 9999px;

    /* ── M3 State Layers ─────────────────────────────────────── */
    --md-sys-state-hover-opacity: 0.08;
    --md-sys-state-focus-opacity: 0.12;
    --md-sys-state-press-opacity: 0.12;

    /* ── Legacy aliases (backward compat) ────────────────────── */
    --primary-color: var(--md-sys-color-primary);
    --primary-hover: #1554b0;
    --secondary-color: var(--md-sys-color-secondary);
    --danger-color: var(--md-sys-color-error);
    --warning-color: var(--md-sys-color-warning);
    --success-color: var(--md-sys-color-success);
    --bg-light-gray: var(--md-sys-color-surface);
    --bg-white: var(--md-sys-color-surface-container-lowest);
    --text-dark: var(--md-sys-color-on-surface);
    --text-gray: var(--md-sys-color-on-surface-variant);
    --border-gray: var(--md-sys-color-outline-variant);
    --card-shadow: var(--md-sys-elevation-1);
    --input-bg: var(--md-sys-color-surface-container-lowest);
    --sidebar-bg: var(--md-sys-color-surface-container-lowest);
    --header-bg: var(--md-sys-color-surface-container-lowest);
}

/* ── Dark Mode (M3 Dark Scheme) ────────────────────────────── */
[data-theme="dark"] {
    --md-sys-color-primary: #a4c8ff;
    --md-sys-color-on-primary: #003062;
    --md-sys-color-primary-container: #0f4a8a;
    --md-sys-color-on-primary-container: #d6e3ff;
    --md-sys-color-secondary: #bdc7db;
    --md-sys-color-on-secondary: #283141;
    --md-sys-color-secondary-container: #3e4858;
    --md-sys-color-on-secondary-container: #d9e3f8;
    --md-sys-color-tertiary: #dbbce3;
    --md-sys-color-on-tertiary: #3f2846;
    --md-sys-color-tertiary-container: #573e5d;
    --md-sys-color-on-tertiary-container: #f8d8ff;
    --md-sys-color-error: #ffb4ab;
    --md-sys-color-on-error: #690005;
    --md-sys-color-error-container: #93000a;
    --md-sys-color-on-error-container: #ffdad6;
    --md-sys-color-surface: #121316;
    --md-sys-color-on-surface: #e2e2e9;
    --md-sys-color-surface-variant: #43474e;
    --md-sys-color-on-surface-variant: #c3c6cf;
    --md-sys-color-surface-container-lowest: #0d0e11;
    --md-sys-color-surface-container-low: #1a1c20;
    --md-sys-color-surface-container: #1e2024;
    --md-sys-color-surface-container-high: #282a2f;
    --md-sys-color-surface-container-highest: #33353a;
    --md-sys-color-outline: #8d9199;
    --md-sys-color-outline-variant: #43474e;
    --md-sys-color-inverse-surface: #e2e2e9;
    --md-sys-color-inverse-on-surface: #2f3036;
    --md-sys-color-success: #7adb7f;
    --md-sys-color-on-success: #003910;
    --md-sys-color-success-container: #005319;
    --md-sys-color-on-success-container: #a4f7a5;
    --md-sys-color-warning: #f5bf48;
    --md-sys-color-on-warning: #422d00;
    --md-sys-color-warning-container: #5e4100;
    --md-sys-color-on-warning-container: #ffdea6;

    --md-sys-elevation-1: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
    --md-sys-elevation-2: 0 2px 6px rgba(0,0,0,.4), 0 1px 4px rgba(0,0,0,.3);
    --md-sys-elevation-3: 0 4px 8px rgba(0,0,0,.4), 0 1px 4px rgba(0,0,0,.3);

    --primary-hover: #7eb3ff;
    --bg-light-gray: var(--md-sys-color-surface);
    --bg-white: var(--md-sys-color-surface-container);
    --text-dark: var(--md-sys-color-on-surface);
    --text-gray: var(--md-sys-color-on-surface-variant);
    --border-gray: var(--md-sys-color-outline-variant);
    --card-shadow: var(--md-sys-elevation-1);
    --input-bg: var(--md-sys-color-surface-container);
    --sidebar-bg: var(--md-sys-color-surface-container-low);
    --header-bg: var(--md-sys-color-surface-container);
}

[data-theme="dark"] body {
    background-color: var(--bg-light-gray);
    color: var(--text-dark);
}

[data-theme="dark"] .bg-white,
[data-theme="dark"] .bg-gray-50 {
    background-color: var(--bg-white) !important;
    color: var(--text-dark);
}

[data-theme="dark"] .text-gray-800,
[data-theme="dark"] .text-gray-700,
[data-theme="dark"] .text-gray-600 {
    color: var(--text-dark) !important;
}

[data-theme="dark"] .text-gray-500,
[data-theme="dark"] .text-gray-400 {
    color: var(--text-gray) !important;
}

[data-theme="dark"] .border-gray-200,
[data-theme="dark"] .border-gray-300 {
    border-color: var(--border-gray) !important;
}

[data-theme="dark"] input,
[data-theme="dark"] textarea,
[data-theme="dark"] select {
    background-color: var(--input-bg);
    border-color: var(--border-gray);
    color: var(--text-dark);
}

[data-theme="dark"] thead,
[data-theme="dark"] .bg-gray-50 {
    background-color: #111827 !important;
}

[data-theme="dark"] tbody tr:hover {
    background-color: #374151 !important;
}

[data-theme="dark"] aside {
    background-color: var(--sidebar-bg) !important;
    border-color: var(--border-gray) !important;
}

[data-theme="dark"] aside nav a:hover {
    background-color: #374151 !important;
}

[data-theme="dark"] .shadow,
[data-theme="dark"] .shadow-lg {
    box-shadow: var(--card-shadow) !important;
}

[data-theme="dark"] header {
    background-color: var(--header-bg) !important;
    border-color: var(--border-gray) !important;
}

[data-theme="dark"] footer {
    background-color: var(--bg-light-gray) !important;
    border-color: var(--border-gray) !important;
}

/* Dark mode: active nav link */
[data-theme="dark"] aside nav a.bg-blue-50 {
    background-color: #1e3a5f !important;
    color: #93c5fd !important;
}

/* Dark mode: hover on sidebar footer buttons */
[data-theme="dark"] aside .border-t button:hover {
    background-color: #374151 !important;
}

/* Dark mode: standalone pages (login, register, etc) */
.login-body {
    background: linear-gradient(135deg, #eff6ff, #e0e7ff);
}

.login-card {
    background-color: #ffffff;
    color: var(--text-dark);
}

.login-subtitle {
    color: var(--text-gray);
}

.login-label {
    color: var(--text-gray);
}

[data-theme="dark"] .login-body {
    background: linear-gradient(135deg, #0f172a, #1e1b4b) !important;
}

[data-theme="dark"] .login-card {
    background-color: #1e293b !important;
    color: #f1f5f9 !important;
    border: 1px solid #334155;
}

[data-theme="dark"] .login-subtitle {
    color: #94a3b8 !important;
}

[data-theme="dark"] .login-label {
    color: #94a3b8 !important;
}

[data-theme="dark"] .login-card input {
    background-color: #0f172a !important;
    border-color: #475569 !important;
    color: #f1f5f9 !important;
}

[data-theme="dark"] .login-card input:focus {
    border-color: #3b82f6 !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25) !important;
    background-color: #1e293b !important;
}

[data-theme="dark"] .login-card input::placeholder {
    color: #64748b !important;
}

[data-theme="dark"] .login-card select {
    background-color: #0f172a !important;
    border-color: #475569 !important;
    color: #f1f5f9 !important;
}

[data-theme="dark"] .login-card .text-blue-600 {
    color: #60a5fa !important;
}

[data-theme="dark"] .login-card footer,
[data-theme="dark"] body.login-body footer {
    color: #64748b !important;
}

[data-theme="dark"] body.login-body footer p {
    color: #64748b !important;
}

[data-theme="dark"] .bg-gradient-to-br {
    background: linear-gradient(135deg, #0f172a, #1e1b4b) !important;
}

[data-theme="dark"] .shadow-2xl {
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5) !important;
}

/* Dark mode: settings cards */
[data-theme="dark"] .border-gray-100 {
    border-color: var(--border-gray) !important;
}

[data-theme="dark"] .bg-gray-100 {
    background-color: #374151 !important;
    color: var(--text-dark) !important;
}

[data-theme="dark"] .bg-gray-200 {
    background-color: #4b5563 !important;
}

/* Dark mode: checkboxes label rows */
[data-theme="dark"] label.flex.items-center {
    color: var(--text-dark);
}

/* Dark mode: notification toggle rows */
[data-theme="dark"] .bg-gray-50.rounded-lg {
    background-color: #1a2332 !important;
}

/* ── KPI Gradient Cards ──────────────────────────────────── */
.kpi-card-lg {
    transition: box-shadow 200ms, transform 200ms;
}
.kpi-card-lg:hover {
    box-shadow: var(--md-sys-elevation-4) !important;
    transform: translateY(-2px);
}
.kpi-label {
    color: rgba(255, 255, 255, 0.85);
}
/* Blue — Invoices */
.kpi-blue {
    background: linear-gradient(135deg, #1565c0, #1e88e5) !important;
    color: #ffffff !important;
}
/* Emerald — Revenue */
.kpi-emerald {
    background: linear-gradient(135deg, #047857, #10b981) !important;
    color: #ffffff !important;
}
/* Rose — Purchases */
.kpi-rose {
    background: linear-gradient(135deg, #be123c, #f43f5e) !important;
    color: #ffffff !important;
}
/* Teal — Profit */
.kpi-teal {
    background: linear-gradient(135deg, #0f766e, #14b8a6) !important;
    color: #ffffff !important;
}

/* Dark mode KPI gradients — slightly muted but still vibrant */
[data-theme="dark"] .kpi-blue {
    background: linear-gradient(135deg, #1e3a5f, #2563eb) !important;
    color: #e0f2fe !important;
}
[data-theme="dark"] .kpi-emerald {
    background: linear-gradient(135deg, #064e3b, #059669) !important;
    color: #d1fae5 !important;
}
[data-theme="dark"] .kpi-rose {
    background: linear-gradient(135deg, #4c0519, #e11d48) !important;
    color: #ffe4e6 !important;
}
[data-theme="dark"] .kpi-teal {
    background: linear-gradient(135deg, #134e4a, #0d9488) !important;
    color: #ccfbf1 !important;
}
[data-theme="dark"] .kpi-label {
    color: rgba(255, 255, 255, 0.8);
}

/* Dark mode: chart containers text */
[data-theme="dark"] h3.text-gray-800 {
    color: var(--text-dark) !important;
}

/* Dark mode: global loading overlay */
[data-theme="dark"] #global-loading > div {
    background-color: #1f2937 !important;
    color: var(--text-dark);
}

/* Dark mode: badges */
[data-theme="dark"] .bg-green-100 { background-color: #064e3b !important; }
[data-theme="dark"] .text-green-800 { color: #6ee7b7 !important; }
[data-theme="dark"] .bg-red-100 { background-color: #7f1d1d !important; }
[data-theme="dark"] .text-red-800 { color: #fca5a5 !important; }
[data-theme="dark"] .bg-yellow-100 { background-color: #78350f !important; }
[data-theme="dark"] .text-yellow-800 { color: #fcd34d !important; }
[data-theme="dark"] .bg-blue-100 { background-color: #1e3a5f !important; }
[data-theme="dark"] .text-blue-800 { color: #93c5fd !important; }
[data-theme="dark"] .bg-orange-100 { background-color: #7c2d12 !important; }
[data-theme="dark"] .text-orange-800 { color: #fdba74 !important; }
[data-theme="dark"] .bg-amber-100 { background-color: #78350f !important; }
[data-theme="dark"] .text-amber-800 { color: #fcd34d !important; }
[data-theme="dark"] .bg-red-600 { background-color: #dc2626 !important; }

/* Dark mode: secondary/gray buttons */
[data-theme="dark"] .bg-gray-300 {
    background-color: #374151 !important;
    color: var(--text-dark) !important;
}
[data-theme="dark"] .bg-gray-300:hover,
[data-theme="dark"] .hover\:bg-gray-400:hover {
    background-color: #4b5563 !important;
}

/* Dark mode: pagination links */
[data-theme="dark"] a.border.rounded,
[data-theme="dark"] .border.rounded {
    border-color: var(--border-gray) !important;
    color: var(--text-dark) !important;
}

/* Dark mode: modals/popups */
[data-theme="dark"] .bg-black\/50,
[data-theme="dark"] [class*="bg-black/"] {
    background-color: rgba(0, 0, 0, 0.7) !important;
}

/* Dark mode: shadow-sm cards (search, detail) */
[data-theme="dark"] .shadow-sm {
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4) !important;
}

/* Dark mode: text-blue-600 links */
[data-theme="dark"] .text-blue-600 { color: #60a5fa !important; }
[data-theme="dark"] .text-green-600 { color: #4ade80 !important; }
[data-theme="dark"] .text-red-600 { color: #f87171 !important; }
[data-theme="dark"] .text-purple-600 { color: #c084fc !important; }
[data-theme="dark"] .text-yellow-600 { color: #fbbf24 !important; }
[data-theme="dark"] .text-cyan-600 { color: #22d3ee !important; }
[data-theme="dark"] .text-orange-600 { color: #fb923c !important; }
[data-theme="dark"] .text-amber-600 { color: #fbbf24 !important; }
[data-theme="dark"] .bg-purple-500 { background-color: #a855f7 !important; }
[data-theme="dark"] .bg-cyan-500 { background-color: #06b6d4 !important; }
[data-theme="dark"] .bg-orange-500 { background-color: #f97316 !important; }
[data-theme="dark"] .bg-amber-500 { background-color: #f59e0b !important; }
[data-theme="dark"] .bg-red-500 { background-color: #ef4444 !important; }

/* Dark mode: QR code area */
[data-theme="dark"] #qr-code {
    background-color: #ffffff !important;
}

/* Dark mode: table borders (purchase bills, invoices) */
[data-theme="dark"] table,
[data-theme="dark"] th,
[data-theme="dark"] td {
    border-color: var(--border-gray) !important;
}

[data-theme="dark"] .border {
    border-color: var(--border-gray) !important;
}

[data-theme="dark"] .border-b {
    border-color: var(--border-gray) !important;
}

[data-theme="dark"] .border-t {
    border-color: var(--border-gray) !important;
}

/* Dark mode: hover states on table rows */
[data-theme="dark"] tr.hover\:bg-gray-50:hover {
    background-color: #374151 !important;
}

[data-theme="dark"] tr.hover\:bg-blue-50:hover {
    background-color: #1e3a5f !important;
}

[data-theme="dark"] tr.hover\:bg-red-50:hover {
    background-color: #3b1a1a !important;
}

[data-theme="dark"] tr.hover\:bg-purple-50:hover {
    background-color: #2d1b69 !important;
}

/* Dark mode: shadow-md cards */
[data-theme="dark"] .shadow-md {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4) !important;
}

/* Dark mode: rounded-lg white containers */
[data-theme="dark"] .rounded-lg.shadow,
[data-theme="dark"] .rounded-xl.shadow-sm {
    background-color: var(--bg-white) !important;
    color: var(--text-dark) !important;
}

/* Dark mode: error alert banners (clients, orders, stores, branches) */
[data-theme="dark"] .bg-red-50 {
    background-color: #3b1a1a !important;
}
[data-theme="dark"] .border-red-200 {
    border-color: #7f1d1d !important;
}
[data-theme="dark"] .border-red-400 {
    border-color: #dc2626 !important;
}
[data-theme="dark"] .text-red-700 {
    color: #fca5a5 !important;
}

/* Dark mode: info/active states (settings, badges) */
[data-theme="dark"] .bg-blue-50 {
    background-color: #1e3a5f !important;
}
[data-theme="dark"] .border-blue-200 {
    border-color: #1e40af !important;
}
[data-theme="dark"] .text-blue-700 {
    color: #93c5fd !important;
}

/* Dark mode: divide borders (users table) */
[data-theme="dark"] .divide-gray-200 > :not([hidden]) ~ :not([hidden]),
[data-theme="dark"] .divide-y > :not([hidden]) ~ :not([hidden]) {
    border-color: var(--border-gray) !important;
}

/* Dark mode: hover states (settings labels, generic elements) */
[data-theme="dark"] .hover\:bg-gray-100:hover {
    background-color: #374151 !important;
}

[data-theme="dark"] .hover\:text-gray-600:hover {
    color: var(--text-dark) !important;
}

[data-theme="dark"] .hover\:bg-gray-50:hover {
    background-color: #374151 !important;
}

[data-theme="dark"] .hover\:bg-gray-300:hover {
    background-color: #6b7280 !important;
}

/* Dark mode: yellow/amber alert banners */
[data-theme="dark"] .bg-yellow-50 {
    background-color: #3b2f12 !important;
}
[data-theme="dark"] .border-yellow-200 {
    border-color: #78350f !important;
}
[data-theme="dark"] .text-yellow-700 {
    color: #fcd34d !important;
}

/* Dark mode: green alert banners */
[data-theme="dark"] .bg-green-50 {
    background-color: #052e16 !important;
}
[data-theme="dark"] .border-green-200 {
    border-color: #064e3b !important;
}
[data-theme="dark"] .border-green-400 {
    border-color: #16a34a !important;
}
[data-theme="dark"] .text-green-700 {
    color: #6ee7b7 !important;
}

/* Dark mode: extended color buttons (settings page) */
[data-theme="dark"] .bg-teal-600:hover { background-color: #0d9488 !important; }
[data-theme="dark"] .bg-indigo-600:hover { background-color: #6366f1 !important; }

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

/* ── Sidebar collapse ──────────────────────────────────── */
#sidebar {
    width: 14rem;
    transition: width 0.25s cubic-bezier(.4,0,.2,1);
    will-change: width;
}

#sidebar.collapsed {
    width: 3.5rem;
}

#sidebar .sidebar-label {
    white-space: nowrap;
    overflow: hidden;
}

#sidebar.collapsed .sidebar-label {
    display: none;
}

#sidebar.collapsed nav a.nav-link {
    justify-content: center;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}

#sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 0.75rem 0.5rem;
}

#sidebar.collapsed .sidebar-section {
    margin-top: 0.25rem;
}

#sidebar.collapsed #dark-mode-toggle,
#sidebar.collapsed #lang-toggle {
    justify-content: center;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}

/* Section collapse */
.sidebar-section-items {
    max-height: 500px;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.2s ease;
    opacity: 1;
}

.sidebar-section.closed .sidebar-section-items {
    max-height: 0;
    opacity: 0;
}

.sidebar-section .section-chevron {
    transition: transform 0.2s ease;
}

.sidebar-section.closed .section-chevron {
    transform: rotate(-90deg);
}

/* Active nav icon */
#sidebar nav a.nav-link.bg-blue-50 svg {
    color: #3b82f6 !important;
}

[data-theme="dark"] #sidebar nav a.nav-link.bg-blue-50 svg {
    color: #93c5fd !important;
}

body {
    font-family: 'Cairo', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-light-gray);
    color: var(--text-dark);
}

/* HTMX Loading State */
.htmx-request .htmx-indicator {
    display: inline-block;
}

.htmx-indicator {
    display: none;
}

.htmx-request.htmx-swapping .htmx-swapping {
    opacity: 0;
    transition: opacity 200ms ease-out;
}

.htmx-request.htmx-settling .htmx-settling {
    opacity: 1;
    transition: opacity 200ms ease-in;
}

/* Disabled submit button during HTMX request */
button.htmx-requesting {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* ── Field Validation Errors ────────────────────────────────── */
/* Inline error message below form fields */
.field-error {
    color: #dc2626;
    font-size: 0.8125rem;
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}
.field-error::before {
    content: "⚠";
    font-size: 0.75rem;
}

/* Highlight invalid input border */
.input-error,
input.input-error,
select.input-error,
textarea.input-error {
    border-color: #dc2626 !important;
    box-shadow: 0 0 0 1px #dc2626;
}
.input-error:focus {
    border-color: #dc2626 !important;
    box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.3);
}

/* Dark mode field errors */
[data-theme="dark"] .field-error {
    color: #f87171;
}
[data-theme="dark"] .input-error,
[data-theme="dark"] input.input-error,
[data-theme="dark"] select.input-error,
[data-theme="dark"] textarea.input-error {
    border-color: #f87171 !important;
    box-shadow: 0 0 0 1px #f87171;
}
[data-theme="dark"] .input-error:focus {
    border-color: #f87171 !important;
    box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.3);
}

/* Form error summary box (optional, for top-of-form error list) */
.form-error-summary {
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    color: #991b1b;
    font-size: 0.875rem;
}
.form-error-summary ul {
    list-style: disc;
    padding-inline-start: 1.25rem;
    margin: 0.25rem 0 0 0;
}
[data-theme="dark"] .form-error-summary {
    background-color: rgba(220, 38, 38, 0.1);
    border-color: rgba(248, 113, 113, 0.3);
    color: #fca5a5;
}

/* ── Skeleton Loader ────────────────────────────────────────── */
@keyframes skeletonPulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

.skeleton {
    background: linear-gradient(90deg, var(--border-gray) 25%, #e2e8f0 50%, var(--border-gray) 75%);
    background-size: 200% 100%;
    animation: skeletonPulse 1.5s ease-in-out infinite;
    border-radius: 0.375rem;
}

.skeleton-row {
    display: flex;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border-gray);
}

.skeleton-cell {
    height: 1rem;
    border-radius: 0.25rem;
    background: var(--border-gray);
    animation: skeletonPulse 1.5s ease-in-out infinite;
}

.skeleton-cell:nth-child(1) { width: 15%; }
.skeleton-cell:nth-child(2) { width: 25%; }
.skeleton-cell:nth-child(3) { width: 20%; }
.skeleton-cell:nth-child(4) { width: 15%; }
.skeleton-cell:nth-child(5) { width: 25%; }

[data-theme="dark"] .skeleton {
    background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
    background-size: 200% 100%;
}

[data-theme="dark"] .skeleton-cell {
    background: #374151;
}

/* Global loading overlay transition */
#global-loading {
    transition: opacity 0.15s ease;
}

/* Transitions */
.transition {
    transition: all 200ms ease-in-out;
}

/* ── M3 Buttons ─────────────────────────────────────────────── */
.btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.5rem;
    min-height: 2.5rem;
    border-radius: var(--md-sys-shape-full);
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    font-family: inherit;
    letter-spacing: 0.01em;
    transition: box-shadow 200ms, background-color 200ms, color 200ms;
    overflow: hidden;
    text-decoration: none;
}
.btn::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    opacity: 0;
    transition: opacity 200ms;
    pointer-events: none;
}
.btn:hover::before {
    background: currentColor;
    opacity: var(--md-sys-state-hover-opacity);
}
.btn:focus-visible {
    outline: 2px solid var(--md-sys-color-primary);
    outline-offset: 2px;
}
.btn:active::before {
    opacity: var(--md-sys-state-press-opacity);
}

/* Filled button */
.btn-primary, .btn-filled {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    box-shadow: var(--md-sys-elevation-1);
}
.btn-primary:hover, .btn-filled:hover {
    box-shadow: var(--md-sys-elevation-2);
}

/* Tonal button */
.btn-tonal {
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
}

/* Outlined button */
.btn-outlined {
    background: transparent;
    border: 1px solid var(--md-sys-color-outline);
    color: var(--md-sys-color-primary);
}
.btn-outlined:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent);
}

/* Text button */
.btn-text {
    background: transparent;
    color: var(--md-sys-color-primary);
    padding-left: 0.75rem;
    padding-right: 0.75rem;
}

/* Danger / Error button */
.btn-danger, .btn-error {
    background-color: var(--md-sys-color-error);
    color: var(--md-sys-color-on-error);
    box-shadow: var(--md-sys-elevation-1);
}
.btn-danger:hover, .btn-error:hover {
    box-shadow: var(--md-sys-elevation-2);
}

/* Success button */
.btn-success {
    background-color: var(--md-sys-color-success);
    color: var(--md-sys-color-on-success);
    box-shadow: var(--md-sys-elevation-1);
}
.btn-success:hover {
    box-shadow: var(--md-sys-elevation-2);
}

/* Warning button */
.btn-warning {
    background-color: var(--md-sys-color-warning);
    color: var(--md-sys-color-on-warning);
    box-shadow: var(--md-sys-elevation-1);
}
.btn-warning:hover {
    box-shadow: var(--md-sys-elevation-2);
}

/* M3 Disabled */
.btn:disabled, .btn[disabled] {
    opacity: 0.38;
    cursor: not-allowed;
    pointer-events: none;
    box-shadow: none;
}

/* Button sizes */
.btn-xs {
    padding: 0.375rem 0.75rem;
    min-height: 2rem;
    font-size: 0.75rem;
}
.btn-sm {
    padding: 0.5rem 1rem;
    min-height: 2.25rem;
    font-size: 0.8125rem;
}
.btn-lg {
    padding: 0.75rem 2rem;
    min-height: 3rem;
    font-size: 1rem;
}

/* Extended color buttons (M3 custom) */
.btn-purple {
    background-color: #7c3aed;
    color: #ffffff;
    box-shadow: var(--md-sys-elevation-1);
}
.btn-purple:hover { box-shadow: var(--md-sys-elevation-2); }

.btn-indigo {
    background-color: #4f46e5;
    color: #ffffff;
    box-shadow: var(--md-sys-elevation-1);
}
.btn-indigo:hover { box-shadow: var(--md-sys-elevation-2); }

.btn-teal {
    background-color: #0d9488;
    color: #ffffff;
    box-shadow: var(--md-sys-elevation-1);
}
.btn-teal:hover { box-shadow: var(--md-sys-elevation-2); }

.btn-amber {
    background-color: var(--md-sys-color-warning-container);
    color: var(--md-sys-color-on-warning-container);
}

/* FAB (Floating Action Button) — M3 */
.fab {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1rem;
    min-width: 3.5rem;
    min-height: 3.5rem;
    border-radius: var(--md-sys-shape-lg);
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    font-family: inherit;
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    box-shadow: var(--md-sys-elevation-3);
    transition: box-shadow 200ms;
    text-decoration: none;
    overflow: hidden;
}
.fab::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: currentColor;
    opacity: 0;
    transition: opacity 200ms;
    pointer-events: none;
}
.fab:hover { box-shadow: var(--md-sys-elevation-4); }
.fab:hover::before { opacity: var(--md-sys-state-hover-opacity); }
.fab-extended { padding: 1rem 1.5rem; }
.fab-small { min-width: 2.5rem; min-height: 2.5rem; padding: 0.5rem; border-radius: var(--md-sys-shape-md); }
.fab-large { min-width: 6rem; min-height: 6rem; border-radius: var(--md-sys-shape-xl); }
.fab-surface { background-color: var(--md-sys-color-surface-container-high); color: var(--md-sys-color-primary); }
.fab-secondary { background-color: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
.fab-tertiary { background-color: var(--md-sys-color-tertiary-container); color: var(--md-sys-color-on-tertiary-container); }

/* ── M3 Text Fields (Outlined variant) ───────────────────────── */
input, textarea, select {
    width: 100%;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: var(--md-sys-shape-xs);
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    line-height: 1.5rem;
    background-color: transparent;
    color: var(--md-sys-color-on-surface);
    font-family: inherit;
    transition: border-color 200ms, box-shadow 200ms;
    caret-color: var(--md-sys-color-primary);
}

/* Checkboxes and radios should NOT be full width */
input[type="checkbox"],
input[type="radio"] {
    width: auto;
}

input:hover, textarea:hover, select:hover {
    border-color: var(--md-sys-color-on-surface);
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--md-sys-color-primary);
    border-width: 2px;
    padding: calc(0.75rem - 0.5px) calc(1rem - 0.5px);
}

input::placeholder, textarea::placeholder {
    color: var(--md-sys-color-on-surface-variant);
    font-size: 0.875rem;
}

/* M3 Label */
label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
    margin-bottom: 0.5rem;
    display: block;
    letter-spacing: 0.02em;
}

/* ── M3 Data Table ───────────────────────────────────────────── */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

thead {
    background-color: var(--md-sys-color-surface-container-highest);
}
thead th {
    font-weight: 600;
    color: var(--md-sys-color-on-surface-variant);
    font-size: 0.75rem;
    letter-spacing: 0.03em;
    text-transform: none;
}

tbody tr {
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    transition: background-color 150ms;
}

tbody tr:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
}

td, th {
    padding: 0.875rem 1rem;
    text-align: right;
}

/* ── M3 Cards ────────────────────────────────────────────────── */
.card, .md-card-elevated {
    background-color: var(--md-sys-color-surface-container-low);
    border-radius: var(--md-sys-shape-md);
    box-shadow: var(--md-sys-elevation-1);
    padding: 1.5rem;
    transition: box-shadow 200ms;
}
.md-card-filled {
    background-color: var(--md-sys-color-surface-container-highest);
    border-radius: var(--md-sys-shape-md);
    padding: 1.5rem;
}
.md-card-outlined {
    background-color: var(--md-sys-color-surface);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-md);
    padding: 1.5rem;
}

/* ── M3 Badges (Tonal pills) ─────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.75rem;
    border-radius: var(--md-sys-shape-sm);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-success {
    background-color: var(--md-sys-color-success-container);
    color: var(--md-sys-color-on-success-container);
}

.badge-warning {
    background-color: var(--md-sys-color-warning-container);
    color: var(--md-sys-color-on-warning-container);
}

.badge-danger {
    background-color: var(--md-sys-color-error-container);
    color: var(--md-sys-color-on-error-container);
}

.badge-info {
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

/* ── M3 Navigation Drawer ────────────────────────────────────── */
aside {
    min-height: 100vh;
    background-color: var(--md-sys-color-surface-container-lowest);
}

aside nav a.nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    margin: 0.125rem 0.5rem;
    color: var(--md-sys-color-on-surface-variant);
    text-decoration: none;
    border-radius: var(--md-sys-shape-full);
    transition: background-color 200ms, color 200ms;
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.4;
}

aside nav a.nav-link:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
    color: var(--md-sys-color-on-surface);
}

/* M3 Active indicator */
aside nav a.nav-link.active,
aside nav a.nav-link.bg-blue-50 {
    background-color: var(--md-sys-color-secondary-container) !important;
    color: var(--md-sys-color-on-secondary-container) !important;
    font-weight: 700;
}

aside nav a.nav-link svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* ── Sidebar compact spacing ──────────────────────────────── */
.sidebar-section {
    margin-top: 0.75rem; /* 12px — override mt-1.5 (6px) for better group separation */
}
.sidebar-section-btn {
    font-size: 0.6875rem !important; /* 11px — override text-[10px] for Arabic readability */
    line-height: 1.3;
}

.sidebar-section-items {
    padding-top: 0.125rem;
}

/* ── M3 Stat Card ────────────────────────────────────────────── */
.stat-card {
    background-color: var(--md-sys-color-surface-container-low);
    border-radius: var(--md-sys-shape-md);
    box-shadow: var(--md-sys-elevation-1);
    padding: 1.5rem;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: box-shadow 200ms;
}

.stat-card:hover {
    box-shadow: var(--md-sys-elevation-2);
}

.stat-card h3 {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
    margin-bottom: 0.5rem;
    letter-spacing: 0.02em;
}

.stat-card p {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--md-sys-color-on-surface);
}

/* ── Mobile Sidebar Drawer ──────────────────────────── */
#sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 45;
    transition: opacity 0.25s ease;
}

#sidebar-overlay.active {
    display: block;
}

[data-theme="dark"] #sidebar-overlay {
    background: rgba(0, 0, 0, 0.6);
}

@media (max-width: 768px) {
    .flex-col-mobile {
        flex-direction: column;
    }

    #sidebar {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 14rem !important;
        transform: translateX(100%);
        transition: transform 0.3s cubic-bezier(.4,0,.2,1);
        z-index: 50;
        box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
    }

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

    /* Never use collapsed mode on mobile, always show label */
    #sidebar.mobile-open .sidebar-label {
        display: inline !important;
    }
    #sidebar.mobile-open nav a.nav-link {
        justify-content: flex-start !important;
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }

    /* Dashboard charts */
    .chart-container {
        min-height: 180px;
        max-height: 240px;
    }

    /* Tables scroll */
    .overflow-x-auto {
        -webkit-overflow-scrolling: touch;
    }

    /* Filter bar stacking */
    .grid.grid-cols-1.sm\:grid-cols-2 {
        grid-template-columns: 1fr;
    }
    .grid.grid-cols-2 {
        grid-template-columns: 1fr;
    }

    /* KPI cards full width on small screens */
    .grid.grid-cols-2.md\:grid-cols-4 {
        grid-template-columns: repeat(2, 1fr);
    }
    .grid.grid-cols-2.md\:grid-cols-5 {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Touch targets: table action links min 44px tap height */
    td a, td button {
        display: inline-block;
        min-height: 2.25rem;
        line-height: 2.25rem;
        padding-left: 0.375rem;
        padding-right: 0.375rem;
    }

    /* Action cells: prevent chaotic wrapping */
    td:last-child {
        white-space: nowrap;
    }
}

@media (max-width: 480px) {
    .grid.grid-cols-2.md\:grid-cols-4 {
        grid-template-columns: 1fr;
    }
    .grid.grid-cols-2.md\:grid-cols-5 {
        grid-template-columns: 1fr;
    }
}

/* ── Chart containers ──────────────────────────────── */
.chart-container {
    position: relative;
    width: 100%;
}

.chart-container canvas {
    width: 100% !important;
    height: auto !important;
}

/* ── Chart.js dark mode ────────────────────────────── */
[data-theme="dark"] .chart-container {
    color: #e5e7eb;
}
/* ── M3 Pagination ───────────────────────────────────────────── */
.pagination-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.625rem 1.25rem;
    min-height: 2.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: var(--md-sys-shape-full);
    color: var(--md-sys-color-on-surface);
    background: var(--md-sys-color-surface);
    text-decoration: none;
    transition: all 200ms;
    cursor: pointer;
    overflow: hidden;
}
.pagination-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: currentColor;
    opacity: 0;
    transition: opacity 200ms;
    pointer-events: none;
}
.pagination-btn:hover {
    border-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-primary);
}
.pagination-btn:hover::before {
    opacity: var(--md-sys-state-hover-opacity);
}

/* ── M3 Back navigation ──────────────────────────────────────── */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--md-sys-color-primary);
    text-decoration: none;
    border-radius: var(--md-sys-shape-full);
    transition: all 200ms;
    margin-bottom: 0.75rem;
}
.back-link:hover {
    background: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent);
}

/* ── M3 Snackbar (Toast replacement) ─────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-radius: var(--md-sys-shape-xs);
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: var(--md-sys-elevation-3);
    min-width: 320px;
    max-width: 520px;
    animation: snackIn 0.25s cubic-bezier(.2,0,0,1) forwards;
    font-family: 'Cairo', sans-serif;
    direction: rtl;
    border: none;
}
.toast.toast-out {
    animation: snackOut 0.2s cubic-bezier(.2,0,0,1) forwards;
}
.toast-error {
    background-color: var(--md-sys-color-error-container);
    color: var(--md-sys-color-on-error-container);
}
.toast-success {
    background-color: var(--md-sys-color-success-container);
    color: var(--md-sys-color-on-success-container);
}
.toast-warning {
    background-color: var(--md-sys-color-warning-container);
    color: var(--md-sys-color-on-warning-container);
}
.toast-info {
    background-color: var(--md-sys-color-inverse-surface);
    color: var(--md-sys-color-inverse-on-surface);
}
.toast .toast-close {
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 200ms;
    margin-right: auto;
    background: none;
    border: none;
    color: inherit;
    font-size: 1rem;
    line-height: 1;
    padding: 0.25rem;
    border-radius: var(--md-sys-shape-full);
}
.toast .toast-close:hover {
    opacity: 1;
    background: color-mix(in srgb, currentColor 12%, transparent);
}
@keyframes snackIn {
    from { opacity: 0; transform: translateY(1rem) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes snackOut {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to   { opacity: 0; transform: translateY(1rem) scale(0.95); }
}

/* ═══════════════════════════════════════════════════════════════
   M3 PAGE-LEVEL UTILITY CLASSES
   These replace repeated inline Tailwind across all templates.
   ═══════════════════════════════════════════════════════════════ */

/* ── Page Cards (detail/form wrappers) ──────────────────────── */
.page-card {
    max-width: 42rem;
    margin-inline: auto;
    background: var(--md-sys-color-surface-container-lowest);
    border-radius: var(--md-sys-shape-md);
    box-shadow: var(--md-sys-elevation-1);
    padding: 1.5rem;
}
.page-card-wide {
    max-width: 56rem;
    margin-inline: auto;
    background: var(--md-sys-color-surface-container-lowest);
    border-radius: var(--md-sys-shape-md);
    box-shadow: var(--md-sys-elevation-1);
    padding: 1.5rem;
}

/* ── Data Table Wrapper ─────────────────────────────────────── */
.data-table-wrapper {
    background: var(--md-sys-color-surface-container-lowest);
    border-radius: var(--md-sys-shape-md);
    box-shadow: var(--md-sys-elevation-1);
    overflow-x: auto;
}

/* ── List Page Toolbar ──────────────────────────────────────── */
.list-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 0.75rem;
    margin-bottom: 1rem;
}
.list-toolbar form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.list-toolbar .toolbar-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-inline-start: auto;
}

/* Normalize toolbar element heights & styling */
.list-toolbar input,
.list-toolbar select {
    height: 2.25rem;
    padding: 0 0.5rem;
    font-size: 0.8125rem;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: var(--md-sys-shape-xs);
    background-color: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    width: auto;
}
.list-toolbar select {
    padding-left: 1.75rem;  /* room for the dropdown arrow (RTL: left = end) */
    padding-right: 0.5rem;
}
.list-toolbar input.search-input {
    flex: 1 1 0;
    min-width: 12rem;
    max-width: 24rem;
    height: 2.5rem;
    font-size: 0.875rem;
    padding: 0 0.75rem;
}
.list-toolbar .btn {
    height: 2.25rem;
    white-space: nowrap;
}

/* ── Detail Fields (key-value pairs) ────────────────────────── */
.detail-field {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.625rem 0;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
}
.detail-field:last-child {
    border-bottom: none;
}
.detail-label {
    font-size: 0.875rem;
    color: var(--md-sys-color-on-surface-variant);
}
.detail-value {
    font-weight: 600;
    color: var(--md-sys-color-on-surface);
}

/* Vertical variant (product-detail, store-detail) */
.detail-field-v {
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    padding-bottom: 0.75rem;
}
.detail-field-v .detail-label {
    font-size: 0.75rem;
    display: block;
    margin-bottom: 0.25rem;
}
.detail-field-v .detail-value {
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
}

/* ── Form Groups ────────────────────────────────────────────── */
.form-group {
    margin-bottom: 1rem;
}
.form-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--md-sys-color-on-surface-variant);
    margin-bottom: 0.5rem;
    letter-spacing: 0.02em;
}
.required-mark {
    color: var(--md-sys-color-error);
    margin-inline-start: 0.125rem;
}

/* ── Excel Import Wizard ────────────────────────────────────── */
.excel-wizard-step {
    border: 1px solid var(--md-sys-color-outline-variant, var(--md-sys-color-outline));
    border-radius: 0.5rem;
    overflow: hidden;
}
.excel-wizard-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background-color: var(--md-sys-color-surface-container, rgba(0,0,0,0.03));
    border-bottom: 1px solid var(--md-sys-color-outline-variant, var(--md-sys-color-outline));
    font-size: 0.875rem;
    font-weight: 600;
}
.excel-wizard-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary, #fff);
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}
.excel-wizard-body {
    padding: 1rem;
}
.btn-text-sm {
    font-size: 0.75rem;
    color: var(--md-sys-color-primary);
    cursor: pointer;
    border: none;
    background: none;
    text-decoration: underline;
    margin-inline-start: auto;
}
.btn-text-sm:hover { text-decoration-thickness: 2px; }

.excel-mapping-row {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* Preview table */
.excel-preview-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--md-sys-color-outline-variant, var(--md-sys-color-outline));
    border-radius: var(--md-sys-shape-xs);
    max-height: 14rem;
}
.excel-preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
}
.excel-preview-table th {
    position: sticky;
    top: 0;
    background-color: var(--md-sys-color-surface-container, #f5f5f5);
    font-weight: 600;
    padding: 0.375rem 0.5rem;
    text-align: start;
    border-bottom: 1px solid var(--md-sys-color-outline);
    white-space: nowrap;
}
.excel-preview-table td {
    padding: 0.3rem 0.5rem;
    border-bottom: 1px solid var(--md-sys-color-outline-variant, rgba(0,0,0,0.08));
    white-space: nowrap;
    max-width: 12rem;
    overflow: hidden;
    text-overflow: ellipsis;
}
.excel-preview-table tbody tr:hover {
    background-color: rgba(0, 100, 210, 0.04);
}

/* Dark mode */
[data-theme="dark"] .excel-wizard-step {
    border-color: var(--border-gray);
}
[data-theme="dark"] .excel-wizard-header {
    background-color: var(--md-sys-color-surface-container-highest, rgba(255,255,255,0.06));
    border-color: var(--border-gray);
}
[data-theme="dark"] .excel-preview-table-wrap {
    border-color: var(--border-gray);
}
[data-theme="dark"] .excel-preview-table th {
    background-color: var(--md-sys-color-surface-container-highest, #2a2a2a);
    border-color: var(--border-gray);
}
[data-theme="dark"] .excel-preview-table td {
    border-color: rgba(255,255,255,0.06);
}
[data-theme="dark"] .excel-preview-table tbody tr:hover {
    background-color: rgba(100, 170, 255, 0.06);
}

/* ── Bulk Import Preview Cards ───────────────────────────────── */
.bulk-preview-summary {
    display: flex;
    align-items: center;
    font-size: 0.875rem;
    color: var(--md-sys-color-on-surface-variant);
    padding: 0.5rem 0;
}
.bulk-preview-card {
    border: 1px solid var(--md-sys-color-outline-variant, #c4c7c5);
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
    overflow: hidden;
    background: var(--md-sys-color-surface, #fff);
}
.bulk-preview-card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--md-sys-color-surface-container-low, #f5f5f5);
    border-bottom: 1px solid var(--md-sys-color-outline-variant, #c4c7c5);
    font-size: 0.8125rem;
    font-weight: 600;
}
.bulk-preview-card-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.375rem;
    height: 1.375rem;
    border-radius: 50%;
    background: var(--md-sys-color-primary, #0064d2);
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 700;
    flex-shrink: 0;
}
.bulk-preview-card-title { flex: 1; }
.bulk-preview-card-count {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--md-sys-color-on-surface-variant);
}
.bulk-preview-info {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    color: var(--md-sys-color-on-surface-variant);
}
.bulk-preview-total {
    display: flex;
    justify-content: flex-end;
    gap: 1.5rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 600;
    border-top: 1px solid var(--md-sys-color-outline-variant, #c4c7c5);
    background: var(--md-sys-color-surface-container-low, #f5f5f5);
}

/* Bulk results */
.bulk-results-list {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    padding: 0.5rem 0;
}
.bulk-result-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    padding: 0.375rem 0.5rem;
    border-radius: 0.375rem;
}
.bulk-result-ok {
    background: rgba(0, 150, 50, 0.04);
}
.bulk-result-fail {
    background: rgba(220, 38, 38, 0.04);
}
.bulk-result-error {
    margin-inline-start: auto;
    font-size: 0.6875rem;
    color: #dc2626;
    max-width: 50%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Dark mode bulk preview */
[data-theme="dark"] .bulk-preview-card {
    border-color: var(--border-gray);
    background: var(--md-sys-color-surface, #1a1a1a);
}
[data-theme="dark"] .bulk-preview-card-header {
    background: var(--md-sys-color-surface-container-highest, rgba(255,255,255,0.06));
    border-color: var(--border-gray);
}
[data-theme="dark"] .bulk-preview-total {
    background: var(--md-sys-color-surface-container-highest, rgba(255,255,255,0.06));
    border-color: var(--border-gray);
}
[data-theme="dark"] .bulk-result-ok {
    background: rgba(0, 150, 50, 0.08);
}
[data-theme="dark"] .bulk-result-fail {
    background: rgba(220, 38, 38, 0.08);
}

/* ── Custom File Upload ─────────────────────────────────────── */

/* Drop zone box */
.file-upload-zone {
    border: 2px dashed var(--md-sys-color-outline);
    border-radius: 0.5rem;
    padding: 1.25rem 1rem;
    transition: border-color 200ms, background-color 200ms;
    background-color: var(--md-sys-color-surface-container-lowest, rgba(0,0,0,0.015));
    cursor: pointer;
    text-align: center;
}
.file-upload-zone:hover {
    border-color: var(--md-sys-color-primary);
    background-color: rgba(0, 100, 210, 0.06);
}
.file-upload-zone.drag-over {
    border-color: var(--md-sys-color-primary);
    border-style: solid;
    background-color: rgba(0, 100, 210, 0.10);
}
.file-upload-zone.has-file {
    border-color: var(--md-sys-color-primary);
    border-style: solid;
    background-color: rgba(0, 100, 210, 0.03);
}
.file-upload-zone.has-error {
    border-color: var(--md-sys-color-error);
    background-color: rgba(200, 0, 0, 0.03);
}

/* Label — vertical centered column */
.file-upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
}

/* Icon circle */
.file-upload-icon {
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background-color: rgba(0, 100, 210, 0.08);
    color: var(--md-sys-color-primary);
    margin-bottom: 0.25rem;
    transition: background-color 200ms, transform 200ms;
}
.file-upload-zone:hover .file-upload-icon {
    background-color: rgba(0, 100, 210, 0.15);
    transform: translateY(-1px);
}
.file-upload-zone.drag-over .file-upload-icon {
    background-color: rgba(0, 100, 210, 0.2);
    transform: translateY(-2px);
}

/* Main instruction text */
.file-upload-text {
    font-size: 0.8125rem;
    color: var(--md-sys-color-on-surface-variant);
    line-height: 1.4;
}

/* Browse link */
.file-upload-browse {
    font-size: 0.8125rem;
    color: var(--md-sys-color-primary);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color 150ms;
}
.file-upload-zone:hover .file-upload-browse {
    text-decoration-thickness: 2px;
}

/* Hint line */
.file-upload-hint {
    font-size: 0.6875rem;
    color: var(--md-sys-color-on-surface-variant);
    opacity: 0.55;
    margin-top: 0.125rem;
}

/* File preview chip */
.file-upload-preview {
    display: none;
    align-items: center;
    gap: 0.375rem;
    margin-top: 0.5rem;
    padding: 0.3rem 0.625rem;
    border-radius: var(--md-sys-shape-xs);
    background-color: var(--md-sys-color-surface-container);
    font-size: 0.75rem;
    color: var(--md-sys-color-on-surface);
    text-align: start;
}
.file-upload-zone.has-file .file-upload-preview { display: inline-flex; }
.file-upload-preview .file-name {
    font-weight: 500; flex: 1; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-upload-preview .file-size {
    color: var(--md-sys-color-on-surface-variant);
    font-size: 0.6875rem; flex-shrink: 0;
}
.file-upload-preview .file-remove {
    color: var(--md-sys-color-error); cursor: pointer;
    font-size: 0.875rem; line-height: 1;
    padding: 0.125rem 0.25rem; border-radius: var(--md-sys-shape-xs);
    transition: background-color 150ms; flex-shrink: 0;
}
.file-upload-preview .file-remove:hover { background-color: rgba(200,0,0,0.1); }

/* Multi-file list */
.file-upload-multi-preview {
    display: none; flex-direction: column;
    gap: 0.25rem; margin-top: 0.5rem;
    text-align: start;
}
.file-upload-zone.has-file .file-upload-multi-preview { display: flex; }
.file-upload-multi-preview .file-item {
    display: flex; align-items: center; gap: 0.375rem;
    padding: 0.25rem 0.625rem; border-radius: var(--md-sys-shape-xs);
    background-color: var(--md-sys-color-surface-container);
    font-size: 0.75rem; color: var(--md-sys-color-on-surface);
}

/* Dark mode */
[data-theme="dark"] .file-upload-zone {
    border-color: var(--border-gray);
    background-color: rgba(255, 255, 255, 0.02);
}
[data-theme="dark"] .file-upload-zone:hover {
    border-color: var(--md-sys-color-primary);
    background-color: rgba(100, 170, 255, 0.08);
}
[data-theme="dark"] .file-upload-zone.drag-over {
    background-color: rgba(100, 170, 255, 0.14);
}
[data-theme="dark"] .file-upload-zone.has-file {
    background-color: rgba(100, 170, 255, 0.05);
}
[data-theme="dark"] .file-upload-icon {
    background-color: rgba(100, 170, 255, 0.12);
}
[data-theme="dark"] .file-upload-zone:hover .file-upload-icon {
    background-color: rgba(100, 170, 255, 0.2);
}
[data-theme="dark"] .file-upload-preview,
[data-theme="dark"] .file-upload-multi-preview .file-item {
    background-color: var(--md-sys-color-surface-container-highest);
}

/* ── Action Links (table rows) ──────────────────────────────── */
.action-link {
    font-size: 0.8125rem;
    font-weight: 500;
    text-decoration: none;
    padding: 0.5rem 0.625rem;
    min-height: 2.25rem;
    display: inline-flex;
    align-items: center;
    border-radius: var(--md-sys-shape-xs);
    transition: background-color 200ms, color 200ms;
}
.action-link:hover {
    text-decoration: underline;
}
.action-view {
    color: var(--md-sys-color-primary);
}
.action-edit {
    color: var(--md-sys-color-success);
}
.action-delete {
    color: var(--md-sys-color-error);
}
.action-print {
    color: var(--md-sys-color-tertiary);
}
.action-pdf {
    color: var(--md-sys-color-success);
}
.action-credit {
    color: var(--md-sys-color-warning);
}

/* ── Detail Actions Bar ─────────────────────────────────────── */
.detail-actions {
    margin-top: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* ── Page Title ─────────────────────────────────────────────── */
.page-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--md-sys-color-on-surface);
    margin-bottom: 1rem;
}

/* ── Section Card (settings, info sections) ─────────────────── */
.section-card {
    background: var(--md-sys-color-surface-container-lowest);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-md);
    padding: 1.5rem;
}
.section-card-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--md-sys-color-on-surface);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ── M3 Status Badges (semantic) ────────────────────────────── */
.badge-active {
    background-color: var(--md-sys-color-success-container);
    color: var(--md-sys-color-on-success-container);
}
.badge-inactive {
    background-color: var(--md-sys-color-error-container);
    color: var(--md-sys-color-on-error-container);
}
.badge-pending {
    background-color: var(--md-sys-color-warning-container);
    color: var(--md-sys-color-on-warning-container);
}
.badge-draft {
    background-color: var(--md-sys-color-surface-container-high);
    color: var(--md-sys-color-on-surface-variant);
}
.badge-processing {
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}
.badge-issued {
    background-color: var(--md-sys-color-success-container);
    color: var(--md-sys-color-on-success-container);
}

/* ── M3 Dialog / Modal ──────────────────────────────────────── */
/* ── Empty state (tables & standalone) ───────────────────────── */
.empty-state-cell {
    padding: 2.5rem 1.5rem;
    text-align: center;
    color: var(--md-sys-color-on-surface-variant);
}
.empty-state-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}
.empty-state-icon {
    width: 3rem;
    height: 3rem;
    opacity: 0.45;
    color: var(--md-sys-color-on-surface-variant);
}
.empty-state-msg {
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
}
.empty-state-standalone {
    padding: 3rem 1rem;
    text-align: center;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.32);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-overlay.hidden {
    display: none;
}
.modal-container {
    background: var(--md-sys-color-surface-container-high);
    border-radius: var(--md-sys-shape-xl);
    box-shadow: var(--md-sys-elevation-3);
    width: 100%;
    max-width: 42rem;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
}
.modal-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--md-sys-color-on-surface);
}
.modal-close {
    color: var(--md-sys-color-on-surface-variant);
    cursor: pointer;
    font-size: 1.5rem;
    background: none;
    border: none;
    padding: 0.25rem;
    border-radius: var(--md-sys-shape-full);
    transition: background-color 200ms;
}
.modal-close:hover {
    background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
}
.modal-body {
    padding: 1.5rem;
}
.modal-actions {
    display: flex;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--md-sys-color-outline-variant);
}

/* ── Grid Helpers ───────────────────────────────────────────── */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    gap: 1rem;
}
@media (min-width: 768px) {
    .grid-2 { grid-template-columns: repeat(2, 1fr); }
}

/* ── Search Input in toolbar ────────────────────────────────── */
.search-input {
    width: 100%;
}

@media (max-width: 768px) {
    .list-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .list-toolbar form {
        flex-wrap: wrap;
    }
    .search-input {
        max-width: 100%;
    }
}

/* ═══════════════════════════════════════════════════════════════
   UI/UX AUDIT FIXES — Critical & High Priority
   ═══════════════════════════════════════════════════════════════ */

/* ── H7: Select dropdown arrow ───────────────────────────────── */
select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%2349454f' d='M4 6l4 4.5L12 6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 0.625rem center;
    background-size: 16px;
    padding-left: 2.25rem;
}

[data-theme="dark"] select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%23c4c6d0' d='M4 6l4 4.5L12 6'/%3E%3C/svg%3E");
}

/* ── C1: Table scroll shadow indicators ─────────────────────── */
.data-table-wrapper {
    position: relative;
}
.data-table-wrapper::before,
.data-table-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 24px;
    pointer-events: none;
    z-index: 2;
    opacity: 0;
    transition: opacity 200ms;
}
.data-table-wrapper::before {
    right: 0;
    background: linear-gradient(to left, rgba(0,0,0,.08), transparent);
}
.data-table-wrapper::after {
    left: 0;
    background: linear-gradient(to right, rgba(0,0,0,.08), transparent);
}
[data-theme="dark"] .data-table-wrapper::before {
    background: linear-gradient(to left, rgba(0,0,0,.25), transparent);
}
[data-theme="dark"] .data-table-wrapper::after {
    background: linear-gradient(to right, rgba(0,0,0,.25), transparent);
}
/* JS toggles .scroll-left / .scroll-right classes */
.data-table-wrapper.scroll-right::before { opacity: 1; }
.data-table-wrapper.scroll-left::after { opacity: 1; }

/* ── C2: Mobile action overflow menu ────────────────────────── */
/* Desktop: links shown inline. Mobile: collapsed into overflow dropdown. */
/* Template markup: <div class="action-cell"><div class="action-links">...links...</div><button class="action-overflow-btn">⋮</button></div> */
.action-cell {
    position: relative;
    white-space: nowrap;
}
.action-cell .action-links {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}
.action-cell .action-overflow-btn {
    display: none;
    background: none;
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-sm);
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
    color: var(--md-sys-color-on-surface-variant);
    transition: background-color 200ms;
}
.action-cell .action-overflow-btn:hover {
    background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
}

@media (max-width: 768px) {
    .action-cell .action-links {
        display: none;
        position: absolute;
        left: 0;
        top: 100%;
        z-index: 20;
        flex-direction: column;
        background: var(--md-sys-color-surface-container-lowest);
        border: 1px solid var(--md-sys-color-outline-variant);
        border-radius: var(--md-sys-shape-sm);
        box-shadow: var(--md-sys-elevation-3);
        padding: 0.25rem 0;
        min-width: 10rem;
        white-space: normal;
    }
    .action-cell .action-links.show {
        display: flex;
    }
    .action-cell .action-links a,
    .action-cell .action-links button {
        display: block;
        width: 100%;
        text-align: right;
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
        font-weight: 500;
        text-decoration: none;
        border: none;
        background: none;
        cursor: pointer;
        color: var(--md-sys-color-on-surface);
        transition: background-color 200ms;
    }
    .action-cell .action-links a:hover,
    .action-cell .action-links button:hover {
        background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
    }
    .action-cell .action-overflow-btn { display: inline-flex; }
}

/* ── C3: Form grids collapse on narrow screens ──────────────── */
@media (max-width: 480px) {
    .grid.grid-cols-1.md\:grid-cols-3 {
        grid-template-columns: 1fr;
    }
}

/* ── C4: Dashboard filter mobile ────────────────────────────── */
@media (max-width: 640px) {
    .grid.grid-cols-1.sm\:grid-cols-2.md\:grid-cols-5 {
        grid-template-columns: 1fr;
    }
}

/* ── Permission table (edit-user) dark mode ─── */
.perm-table tbody {
    border-color: var(--md-sys-color-outline-variant);
}
.perm-table tbody tr {
    border-color: var(--md-sys-color-outline-variant);
}
.perm-table tbody tr:hover {
    background: var(--md-sys-color-surface-container-low);
}
.perm-table tbody td.font-semibold {
    color: var(--md-sys-color-on-surface);
}
.perm-table input[type="checkbox"] {
    border-color: var(--md-sys-color-outline);
}

/* ── Alert banners (dark-mode compatible) ─── */
.alert {
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    line-height: 1.5;
}
.alert-success {
    background: var(--md-sys-color-success-container, #d1fae5);
    color: var(--md-sys-color-on-success-container, #065f46);
    border: 1px solid var(--md-sys-color-success, #34d399);
}
.alert-error {
    background: var(--md-sys-color-error-container);
    color: var(--md-sys-color-on-error-container);
    border: 1px solid var(--md-sys-color-error);
}

/* ── H8: Print styles ───────────────────────────────────────── */
@media print {
    /* Hide non-printable UI elements */
    #sidebar,
    #sidebar-overlay,
    header,
    .mobile-menu-btn,
    .back-link,
    .detail-actions,
    .action-link,
    .btn,
    .list-toolbar,
    .pagination-btn,
    .no-print,
    footer,
    #toast-container,
    .htmx-indicator,
    #global-loading {
        display: none !important;
    }

    /* Remove backgrounds and shadows for clean print */
    body {
        background: white !important;
        color: black !important;
    }
    main {
        margin: 0 !important;
        padding: 0 !important;
    }
    .page-card,
    .page-card-wide,
    .section-card,
    .data-table-wrapper {
        box-shadow: none !important;
        border: none !important;
        padding: 0 !important;
        max-width: 100% !important;
    }
    table {
        font-size: 0.75rem;
    }
    th, td {
        padding: 0.375rem 0.5rem;
    }

    /* Ensure content fills page */
    .flex-1 {
        margin-right: 0 !important;
    }
}
