/*
    Isusik Banking Design System (Compact V2)
    Theme Support: Light (default) / Dark
    Glassmorphism approach for both themes
*/

/* ========================================
   THEME SYSTEM - CSS VARIABLES
   ======================================== */

:root {
    /* --- Typography (shared) --- */
    --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: "JetBrains Mono", Consolas, monospace;

    /* --- Spacing (Compact) --- */
    --space-2xs: 2px;
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 20px;
    --space-2xl: 24px;

    /* --- Components (shared) --- */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-xl: 12px;
    --radius-pill: 999px;

    /* Layout Sizes */
    --sidebar-width: 260px;
    --header-height: 56px;

    /* ========================================
       LIGHT THEME (Default) - Glassmorphism
       ======================================== */

    /* Background */
    --bg-page: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 50%, #f1f5f9 100%);
    --bg-page-solid: #f1f5f9;
    --bg-surface: rgba(255, 255, 255, 0.85);
    --bg-surface-solid: #ffffff;
    --bg-surface-hover: rgba(248, 250, 252, 0.9);
    --bg-sidebar: rgba(255, 255, 255, 0.9);

    /* Blur decorations */
    --blur-1-color: rgba(59, 130, 246, 0.12);
    --blur-2-color: rgba(100, 116, 139, 0.08);
    --blur-1-opacity: 0.6;
    --blur-2-opacity: 0.5;

    /* Text */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-tertiary: #64748b;
    --text-on-primary: #ffffff;

    /* Borders */
    --border-default: rgba(0, 0, 0, 0.08);
    --border-hover: rgba(0, 0, 0, 0.12);
    --border-subtle: rgba(0, 0, 0, 0.05);

    /* Action Colors */
    --action-primary: #2563eb;
    --action-primary-hover: #1d4ed8;
    --action-primary-bg: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    --action-danger: #ef4444;
    --action-danger-hover: #dc2626;
    --action-success: #16a34a;
    --action-warning: #f59e0b;

    /* Shadows */
    --shadow-none: none;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px -4px rgba(0, 0, 0, 0.1);
    --shadow-card: 0 4px 16px -4px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.8);

    /* Cards */
    --card-bg: rgba(255, 255, 255, 0.85);
    --card-border: rgba(0, 0, 0, 0.06);
    --card-shadow: var(--shadow-card);

    /* Inputs */
    --input-bg: rgba(255, 255, 255, 0.8);
    --input-border: rgba(0, 0, 0, 0.1);
    --input-focus-border: rgba(59, 130, 246, 0.5);
    --input-placeholder: #94a3b8;

    /* Alerts */
    --alert-error-bg: rgba(239, 68, 68, 0.1);
    --alert-error-border: rgba(239, 68, 68, 0.2);
    --alert-error-text: #dc2626;
    --alert-info-bg: rgba(59, 130, 246, 0.1);
    --alert-info-border: rgba(59, 130, 246, 0.2);
    --alert-info-text: #2563eb;
    --alert-success-bg: rgba(22, 163, 74, 0.1);
    --alert-success-border: rgba(22, 163, 74, 0.2);
    --alert-success-text: #15803d;

    /* Scrollbar */
    --scrollbar-thumb: #cbd5e1;
    --scrollbar-thumb-hover: #94a3b8;

    /* Theme meta */
    --theme-color-meta: #f1f5f9;
}

/* ========================================
   DARK THEME - Glassmorphism
   ======================================== */

[data-theme="dark"] {
    /* Background */
    --bg-page: linear-gradient(135deg,
        #0f172a 0%,
        #1e293b 25%,
        #334155 50%,
        #1e3a5f 75%,
        #1e293b 100%
    );
    --bg-page-solid: #0f172a;
    --bg-surface: rgba(255, 255, 255, 0.06);
    --bg-surface-solid: #1e293b;
    --bg-surface-hover: rgba(255, 255, 255, 0.08);
    --bg-sidebar: rgba(15, 23, 42, 0.95);

    /* Blur decorations */
    --blur-1-color: rgba(59, 130, 246, 0.35);
    --blur-2-color: rgba(71, 85, 105, 0.3);
    --blur-1-opacity: 0.5;
    --blur-2-opacity: 0.4;

    /* Text */
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;
    --text-on-primary: #ffffff;

    /* Borders */
    --border-default: rgba(255, 255, 255, 0.1);
    --border-hover: rgba(255, 255, 255, 0.15);
    --border-subtle: rgba(255, 255, 255, 0.05);

    /* Action Colors */
    --action-primary: #3b82f6;
    --action-primary-hover: #60a5fa;
    --action-primary-bg: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    --action-danger: #f87171;
    --action-danger-hover: #fca5a5;
    --action-success: #4ade80;
    --action-warning: #fbbf24;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px -4px rgba(0, 0, 0, 0.5);
    --shadow-card: 0 4px 16px -4px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.08);

    /* Cards */
    --card-bg: rgba(255, 255, 255, 0.06);
    --card-border: rgba(255, 255, 255, 0.1);
    --card-shadow: var(--shadow-card);

    /* Inputs */
    --input-bg: rgba(255, 255, 255, 0.05);
    --input-border: rgba(255, 255, 255, 0.1);
    --input-focus-border: rgba(59, 130, 246, 0.5);
    --input-placeholder: #64748b;

    /* Alerts */
    --alert-error-bg: rgba(239, 68, 68, 0.15);
    --alert-error-border: rgba(239, 68, 68, 0.25);
    --alert-error-text: #fca5a5;
    --alert-info-bg: rgba(59, 130, 246, 0.15);
    --alert-info-border: rgba(59, 130, 246, 0.25);
    --alert-info-text: #93c5fd;
    --alert-success-bg: rgba(74, 222, 128, 0.15);
    --alert-success-border: rgba(74, 222, 128, 0.25);
    --alert-success-text: #86efac;

    /* Scrollbar */
    --scrollbar-thumb: #475569;
    --scrollbar-thumb-hover: #64748b;

    /* Theme meta */
    --theme-color-meta: #1e293b;
}

/* Base Reset & Typography */
* {
    box-sizing: border-box;
}

body.design-system-enabled {
    background: var(--bg-page);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    margin: 0;
    min-height: 100vh;
    transition: background 0.3s ease, color 0.3s ease;
}

/* Animated gradient for dark theme */
[data-theme="dark"] body.design-system-enabled {
    background-size: 400% 400%;
    animation: gradientShift 20s ease infinite;
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

/* Disable gradient animation for battery savings & accessibility */
@media (prefers-reduced-motion: reduce) {
    [data-theme="dark"] body.design-system-enabled {
        animation: none;
        background-size: 100% 100%;
    }
}

@media (max-width: 768px) {
    [data-theme="dark"] body.design-system-enabled {
        animation: none;
        background-size: 100% 100%;
    }
}

body.is-sidebar-open {
    overflow: hidden;
}

/* ========================================
   THEME TOGGLE BUTTON
   ======================================== */

.theme-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--bg-surface);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-toggle-btn:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
    transform: translateY(-1px);
}

/* ========================================
   GLASSMORPHISM UTILITIES
   ======================================== */

.glass {
    background: var(--bg-surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-default);
}

.glass-subtle {
    background: var(--bg-surface);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.design-system-enabled h1 {
    font-size: 20px;
    line-height: 28px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.design-system-enabled h2 {
    font-size: 16px;
    line-height: 24px;
    font-weight: 600;
}

.design-system-enabled h3 {
    font-size: 14px;
    line-height: 20px;
    font-weight: 600;
}

/* Auth Layout */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-page);
    padding: var(--space-xl);
    position: relative;
}

.auth-card {
    width: 100%;
    max-width: 420px;
}

.auth-top-links {
    position: absolute;
    top: var(--space-lg);
    right: var(--space-lg);
    display: flex;
    gap: var(--space-xs);
}

.auth-lang-btn.active {
    border-color: var(--action-primary);
    color: var(--action-primary);
}

/* Text Utilities */
.text-primary {
    color: var(--text-primary);
}

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

.text-tertiary {
    color: var(--text-tertiary);
}

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

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

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

/* Status message color states (theme-aware; replaces inline JS hex colors). */
.status-msg--warning {
    color: var(--action-warning);
}

.status-msg--success {
    color: var(--action-success);
}

.status-msg--error {
    color: var(--action-danger);
}

.text-mono {
    font-family: var(--font-mono);
}

.text-xs {
    font-size: 11px;
    line-height: 14px;
}

.text-sm {
    font-size: 12px;
    line-height: 16px;
}

.font-medium {
    font-weight: 500;
}

.font-semibold {
    font-weight: 600;
}

.font-bold {
    font-weight: 700;
}

/* Formalized Label Style */
.design-system-enabled .form-label,
.form-label {
    display: block;
    font-size: 11px;
    color: var(--text-tertiary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    margin-bottom: 4px;
}

.uppercase {
    text-transform: uppercase;
}

.tracking-wide {
    letter-spacing: 0.05em;
}

/* Buttons (Compact) */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    /* Compact height */
    padding: 0 12px;
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    gap: 6px;
    line-height: 1;
    white-space: nowrap;
}

.btn-sm {
    height: 28px;
    padding: 0 8px;
    font-size: 12px;
}

.btn-lg {
    height: 40px;
    font-size: 14px;
    padding: 0 20px;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--action-primary-bg);
    color: var(--text-on-primary);
    border-color: transparent;
}

.btn-primary:hover:not(:disabled) {
    background: var(--action-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-surface);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-color: var(--border-default);
    color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
    border-color: var(--border-hover);
    background: var(--bg-surface-hover);
}

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

.btn-danger:hover:not(:disabled) {
    background-color: var(--action-danger-hover);
}

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

.btn-ghost:hover:not(:disabled) {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

[data-theme="dark"] .btn-ghost:hover:not(:disabled) {
    background-color: rgba(255, 255, 255, 0.08);
}

/* Inputs (Compact) - Glassmorphism */
.design-system-enabled .form-input,
.design-system-enabled .form-select,
.design-system-enabled .form-textarea,
.form-input,
.form-select,
.form-textarea {
    display: block;
    width: 100%;
    height: 32px;
    padding: 0 10px;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius-md);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--input-focus-border);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

[data-theme="dark"] .form-input:focus,
[data-theme="dark"] .form-select:focus,
[data-theme="dark"] .form-textarea:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(96, 165, 250, 0.7);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

.form-select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    padding-right: 2.5rem;
}

.form-textarea {
    height: auto;
    padding: 8px 10px;
}

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

.form-input.is-valid {
    border-color: var(--action-primary);
    box-shadow: 0 0 0 1px var(--action-primary);
}

.form-checkbox {
    width: 16px;
    height: 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-default);
    accent-color: var(--action-primary);
}

.form-checkbox:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

/* Cards (Compact) - Glassmorphism */
.card {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: var(--card-shadow);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateY(0);
}

/* Interactive card with hover lift effect */
.card-interactive,
.card[href],
.card.cursor-pointer,
a .card,
.grid-autofit-md .card {
    cursor: pointer;
}

.card-interactive:hover,
.card[href]:hover,
.card.cursor-pointer:hover,
a:hover .card,
.grid-autofit-md .card:hover {
    transform: translateY(-4px);
    box-shadow:
        0 12px 32px -8px rgba(0, 0, 0, 0.15),
        0 4px 8px -2px rgba(0, 0, 0, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    border-color: var(--action-primary);
}

[data-theme="dark"] .card-interactive:hover,
[data-theme="dark"] .card[href]:hover,
[data-theme="dark"] .card.cursor-pointer:hover,
[data-theme="dark"] a:hover .card,
[data-theme="dark"] .grid-autofit-md .card:hover {
    box-shadow:
        0 12px 32px -8px rgba(0, 0, 0, 0.5),
        0 4px 8px -2px rgba(0, 0, 0, 0.3),
        0 0 20px rgba(59, 130, 246, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* Card press effect */
.card-interactive:active,
.card[href]:active,
.card.cursor-pointer:active,
.grid-autofit-md .card:active {
    transform: translateY(-2px);
    transition-duration: 0.1s;
}

.card.no-padding {
    padding: 0;
}

/* Solid card variant (no blur) */
.card.card-solid {
    background: var(--bg-surface-solid);
    backdrop-filter: none;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px;
    border-radius: var(--radius-md);
    /* Squarer badges */
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
}

.badge-success {
    background: #dcfce7;
    color: #15803d;
    border: 1px solid #bbf7d0;
}

.badge-warning {
    background: #fef9c3;
    color: #a16207;
    border: 1px solid #fde047;
}

.badge-error {
    background: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.badge-info {
    background: #e0f2fe;
    color: #0369a1;
    border: 1px solid #bae6fd;
}

.badge-neutral {
    background: var(--bg-page);
    color: var(--text-secondary);
    border: 1px solid var(--border-default);
}

/* Dark theme badge overrides (WCAG AA contrast on dark bg) */
[data-theme="dark"] .badge-success {
    background: rgba(74, 222, 128, 0.2);
    color: #4ade80;
    border-color: rgba(74, 222, 128, 0.4);
}

[data-theme="dark"] .badge-warning {
    background: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
    border-color: rgba(251, 191, 36, 0.4);
}

[data-theme="dark"] .badge-error {
    background: rgba(248, 113, 113, 0.2);
    color: #f87171;
    border-color: rgba(248, 113, 113, 0.4);
}

[data-theme="dark"] .badge-info {
    background: rgba(96, 165, 250, 0.2);
    color: #60a5fa;
    border-color: rgba(96, 165, 250, 0.4);
}

/* Tables (Dense) */
.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.table-scroll {
    min-width: 720px;
}

.table th {
    text-align: left;
    padding: 8px 12px;
    background-color: var(--bg-surface-hover);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border-default);
}

.table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-default);
    color: var(--text-primary);
    font-size: 13px;
    vertical-align: middle;
}

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

.table tr:hover td {
    background-color: var(--bg-surface-hover);
}

.table-hover tbody tr:hover td {
    background-color: var(--bg-page);
}

/* Helper for clickable cards */
.stretched-link::after {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1;
    content: "";
}

/* Text utilities */
.no-underline {
    text-decoration: none;
}

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

/* Sidebar Section Title */
.sidebar-section-title {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-tertiary);
    font-weight: 600;
    letter-spacing: 0.05em;
    margin-top: 24px;
    margin-bottom: 8px;
    padding-left: 12px;
}

/* Layout Utilities */
.sidebar-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: 100vh;
}

.sidebar-overlay {
    display: none;
}

.sidebar-layout .sidebar {
    background: var(--bg-sidebar);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-default);
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    transition: background 0.3s ease, border-color 0.3s ease;
}

.sidebar-layout .main-content {
    background: transparent;
    min-width: 0;
    /* Prevent grid blowout */
    padding: 0;
    position: relative;
}

/* Decorative blur shapes for main content */
.sidebar-layout .main-content::before,
.sidebar-layout .main-content::after {
    content: '';
    position: fixed;
    border-radius: 50%;
    filter: blur(100px);
    pointer-events: none;
    z-index: -1;
    transition: background 0.3s ease, opacity 0.3s ease;
}

.sidebar-layout .main-content::before {
    width: 500px;
    height: 500px;
    background: var(--blur-1-color);
    top: -150px;
    right: -100px;
    opacity: var(--blur-1-opacity);
}

.sidebar-layout .main-content::after {
    width: 400px;
    height: 400px;
    background: var(--blur-2-color);
    bottom: -100px;
    left: 20%;
    opacity: var(--blur-2-opacity);
}

@media (max-width: 768px) {
    .sidebar-layout {
        grid-template-columns: 1fr;
    }

    .sidebar-layout .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        /* Use dvh for mobile browsers that account for address bar */
        height: 100vh;
        height: 100dvh;
        max-height: -webkit-fill-available;
        width: min(86vw, var(--sidebar-width));
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        z-index: 40;
        box-shadow: var(--shadow-md);
        /* Extra padding to ensure logout button is above browser UI */
        padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
    }

    .sidebar-layout .main-content {
        width: 100%;
    }

    .sidebar-layout.is-sidebar-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.4);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
        z-index: 30;
    }

    .sidebar-layout.is-sidebar-open .sidebar-overlay {
        opacity: 1;
        pointer-events: auto;
    }
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-default);
}

.sidebar-footer {
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-default);
    margin-top: auto;
}

/* Mobile: ensure logout button is visible above browser chrome */
@media (max-width: 768px) {
    .sidebar-footer {
        padding-bottom: max(20px, env(safe-area-inset-bottom, 20px));
        flex-shrink: 0;
    }
}

.sidebar-nav {
    padding: var(--space-md);
    gap: var(--space-xs);
    flex: 1;
    display: flex;
    flex-direction: column;
}

.main-header {
    height: var(--header-height);
    background: var(--bg-surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-default);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 10;
    transition: background 0.3s ease, border-color 0.3s ease;
}

.content-wrapper {
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
}

.sidebar-toggle {
    display: none;
    min-width: 32px;
    padding: 0;
    background: transparent;
    border: none;
}

/* Hamburger base (when used as sidebar-toggle) */
.hamburger.sidebar-toggle {
    width: 24px;
    height: 20px;
    position: relative;
    cursor: pointer;
    flex-direction: column;
    justify-content: space-between;
    align-items: stretch;
    padding: 0;
}

.hamburger.sidebar-toggle span {
    display: block;
    width: 100%;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: center;
}

.hamburger.is-active span:nth-child(1) {
    transform: translateY(9px) rotate(45deg);
}

.hamburger.is-active span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}

.hamburger.is-active span:nth-child(3) {
    transform: translateY(-9px) rotate(-45deg);
}

@media (max-width: 768px) {
    .main-header {
        padding: 8px 12px;
        height: auto;
        min-height: var(--header-height);
        flex-wrap: wrap;
        gap: 8px;
    }

    .sidebar-toggle {
        display: flex;
    }

    .content-wrapper {
        padding: 12px;
    }

    .tab-nav {
        padding: 0 12px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .tab-trigger {
        white-space: nowrap;
    }
}

/* Flex & Grid Helpers */
.flex {
    display: flex;
}

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

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

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

.justify-end {
    justify-content: flex-end;
}

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

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

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

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

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

.gap-1 {
    gap: var(--space-xs);
}

.gap-2 {
    gap: var(--space-sm);
}

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

.flex-1 {
    flex: 1 1 0%;
}

.flex-wrap {
    flex-wrap: wrap;
}

.w-auto {
    width: auto;
}

.w-full {
    width: 100%;
}

.h-full {
    height: 100%;
}

.min-w-0 {
    min-width: 0;
}

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

.grid {
    display: grid;
}

/* Dense Form Grid */
.grid-dense-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

@media (max-width: 1024px) {
    .grid-dense-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .grid-dense-4 {
        grid-template-columns: 1fr;
    }
}

/* Utilities */
.p-0 {
    padding: 0;
}

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

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

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

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

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

.px-1 {
    padding-left: var(--space-xs);
    padding-right: var(--space-xs);
}

.px-2 {
    padding-left: var(--space-sm);
    padding-right: var(--space-sm);
}

.px-3 {
    padding-left: var(--space-md);
    padding-right: var(--space-md);
}

.py-1 {
    padding-top: var(--space-xs);
    padding-bottom: var(--space-xs);
}

.py-2 {
    padding-top: var(--space-sm);
    padding-bottom: var(--space-sm);
}

.py-3 {
    padding-top: var(--space-md);
    padding-bottom: var(--space-md);
}

.pt-3 {
    padding-top: var(--space-md);
}

.pt-4 {
    padding-top: var(--space-lg);
}

.pt-6 {
    padding-top: var(--space-2xl);
}

.mt-1 {
    margin-top: var(--space-xs);
}

.mt-2 {
    margin-top: var(--space-sm);
}

.mt-4 {
    margin-top: var(--space-lg);
}

.mt-8 {
    margin-top: calc(var(--space-2xl) + var(--space-lg));
}

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

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

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

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

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

.hidden {
    display: none !important;
}

.relative {
    position: relative !important;
}

.cursor-pointer {
    cursor: pointer;
}

.overflow-hidden {
    overflow: hidden;
}

.border-t {
    border-top: 1px solid var(--border-default);
}

.border-b {
    border-bottom: 1px solid var(--border-default);
}

.border {
    border: 1px solid var(--border-default);
}

.border-default {
    border: 1px solid var(--border-default);
}

.border-2 {
    border-width: 2px;
    border-style: solid;
    border-color: var(--border-default);
}

.border-dashed {
    border-style: dashed;
}

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

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

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

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

.bg-page {
    background: var(--bg-page);
}

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

.bg-border-default {
    background: var(--border-default);
}

.bg-white,
.bg-surface-solid {
    background: var(--bg-surface-solid);
}

/* Warning/Alert backgrounds */
.bg-warning-50 {
    background: #fef9c3;
}

[data-theme="dark"] .bg-warning-50 {
    background: rgba(251, 191, 36, 0.15);
}

.border-warning {
    border-color: #fde047;
}

[data-theme="dark"] .border-warning {
    border-color: rgba(251, 191, 36, 0.4);
}

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

/* Max height utilities */
.max-h-96 {
    max-height: 24rem; /* 384px */
}

.max-h-80 {
    max-height: 20rem; /* 320px */
}

.max-h-64 {
    max-height: 16rem; /* 256px */
}

.max-h-48 {
    max-height: 12rem; /* 192px */
}

.max-h-40 {
    max-height: 10rem; /* 160px */
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
    transition: background 0.2s ease;
}

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

/* --- Empty State --- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl);
    text-align: center;
    color: var(--text-secondary);
    background: var(--bg-page);
    border: 1px dashed var(--border-default);
    border-radius: var(--radius-lg);
    min-height: 120px;
}

.empty-state__icon {
    font-size: 2rem;
    margin-bottom: var(--space-sm);
    opacity: 0.6;
}

.empty-state__title {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: var(--space-xs);
}

.empty-state__description {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-bottom: var(--space-md);
}

/* --- Loading States --- */
.btn.is-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn.is-loading::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid currentColor;
    border-radius: 50%;
    border-right-color: transparent;
    animation: spin 0.6s linear infinite;
}

.btn-primary.is-loading::after {
    border-color: rgba(255, 255, 255, 0.3);
    border-right-color: transparent;
}

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

/* Skeleton loader - see detailed definitions in Mobile section */

/* --- Required Field Indicator --- */
.form-label.required::after,
.required .form-label::after {
    content: " *";
    color: var(--action-danger);
    font-weight: 600;
}

/* --- Mobile Responsive Tables --- */
@media (max-width: 768px) {
    .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table-card-mobile tbody tr {
        display: flex;
        flex-direction: column;
        padding: var(--space-md);
        margin-bottom: var(--space-sm);
        background: var(--bg-surface);
        border: 1px solid var(--border-default);
        border-radius: var(--radius-md);
    }

    .table-card-mobile thead {
        display: none;
    }

    .table-card-mobile td {
        display: flex;
        justify-content: space-between;
        padding: var(--space-xs) 0;
        border: none;
    }

    .table-card-mobile td::before {
        content: attr(data-label);
        font-weight: 500;
        color: var(--text-secondary);
        font-size: 11px;
        text-transform: uppercase;
    }

    /* Grid responsive */
    .grid-dense-4 {
        grid-template-columns: repeat(2, 1fr) !important;
    }

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

    /* Increase touch targets (44px = Apple HIG minimum) */
    .btn {
        min-height: 44px;
    }

    .btn-sm {
        min-height: 40px;
    }

    .form-input,
    .form-select,
    .form-textarea {
        min-height: 44px;
    }
}

/* Tablet touch targets — WCAG 2.5.5 / Apple HIG 44px floor up to 1024px */
@media (max-width: 1024px) and (min-width: 769px) {
    .btn {
        min-height: 44px;
    }

    .btn-sm {
        min-height: 40px;
    }

    .form-input,
    .form-select,
    .form-textarea {
        min-height: 44px;
    }
}

@media (max-width: 480px) {
    .grid-dense-4,
    .grid-cols-4,
    .grid-cols-2 {
        grid-template-columns: 1fr !important;
    }
}

/* --- Keyboard Focus Styles --- */
.tab-trigger:focus-visible,
.btn:focus-visible {
    outline: 2px solid var(--action-primary);
    outline-offset: 2px;
}

/* Tab navigation accessibility */
.tab-trigger[aria-selected="true"] {
    color: var(--action-primary);
    border-bottom-color: var(--action-primary);
}

/* --- Tooltips --- */
[data-tooltip] {
    position: relative;
    cursor: help;
}

[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    background: var(--text-primary);
    color: white;
    font-size: 11px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 1001;
    margin-bottom: 4px;
}

[data-tooltip]:hover::before,
[data-tooltip]:focus::before {
    opacity: 1;
    visibility: visible;
}

/* --- Status Legend --- */
.status-legend {
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
    padding: var(--space-sm) var(--space-md);
    background: var(--card-bg);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    font-size: 11px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.status-legend__item {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

/* --- Modals --- */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal-backdrop.active {
    display: flex;
}

.modal {
    background: var(--bg-surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: background 0.3s ease, border-color 0.3s ease;
}

.modal.modal-wide {
    max-width: 800px;
}

/* Modal size variants */
.modal.modal-sm {
    max-width: 400px;
}

.modal.modal-md {
    max-width: 600px;
}

.modal.modal-lg {
    max-width: 900px;
}

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

.modal-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-body {
    padding: 24px;
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-default);
    background: var(--bg-surface-hover);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    flex-shrink: 0;
    transition: background 0.3s ease, border-color 0.3s ease;
}

/* Form inside modal inherits flex column layout (createUserModal, editUserModal) */
.modal > form {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

/* --- Admin Components --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    margin: 8px 0;
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.stat-label {
    color: var(--text-secondary);
    font-size: 13px;
}

.admin-toolbar {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Admin: user modal details */
.muted-text {
    color: var(--text-tertiary);
}

.admin-action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--space-xs);
}

.admin-action-grid .btn {
    width: 100%;
}

.activity-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs) var(--space-sm);
    font-size: 12px;
    color: var(--text-primary);
}

.activity-row + .activity-row {
    margin-top: var(--space-xs);
}

.activity-label {
    font-weight: 600;
    color: var(--text-secondary);
}

.activity-value {
    flex: 1;
    min-width: 0;
    word-break: break-word;
}

.device-card {
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-surface);
}

.device-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    margin-bottom: var(--space-xs);
}

.device-hash {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-primary);
    word-break: break-all;
}

.device-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs) var(--space-sm);
    font-size: 12px;
    color: var(--text-secondary);
}

.device-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    background: var(--border-default);
    color: var(--text-primary);
    font-size: 11px;
    font-weight: 600;
    max-width: 100%;
    word-break: break-word;
    white-space: normal;
    overflow-wrap: anywhere;
}

.device-tag.info {
    background: rgba(37, 99, 235, 0.12);
    color: #1d4ed8;
}

[data-theme="dark"] .device-tag.info {
    background: rgba(96, 165, 250, 0.2);
    color: #93c5fd;
}

.device-tag.warn {
    background: rgba(234, 179, 8, 0.16);
    color: #92400e;
}

[data-theme="dark"] .device-tag.warn {
    background: rgba(251, 191, 36, 0.2);
    color: #fde047;
}

/* --- Tabs (Migrated from layout.css) --- */
.tab-nav {
    display: flex;
    gap: 8px;
    padding: 0 24px;
    background: var(--bg-surface);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-default);
    transition: background 0.3s ease, border-color 0.3s ease;
}

.tab-trigger {
    padding: 12px 16px;
    /* Adjusted for compact */
    color: var(--text-secondary);
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    font-size: 13px;
}

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

.tab-trigger.active {
    color: var(--action-primary);
    border-bottom-color: var(--action-primary);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* --- New Utilities (PR2) --- */
.grid-cols-1 {
    grid-template-columns: repeat(1, minmax(0, 1fr));
}

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

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

.w-6 {
    width: 24px;
}

.h-6 {
    height: 24px;
}

.text-lg {
    font-size: 18px;
}

.text-xl {
    font-size: 20px;
}

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.max-w-xs {
    max-width: 150px;
}

/* --- PR4: Bank Selector Utilities --- */
.grid-autofit-md {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}

.icon-box {
    width: 32px;
    height: 32px;
    background: var(--bg-page);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-secondary);
    border: 1px solid var(--border-default);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--text-tertiary);
}

.status-dot.active {
    background-color: var(--action-success);
}

/* Bank status indicators */
.status-dot.full {
    background-color: #22c55e;  /* Зелёный — полная поддержка */
}

.status-dot.partial {
    background-color: #eab308;  /* Жёлтый — частичная поддержка */
}

.status-dot.unsupported {
    background-color: #ef4444;  /* Красный — не поддерживается */
}

/* Bank icon in selector */
.bank-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    object-fit: contain;
    border: 1px solid var(--border-default);
    background: var(--bg-page);
}

.footer-grid {
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    gap: 16px;
}

@media (min-width: 768px) {
    .footer-grid {
        grid-template-columns: repeat(3, 1fr);
    }

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

    .md\:border-r {
        border-right: 1px solid var(--border-default);
    }
}

/* --- PR5: Sidebar Profiles & Metrics --- */
.profile-item {
    padding: 8px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.1s;
    border: 1px solid transparent;
    font-size: 13px;
}

.profile-item:hover {
    background: var(--bg-page);
}

.profile-item.active {
    background: #eff6ff;
    border-color: var(--action-primary);
    color: var(--action-primary);
    font-weight: 500;
}

.sidebar-metric {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-default);
    margin-bottom: 8px;
}

.sidebar-metric-label {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-tertiary);
    letter-spacing: 0.05em;
    margin-bottom: 2px;
}

.sidebar-metric-value {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 14px;
}

.metric-editor {
    display: none;
}

.sidebar-metric.is-editing .sidebar-metric-value {
    display: none;
}

.sidebar-metric.is-editing .metric-editor {
    display: block;
}

.metric-mode-btn {
    opacity: 0.3;
    transition: opacity 0.2s;
    cursor: pointer;
    font-size: 10px;
    padding: 2px 4px;
    border-radius: 4px;
    background: transparent;
    border: 1px solid currentColor;
}

.metric-mode-btn:hover {
    opacity: 0.7;
}

.metric-mode-btn.active {
    opacity: 1;
    background: rgba(0, 0, 0, 0.05);
    font-weight: bold;
}

/* --- PR6: Admin Utilities --- */
.overflow-x-auto {
    overflow-x: auto;
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    font-size: 13px;
    border: 1px solid transparent;
    transition: all 0.3s ease;
}

.alert-error {
    background: var(--alert-error-bg);
    color: var(--alert-error-text);
    border-color: var(--alert-error-border);
}

.alert-info {
    background: var(--alert-info-bg);
    color: var(--alert-info-text);
    border-color: var(--alert-info-border);
}

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

.icon-box-rounded {
    width: 32px;
    height: 32px;
    background: #e2e8f0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- PR Refinement: Operations Form Fixes --- */
.form-group {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.field-hint {
    display: block;
    width: 100%;
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: var(--space-xs);
    line-height: 1.2;
}

/* Ensure empty selects have height */
.form-select:empty {
    height: 32px;
}

/* --- PR Refinement: Table Fixes --- */
.table-striped tbody tr:nth-of-type(odd) {
    background-color: var(--bg-page);
}

.table-striped tbody tr:nth-of-type(even) {
    background-color: transparent;
}

/* Fix table action alignment */
.table th:last-child {
    text-align: right;
}

.table td:last-child {
    text-align: right;
}

.table td:last-child .flex {
    justify-content: flex-end;
}

/* Audit Fixes (UI Regression) */
.col-span-2 {
    grid-column: span 2;
}

.container-limited {
    max-width: 1000px;
    margin: 0 auto;
    padding-top: 20px;
}

.circle {
    border-radius: 50%;
}

.sidebar-content {
    padding: 16px;
}

.col-span-full {
    grid-column: 1 / -1;
}

.min-w-120 {
    min-width: 120px;
}

.min-w-140 {
    min-width: 140px;
}

.text-right {
    text-align: right;
}

.border-r-0 {
    border-right: 0;
}

.min-h-\[56px\] {
    min-height: 56px;
}

.text-\[10px\] {
    font-size: 10px;
    line-height: 12px;
}

.w-fixed-80 {
    width: 80px;
}

.w-fixed-100 {
    width: 100px;
}

.w-fixed-120 {
    width: 120px;
}/* Operations Actions */
.operation-actions-cell {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    justify-content: flex-end;
}

/* Operations table truncation */
.operations-table {
    table-layout: fixed;
}

.operations-table .op-nowrap,
.operations-table .operation-description-cell {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===========================================
   MOBILE MUST-HAVE IMPROVEMENTS
   =========================================== */

/* --- 1. Safe Area Insets (iPhone notch support) --- */
@supports (padding: env(safe-area-inset-top)) {
    .main-header {
        padding-top: env(safe-area-inset-top);
    }

    .sidebar {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
    }

    .modal-footer {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .content-wrapper {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}


/* --- 3. Bottom Sheet Modals on Mobile --- */
@media (max-width: 768px) {
    .modal-backdrop.active {
        align-items: flex-end;
    }

    .modal {
        max-width: 100% !important;
        width: 100%;
        margin: 0;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        max-height: 90vh;
        max-height: 90dvh;
        animation: slideUp 0.25s ease-out;
    }

    @keyframes slideUp {
        from {
            transform: translateY(100%);
            opacity: 0.5;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }

    .modal-body {
        padding: 16px;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    /* Drag handle indicator */
    .modal-header::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        background: var(--border-default);
        border-radius: 2px;
    }

    .modal-header {
        position: relative;
        padding: 20px 16px 12px;
    }

    .modal-footer {
        background: var(--bg-surface);
        border-top: 1px solid var(--border-default);
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        flex-wrap: wrap;
    }

    .modal-footer .btn {
        flex: 1 1 auto;
        min-width: 0;
    }

    .admin-user-modal #viewPaymentsList,
    .admin-user-modal #viewDevicesList {
        max-height: none;
        overflow: visible;
    }

    .admin-action-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .admin-action-grid .btn {
        white-space: normal;
        height: auto;
        padding: 8px 10px;
        line-height: 1.2;
    }
}

/* --- 4. Scroll Indicator for Horizontal Scroll --- */
.scroll-indicator {
    position: relative;
}

.scroll-indicator::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 40px;
    background: linear-gradient(to right, transparent, var(--bg-surface));
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.2s;
}

.scroll-indicator.scrolled-end::after {
    opacity: 0;
}

/* Table scroll indicator */
@media (max-width: 768px) {
    .table-responsive {
        position: relative;
    }

    .table-responsive::after {
        content: '→';
        position: absolute;
        right: 8px;
        top: 50%;
        transform: translateY(-50%);
        background: var(--bg-surface);
        padding: 4px 8px;
        border-radius: var(--radius-sm);
        box-shadow: var(--shadow-sm);
        font-size: 12px;
        color: var(--text-secondary);
        animation: scrollHint 1.5s ease-in-out infinite;
        pointer-events: none;
    }

    .table-responsive.has-scrolled::after {
        display: none;
    }

    @keyframes scrollHint {
        0%, 100% { opacity: 0.5; transform: translateY(-50%) translateX(0); }
        50% { opacity: 1; transform: translateY(-50%) translateX(5px); }
    }
}

/* --- 5. Reduced Motion Support --- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .modal {
        animation: none;
    }

    .sidebar {
        transition: none;
    }
}

/* --- 6. Improved Mobile Typography --- */
@media (max-width: 768px) {
    body.design-system-enabled {
        font-size: 14px;
        /* Slightly larger for readability */
    }

    .form-label {
        font-size: 13px;
    }

    /* Prevent text size adjustment on orientation change */
    html {
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }
}

/* --- 7. Pull-down Indicator (visual hint) --- */
.pull-indicator {
    display: none;
}

@media (max-width: 768px) {
    .pull-indicator {
        display: block;
        text-align: center;
        padding: 8px;
        color: var(--text-tertiary);
        font-size: 11px;
    }

    .pull-indicator::before {
        content: '↓';
        display: block;
        animation: pullBounce 2s ease-in-out infinite;
    }

    @keyframes pullBounce {
        0%, 100% { transform: translateY(0); }
        50% { transform: translateY(3px); }
    }
}

/* --- 8. Better Form Spacing on Mobile --- */
@media (max-width: 768px) {
    .form-group {
        margin-bottom: 16px;
    }

    .form-input,
    .form-select,
    .form-textarea {
        font-size: 16px;
        /* Prevents iOS zoom on focus */
    }

    /* Stack form buttons on mobile */
    .modal-footer .flex {
        flex-direction: column-reverse;
        gap: 8px;
    }

    .modal-footer .btn {
        width: 100%;
    }
}

@media (max-width: 420px) {
    .admin-action-grid {
        grid-template-columns: 1fr;
    }
}

/* --- 9. Swipe Close Area for Sidebar --- */
@media (max-width: 768px) {
    .sidebar-swipe-area {
        position: absolute;
        right: -20px;
        top: 0;
        bottom: 0;
        width: 20px;
        background: transparent;
    }
}

/* --- 10. Landscape Orientation Fixes --- */
@media (max-width: 768px) and (orientation: landscape) {
    .modal {
        max-height: 85vh;
        max-height: 85dvh;
    }

    .content-wrapper {
        padding: 12px 20px;
    }
}

/* --- 11. Focus States for Accessibility --- */
@media (max-width: 768px) {
    input:focus,
    select:focus,
    textarea:focus,
    button:focus {
        outline: 2px solid var(--action-primary);
        outline-offset: 2px;
    }
}

/* --- 12. Loading Skeleton for Mobile --- */
.skeleton {
    background: linear-gradient(90deg,
        var(--bg-page) 25%,
        var(--border-default) 50%,
        var(--bg-page) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
}

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

@media (prefers-reduced-motion: reduce) {
    .skeleton {
        animation: none;
        background: var(--bg-page);
    }
}

/* ===========================================
   TOAST NOTIFICATIONS
   =========================================== */

.toast-container {
    position: fixed;
    top: max(20px, env(safe-area-inset-top));
    right: max(20px, env(safe-area-inset-right));
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

@media (max-width: 768px) {
    .toast-container {
        top: auto;
        bottom: max(20px, env(safe-area-inset-bottom));
        left: max(12px, env(safe-area-inset-left));
        right: max(12px, env(safe-area-inset-right));
    }
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 280px;
    max-width: 420px;
    pointer-events: auto;
    animation: toastSlideIn 0.3s ease-out;
    transform-origin: top right;
    transition: background 0.3s ease, border-color 0.3s ease;
}

.toast.is-leaving {
    animation: toastSlideOut 0.2s ease-in forwards;
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(100%) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

@keyframes toastSlideOut {
    from {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateX(100%) scale(0.9);
    }
}

@media (max-width: 768px) {
    .toast {
        min-width: 100%;
        max-width: 100%;
    }

    @keyframes toastSlideIn {
        from {
            opacity: 0;
            transform: translateY(100%);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    @keyframes toastSlideOut {
        from {
            opacity: 1;
            transform: translateY(0);
        }
        to {
            opacity: 0;
            transform: translateY(100%);
        }
    }
}

.toast-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.toast-content {
    flex: 1;
    min-width: 0;
}

.toast-title {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.toast-message {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.toast-close {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
    font-size: 16px;
}

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

/* Toast variants */
.toast--success {
    border-left: 3px solid var(--action-success);
}

.toast--success .toast-icon {
    color: var(--action-success);
}

.toast--error {
    border-left: 3px solid var(--action-danger);
}

.toast--error .toast-icon {
    color: var(--action-danger);
}

.toast--warning {
    border-left: 3px solid #f59e0b;
}

.toast--warning .toast-icon {
    color: #f59e0b;
}

.toast--info {
    border-left: 3px solid var(--action-primary);
}

.toast--info .toast-icon {
    color: var(--action-primary);
}

/* Toast progress bar */
.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: currentColor;
    opacity: 0.3;
    border-radius: 0 0 0 var(--radius-md);
}

/* ===========================================
   CONTEXT MENU
   =========================================== */

.context-menu-overlay {
    position: fixed;
    inset: 0;
    z-index: 9998;
}

.context-menu {
    position: fixed;
    z-index: 9999;
    min-width: 180px;
    max-width: 280px;
    background: var(--bg-surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 4px;
    animation: contextMenuIn 0.15s ease-out;
    transform-origin: top left;
    transition: background 0.3s ease, border-color 0.3s ease;
}

@keyframes contextMenuIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text-primary);
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background 0.1s;
}

.context-menu-item:hover {
    background: var(--bg-page);
}

.context-menu-item:active {
    background: var(--border-default);
}

.context-menu-item--danger {
    color: var(--action-danger);
}

.context-menu-item--danger:hover {
    background: #fef2f2;
}

.context-menu-item-icon {
    width: 16px;
    text-align: center;
    flex-shrink: 0;
}

.context-menu-item-label {
    flex: 1;
}

.context-menu-item-shortcut {
    font-size: 11px;
    color: var(--text-tertiary);
    font-family: var(--font-mono);
}

.context-menu-divider {
    height: 1px;
    background: var(--border-default);
    margin: 4px 0;
}

/* ===========================================
   SKELETON LOADING VARIANTS
   =========================================== */

.skeleton-text {
    height: 14px;
    border-radius: 4px;
}

.skeleton-text--sm {
    height: 12px;
}

.skeleton-text--lg {
    height: 18px;
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.skeleton-button {
    height: 36px;
    width: 100px;
    border-radius: var(--radius-md);
}

.skeleton-card {
    padding: 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-default);
}

.skeleton-row {
    display: flex;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-default);
}

.skeleton-table {
    width: 100%;
}

.skeleton-table-row {
    display: grid;
    grid-template-columns: 1fr 2fr 1fr 1fr 80px;
    gap: 12px;
    padding: 12px;
    border-bottom: 1px solid var(--border-default);
}

/* ===========================================
   VIRTUAL LIST
   =========================================== */

.virtual-list {
    position: relative;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.virtual-list-content {
    position: relative;
}

.virtual-list-item {
    position: absolute;
    left: 0;
    right: 0;
    will-change: transform;
}

.virtual-list-spacer {
    pointer-events: none;
}

/* Virtual list loading states */
.virtual-list-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 13px;
    gap: 8px;
}

.virtual-list-loading::before {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-default);
    border-top-color: var(--action-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.virtual-list-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    text-align: center;
}

.virtual-list-empty-icon {
    font-size: 32px;
    margin-bottom: 12px;
    opacity: 0.5;
}

/* --- Preview containers --- */
.message-list-preview {
    max-height: 200px;
    min-height: 60px;
    background: var(--bg-page);
    padding: var(--space-sm);
    border-radius: var(--radius-sm);
}

/* --- Support/Statement/Replacements Panels --- */
.support-panel,
.statement-panel,
.replacements-panel {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.support-modal__header,
.support-panel__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-md);
    border-bottom: 1px solid var(--border-default);
    padding-bottom: var(--space-sm);
}

.statement-panel__header,
.replacements-panel__header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    border-bottom: 1px solid var(--border-default);
    padding-bottom: var(--space-sm);
}

.support-modal__title-wrap {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.support-modal__subtitle {
    margin: 0;
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.45;
}

.support-panel__title,
.statement-panel__title,
.replacements-panel__title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.statement-panel__subtitle,
.replacements-panel__subtitle {
    margin: 0;
    font-size: 13px;
    line-height: 1.45;
    color: var(--text-secondary);
}

.support-modal__body,
.support-panel__body {
    background:
        radial-gradient(circle at 10% 5%, rgba(59, 130, 246, 0.08), transparent 35%),
        radial-gradient(circle at 90% 95%, rgba(16, 185, 129, 0.08), transparent 40%),
        var(--bg-surface);
    border-radius: var(--radius-md);
    padding: var(--space-sm);
}

.statement-panel__body,
.replacements-panel__body {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    background:
        linear-gradient(180deg, rgba(15, 23, 42, 0.03), transparent 45%),
        var(--bg-surface);
    border-radius: var(--radius-md);
    padding: var(--space-sm);
}

.replacements-panel__body .card.is-selected .border-dashed {
    border-color: var(--accent-primary, #3b82f6);
    background: rgba(59, 130, 246, 0.05);
}

.replacements-panel__body .card.has-file .border-dashed {
    border-color: var(--alert-success-border, #22c55e);
    background: rgba(34, 197, 94, 0.05);
}

.support-layout {
    display: grid;
    grid-template-columns: minmax(320px, 0.95fr) minmax(0, 1.45fr);
    gap: var(--space-md);
    align-items: start;
}

.support-compose,
.support-history {
    background: var(--bg-surface);
}

.support-compose {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.support-block {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.support-block__title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-tertiary);
}

.support-operator-row {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
}

.support-inline-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
    gap: var(--space-sm);
}

.support-datetime-inputs input {
    min-width: 0;
}

.support-textarea {
    min-height: 116px;
    resize: vertical;
}

.support-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.support-btn-main {
    min-width: 180px;
}

.support-btn-secondary {
    min-width: 120px;
}

.support-btn-danger {
    min-width: 48px;
}

.support-history {
    display: flex;
    flex-direction: column;
    min-height: 520px;
}

.support-history__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--border-default);
}

.support-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 24px;
    padding: 0 8px;
    border-radius: 999px;
    border: 1px solid var(--border-default);
    background: rgba(37, 99, 235, 0.1);
    color: #1d4ed8;
    font-size: 12px;
    font-weight: 700;
    font-family: var(--font-mono);
}

.support-messages {
    flex: 1 1 auto;
    max-height: none;
    min-height: 280px;
    padding: 10px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background:
        linear-gradient(180deg, rgba(148, 163, 184, 0.06), rgba(148, 163, 184, 0)),
        var(--bg-page);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.message-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 84px;
    border: 1px dashed var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 12px;
    text-align: center;
    padding: 0 var(--space-sm);
}

.message-item {
    border: 1px solid var(--border-default);
    border-left-width: 3px;
    border-radius: 12px;
    background: var(--bg-surface);
    padding: 10px 12px;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.04);
}

.message-item.is-editing {
    outline: 2px solid rgba(37, 99, 235, 0.35);
    outline-offset: 1px;
}

.message-user {
    border-left-color: #2563eb;
}

.message-system {
    border-left-color: #64748b;
}

.message-operator {
    border-left-color: #0891b2;
}

.message-bank {
    border-left-color: #d97706;
}

.message-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
    margin-bottom: 8px;
}

.message-sender-chip {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.1);
    color: #1d4ed8;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    padding: 4px 9px;
}

.message-op,
.message-time {
    font-size: 11px;
    color: var(--text-secondary);
}

.message-actions {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.message-action-btn {
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--bg-surface-hover);
    color: var(--text-primary);
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, border-color 0.2s ease, background 0.2s ease;
}

.message-action-btn:hover {
    transform: translateY(-1px);
}

.message-action-btn--edit:hover {
    border-color: rgba(2, 132, 199, 0.45);
    background: rgba(6, 182, 212, 0.12);
}

.message-action-btn--delete:hover {
    border-color: rgba(220, 38, 38, 0.45);
    background: rgba(239, 68, 68, 0.12);
}

.message-text {
    font-size: 14px;
    line-height: 1.48;
    color: var(--text-primary);
    white-space: normal;
    word-break: break-word;
}

[data-theme="dark"] .support-count {
    color: #93c5fd;
    background: rgba(59, 130, 246, 0.2);
}

[data-theme="dark"] .message-sender-chip {
    color: #bfdbfe;
    background: rgba(96, 165, 250, 0.25);
}

@media (max-width: 980px) {
    .support-layout {
        grid-template-columns: 1fr;
    }

    .support-history {
        min-height: 0;
    }

    .support-messages {
        min-height: 220px;
        max-height: 42vh;
    }

    .support-inline-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .support-modal__header {
        padding-bottom: 12px;
    }

    .support-actions {
        flex-direction: column;
    }

    .support-btn-main,
    .support-btn-secondary,
    .support-btn-danger {
        width: 100%;
    }
}

.preview-box {
    min-height: 60px;
    background: var(--bg-page);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-default);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ========================================
   MICRO-INTERACTIONS & ANIMATIONS
   ======================================== */

/* Page load animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

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

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Animation utility classes */
.animate-fade-in {
    animation: fadeIn 0.4s ease-out forwards;
}

.animate-fade-in-up {
    animation: fadeInUp 0.5s ease-out forwards;
}

.animate-fade-in-down {
    animation: fadeInDown 0.5s ease-out forwards;
}

.animate-fade-in-scale {
    animation: fadeInScale 0.4s ease-out forwards;
}

.animate-slide-in-left {
    animation: slideInLeft 0.5s ease-out forwards;
}

.animate-slide-in-right {
    animation: slideInRight 0.5s ease-out forwards;
}

/* Staggered animations for lists */
.animate-stagger > * {
    opacity: 0;
    animation: fadeInUp 0.4s ease-out forwards;
}

.animate-stagger > *:nth-child(1) { animation-delay: 0.05s; }
.animate-stagger > *:nth-child(2) { animation-delay: 0.1s; }
.animate-stagger > *:nth-child(3) { animation-delay: 0.15s; }
.animate-stagger > *:nth-child(4) { animation-delay: 0.2s; }
.animate-stagger > *:nth-child(5) { animation-delay: 0.25s; }
.animate-stagger > *:nth-child(6) { animation-delay: 0.3s; }
.animate-stagger > *:nth-child(7) { animation-delay: 0.35s; }
.animate-stagger > *:nth-child(8) { animation-delay: 0.4s; }
.animate-stagger > *:nth-child(9) { animation-delay: 0.45s; }
.animate-stagger > *:nth-child(10) { animation-delay: 0.5s; }
.animate-stagger > *:nth-child(n+11) { animation-delay: 0.55s; }

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .animate-fade-in,
    .animate-fade-in-up,
    .animate-fade-in-down,
    .animate-fade-in-scale,
    .animate-slide-in-left,
    .animate-slide-in-right,
    .animate-stagger > * {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
    }
}

/* ========================================
   RIPPLE EFFECT FOR BUTTONS
   ======================================== */

.btn {
    position: relative;
    overflow: hidden;
}

.btn .ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    transform: scale(0);
    animation: ripple-effect 0.6s ease-out;
    pointer-events: none;
}

[data-theme="dark"] .btn .ripple {
    background: rgba(255, 255, 255, 0.2);
}

.btn-ghost .ripple,
.btn-secondary .ripple {
    background: rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .btn-ghost .ripple,
[data-theme="dark"] .btn-secondary .ripple {
    background: rgba(255, 255, 255, 0.15);
}

@keyframes ripple-effect {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* ========================================
   IMPROVED MOBILE SIDEBAR
   ======================================== */

@media (max-width: 768px) {
    /* Sidebar slide animation */
    .sidebar-layout .sidebar {
        transform: translateX(-100%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                    opacity 0.35s ease;
        opacity: 0;
        will-change: transform, opacity;
    }

    .sidebar-layout .sidebar.is-open {
        transform: translateX(0);
        opacity: 1;
    }

    /* Overlay animation - must be BELOW sidebar (z-index 40) */
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0);
        backdrop-filter: blur(0);
        -webkit-backdrop-filter: blur(0);
        transition: background 0.35s ease, backdrop-filter 0.35s ease;
        z-index: 30;
        pointer-events: none;
    }

    .sidebar-overlay.is-visible {
        display: block;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        pointer-events: auto;
    }

    /* Touch-friendly tap targets */
    .btn {
        min-height: 44px;
        min-width: 44px;
    }

    .btn-sm {
        min-height: 36px;
        min-width: 36px;
    }

    .btn-xs {
        min-height: 32px;
        min-width: 32px;
    }
}

/* ========================================
   BOTTOM SHEET (MOBILE MODALS)
   ======================================== */

.bottom-sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0);
    -webkit-backdrop-filter: blur(0);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.bottom-sheet-backdrop.is-active {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 1;
    visibility: visible;
}

.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-surface-solid);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.2);
    max-height: 90vh;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1001;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.bottom-sheet-backdrop.is-active .bottom-sheet {
    transform: translateY(0);
}

.bottom-sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--border-default);
    border-radius: 2px;
    margin: 12px auto;
    flex-shrink: 0;
}

.bottom-sheet-header {
    padding: 0 20px 16px;
    border-bottom: 1px solid var(--border-default);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.bottom-sheet-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.bottom-sheet-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.bottom-sheet-close:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

.bottom-sheet-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    overscroll-behavior: contain;
}

.bottom-sheet-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-default);
    background: var(--bg-surface);
    display: flex;
    gap: 12px;
}

/* Safe area for iOS */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .bottom-sheet-footer {
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
}

/* Desktop: use regular modal instead */
@media (min-width: 769px) {
    .bottom-sheet-backdrop {
        display: none;
    }
}

/* ========================================
   SWIPE INDICATOR
   ======================================== */

.swipe-indicator {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 80px;
    background: var(--action-primary);
    border-radius: 0 4px 4px 0;
    opacity: 0;
    transition: opacity 0.2s ease, width 0.2s ease;
    pointer-events: none;
    z-index: 100;
}

.swipe-indicator.is-visible {
    opacity: 0.5;
    width: 8px;
}

/* ========================================
   PULSE & GLOW EFFECTS
   ======================================== */

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

@keyframes glow {
    0%, 100% {
        box-shadow: 0 0 5px rgba(59, 130, 246, 0.3);
    }
    50% {
        box-shadow: 0 0 20px rgba(59, 130, 246, 0.6);
    }
}

.animate-pulse {
    animation: pulse 2s ease-in-out infinite;
}

.animate-glow {
    animation: glow 2s ease-in-out infinite;
}

/* Status dot pulse for active items */
.status-dot.active {
    animation: pulse 2s ease-in-out infinite;
}

/* ========================================
   CHECKBOX OPTIONS & SERVICES GRID
   ======================================== */

.replacements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-sm);
}

.replacements-grid.grid-cols-1 {
    grid-template-columns: 1fr;
}

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

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

.checkbox-option {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-surface);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 13px;
    color: var(--text-primary);
    user-select: none;
    min-height: 40px;
}

.checkbox-option:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-hover);
}

.checkbox-option:has(input:checked) {
    background: rgba(59, 130, 246, 0.1);
    border-color: var(--action-primary);
}

[data-theme="dark"] .checkbox-option:has(input:checked) {
    background: rgba(59, 130, 246, 0.15);
}

.checkbox-option:has(input:focus-visible) {
    outline: 2px solid var(--action-primary);
    outline-offset: 2px;
}

.checkbox-option input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: var(--action-primary);
    cursor: pointer;
    flex-shrink: 0;
}

.checkbox-option span {
    flex: 1;
    line-height: 1.3;
}

/* Service card variant - more prominent styling */
.service-option {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 13px;
    color: var(--text-primary);
    user-select: none;
}

.service-option:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--border-hover);
}

.service-option:has(input:checked) {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.12) 0%, rgba(37, 99, 235, 0.08) 100%);
    border-color: var(--action-primary);
    box-shadow: 0 0 0 1px var(--action-primary), var(--shadow-sm);
}

[data-theme="dark"] .service-option:has(input:checked) {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2) 0%, rgba(37, 99, 235, 0.12) 100%);
}

.service-option:active {
    transform: translateY(0);
}

.service-option input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin: 0;
    accent-color: var(--action-primary);
    cursor: pointer;
    flex-shrink: 0;
}

.service-option .service-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    font-size: 16px;
    flex-shrink: 0;
}

.service-option:has(input:checked) .service-icon {
    background: var(--action-primary);
    color: white;
}

.service-option .service-info {
    flex: 1;
    min-width: 0;
}

.service-option .service-name {
    font-weight: 500;
    margin-bottom: 2px;
}

.service-option .service-desc {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Toggle switch variant */
.toggle-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    transition: all 0.2s ease;
}

.toggle-option:hover {
    border-color: var(--border-hover);
}

.toggle-option .toggle-label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-weight: 500;
    color: var(--text-primary);
}

.toggle-option .toggle-label .icon {
    font-size: 16px;
}

/* Custom toggle switch */
.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

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

.toggle-switch .slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border-default);
    border-radius: var(--radius-pill);
    transition: all 0.3s ease;
}

.toggle-switch .slider::before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: var(--bg-surface-solid);
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

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

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

.toggle-switch input:focus-visible + .slider {
    outline: 2px solid var(--action-primary);
    outline-offset: 2px;
}

/* Mobile touch-friendly sizing */
@media (max-width: 768px) {
    .checkbox-option {
        min-height: 48px;
        padding: var(--space-md);
    }

    .checkbox-option input[type="checkbox"] {
        width: 22px;
        height: 22px;
    }

    .service-option {
        padding: var(--space-lg);
    }

    .service-option input[type="checkbox"] {
        width: 24px;
        height: 24px;
    }
}

/* ========================================
   MOBILE OPERATIONS TOOLBAR FIX
   ======================================== */

.flex-wrap {
    flex-wrap: wrap;
}

.hidden-mobile {
    display: block;
}

@media (max-width: 768px) {
    .hidden-mobile {
        display: none !important;
    }

    .gap-md-desktop {
        gap: var(--space-sm);
    }

    /* Operations toolbar - stack on mobile */
    .operations-toolbar {
        flex-direction: column;
        align-items: stretch !important;
        gap: var(--space-sm) !important;
    }

    .operations-toolbar h3 {
        text-align: center;
        width: 100%;
    }

    .operations-selects {
        width: 100%;
        justify-content: stretch;
    }

    .operations-selects select {
        flex: 1;
        min-width: 0 !important;
    }

    .operations-actions {
        width: 100%;
        justify-content: stretch;
    }

    .operations-actions .btn {
        flex: 1;
        justify-content: center;
    }

    /* Ensure Add Operation button is prominent */
    .operations-actions .btn-primary {
        order: -1;
        flex: 2;
    }
}

/* ========================================
   MOBILE FORM INPUTS FIX
   ======================================== */

@media (max-width: 768px) {
    /* Grid collapse at 768px instead of 480px */
    .grid-cols-2:not(.no-collapse) {
        grid-template-columns: 1fr !important;
    }

    /* Date/time inputs - stack vertically */
    .form-group .flex.gap-xs {
        flex-direction: column;
    }

    .form-group .flex.gap-xs input {
        width: 100%;
    }

    /* Remove cramped text-xs on form inputs */
    .form-input.text-xs {
        font-size: 14px;
        padding: 8px 12px;
    }

    /* Ensure minimum touch targets */
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"] {
        min-height: 44px;
        font-size: 16px; /* Prevents iOS zoom on focus */
    }
}

/* ========================================
   MOBILE MODAL FIX
   ======================================== */

@media (max-width: 768px) {
    .modal {
        max-width: min(90vw, 600px) !important;
        width: 90vw !important;
    }

    .modal.modal-lg {
        max-width: 95vw !important;
        width: 95vw !important;
    }

    /* Datetime inputs - stack on mobile */
    .datetime-inputs {
        flex-direction: column;
    }

    .datetime-inputs input {
        width: 100%;
    }
}

/* ========================================
   MITM STATUS INDICATOR
   ======================================== */

.mitm-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.mitm-dot--ok {
    background-color: var(--color-success, #22c55e);
    box-shadow: 0 0 4px var(--color-success, #22c55e);
}

.mitm-dot--off {
    background-color: var(--color-error, #ef4444);
    box-shadow: 0 0 4px var(--color-error, #ef4444);
}

/* ========================================
   PERFORMANCE: Disable blur on mobile
   backdrop-filter is GPU-expensive on mobile/Android
   ======================================== */
@media (max-width: 768px) {
    .glass, .glass-subtle,
    .sidebar, .card, .modal-overlay .modal,
    .theme-toggle-btn, .toast {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
}

/* ========================================
   ADMIN PANEL — Professional Components
   ======================================== */

/* ── User avatar ── */
.ua {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #2563eb, #4f46e5);
}
.ua--blocked { background: linear-gradient(135deg, #64748b, #475569); }
.ua--expired  { background: linear-gradient(135deg, #ef4444, #dc2626); }

/* ── Status dot ── */
.status-dot {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
}
.status-dot::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status-dot--active::before  { background: #22c55e; box-shadow: 0 0 0 2px rgba(34,197,94,.2); }
.status-dot--blocked::before { background: #94a3b8; }
.status-dot--expired::before { background: #ef4444; box-shadow: 0 0 0 2px rgba(239,68,68,.2); }

/* ── Compact user table ── */
.user-table { width: 100%; border-collapse: collapse; }
.user-table thead tr {
    border-bottom: 1px solid var(--border-subtle);
}
.user-table thead th {
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-tertiary);
    text-align: left;
    white-space: nowrap;
}
.user-table tbody tr {
    border-bottom: 1px solid var(--border-subtle);
    transition: background 0.12s ease;
    cursor: pointer;
    position: relative;
}
.user-table tbody tr:last-child { border-bottom: none; }
.user-table tbody tr:hover { background: var(--bg-surface-hover); }
.user-table tbody tr.is-blocked { opacity: 0.6; }
.user-table tbody td {
    padding: 10px 12px;
    vertical-align: middle;
    font-size: 13px;
}

/* Row actions — hidden until hover */
.row-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.12s ease;
    justify-content: flex-end;
}
.user-table tbody tr:hover .row-actions { opacity: 1; }

/* Bank pill — tiny */
.bank-pill {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
    background: var(--bg-surface-hover);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Subscription date — relative hint */
.sub-date { font-size: 13px; color: var(--text-primary); }
.sub-date__rel { font-size: 11px; color: var(--text-tertiary); margin-top: 1px; }
.sub-date--expiring .sub-date { color: #f59e0b; }
.sub-date--expired  .sub-date { color: var(--action-danger); }
.sub-date--none     .sub-date { color: var(--text-tertiary); }

/* ── User name cell ── */
.uname { font-weight: 600; font-size: 13px; color: var(--text-primary); line-height: 1.3; }
.uname__uid { font-size: 11px; color: var(--text-tertiary); font-family: var(--font-mono); margin-top: 1px; }

/* ── Sidebar nav item with icon ── */
.nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}
.nav-item:hover { background: var(--bg-surface-hover); color: var(--text-primary); }
.nav-item--active { background: var(--bg-surface-hover); color: var(--text-primary); font-weight: 600; }

/* ── Profile layout ── */
.profile-grid {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 16px;
    align-items: start;
}
@media (max-width: 900px) {
    .profile-grid { grid-template-columns: 1fr; }
}

/* ── Cred block ── */
.cred-block {
    background: var(--bg-page-solid);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
}
[data-theme="dark"] .cred-block { background: rgba(0,0,0,.3); }
.cred-item {
    display: flex;
    align-items: center;
    padding: 9px 14px;
    gap: 12px;
    border-bottom: 1px solid var(--border-subtle);
}
.cred-item:last-child { border-bottom: none; }
.cred-item__label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    width: 60px;
    flex-shrink: 0;
}
.cred-item__val {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-primary);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cred-item__copy {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    color: var(--text-tertiary);
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
    flex-shrink: 0;
}
.cred-item:hover .cred-item__copy { opacity: 1; }
.cred-item__copy:hover { background: var(--bg-surface-hover); color: var(--text-primary); }

/* ── Info list ── */
.info-list { display: flex; flex-direction: column; }
.info-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 7px 0;
    border-bottom: 1px solid var(--border-subtle);
    gap: 12px;
}
.info-row:last-child { border-bottom: none; }
.info-row__key { font-size: 12px; color: var(--text-tertiary); white-space: nowrap; flex-shrink: 0; }
.info-row__val { font-size: 13px; color: var(--text-primary); font-weight: 500; text-align: right; }
.info-row__val--mono { font-family: var(--font-mono); font-size: 12px; }

