/* ============================================
   Afiya Plus - Professional Hospital Management System
   Design System v2.0 - Medical Dashboard Theme
   ============================================ */

/* ============================================
   1. DESIGN TOKENS (CSS Custom Properties)
   ============================================ */
:root {
    /* Primary Palette - Medical Blue */
    --primary: #0f62fe;
    --primary-dark: #0043ce;
    --primary-light: #4589ff;
    --primary-50: #edf5ff;
    --primary-100: #d0e2ff;
    --primary-hover: #0050e6;

    /* Secondary - Teal */
    --secondary: #0f9d58;
    --secondary-dark: #0a7a43;
    --secondary-light: #4caf7d;

    /* Semantic Colors */
    --success: #24a148;
    --success-dark: #0e6027;
    --success-bg: #defbe6;
    --success-border: #a7f0c5;
    --warning: #f1c21b;
    --warning-dark: #8e6a00;
    --warning-bg: #fdf6dd;
    --warning-border: #fde68a;
    --danger: #da1e28;
    --danger-dark: #a2191f;
    --danger-bg: #fff1f1;
    --danger-border: #fcd8d8;
    --info: #4589ff;
    --info-dark: #0043ce;
    --info-bg: #edf5ff;
    --info-border: #b8d4fe;

    /* Neutrals - Carbon-inspired gray scale */
    --gray-50: #f4f4f4;
    --gray-100: #e0e0e0;
    --gray-200: #c6c6c6;
    --gray-300: #a8a8a8;
    --gray-400: #8d8d8d;
    --gray-500: #6f6f6f;
    --gray-600: #525252;
    --gray-700: #393939;
    --gray-800: #262626;
    --gray-900: #161616;

    /* Surface Colors */
    --bg-body: #f4f4f4;
    --bg-card: #ffffff;
    --bg-elevated: #ffffff;
    --bg-hover: #e8e8e8;
    --bg-active: #d0e2ff;

    /* Text */
    --text-primary: #161616;
    --text-secondary: #525252;
    --text-tertiary: #6f6f6f;
    --text-placeholder: #a8a8a8;
    --text-inverse: #ffffff;
    --text-on-color: #ffffff;
    --text-link: #0f62fe;

    /* Borders */
    --border-subtle: #e0e0e0;
    --border-strong: #8d8d8d;
    --border-interactive: #0f62fe;

    /* Shadows - Subtle, layered */
    --shadow-xs: 0 1px 2px rgba(22, 22, 22, 0.04);
    --shadow-sm: 0 2px 6px rgba(22, 22, 22, 0.06);
    --shadow-md: 0 4px 12px rgba(22, 22, 22, 0.08);
    --shadow-lg: 0 8px 24px rgba(22, 22, 22, 0.1);
    --shadow-xl: 0 12px 40px rgba(22, 22, 22, 0.12);

    /* Radii */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;
    --radius-full: 9999px;

    /* Spacing Scale - 4px base */
    --space-2xs: 2px;
    --space-xs: 4px;
    --space-sm: 8px;
    --space-3: 12px;
    --space-md: 16px;
    --space-5: 20px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 40px;
    --space-3xl: 48px;
    --space-4xl: 64px;

    /* Component Sizes */
    --input-height: 44px;
    --input-height-sm: 36px;
    --input-height-lg: 48px;
    --button-height: 44px;
    --button-height-sm: 36px;
    --button-height-lg: 48px;

    /* Typography */
    --font-sans: 'Cairo', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'IBM Plex Mono', 'SF Mono', 'Cascadia Code', monospace;

    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 2rem;

    --leading-tight: 1.25;
    --leading-normal: 1.5;
    --leading-relaxed: 1.625;

    /* Layout */
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 72px;
    --header-height: 60px;
    --content-max-width: 1440px;

    /* Transitions */
    --transition-fast: 120ms cubic-bezier(0.2, 0, 0.38, 0.9);
    --transition-normal: 200ms cubic-bezier(0.2, 0, 0.38, 0.9);
    --transition-slow: 300ms cubic-bezier(0.2, 0, 0.38, 0.9);

    /* Z-index scale */
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-overlay: 300;
    --z-modal: 400;
    --z-toast: 500;
}

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

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--text-primary);
    background: var(--bg-body);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-y: auto;
}

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

img, video { max-width: 100%; height: auto; }

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
}

input[type="submit"],
input[type="button"],
button {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Remove input spinners */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type="number"] { -moz-appearance: textfield; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-300); }
* { scrollbar-width: thin; scrollbar-color: var(--gray-200) transparent; }

/* Focus */
*:focus { outline: none; }
*:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ============================================
   3. APP LAYOUT
   ============================================ */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* ============================================
   4. SIDEBAR - Professional Medical Dashboard
   ============================================ */
/* ============================================
   SIDEBAR - Dark Professional Design
   ============================================ */
.sidebar {
    width: var(--sidebar-width);
    background: #111318;
    color: var(--text-inverse);
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: var(--z-sticky);
    transition: transform var(--transition-slow);
    direction: rtl;
}

/* Sidebar Header */
.sidebar-header {
    padding: 20px 20px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    min-height: 72px;
    flex-shrink: 0;
}

.sidebar-logo {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    object-fit: cover;
    flex-shrink: 0;
}

.sidebar-logo-fallback {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.sidebar-brand {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.sidebar-brand h1 {
    font-size: 0.95rem;
    font-weight: 700;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
    color: #fff;
}

.sidebar-brand p {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.45);
    margin: 2px 0 0;
    white-space: nowrap;
}

/* Sidebar Close Button (Mobile) */
.sidebar-close-btn {
    display: none;
    position: absolute;
    top: 16px;
    left: 16px;
    background: rgba(255,255,255,0.08);
    border: none;
    color: rgba(255,255,255,0.6);
    width: 34px;
    height: 34px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.sidebar-close-btn:hover { background: rgba(255,255,255,0.15); color: #fff; }

/* ============================================
   SIDEBAR NAVIGATION
   ============================================ */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 0;
}

/* Custom scrollbar */
.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}
.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
}
.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.2);
}

.nav-menu {
    list-style: none;
    padding: 0 10px;
    margin: 0;
}

/* ============================================
   NAV SECTION - Color-Coded System
   ============================================ */
.nav-section {
    margin-bottom: 2px;
    --section-accent: #3b82f6;
}

.nav-section-title {
    font-size: var(--sb-section-font-size, 0.8125rem);
    font-weight: 700;
    letter-spacing: 0.02em;
    color: rgba(255,255,255,0.45);
    padding: 12px 12px 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
    direction: rtl;
    transition: color 0.15s;
}

.nav-section-title:hover {
    color: rgba(255,255,255,0.55);
}

.nav-section-label {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Color-coded dot indicator */
.nav-section-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--section-accent);
    flex-shrink: 0;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.nav-section.is-active .nav-section-dot,
.nav-section:hover .nav-section-dot {
    opacity: 1;
}

.nav-section-icon {
    font-size: 0.65rem;
    width: 16px;
    text-align: center;
    opacity: 0.6;
    color: var(--section-accent);
    transition: opacity 0.15s;
}

.nav-section.is-active .nav-section-icon {
    opacity: 0.9;
}

.nav-section-arrow {
    display: flex;
    align-items: center;
    transition: transform 0.2s ease;
    font-size: 0.55rem;
    opacity: 0.5;
}
.nav-section-arrow.collapsed {
    transform: rotate(-90deg);
}

/* ============================================
   NAV ITEMS - Color-Coded Hover & Active
   ============================================ */
.nav-items {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nav-item {
    margin: 1px 0;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    color: rgba(255,255,255,0.55);
    text-decoration: none;
    border-radius: 7px;
    transition: all 0.15s ease;
    font-size: var(--sb-item-font-size, 0.8125rem);
    direction: rtl;
    text-align: right;
    justify-content: flex-start;
    min-height: 36px;
    position: relative;
    font-weight: 400;
    line-height: 1.3;
}

/* Hover - subtle accent color */
.nav-section .nav-link:hover {
    background: rgba(255,255,255,0.05);
    color: rgba(255,255,255,0.92);
}
.nav-section .nav-link:hover .nav-icon {
    color: var(--section-accent);
    opacity: 0.9;
}

/* Active State - section accent color */
.nav-section .nav-link.active {
    background: rgba(255,255,255,0.08);
    color: #fff;
    font-weight: 600;
}

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

.nav-section .nav-link.active .nav-icon {
    color: var(--section-accent);
    opacity: 1;
}

.nav-icon {
    width: 18px;
    text-align: center;
    font-size: 0.8rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
}

.nav-link.active .nav-icon {
    opacity: 1;
}

/* ============================================
   SIDEBAR FOOTER
   ============================================ */
.sidebar-footer {
    padding: 0 10px 14px;
    flex-shrink: 0;
}

.sidebar-footer-divider {
    height: 1px;
    background: rgba(255,255,255,0.06);
    margin: 4px 12px 10px;
}

.user-box {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(255,255,255,0.04);
    margin-bottom: 6px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
    color: #fff;
}

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

.user-info .name {
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #fff;
}

.user-info .role {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.45);
    white-space: nowrap;
}

.sidebar-footer-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    color: rgba(255,255,255,0.55);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.15s ease;
    font-size: 0.85rem;
    min-height: 40px;
    direction: rtl;
    text-align: right;
}
.sidebar-footer-link .nav-icon {
    opacity: 0.75;
}
.sidebar-footer-link:hover {
    background: rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.9);
}

.lang-link {
    margin-bottom: 2px;
}

.logout-link {
    color: #f87171;
}
.logout-link .nav-icon {
    color: #f87171;
    opacity: 0.85;
}
.logout-link:hover {
    background: rgba(239, 68, 68, 0.12);
    color: #fca5a5;
}

/* ============================================
   5. TOP HEADER BAR
   ============================================ */
.main-wrapper {
    flex: 1;
    margin-right: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin var(--transition-slow);
}

.main-header {
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-lg);
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    gap: var(--space-md);
    direction: rtl;
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

/* Breadcrumb */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: var(--text-sm);
    color: var(--text-tertiary);
    direction: rtl;
}

.breadcrumb a {
    color: var(--text-tertiary);
    transition: color var(--transition-fast);
}
.breadcrumb a:hover { color: var(--primary); }

.breadcrumb .separator {
    color: var(--gray-300);
    font-size: 0.75rem;
}

.breadcrumb .current {
    color: var(--text-primary);
    font-weight: 500;
}

/* Search Box */
.header-search {
    position: relative;
    width: 280px;
}

.header-search input {
    width: 100%;
    padding: 0.5rem 1rem 0.5rem 2.25rem;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    font-size: var(--text-sm);
    background: var(--gray-50);
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

[dir="rtl"] .header-search input {
    padding: 0.5rem 2.25rem 0.5rem 1rem;
}

.header-search input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--bg-card);
    box-shadow: 0 0 0 2px var(--primary-50);
}

.header-search .search-icon {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-placeholder);
    font-size: var(--text-sm);
    pointer-events: none;
}

[dir="rtl"] .header-search .search-icon {
    right: 0.75rem;
    left: auto;
}
[dir="ltr"] .header-search .search-icon {
    left: 0.75rem;
    right: auto;
}

/* Header Icon Buttons */
.header-icon-btn {
    position: relative;
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}
.header-icon-btn:hover {
    background: var(--gray-50);
    color: var(--text-primary);
}

.header-icon-btn .badge-dot {
    position: absolute;
    top: 6px;
    left: 8px;
    width: 8px;
    height: 8px;
    background: var(--danger);
    border-radius: var(--radius-full);
    border: 2px solid var(--bg-card);
}

[dir="rtl"] .header-icon-btn .badge-dot {
    left: auto;
    right: 8px;
}

/* User Menu */
.user-menu-trigger {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition-fast);
    border: none;
    background: transparent;
}
.user-menu-trigger:hover { background: var(--gray-50); }

.user-menu-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--primary);
    color: var(--text-inverse);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: var(--text-xs);
    flex-shrink: 0;
}

.user-menu-info {
    text-align: right;
    line-height: var(--leading-tight);
}
[dir="ltr"] .user-menu-info { text-align: left; }

.user-menu-name {
    font-weight: 600;
    font-size: var(--text-sm);
    color: var(--text-primary);
}

.user-menu-role {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

/* Language Toggle */
.lang-toggle {
    display: flex;
    background: var(--gray-100);
    border-radius: var(--radius);
    padding: 2px;
    gap: 2px;
}

.lang-toggle a {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    text-decoration: none;
    display: block;
}
.lang-toggle a:hover { color: var(--text-primary); }
.lang-toggle a.active {
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: var(--shadow-xs);
}

/* ============================================
   6. MAIN CONTENT
   ============================================ */
.main-content {
    flex: 1;
    padding: var(--space-lg);
    max-width: var(--content-max-width);
    width: 100%;
    direction: rtl;
}

/* Page Header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-lg);
    gap: var(--space-md);
    flex-wrap: wrap;
}

.page-header h2 {
    font-size: var(--text-2xl);
    font-weight: 700;
    color: var(--text-primary);
    line-height: var(--leading-tight);
}

.page-header p {
    color: var(--text-tertiary);
    font-size: var(--text-sm);
    margin-top: 2px;
}

/* ============================================
   7. STAT CARDS - Dashboard
   ============================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    transition: all var(--transition-normal);
    border: 1px solid var(--border-subtle);
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.stat-card::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 4px;
    height: 100%;
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
}

.stat-card.blue::after { background: var(--primary); }
.stat-card.green::after { background: var(--success); }
.stat-card.yellow::after { background: var(--warning); }
.stat-card.red::after { background: var(--danger); }
.stat-card.purple::after { background: #8b5cf6; }
.stat-card.cyan::after { background: #06b6d4; }

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.stat-icon.blue { background: var(--primary-50); color: var(--primary); }
.stat-icon.green { background: var(--success-bg); color: var(--success); }
.stat-icon.yellow { background: var(--warning-bg); color: #b28600; }
.stat-icon.red { background: var(--danger-bg); color: var(--danger); }
.stat-icon.purple { background: #f4f0ff; color: #8b5cf6; }
.stat-icon.cyan { background: #e0f7fa; color: #0891b2; }

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

.stat-info h3 {
    font-size: var(--text-3xl);
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.stat-info p {
    color: var(--text-tertiary);
    font-size: var(--text-sm);
    margin-top: var(--space-xs);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================
   8. CARDS
   ============================================ */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--space-lg);
    overflow: hidden;
    border: 1px solid var(--border-subtle);
}

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

.card-header h3 {
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.card-body {
    padding: var(--space-lg);
}

.card-body-compact {
    padding: 0;
}

/* ============================================
   9. TABLES
   ============================================ */
.table-responsive {
    overflow-x: auto;
}

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

th, td {
    padding: 0.875rem 1rem;
    text-align: right;
    border-bottom: 1px solid var(--border-subtle);
}

[dir="ltr"] th, [dir="ltr"] td { text-align: left; }

th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--transition-fast); }
tbody tr:hover { background: var(--gray-50); }

td {
    font-size: var(--text-sm);
    color: var(--text-primary);
}

/* ============================================
   10. BUTTONS
   ============================================ */
.btn {
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    text-decoration: none;
    font-size: var(--text-sm);
    line-height: var(--leading-normal);
    white-space: nowrap;
    user-select: none;
    min-height: var(--button-height);
    padding: var(--space-sm) var(--space-md);
}

.btn:active { transform: scale(0.98); }

.btn-primary {
    background: var(--primary);
    color: var(--text-inverse);
    border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-secondary {
    background: var(--secondary);
    color: var(--text-inverse);
    border-color: var(--secondary);
}
.btn-secondary:hover { background: var(--secondary-dark); border-color: var(--secondary-dark); }

.btn-danger {
    background: var(--danger);
    color: var(--text-inverse);
    border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger-dark); border-color: var(--danger-dark); }

.btn-warning {
    background: var(--warning);
    color: var(--gray-900);
    border-color: var(--warning);
}
.btn-warning:hover { background: var(--warning-dark); border-color: var(--warning-dark); }

.btn-info {
    background: var(--info);
    color: var(--text-inverse);
    border-color: var(--info);
}
.btn-info:hover { background: var(--info-dark); border-color: var(--info-dark); }

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
}
.btn-outline:hover {
    background: var(--gray-50);
    border-color: var(--gray-300);
}

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

.btn-success {
    background: var(--success);
    color: var(--text-inverse);
    border-color: var(--success);
}
.btn-success:hover { background: var(--success-dark); border-color: var(--success-dark); }

.btn-sm {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--text-xs);
    min-height: var(--button-height-sm);
}

.btn-lg {
    padding: var(--space-sm) var(--space-lg);
    font-size: var(--text-base);
    min-height: var(--button-height-lg);
}

.btn-icon {
    width: var(--button-height);
    height: var(--button-height);
    padding: 0;
    border-radius: var(--radius);
}

.btn-block {
    display: flex;
    width: 100%;
}

/* ============================================
   11. FORMS
   ============================================ */
.form-group {
    margin-bottom: var(--space-lg);
}

.form-group label,
.form-label {
    display: block;
    margin-bottom: var(--space-sm);
    font-weight: 500;
    color: var(--text-primary);
    font-size: var(--text-sm);
}

.form-control {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    font-size: var(--text-sm);
    color: var(--text-primary);
    background: var(--bg-card);
    transition: all var(--transition-fast);
    min-height: var(--input-height);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-50);
}

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

textarea.form-control {
    resize: vertical;
    min-height: 100px;
    line-height: var(--leading-relaxed);
}

select.form-control {
    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='%236f6f6f' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: left 0.75rem center;
    background-repeat: no-repeat;
    background-size: 1.25em;
    padding-left: 2.5rem;
}

[dir="rtl"] select.form-control {
    background-position: right 0.75rem center;
    padding-left: var(--space-md);
    padding-right: 2.5rem;
}

.form-control-sm {
    min-height: var(--input-height-sm);
    padding: var(--space-xs) var(--space-sm);
}

.form-control-lg {
    min-height: var(--input-height-lg);
    padding: var(--space-sm) var(--space-lg);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-lg);
}

.form-row-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-lg);
}

.form-section {
    margin-bottom: var(--space-xl);
}

.form-section-title {
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--border-subtle);
}

.form-check {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.form-check input[type="checkbox"],
.form-check input[type="radio"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary);
}

.form-hint {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    margin-top: var(--space-xs);
}

.form-error {
    font-size: var(--text-xs);
    color: var(--danger);
    margin-top: var(--space-xs);
}

.form-control.is-error {
    border-color: var(--danger);
}

.form-control.is-error:focus {
    box-shadow: 0 0 0 3px var(--danger-bg);
}

@media (max-width: 768px) {
    .form-row,
    .form-row-3 {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   12. BADGES
   ============================================ */
.badge {
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    white-space: nowrap;
    line-height: var(--leading-normal);
}

.badge-success { background: var(--success-bg); color: var(--success-dark); }
.badge-warning { background: var(--warning-bg); color: var(--warning-dark); }
.badge-danger { background: var(--danger-bg); color: var(--danger-dark); }
.badge-info { background: var(--info-bg); color: var(--info-dark); }
.badge-secondary { background: var(--gray-100); color: var(--gray-700); }
.badge-neutral { background: var(--gray-100); color: var(--gray-600); }

/* ============================================
   13. ALERTS
   ============================================ */
.alert {
    padding: var(--space-md);
    border-radius: var(--radius);
    margin-bottom: var(--space-lg);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    font-size: var(--text-sm);
    border: 1px solid transparent;
}

.alert-success { background: var(--success-bg); color: var(--success-dark); border-color: var(--success-border); }
.alert-danger { background: var(--danger-bg); color: var(--danger-dark); border-color: var(--danger-border); }
.alert-warning { background: var(--warning-bg); color: var(--warning-dark); border-color: var(--warning-border); }
.alert-info { background: var(--info-bg); color: var(--info-dark); border-color: var(--info-border); }

.alert i { font-size: 1.125rem; flex-shrink: 0; }

/* ============================================
   14. MODALS
   ============================================ */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(22, 22, 22, 0.5);
    backdrop-filter: blur(2px);
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    padding: var(--space-md);
}
.modal-overlay.active {
    display: flex;
    animation: fadeIn var(--transition-fast) ease;
}

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

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp var(--transition-slow) ease;
    box-shadow: var(--shadow-xl);
    margin: var(--space-md);
}

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

/* Bootstrap-style modals */
.modal.fade {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 1050;
    overflow-y: auto;
}
.modal.fade.show {
    display: block;
    background: rgba(22,22,22,0.5);
    backdrop-filter: blur(2px);
}
.modal-dialog {
    margin: 5vh auto;
    max-width: 640px;
}
.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
}
.modal-lg { max-width: 800px; }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);
}
.modal-header h3 {
    font-size: var(--text-lg);
    font-weight: 600;
}

.modal-close {
    background: var(--gray-50);
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-tertiary);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    transition: all var(--transition-fast);
    flex-shrink: 0;
}
.modal-close:hover {
    background: var(--gray-100);
    color: var(--text-primary);
}

.modal-body { padding: var(--space-lg); }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding: var(--space-lg);
    border-top: 1px solid var(--border-subtle);
}

/* ============================================
   15. TABS
   ============================================ */
.tabs {
    display: flex;
    gap: 0;
    margin-bottom: var(--space-lg);
    border-bottom: 2px solid var(--border-subtle);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab-btn {
    padding: 0.75rem 1.25rem;
    border: none;
    background: transparent;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-tertiary);
    transition: all var(--transition-fast);
    white-space: nowrap;
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

/* ============================================
   16. GRIDS
   ============================================ */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-lg);
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-lg);
}

/* ============================================
   17. UTILITY CLASSES
   ============================================ */
/* Text */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }
.text-primary { color: var(--primary) !important; }
.text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; }
.text-warning { color: var(--warning-dark) !important; }
.text-muted { color: var(--text-tertiary) !important; }
.text-secondary { color: var(--text-secondary) !important; }

/* Font */
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-md { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-medium { font-weight: 500; }
.font-mono { font-family: var(--font-mono); }

/* Background */
.bg-card { background: var(--bg-card); }
.bg-main { background: var(--bg-body); }
.bg-primary-light { background: var(--primary-50); }
.bg-success-light { background: var(--success-bg); }
.bg-danger-light { background: var(--danger-bg); }
.bg-warning-light { background: var(--warning-bg); }

/* Padding */
.p-xs { padding: var(--space-xs); }
.p-sm { padding: var(--space-sm); }
.p-md { padding: var(--space-md); }
.p-lg { padding: var(--space-lg); }
.p-xl { padding: var(--space-xl); }
.px-sm { padding-left: var(--space-sm); padding-right: var(--space-sm); }
.px-md { padding-left: var(--space-md); padding-right: var(--space-md); }
.py-sm { padding-top: var(--space-sm); padding-bottom: var(--space-sm); }
.py-md { padding-top: var(--space-md); padding-bottom: var(--space-md); }

/* Margin */
.mt-xs { margin-top: var(--space-xs); }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-xs { margin-bottom: var(--space-xs); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

/* Gap */
.gap-xs { gap: var(--space-xs); }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* Display */
.d-flex { display: flex; }
.d-block { display: block; }
.d-none { display: none; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }

/* Border */
.border { border: 1px solid var(--border-subtle); }
.border-primary { border-color: var(--primary) !important; }
.border-success { border-color: var(--success) !important; }
.border-danger { border-color: var(--danger) !important; }

/* Rounded */
.rounded-sm { border-radius: var(--radius-sm); }
.rounded-md { border-radius: var(--radius-lg); }
.rounded-lg { border-radius: var(--radius-xl); }
.rounded-full { border-radius: var(--radius-full); }

/* Section Label */
.section-label {
    color: var(--primary);
    font-weight: 600;
    font-size: var(--text-sm);
    margin-bottom: var(--space-sm);
}

/* Info Box */
.info-box {
    background: var(--gray-50);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-md);
    font-size: var(--text-sm);
}

/* View Label */
.view-label {
    color: var(--text-tertiary);
    font-size: var(--text-xs);
    font-weight: 600;
    margin-bottom: var(--space-xs);
}

/* Required Star */
.required-star { color: var(--danger); }

/* Expiry Badge */
.expiry-badge {
    background: var(--danger-bg);
    color: var(--danger-dark);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: 500;
}

/* ============================================
   18. MOBILE HEADER
   ============================================ */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-subtle);
    padding: 0 var(--space-md);
    z-index: calc(var(--z-sticky) - 1);
    align-items: center;
    justify-content: space-between;
}

.mobile-brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex: 1;
}

.mobile-title {
    font-weight: 600;
    font-size: var(--text-sm);
    color: var(--text-primary);
}

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

.mobile-lang-btn {
    padding: 4px 10px;
    background: var(--gray-100);
    border-radius: var(--radius);
    font-size: var(--text-xs);
    font-weight: 600;
    text-decoration: none;
    color: var(--text-primary);
    transition: background var(--transition-fast);
}
.mobile-lang-btn:hover { background: var(--gray-200); }

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    padding: var(--space-sm);
    color: var(--text-primary);
    border-radius: var(--radius);
    transition: background var(--transition-fast);
}
.mobile-menu-btn:hover { background: var(--gray-50); }

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(2px);
    z-index: calc(var(--z-sticky) - 1);
}
.sidebar-overlay.active { display: block; }

/* ============================================
   19. RESPONSIVE - Tablet (ó1024px)
   ============================================ */
@media (max-width: 1024px) {
    .mobile-header { display: flex; }

    .sidebar {
        transform: translateX(100%);
    }
    [dir="rtl"] .sidebar {
        right: 0; left: auto;
        transform: translateX(100%);
    }
    [dir="ltr"] .sidebar {
        right: auto; left: 0;
        transform: translateX(-100%);
    }

    .sidebar.active {
        transform: translateX(0) !important;
        box-shadow: -4px 0 30px rgba(0,0,0,0.3);
    }
    [dir="rtl"] .sidebar.active {
        box-shadow: 4px 0 30px rgba(0,0,0,0.3);
    }

    .sidebar-close-btn { display: flex; }
    .sidebar-header { padding-right: 3.5rem; }

    .main-wrapper {
        margin-right: 0;
        margin-left: 0;
        padding-top: var(--header-height);
    }

    .main-header { display: none; }
    .mobile-menu-btn { display: flex; }

    .form-row, .form-row-3 { grid-template-columns: 1fr; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-sm);
    }
    [dir="rtl"] .page-header { align-items: flex-end; }
    .page-header .btn { width: 100%; justify-content: center; }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-sm);
    }
    [dir="rtl"] .card-header { align-items: flex-end; }

    .tabs { gap: 0; }
    .tab-btn {
        white-space: nowrap;
        padding: 0.625rem 1rem;
        font-size: var(--text-sm);
    }

    .header-search { width: 200px; }
}

/* ============================================
   20. RESPONSIVE - Mobile (ó768px)
   ============================================ */
@media (max-width: 768px) {
    :root {
        --header-height: 48px;
        --space-lg: 16px;
    }

    body { font-size: 14px; }

    .main-content { padding: var(--space-md); }

    .main-header { display: none; }
    .mobile-header { display: flex; height: var(--header-height); }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-sm);
    }

    .stat-card {
        padding: var(--space-md);
        flex-direction: column;
        text-align: center;
        gap: var(--space-sm);
    }

    .stat-icon { width: 40px; height: 40px; font-size: 1.125rem; }
    .stat-info h3 { font-size: var(--text-2xl); }
    .stat-info p { font-size: var(--text-xs); }

    .card { border-radius: var(--radius); margin-bottom: var(--space-md); }
    .card-header { padding: var(--space-md); }
    .card-body { padding: var(--space-md); }

    .modal {
        margin: var(--space-sm);
        max-height: 90vh;
        border-radius: var(--radius-lg);
    }
    .modal-header, .modal-body, .modal-footer { padding: var(--space-md); }
    .modal-footer { flex-direction: column-reverse; gap: var(--space-sm); }
    .modal-footer .btn { width: 100%; min-height: 44px; }

    .page-header h2 { font-size: var(--text-xl); }

    .btn {
        min-height: 40px;
        padding: 0.5rem 1rem;
        font-size: var(--text-sm);
    }
    .btn-sm { min-height: 36px; padding: 0.375rem 0.75rem; }

    .form-group { margin-bottom: var(--space-sm); }
    .form-group label { font-size: var(--text-sm); }
    .form-control {
        padding: 0.5rem 0.75rem;
        font-size: 16px;
        min-height: 44px;
    }
    textarea.form-control { min-height: 80px; }

    .badge { padding: 0.1875rem 0.5rem; font-size: 0.6875rem; }
    .alert { padding: var(--space-sm) var(--space-md); font-size: var(--text-sm); }

    .lang-switch { width: 100%; }
    .lang-btn { flex: 1; text-align: center; }

    .login-card { padding: 1.5rem; margin: var(--space-sm); }
    .login-header h1 { font-size: 1.5rem; }
    .login-logo { width: 200px; height: 200px; }

    .invoice-item { grid-template-columns: 1fr !important; }
    .invoice-item > div { margin-bottom: var(--space-sm); }

    .table-responsive {
        margin: calc(var(--space-md) * -1);
        padding: 0 var(--space-md);
        overflow-x: auto;
    }
    table { min-width: 600px; }
    th, td { padding: 0.625rem 0.5rem; font-size: var(--text-xs); white-space: nowrap; }
}

/* ============================================
   21. RESPONSIVE - Small Mobile (ó480px)
   ============================================ */
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .stat-card { flex-direction: row; text-align: right; }

    .page-header h2 { font-size: var(--text-lg); }
    .card-header h3 { font-size: var(--text-sm); }

    .grid-2, .grid-3 { gap: var(--space-md); }

    .flex-between {
        flex-direction: column;
        align-items: stretch;
        gap: var(--space-sm);
    }
    .flex-between .btn { width: 100%; justify-content: center; }

    .modal { margin: var(--space-xs); }
    .mobile-title { font-size: var(--text-sm); }
}

/* ============================================
   22. TOUCH FRIENDLY
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    .btn { min-height: 44px; min-width: 44px; }
    .nav-link { min-height: 46px; padding: 0.7rem 12px; }
    .form-control { min-height: 48px; }
    .form-check input { width: 22px; height: 22px; }
    .tab-btn { min-height: 44px; padding: 0.75rem 1.25rem; }
    .modal-close { min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; }
    .sidebar-close-btn { min-width: 44px; min-height: 44px; }
}

/* ============================================
   23. INVOICE PRINT STYLES
   ============================================ */
.invoice-print {
    background: white;
    padding: 2rem;
    max-width: 800px;
    margin: 0 auto;
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-subtle);
}

.invoice-logo { max-width: 150px; max-height: 80px; }
.invoice-info { text-align: left; }

.invoice-table { width: 100%; margin-bottom: 2rem; }
.invoice-table th { background: var(--gray-50); padding: 0.75rem; font-size: var(--text-sm); }
.invoice-table td { padding: 0.75rem; border-bottom: 1px solid var(--border-subtle); }

.invoice-total { display: flex; justify-content: flex-end; }
.invoice-total-box { width: 250px; padding: 1rem; background: var(--gray-50); border-radius: var(--radius); }
.invoice-total-row { display: flex; justify-content: space-between; padding: 0.5rem 0; }
.invoice-total-row.grand-total { border-top: 2px solid var(--border-subtle); font-weight: 700; font-size: 1.1rem; }

/* ============================================
   24. PRINT STYLES
   ============================================ */
@media print {
    .sidebar, .main-header, .btn, .no-print, .mobile-menu-btn, .mobile-header {
        display: none !important;
    }
    .main-wrapper { margin: 0; }
    .main-content { padding: 0; }
    .card { box-shadow: none; border: 1px solid #ddd; }
    body { font-size: 12pt; }
}

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

@media (prefers-contrast: high) {
    .btn-primary { background: #0000ee; }
    .badge { border: 1px solid currentColor; }
    .card { border-width: 2px; }
}

/* ============================================
   26. BROWSER COMPATIBILITY
   ============================================ */
@-moz-document url-prefix() {
    .form-control { padding-top: 0.5625rem; padding-bottom: 0.5625rem; }
}

@media not all and (min-resolution:.001dpcm) {
    @supports (-webkit-appearance:none) {
        .form-control { -webkit-appearance: none; }
        select.form-control { -webkit-appearance: menulist; }
        .sidebar { -webkit-backface-visibility: hidden; }
    }
}

@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
    .form-row { display: flex; flex-wrap: wrap; }
    .form-row > div { flex: 1; min-width: 200px; }
    .stats-grid { display: flex; flex-wrap: wrap; }
    .stat-card { flex: 1; min-width: 200px; }
}

/* Chrome autofill */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--text-primary);
    -webkit-box-shadow: 0 0 0px 1000px var(--bg-card) inset;
    transition: background-color 5000s ease-in-out 0s;
}

/* iOS input zoom fix */
@media screen and (max-width: 768px) {
    input[type="text"], input[type="email"], input[type="password"],
    input[type="number"], input[type="tel"], input[type="url"],
    input[type="search"], textarea, select {
        font-size: 16px !important;
    }
}

/* ============================================
   27. RTL LAYOUT
   ============================================ */
[dir="rtl"] .sidebar { right: 0; left: auto; }
[dir="rtl"] .main-wrapper { margin-right: var(--sidebar-width); margin-left: 0; }

[dir="rtl"] .nav-link {
    flex-direction: row;
    direction: rtl;
    text-align: right;
    justify-content: flex-start;
}
[dir="ltr"] .sidebar .nav-link {
    flex-direction: row;
    direction: rtl;
    text-align: right;
    justify-content: flex-start;
}
.sidebar .nav-link {
    flex-direction: row;
    direction: rtl;
    text-align: right;
    justify-content: flex-start;
}

[dir="rtl"] .sidebar-header {
    flex-direction: row;
    padding-left: 20px;
    padding-right: 48px;
}

[dir="rtl"] .sidebar-close-btn { right: 16px; left: auto; }
[dir="rtl"] .sidebar-header .sidebar-close-btn { right: 16px; left: auto; }
[dir="rtl"] .user-box { flex-direction: row-reverse; }

[dir="rtl"] .sidebar-brand h1,
[dir="rtl"] .sidebar-brand p { text-align: right; }

[dir="rtl"] .user-info .name,
[dir="rtl"] .user-info .role { text-align: right; }

[dir="rtl"] .nav-section-title { text-align: right; }

[dir="rtl"] .sidebar-footer-link {
    flex-direction: row;
    direction: rtl;
    text-align: right;
}

[dir="rtl"] .page-header { text-align: right; }
[dir="rtl"] .card-header { text-align: right; }

[dir="rtl"] .form-group label,
[dir="rtl"] .form-label { text-align: right; }

[dir="rtl"] .form-control,
[dir="rtl"] input[type="text"], [dir="rtl"] input[type="email"],
[dir="rtl"] input[type="password"], [dir="rtl"] input[type="number"],
[dir="rtl"] input[type="tel"], [dir="rtl"] input[type="date"],
[dir="rtl"] input[type="time"], [dir="rtl"] textarea,
[dir="rtl"] select { text-align: right; }

[dir="rtl"] th, [dir="rtl"] td { text-align: right; }
[dir="rtl"] .badge { margin-right: 0; margin-left: var(--space-xs); }
[dir="rtl"] .alert { text-align: right; }

[dir="rtl"] .d-flex { flex-direction: row-reverse; }
[dir="rtl"] .justify-content-end { justify-content: flex-start; }
[dir="rtl"] .justify-content-start { justify-content: flex-end; }
[dir="rtl"] .pagination { flex-direction: row-reverse; }
[dir="rtl"] .modal-header { text-align: right; }
[dir="rtl"] .modal-footer { flex-direction: row-reverse; }

/* ============================================
   28. TOAST ANIMATIONS
   ============================================ */
@keyframes slideInRight {
    from { opacity: 0; transform: translateX(100px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes slideOutRight {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(100px); }
}
[dir="rtl"] @keyframes slideInRight {
    from { opacity: 0; transform: translateX(-100px); }
    to { opacity: 1; transform: translateX(0); }
}
[dir="rtl"] @keyframes slideOutRight {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(-100px); }
}

.toast {
    position: fixed;
    bottom: var(--space-lg);
    right: var(--space-lg);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-toast);
    font-size: var(--text-sm);
    font-weight: 500;
    display: flex;
    align-items: center;
    animation: slideInRight 0.25s ease;
    max-width: 400px;
}
.toast-success { background: var(--success); color: var(--text-inverse); }
.toast-error { background: var(--danger); color: var(--text-inverse); }
.toast-warning { background: var(--warning); color: var(--text-primary); }
.toast-info { background: var(--info); color: var(--text-inverse); }
[dir="rtl"] .toast { right: auto; left: var(--space-lg); }

/* ============================================
   29. USER MENU DROPDOWN
   ============================================ */
.user-menu-trigger {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius);
    transition: background var(--transition-fast);
    position: relative;
}
.user-menu-trigger:hover { background: var(--gray-50); }

.user-menu-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--primary);
    color: var(--text-inverse);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: var(--text-sm);
    flex-shrink: 0;
}

.user-menu-info {
    text-align: start;
    line-height: var(--leading-tight);
}

.user-menu-name {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
}

.user-menu-role {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

.user-menu-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: var(--space-sm);
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    z-index: var(--z-dropdown);
    overflow: hidden;
}
[dir="rtl"] .user-menu-dropdown {
    left: auto;
    right: 0;
}
.user-menu-dropdown.show { display: block; }

.user-menu-dropdown a {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    color: var(--text-primary);
    text-decoration: none;
    font-size: var(--text-sm);
    transition: background var(--transition-fast);
}
.user-menu-dropdown a:hover { background: var(--gray-50); }
.user-menu-dropdown a i {
    width: 18px;
    text-align: center;
    color: var(--text-tertiary);
}
.user-menu-dropdown .dropdown-divider {
    height: 1px;
    background: var(--border-subtle);
    margin: var(--space-xs) 0;
}
.user-menu-dropdown a.text-danger { color: var(--danger); }
.user-menu-dropdown a.text-danger i { color: var(--danger); }

/* ============================================
   30. SIDEBAR BRAND LOGO FALLBACK
   ============================================ */
.sidebar-logo-fallback {
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-inverse);
    font-size: var(--text-sm);
    font-weight: bold;
    border-radius: var(--radius);
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.mobile-logo {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    object-fit: cover;
}

/* ============================================
   31. EMPTY STATE
   ============================================ */
.empty-state {
    text-align: center;
    padding: var(--space-3xl) var(--space-lg);
    color: var(--text-tertiary);
}
.empty-state i {
    font-size: 3rem;
    margin-bottom: var(--space-md);
    opacity: 0.4;
}
.empty-state p {
    font-size: var(--text-sm);
    margin-top: var(--space-sm);
}

/* ============================================
   32. ACTION DROPDOWN
   ============================================ */
.action-dropdown {
    position: relative;
    display: inline-block;
}
.action-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: var(--space-xs);
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 160px;
    z-index: var(--z-dropdown);
    overflow: hidden;
}
.action-dropdown-menu.show { display: block; }
[dir="rtl"] .action-dropdown-menu { right: auto; left: 0; }

.action-dropdown-menu a {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    color: var(--text-primary);
    text-decoration: none;
    font-size: var(--text-sm);
    transition: background var(--transition-fast);
}
.action-dropdown-menu a:hover { background: var(--gray-50); }
.action-dropdown-menu a i {
    width: 16px;
    text-align: center;
    color: var(--text-tertiary);
    font-size: var(--text-xs);
}

/* ============================================
   33. CROSS-BROWSER RESET
   ============================================ */
* { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; }
html, body { margin: 0; padding: 0; -webkit-text-size-adjust: 100%; -moz-text-size-adjust: 100%; text-size-adjust: 100%; }
html { scroll-behavior: smooth; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
img, video { max-width: 100%; height: auto; }

/* ============================================
   34. COMMON COMPONENT PATTERNS
   ============================================ */

/* Welcome Banner */
.welcome-banner {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: var(--radius-xl);
    padding: var(--space-xl);
    color: var(--text-inverse);
    position: relative;
    overflow: hidden;
}
.welcome-banner h2 {
    font-size: var(--text-2xl);
    font-weight: 700;
    position: relative;
    z-index: 1;
}
.welcome-banner p {
    opacity: 0.85;
    font-size: var(--text-sm);
    position: relative;
    z-index: 1;
    margin-top: var(--space-xs);
}
.welcome-banner .banner-circle {
    position: absolute;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.1);
}
.welcome-banner .banner-circle-1 {
    width: 120px;
    height: 120px;
    top: -30px;
    left: -30px;
}
.welcome-banner .banner-circle-2 {
    width: 80px;
    height: 80px;
    bottom: -20px;
    right: 40px;
}

/* Stats Grid (Secondary - 3 columns) */
.stats-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}
.stat-card-sm {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: var(--space-md) var(--space-lg);
    border: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    min-width: 0;
}
.stat-card-sm .stat-icon-sm {
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}
.stat-card-sm .stat-value {
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--text-primary);
}
.stat-card-sm .stat-label {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* List Items (Dashboard-style) */
.list-items { padding: 0; margin: 0; }
.list-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) 0;
    border-bottom: 1px solid var(--border-subtle);
}
.list-item:last-child { border-bottom: none; }
.list-item-avatar {
    width: 32px; height: 32px;
    border-radius: var(--radius-full);
    background: var(--primary-50); color: var(--primary);
    display: flex; align-items: center; justify-content: center;
    font-size: var(--text-xs); font-weight: 600; flex-shrink: 0;
}
.list-item-info { flex: 1; min-width: 0; }
.list-item-title {
    font-size: var(--text-sm); font-weight: 500; color: var(--text-primary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list-item-subtitle { font-size: var(--text-xs); color: var(--text-tertiary); }

/* Card Header with Arrow */
.card-header-compact {
    display: flex; justify-content: space-between; align-items: center;
    padding: var(--space-md); border-bottom: 1px solid var(--border-subtle);
}
.card-header-compact h3 {
    font-size: var(--text-sm); font-weight: 600;
    display: flex; align-items: center; gap: var(--space-sm);
}
.card-header-compact h3 i { color: var(--primary); }
.card-header-compact .arrow { font-size: 0.7rem; color: var(--text-tertiary); }

/* Empty State */
.empty-state-sm { text-align: center; padding: var(--space-xl); color: var(--text-tertiary); }
.empty-state-sm i { font-size: 2rem; margin-bottom: var(--space-sm); opacity: 0.4; }
.empty-state-sm p { font-size: var(--text-sm); }

/* Avatar (Doctor/Patient) */
.avatar-circle { border-radius: var(--radius-full); object-fit: cover; border: 2px solid var(--border-subtle); }
.avatar-fallback {
    border-radius: var(--radius-full);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; border: 2px solid var(--border-subtle);
}

/* Photo Upload Area */
.photo-upload-area { text-align: center; }
.photo-preview {
    width: 80px; height: 80px; border-radius: var(--radius-full);
    object-fit: cover; border: 3px solid var(--border-subtle);
    margin: 0 auto var(--space-sm); display: block;
}
.photo-placeholder {
    width: 80px; height: 80px; border-radius: var(--radius-full);
    background: var(--gray-100);
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto var(--space-sm); color: var(--text-tertiary); font-size: 1.5rem;
}

/* Custom Fields Divider */
.custom-fields-divider {
    border-top: 2px solid var(--border-subtle);
    padding-top: var(--space-md); margin-top: var(--space-md);
}
.custom-fields-divider h4 {
    font-size: var(--text-sm); font-weight: 600; color: var(--primary); margin-bottom: var(--space-md);
}

/* Required Asterisk */
.required { color: var(--danger); }

/* Inline Form */
.form-inline { display: inline; }

/* Status Select */
.status-select {
    padding: var(--space-xs) var(--space-sm); border-radius: var(--radius);
    font-size: var(--text-xs); font-weight: 600;
    border: 1px solid var(--border-subtle); background: var(--bg-card);
    cursor: pointer; min-height: 32px;
}

/* Action Buttons (Table row) */
.action-btns { display: flex; gap: var(--space-xs); flex-wrap: nowrap; }
.action-btns .btn { padding: var(--space-xs) var(--space-sm); min-height: 32px; font-size: var(--text-xs); }
.action-btn-edit { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.action-btn-edit:hover { background: #fef3c7; }
.action-btn-view { background: var(--primary-50); color: var(--primary-dark); border: 1px solid var(--primary-100); }
.action-btn-view:hover { background: var(--primary-100); }
.action-btn-delete { background: var(--danger-bg); color: var(--danger-dark); border: 1px solid var(--danger-border); }
.action-btn-delete:hover { background: #ffe0e0; }

/* Modal Sizes */
.modal-xl { max-width: 900px; }
.modal-md { max-width: 650px; }
.modal-sm { max-width: 500px; }

/* Info Section (View Modals) */
.info-section { margin-bottom: var(--space-lg); }
.info-section-title {
    font-size: var(--text-sm); font-weight: 600; color: var(--primary); margin-bottom: var(--space-md);
}
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-md); }
.info-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--space-md); }
.info-item-label { font-size: var(--text-xs); color: var(--text-tertiary); margin-bottom: 2px; }
.info-item-value { font-size: var(--text-sm); font-weight: 500; color: var(--text-primary); }

/* Scrollable Checkbox Grid */
.checkbox-grid {
    display: grid; grid-template-columns: 1fr 1fr;
    max-height: 200px; overflow-y: auto;
    border: 1px solid var(--border-subtle); border-radius: var(--radius); padding: var(--space-sm);
}
.checkbox-grid label {
    display: flex; align-items: center; gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm); cursor: pointer; border-radius: var(--radius-sm);
}
.checkbox-grid label:hover { background: var(--gray-50); }

/* Section Note/Box */
.section-box { background: var(--gray-50); border: 1px solid var(--border-subtle); border-radius: var(--radius); padding: var(--space-md); }

/* Medical History Text */
.medical-text { white-space: pre-wrap; }

/* File Attachment Row */
.file-row {
    display: flex; align-items: center; gap: var(--space-md);
    padding: var(--space-sm) 0; border-bottom: 1px solid var(--border-subtle);
}
.file-row:last-child { border-bottom: none; }
.file-row i.file-icon { color: var(--primary); font-size: 1.25rem; }
.file-row .file-date { color: var(--text-tertiary); font-size: var(--text-xs); }
.file-row .file-actions { margin-left: auto; display: flex; gap: var(--space-xs); }

/* Pharmacy Tab Bar */
.tab-bar {
    display: flex; gap: 0; border-bottom: 2px solid var(--border-subtle);
    background: var(--gray-50); padding: 0 var(--space-md);
}
.tab-bar .tab-item {
    padding: var(--space-sm) var(--space-md); border: none; background: transparent;
    border-bottom: 2px solid transparent; margin-bottom: -2px; cursor: pointer;
    font-size: var(--text-sm); font-weight: 500; color: var(--text-tertiary);
    transition: all var(--transition-fast); display: flex; align-items: center; gap: var(--space-sm);
}
.tab-bar .tab-item:hover { color: var(--text-primary); }
.tab-bar .tab-item.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* Pharmacy Quick Info */
.quick-info-box { background: var(--info-bg); border: 1px solid var(--info-border); border-radius: var(--radius); padding: var(--space-md); font-size: var(--text-sm); }

/* Dispense Controls */
.dispense-controls { display: flex; align-items: center; justify-content: center; gap: var(--space-md); }
.dispense-controls input { width: 80px; text-align: center; font-weight: 700; font-size: var(--text-lg); }

/* Total Price Box */
.total-price-box { background: var(--gray-50); border: 1px solid var(--border-subtle); border-radius: var(--radius); padding: var(--space-md); text-align: center; }
.total-price-box .price { font-size: var(--text-xl); font-weight: 700; color: var(--primary); }

/* Print Styles */
.print-content { font-family: Arial, sans-serif; direction: rtl; padding: 20px; }
.print-content h3 { color: var(--primary); }

/* Responsive for new components */
@media (max-width: 640px) { .stats-grid-3 { grid-template-columns: 1fr; } }
@media (max-width: 768px) {
    .info-grid, .info-grid-3, .checkbox-grid { grid-template-columns: 1fr; }
    .action-btns { flex-wrap: wrap; }
}
