/* ==========================================================================
   MedBridge Design System — mb.css
   Bilingual (Arabic / English), RTL-first, token-driven.
   Load once per page:  <link rel="stylesheet" href="/assets/mb.css">
   All layout uses CSS logical properties so [dir="rtl"] mirrors the UI.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design tokens
   -------------------------------------------------------------------------- */
:root {
    /* Brand: teal */
    --mb-primary-50:  #EEF7F5;
    --mb-primary-100: #D6ECE7;
    --mb-primary-200: #A9D8CE;
    --mb-primary-300: #6FBFB0;
    --mb-primary-400: #3AA894;
    --mb-primary-500: #1E9C8B;
    --mb-primary-600: #12867A;
    --mb-primary-700: #0E6B62;
    --mb-primary-800: #0B534C;
    --mb-primary-900: #083E39;

    /* Accent: gold (use sparingly) */
    --mb-accent-100: #F8EFD9;
    --mb-accent-300: #E6C978;
    --mb-accent-500: #C89B3C;
    --mb-accent-700: #9A7325;

    /* Neutrals: warm */
    --mb-neutral-0:   #FFFFFF;
    --mb-neutral-50:  #F8F7F4;
    --mb-neutral-100: #F1EFEA;
    --mb-neutral-200: #E6E2DB;
    --mb-neutral-300: #D3CEC5;
    --mb-neutral-400: #A39E95;
    --mb-neutral-500: #79746C;
    --mb-neutral-600: #5A564F;
    --mb-neutral-700: #3F3C37;
    --mb-neutral-800: #2A2825;
    --mb-neutral-900: #1B1A18;

    /* Semantic */
    --mb-success-100: #DDF3E6;
    --mb-success-600: #1E7F4F;
    --mb-success-700: #176640;
    --mb-warning-100: #FBEBD3;
    --mb-warning-600: #B0620B;
    --mb-warning-700: #8E4F09;
    --mb-danger-100:  #FADEDE;
    --mb-danger-600:  #B42323;
    --mb-danger-700:  #911C1C;
    --mb-info-100:    #DDE8FA;
    --mb-info-600:    #1F5FBF;
    --mb-info-700:    #194C99;

    /* Semantic aliases (theme-able) */
    --mb-bg:             var(--mb-neutral-50);
    --mb-surface:        var(--mb-neutral-0);
    --mb-surface-2:      var(--mb-neutral-100);
    --mb-surface-hover:  var(--mb-neutral-50);
    --mb-text:           var(--mb-neutral-800);
    --mb-text-muted:     var(--mb-neutral-500);
    --mb-text-subtle:    var(--mb-neutral-400);
    --mb-border:         var(--mb-neutral-200);
    --mb-border-strong:  var(--mb-neutral-300);
    --mb-primary:        var(--mb-primary-600);
    --mb-primary-hover:  var(--mb-primary-700);
    --mb-primary-active: var(--mb-primary-800);
    --mb-primary-soft:   var(--mb-primary-50);
    --mb-primary-soft-2: var(--mb-primary-100);
    --mb-on-primary:     #FFFFFF;
    --mb-accent:         var(--mb-accent-500);
    --mb-accent-soft:    var(--mb-accent-100);
    --mb-success:        var(--mb-success-600);
    --mb-success-soft:   var(--mb-success-100);
    --mb-warning:        var(--mb-warning-600);
    --mb-warning-soft:   var(--mb-warning-100);
    --mb-danger:         var(--mb-danger-600);
    --mb-danger-soft:    var(--mb-danger-100);
    --mb-info:           var(--mb-info-600);
    --mb-info-soft:      var(--mb-info-100);
    --mb-focus-ring:     0 0 0 3px rgba(18, 134, 122, 0.28);
    --mb-sidebar-bg:     var(--mb-neutral-0);
    --mb-sidebar-active: var(--mb-primary-50);
    --mb-topbar-bg:      rgba(255, 255, 255, 0.92);
    --mb-overlay:        rgba(27, 26, 24, 0.55);

    /* Typography */
    --mb-font-latin:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --mb-font-arabic: 'IBM Plex Sans Arabic', 'Noto Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
    --mb-font:        var(--mb-font-latin), var(--mb-font-arabic);
    --mb-font-mono:   'JetBrains Mono', 'SF Mono', Consolas, monospace;
    --mb-text-xs:   0.75rem;
    --mb-text-sm:   0.8125rem;
    --mb-text-base: 0.9375rem;
    --mb-text-md:   1rem;
    --mb-text-lg:   1.125rem;
    --mb-text-xl:   1.375rem;
    --mb-text-2xl:  1.75rem;
    --mb-text-3xl:  2.25rem;
    --mb-leading:   1.55;

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

    /* Shape & elevation */
    --mb-radius-sm: 6px;
    --mb-radius-md: 10px;
    --mb-radius-lg: 14px;
    --mb-radius-xl: 20px;
    --mb-radius-full: 999px;
    --mb-shadow-xs: 0 1px 2px rgba(27, 26, 24, 0.05);
    --mb-shadow-sm: 0 1px 3px rgba(27, 26, 24, 0.07), 0 1px 2px rgba(27, 26, 24, 0.04);
    --mb-shadow-md: 0 6px 16px rgba(27, 26, 24, 0.08);
    --mb-shadow-lg: 0 14px 32px rgba(27, 26, 24, 0.14);

    /* Motion */
    --mb-ease: cubic-bezier(0.2, 0.7, 0.2, 1);
    --mb-fast: 140ms var(--mb-ease);
    --mb-base: 220ms var(--mb-ease);
    --mb-slow: 340ms var(--mb-ease);

    /* Layout */
    --mb-sidebar-w: 264px;
    --mb-sidebar-collapsed-w: 76px;
    --mb-topbar-h: 64px;
    --mb-content-max: 1400px;

    /* ---- Backward-compatible aliases (legacy portal CSS) ---- */
    --color-primary:       var(--mb-primary);
    --color-primary-dark:  var(--mb-primary-hover);
    --color-primary-light: var(--mb-primary-soft);
    --color-accent:        var(--mb-primary-300);
    --color-bg:            var(--mb-bg);
    --color-surface:       var(--mb-surface);
    --color-text:          var(--mb-text);
    --color-text-muted:    var(--mb-text-muted);
    --color-border:        var(--mb-border);
    --color-success:       var(--mb-success);
    --color-warning:       var(--mb-warning);
    --color-danger:        var(--mb-danger);
    --color-info:          var(--mb-info);
    --shadow-sm:           var(--mb-shadow-sm);
    --shadow-md:           var(--mb-shadow-md);
    --shadow-lg:           var(--mb-shadow-lg);
    --radius-sm:           var(--mb-radius-sm);
    --radius-md:           var(--mb-radius-md);
    --radius-lg:           var(--mb-radius-lg);
    --radius-xl:           var(--mb-radius-xl);
    --transition-fast:     var(--mb-fast);
    --transition-base:     var(--mb-base);
    --transition-slow:     var(--mb-slow);
    --sidebar-width:       var(--mb-sidebar-w);
    --sidebar-collapsed:   var(--mb-sidebar-collapsed-w);
    --topbar-height:       var(--mb-topbar-h);

    color-scheme: light;
}

[dir="rtl"] {
    --mb-font: var(--mb-font-arabic), var(--mb-font-latin);
}

/* Dark theme: opt-in via <html data-theme="dark"> */
[data-theme="dark"] {
    --mb-bg:             #141513;
    --mb-surface:        #1D1F1D;
    --mb-surface-2:      #262826;
    --mb-surface-hover:  #232523;
    --mb-text:           #ECEAE4;
    --mb-text-muted:     #A5A199;
    --mb-text-subtle:    #7A766F;
    --mb-border:         #2F322F;
    --mb-border-strong:  #3D413D;
    --mb-primary:        var(--mb-primary-400);
    --mb-primary-hover:  var(--mb-primary-300);
    --mb-primary-active: var(--mb-primary-200);
    --mb-primary-soft:   rgba(58, 168, 148, 0.14);
    --mb-primary-soft-2: rgba(58, 168, 148, 0.24);
    --mb-on-primary:     #06211E;
    --mb-success-soft:   rgba(30, 127, 79, 0.2);
    --mb-warning-soft:   rgba(176, 98, 11, 0.2);
    --mb-danger-soft:    rgba(180, 35, 35, 0.2);
    --mb-info-soft:      rgba(31, 95, 191, 0.2);
    --mb-sidebar-bg:     #1A1C1A;
    --mb-sidebar-active: rgba(58, 168, 148, 0.16);
    --mb-topbar-bg:      rgba(29, 31, 29, 0.92);
    --mb-overlay:        rgba(0, 0, 0, 0.7);
    --mb-shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
    --mb-shadow-md: 0 6px 16px rgba(0,0,0,0.45);
    --mb-shadow-lg: 0 14px 32px rgba(0,0,0,0.6);
    color-scheme: dark;
}

/* --------------------------------------------------------------------------
   2. Reset & base
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
    font-family: var(--mb-font);
    font-size: var(--mb-text-base);
    line-height: var(--mb-leading);
    color: var(--mb-text);
    background: var(--mb-bg);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: start;
}
img, svg, video { display: block; max-width: 100%; }
svg { flex-shrink: 0; }
a { color: var(--mb-primary); text-decoration: none; }
a:hover { color: var(--mb-primary-hover); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
button:disabled { cursor: not-allowed; opacity: 0.6; }
h1, h2, h3, h4, h5, h6 { font-weight: 600; line-height: 1.25; color: var(--mb-text); letter-spacing: -0.01em; }
h1 { font-size: var(--mb-text-2xl); }
h2 { font-size: var(--mb-text-xl); }
h3 { font-size: var(--mb-text-lg); }
h4 { font-size: var(--mb-text-md); }
p  { color: inherit; }
small { font-size: var(--mb-text-sm); }
strong, b { font-weight: 600; }
hr { border: 0; border-top: 1px solid var(--mb-border); margin: var(--mb-space-4) 0; }
::selection { background: var(--mb-primary-200); color: var(--mb-neutral-900); }
:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--mb-focus-ring); border-radius: var(--mb-radius-sm); }
[hidden] { display: none !important; }
[dir="rtl"] { letter-spacing: 0; }
[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3, [dir="rtl"] h4 { letter-spacing: 0; }

/* Numbers and Latin identifiers always read LTR inside RTL text */
.ltr, .num, .phone, .email, .code, [dir="rtl"] input[type="email"], [dir="rtl"] input[type="tel"], [dir="rtl"] input[type="number"], [dir="rtl"] input[type="url"] {
    direction: ltr; unicode-bidi: isolate; text-align: start;
}
[dir="rtl"] input[type="email"]::placeholder, [dir="rtl"] input[type="tel"]::placeholder { direction: ltr; text-align: left; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--mb-border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--mb-border-strong); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* --------------------------------------------------------------------------
   3. App shell: sidebar + topbar + content
   -------------------------------------------------------------------------- */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: var(--mb-sidebar-w);
    background: var(--mb-sidebar-bg);
    border-inline-end: 1px solid var(--mb-border);
    display: flex;
    flex-direction: column;
    z-index: 60;
    transition: width var(--mb-base), transform var(--mb-base);
}
.sidebar.collapsed { width: var(--mb-sidebar-collapsed-w); }
.sidebar.collapsed .nav-label,
.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-item .badge,
.sidebar.collapsed .sidebar-section-title { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding-inline: 0; }
.sidebar.collapsed .sidebar-header { justify-content: center; padding-inline: 0; }
.sidebar.collapsed .sidebar-toggle svg { transform: scaleX(-1); }
[dir="rtl"] .sidebar-toggle svg { transform: scaleX(-1); }
[dir="rtl"] .sidebar.collapsed .sidebar-toggle svg { transform: none; }

.sidebar-header {
    height: var(--mb-topbar-h);
    display: flex;
    align-items: center;
    gap: var(--mb-space-3);
    padding-inline: var(--mb-space-5);
    border-bottom: 1px solid var(--mb-border);
    flex-shrink: 0;
}
.logo-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--mb-primary); color: var(--mb-on-primary); display: grid; place-items: center; flex-shrink: 0; }
.logo-text { font-weight: 700; font-size: var(--mb-text-md); color: var(--mb-text); white-space: nowrap; letter-spacing: -0.01em; }
.logo-text .logo-sub { display: block; font-size: var(--mb-text-xs); font-weight: 500; color: var(--mb-text-muted); letter-spacing: 0.02em; text-transform: uppercase; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: var(--mb-space-3) var(--mb-space-3); display: flex; flex-direction: column; gap: 2px; }
.sidebar-section-title { font-size: var(--mb-text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--mb-text-subtle); padding: var(--mb-space-4) var(--mb-space-3) var(--mb-space-2); }
.nav-item {
    display: flex;
    align-items: center;
    gap: var(--mb-space-3);
    width: 100%;
    padding: 0.625rem var(--mb-space-3);
    border-radius: var(--mb-radius-md);
    color: var(--mb-text-muted);
    font-weight: 500;
    font-size: var(--mb-text-base);
    text-align: start;
    transition: background var(--mb-fast), color var(--mb-fast);
    position: relative;
}
.nav-item svg { width: 20px; height: 20px; }
.nav-item:hover { background: var(--mb-surface-hover); color: var(--mb-text); }
.nav-item.active { background: var(--mb-sidebar-active); color: var(--mb-primary); font-weight: 600; }
.nav-item.active::before {
    content: ''; position: absolute; inset-inline-start: -0.75rem; top: 50%; transform: translateY(-50%);
    width: 3px; height: 22px; border-radius: 3px; background: var(--mb-primary);
}
.nav-item .badge { margin-inline-start: auto; }
.nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-footer { padding: var(--mb-space-3); border-top: 1px solid var(--mb-border); display: flex; align-items: center; justify-content: space-between; gap: var(--mb-space-2); }
.sidebar-toggle { width: 36px; height: 36px; border-radius: var(--mb-radius-md); display: grid; place-items: center; color: var(--mb-text-muted); border: 1px solid var(--mb-border); background: var(--mb-surface); }
.sidebar-toggle:hover { color: var(--mb-text); border-color: var(--mb-border-strong); }
.sidebar-toggle svg { transition: transform var(--mb-base); }

.sidebar-backdrop { position: fixed; inset: 0; background: var(--mb-overlay); z-index: 55; opacity: 0; pointer-events: none; transition: opacity var(--mb-base); }
.sidebar-backdrop.open { opacity: 1; pointer-events: auto; }

.main-area {
    flex: 1;
    min-width: 0;
    margin-inline-start: var(--mb-sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin var(--mb-base);
}
.sidebar.collapsed ~ .main-area { margin-inline-start: var(--mb-sidebar-collapsed-w); }

.topbar {
    position: sticky; top: 0; z-index: 50;
    height: var(--mb-topbar-h);
    display: flex; align-items: center; justify-content: space-between; gap: var(--mb-space-4);
    padding-inline: var(--mb-space-6);
    background: var(--mb-topbar-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--mb-border);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: var(--mb-space-3); min-width: 0; }
.topbar h1 { font-size: var(--mb-text-lg); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .org-badge { font-size: var(--mb-text-sm); color: var(--mb-text-muted); padding: 0.2rem 0.6rem; background: var(--mb-surface-2); border-radius: var(--mb-radius-full); white-space: nowrap; }
.mobile-hamburger { display: none; width: 38px; height: 38px; border-radius: var(--mb-radius-md); place-items: center; color: var(--mb-text-muted); }
.mobile-hamburger:hover { background: var(--mb-surface-2); color: var(--mb-text); }

.icon-btn { width: 38px; height: 38px; border-radius: var(--mb-radius-md); display: grid; place-items: center; color: var(--mb-text-muted); position: relative; transition: background var(--mb-fast), color var(--mb-fast); }
.icon-btn:hover { background: var(--mb-surface-2); color: var(--mb-text); }
.icon-btn svg { width: 20px; height: 20px; }

.user-chip { display: flex; align-items: center; gap: var(--mb-space-2); padding: 0.25rem 0.6rem 0.25rem 0.25rem; border-radius: var(--mb-radius-full); border: 1px solid var(--mb-border); background: var(--mb-surface); max-width: 220px; }
[dir="rtl"] .user-chip { padding: 0.25rem 0.25rem 0.25rem 0.6rem; }
.user-chip .user-name, .user-chip > span:not(.avatar) { font-size: var(--mb-text-sm); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--mb-primary-soft-2); color: var(--mb-primary-800); display: grid; place-items: center; font-size: var(--mb-text-xs); font-weight: 700; flex-shrink: 0; letter-spacing: 0.02em; direction: ltr; }
.avatar.lg { width: 44px; height: 44px; font-size: var(--mb-text-base); }
[data-theme="dark"] .avatar { color: var(--mb-primary-200); }

.lang-switch { display: inline-flex; align-items: center; gap: 0.4rem; height: 34px; padding-inline: 0.7rem; border-radius: var(--mb-radius-full); border: 1px solid var(--mb-border); background: var(--mb-surface); color: var(--mb-text-muted); font-size: var(--mb-text-sm); font-weight: 600; transition: all var(--mb-fast); }
.lang-switch:hover { color: var(--mb-primary); border-color: var(--mb-primary-300); }
.lang-switch svg { width: 16px; height: 16px; }

.main-content { flex: 1; padding: var(--mb-space-6); max-width: var(--mb-content-max); width: 100%; }
.page-view { display: none; animation: mb-fade-in var(--mb-base); }
.page-view.active { display: block; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--mb-space-4); flex-wrap: wrap; margin-bottom: var(--mb-space-6); }
.page-header h2 { font-size: var(--mb-text-xl); }
.page-header p { color: var(--mb-text-muted); font-size: var(--mb-text-sm); margin-top: 0.2rem; }
.section-header { display: flex; align-items: center; justify-content: space-between; gap: var(--mb-space-3); flex-wrap: wrap; margin-bottom: var(--mb-space-4); }
.section-header h3 { font-size: var(--mb-text-md); }

@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); box-shadow: none; }
    [dir="rtl"] .sidebar { transform: translateX(100%); }
    .sidebar.open { transform: none; box-shadow: var(--mb-shadow-lg); }
    .sidebar.collapsed { width: var(--mb-sidebar-w); }
    .sidebar.collapsed .nav-label, .sidebar.collapsed .logo-text, .sidebar.collapsed .nav-item .badge { display: initial; }
    .sidebar.collapsed .nav-item { justify-content: flex-start; padding-inline: var(--mb-space-3); }
    .sidebar-footer .sidebar-toggle { display: none; }
    .main-area, .sidebar.collapsed ~ .main-area { margin-inline-start: 0; }
    .mobile-hamburger { display: grid; }
    .topbar { padding-inline: var(--mb-space-4); }
    .main-content { padding: var(--mb-space-4); }
    .topbar .org-badge { display: none; }
}
@media (max-width: 640px) {
    .user-chip .user-name, .user-chip > span:not(.avatar) { display: none; }
    .user-chip { padding: 0.2rem; border: 0; background: transparent; }
    .topbar { gap: var(--mb-space-2); }
    .topbar-left { flex: 1 1 auto; }
    .topbar-left > h1 { min-width: 0; flex: 0 1 auto; font-size: var(--mb-text-md); }
    .topbar-right { flex-shrink: 0; gap: var(--mb-space-1); }
    .btn-signout .btn-text { display: none; }
    .btn-signout { padding-inline: 0.5rem; }
    .lang-switch .lang-label { display: none; }
    .lang-switch { padding-inline: 0.5rem; }
}

/* --------------------------------------------------------------------------
   4. Cards, stats, tables
   -------------------------------------------------------------------------- */
.card, .table-card, .settings-card, .chart-card, .analytics-card, .kpi-card, .detail-section {
    background: var(--mb-surface);
    border: 1px solid var(--mb-border);
    border-radius: var(--mb-radius-lg);
    box-shadow: var(--mb-shadow-xs);
}
.card { padding: var(--mb-space-5); }
.card + .card { margin-top: var(--mb-space-4); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: var(--mb-space-3); flex-wrap: wrap; margin-bottom: var(--mb-space-4); }
.card-header h3, .table-header h3, .table-header h2 { font-size: var(--mb-text-md); font-weight: 600; }
.card-header p { font-size: var(--mb-text-sm); color: var(--mb-text-muted); }
.card-body { }
.card-footer { margin-top: var(--mb-space-4); padding-top: var(--mb-space-4); border-top: 1px solid var(--mb-border); display: flex; gap: var(--mb-space-2); justify-content: flex-end; }
.card.flat { box-shadow: none; }
.card.soft { background: var(--mb-surface-2); border-color: transparent; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: var(--mb-space-4); margin-bottom: var(--mb-space-6); }
.stat-card, .kpi-card, .pa-kpi-card, .my-perf-stat {
    background: var(--mb-surface);
    border: 1px solid var(--mb-border);
    border-radius: var(--mb-radius-lg);
    padding: var(--mb-space-5);
    display: flex; flex-direction: column; gap: var(--mb-space-2);
    position: relative; overflow: hidden;
    transition: transform var(--mb-fast), box-shadow var(--mb-fast);
}
.stat-card:hover { box-shadow: var(--mb-shadow-md); transform: translateY(-1px); }
.stat-card .stat-icon { width: 40px; height: 40px; border-radius: var(--mb-radius-md); display: grid; place-items: center; background: var(--mb-primary-soft); color: var(--mb-primary); margin-bottom: var(--mb-space-1); }
.stat-card .stat-icon svg { width: 20px; height: 20px; }
.stat-card .stat-icon.success { background: var(--mb-success-soft); color: var(--mb-success); }
.stat-card .stat-icon.warning { background: var(--mb-warning-soft); color: var(--mb-warning); }
.stat-card .stat-icon.danger  { background: var(--mb-danger-soft);  color: var(--mb-danger); }
.stat-card .stat-icon.info    { background: var(--mb-info-soft);    color: var(--mb-info); }
.stat-card .stat-icon.accent  { background: var(--mb-accent-soft);  color: var(--mb-accent-700); }
.stat-label, .kpi-label, .pa-kpi-label { font-size: var(--mb-text-sm); font-weight: 500; color: var(--mb-text-muted); }
.stat-value, .stat-number, .kpi-value, .pa-kpi-value { font-size: var(--mb-text-2xl); font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; color: var(--mb-text); font-variant-numeric: tabular-nums; direction: ltr; text-align: start; }
.stat-number.total    { color: var(--mb-primary); }
.stat-number.urgent   { color: var(--mb-danger); }
.stat-number.waiting  { color: var(--mb-warning); }
.stat-number.progress { color: var(--mb-info); }
.stat-number.success  { color: var(--mb-success); }
.stat-trend, .kpi-trend { font-size: var(--mb-text-xs); font-weight: 600; display: inline-flex; align-items: center; gap: 0.25rem; }
.stat-trend.up, .kpi-trend.up { color: var(--mb-success); }
.stat-trend.down, .kpi-trend.down { color: var(--mb-danger); }
.stat-card.accent-primary { border-top: 3px solid var(--mb-primary); }
.stat-card.accent-danger  { border-top: 3px solid var(--mb-danger); }
.stat-card.accent-warning { border-top: 3px solid var(--mb-warning); }
.stat-card.accent-info    { border-top: 3px solid var(--mb-info); }
.stat-card.accent-success { border-top: 3px solid var(--mb-success); }

.table-card { overflow: hidden; }
.table-header { display: flex; align-items: center; justify-content: space-between; gap: var(--mb-space-3); flex-wrap: wrap; padding: var(--mb-space-4) var(--mb-space-5); border-bottom: 1px solid var(--mb-border); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table, table.table { width: 100%; border-collapse: collapse; font-size: var(--mb-text-sm); }
.data-table th, table.table th {
    text-align: start; font-weight: 600; font-size: var(--mb-text-xs); letter-spacing: 0.05em; text-transform: uppercase;
    color: var(--mb-text-muted); background: var(--mb-surface-2); padding: 0.7rem var(--mb-space-4); border-bottom: 1px solid var(--mb-border); white-space: nowrap;
}
[dir="rtl"] .data-table th, [dir="rtl"] table.table th { letter-spacing: 0; text-transform: none; font-size: var(--mb-text-sm); }
.data-table td, table.table td { padding: 0.8rem var(--mb-space-4); border-bottom: 1px solid var(--mb-border); vertical-align: middle; color: var(--mb-text); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr { transition: background var(--mb-fast); }
.data-table tbody tr:hover { background: var(--mb-surface-hover); }
.data-table tr.clickable { cursor: pointer; }
.data-table .td-actions { display: flex; gap: var(--mb-space-2); justify-content: flex-end; white-space: nowrap; }
.data-table .td-num { font-variant-numeric: tabular-nums; direction: ltr; text-align: start; }
.data-table .td-muted { color: var(--mb-text-muted); }
.table-footer { display: flex; align-items: center; justify-content: space-between; gap: var(--mb-space-3); padding: var(--mb-space-3) var(--mb-space-5); border-top: 1px solid var(--mb-border); font-size: var(--mb-text-sm); color: var(--mb-text-muted); }

/* Key/value definition lists */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem var(--mb-space-4); font-size: var(--mb-text-sm); }
.kv dt { color: var(--mb-text-muted); font-weight: 500; }
.kv dd { color: var(--mb-text); }
.detail-section { padding: var(--mb-space-4); margin-bottom: var(--mb-space-4); }
.detail-title { font-size: var(--mb-text-xs); font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--mb-text-muted); margin-bottom: var(--mb-space-2); }
[dir="rtl"] .detail-title { letter-spacing: 0; text-transform: none; font-size: var(--mb-text-sm); }
.detail-content { font-size: var(--mb-text-sm); line-height: 1.6; }

/* Lists */
.list { display: flex; flex-direction: column; gap: var(--mb-space-2); }
.list-item { display: flex; align-items: center; gap: var(--mb-space-3); padding: var(--mb-space-3) var(--mb-space-4); border: 1px solid var(--mb-border); border-radius: var(--mb-radius-md); background: var(--mb-surface); transition: border-color var(--mb-fast), box-shadow var(--mb-fast); }
.list-item:hover { border-color: var(--mb-border-strong); box-shadow: var(--mb-shadow-xs); }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 600; font-size: var(--mb-text-base); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .li-sub { font-size: var(--mb-text-sm); color: var(--mb-text-muted); }
.list-item .li-actions { display: flex; gap: var(--mb-space-2); flex-shrink: 0; }

/* Patient card (queue / dashboard) */
.patient-card { background: var(--mb-surface); border: 1px solid var(--mb-border); border-radius: var(--mb-radius-lg); padding: var(--mb-space-4) var(--mb-space-5); display: flex; flex-direction: column; gap: var(--mb-space-3); border-inline-start: 4px solid var(--mb-border-strong); transition: box-shadow var(--mb-fast), transform var(--mb-fast); }
.patient-card:hover { box-shadow: var(--mb-shadow-md); }
.patient-card.urgency-high   { border-inline-start-color: var(--mb-danger); }
.patient-card.urgency-medium { border-inline-start-color: var(--mb-warning); }
.patient-card.urgency-low    { border-inline-start-color: var(--mb-success); }
.patient-card .pc-head { display: flex; align-items: center; justify-content: space-between; gap: var(--mb-space-3); flex-wrap: wrap; }
.patient-card .pc-name { font-weight: 600; font-size: var(--mb-text-md); }
.patient-card .pc-meta { font-size: var(--mb-text-sm); color: var(--mb-text-muted); display: flex; gap: var(--mb-space-3); flex-wrap: wrap; }
.patient-card .pc-complaint { font-size: var(--mb-text-sm); color: var(--mb-text); }
.patient-card .pc-actions { display: flex; gap: var(--mb-space-2); flex-wrap: wrap; }
.patients-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--mb-space-4); }

.symptoms-list, .tag-list { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.symptom-tag, .tag { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.2rem 0.6rem; border-radius: var(--mb-radius-full); background: var(--mb-surface-2); color: var(--mb-text); font-size: var(--mb-text-xs); font-weight: 500; border: 1px solid var(--mb-border); }

/* --------------------------------------------------------------------------
   5. Buttons
   -------------------------------------------------------------------------- */
.btn, .action-btn, .login-button, .btn-submit, .btn-cancel, .confirm-btn, .export-btn, .ctrl-btn, .consult-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
    height: 38px; padding-inline: 0.95rem;
    border-radius: var(--mb-radius-md);
    border: 1px solid var(--mb-border);
    background: var(--mb-surface);
    color: var(--mb-text);
    font-size: var(--mb-text-sm); font-weight: 600; line-height: 1;
    white-space: nowrap;
    transition: background var(--mb-fast), border-color var(--mb-fast), color var(--mb-fast), box-shadow var(--mb-fast), transform var(--mb-fast);
    user-select: none;
}
.btn svg, .action-btn svg { width: 16px; height: 16px; }
.btn:hover, .action-btn:hover { background: var(--mb-surface-hover); border-color: var(--mb-border-strong); }
.btn:active, .action-btn:active { transform: translateY(1px); }
.btn:focus-visible, .action-btn:focus-visible { box-shadow: var(--mb-focus-ring); }

.btn-primary, .btn.primary, .action-btn.primary, .login-button, .btn-submit, .confirm-btn.primary {
    background: var(--mb-primary); border-color: var(--mb-primary); color: var(--mb-on-primary);
    box-shadow: 0 1px 2px rgba(8, 62, 57, 0.18);
}
.btn-primary:hover, .btn.primary:hover, .action-btn.primary:hover, .login-button:hover, .btn-submit:hover, .confirm-btn.primary:hover { background: var(--mb-primary-hover); border-color: var(--mb-primary-hover); color: var(--mb-on-primary); }
.btn-secondary, .btn.secondary, .btn-cancel, .confirm-btn.cancel { background: var(--mb-surface); border-color: var(--mb-border); color: var(--mb-text); }
.btn-ghost, .btn.ghost, .btn.flat, .action-btn.flat { background: transparent; border-color: transparent; color: var(--mb-text-muted); }
.btn-ghost:hover, .btn.ghost:hover, .btn.flat:hover, .action-btn.flat:hover { background: var(--mb-surface-2); color: var(--mb-text); }
.btn-soft, .btn.soft { background: var(--mb-primary-soft); border-color: transparent; color: var(--mb-primary-800); }
.btn-soft:hover, .btn.soft:hover { background: var(--mb-primary-soft-2); }
[data-theme="dark"] .btn-soft, [data-theme="dark"] .btn.soft { color: var(--mb-primary-200); }
.btn-danger, .btn.danger, .action-btn.danger, .confirm-btn.danger { background: var(--mb-danger); border-color: var(--mb-danger); color: #fff; }
.btn-danger:hover, .btn.danger:hover, .action-btn.danger:hover, .confirm-btn.danger:hover { background: var(--mb-danger-700); border-color: var(--mb-danger-700); color: #fff; }
.btn-danger-soft, .btn.danger-soft { background: var(--mb-danger-soft); border-color: transparent; color: var(--mb-danger-700); }
.btn-success, .btn.success, .action-btn.success { background: var(--mb-success); border-color: var(--mb-success); color: #fff; }
.btn-success:hover, .btn.success:hover, .action-btn.success:hover { background: var(--mb-success-700); border-color: var(--mb-success-700); color: #fff; }
.btn-warning, .btn.warning, .action-btn.warning { background: var(--mb-warning-soft); border-color: transparent; color: var(--mb-warning-700); }
.btn-sm, .btn.sm, .action-btn.sm { height: 32px; padding-inline: 0.7rem; font-size: var(--mb-text-xs); border-radius: var(--mb-radius-sm); }
.btn-sm svg, .btn.sm svg { width: 14px; height: 14px; }
.btn-lg, .btn.lg { height: 46px; padding-inline: 1.4rem; font-size: var(--mb-text-base); border-radius: var(--mb-radius-lg); }
.btn-block, .btn.block, .login-button, .btn-submit.block { width: 100%; }
.btn-icon, .btn.icon { width: 38px; padding-inline: 0; }
.btn-icon.sm { width: 32px; height: 32px; }
.btn-signout { display: inline-flex; align-items: center; gap: 0.4rem; height: 34px; padding-inline: 0.7rem; border-radius: var(--mb-radius-md); border: 1px solid var(--mb-border); color: var(--mb-text-muted); font-size: var(--mb-text-sm); font-weight: 600; background: var(--mb-surface); }
.btn-signout:hover { color: var(--mb-danger); border-color: var(--mb-danger); background: var(--mb-danger-soft); }
.btn .spinner, .login-button .spinner { width: 16px; height: 16px; border-width: 2px; margin: 0; }
.btn-group { display: inline-flex; gap: var(--mb-space-2); flex-wrap: wrap; }
.action-buttons-top, .controls { display: flex; align-items: center; justify-content: space-between; gap: var(--mb-space-3); flex-wrap: wrap; }
.controls { margin-bottom: var(--mb-space-4); }
.filters { display: flex; gap: var(--mb-space-2); flex-wrap: wrap; }

/* Filter pills / segmented toggles */
.filter-btn, .range-btn, .chip-btn, .tab-pill {
    display: inline-flex; align-items: center; gap: 0.35rem;
    height: 32px; padding-inline: 0.8rem; border-radius: var(--mb-radius-full);
    border: 1px solid var(--mb-border); background: var(--mb-surface); color: var(--mb-text-muted);
    font-size: var(--mb-text-xs); font-weight: 600; transition: all var(--mb-fast);
}
.filter-btn:hover, .range-btn:hover, .chip-btn:hover { border-color: var(--mb-primary-300); color: var(--mb-primary); }
.filter-btn.active, .range-btn.active, .chip-btn.active { background: var(--mb-primary); border-color: var(--mb-primary); color: var(--mb-on-primary); }
.segmented { display: inline-flex; padding: 3px; background: var(--mb-surface-2); border-radius: var(--mb-radius-md); border: 1px solid var(--mb-border); }
.segmented button { height: 30px; padding-inline: 0.8rem; border-radius: 7px; font-size: var(--mb-text-xs); font-weight: 600; color: var(--mb-text-muted); }
.segmented button.active { background: var(--mb-surface); color: var(--mb-text); box-shadow: var(--mb-shadow-xs); }

/* --------------------------------------------------------------------------
   6. Forms
   -------------------------------------------------------------------------- */
.form-group { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: var(--mb-space-4); }
.form-group:last-child { margin-bottom: 0; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--mb-space-3); }
.form-row .form-group { margin-bottom: var(--mb-space-4); }
.form-group label, label.form-label, .form-label { font-size: var(--mb-text-sm); font-weight: 600; color: var(--mb-text); }
.form-label .req, label .req { color: var(--mb-danger); margin-inline-start: 0.15rem; }
.form-input, .form-control, .consult-input,
input[type="text"], input[type="email"], input[type="password"], input[type="tel"], input[type="number"],
input[type="date"], input[type="time"], input[type="datetime-local"], input[type="search"], input[type="url"],
select, textarea {
    width: 100%; min-height: 40px;
    padding: 0.5rem 0.8rem;
    border: 1px solid var(--mb-border-strong);
    border-radius: var(--mb-radius-md);
    background: var(--mb-surface);
    color: var(--mb-text);
    font-size: var(--mb-text-base);
    transition: border-color var(--mb-fast), box-shadow var(--mb-fast);
}
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
select {
    appearance: none; -webkit-appearance: none;
    padding-inline-end: 2.2rem;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%2379746C' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><path d='M4 6l4 4 4-4'/></svg>");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 16px;
}
[dir="rtl"] select { background-position: left 0.75rem center; }
input::placeholder, textarea::placeholder { color: var(--mb-text-subtle); }
input:hover, select:hover, textarea:hover { border-color: var(--mb-neutral-400); }
input:focus, select:focus, textarea:focus, .form-input:focus, .form-control:focus { border-color: var(--mb-primary); box-shadow: var(--mb-focus-ring); outline: none; }
input:disabled, select:disabled, textarea:disabled { background: var(--mb-surface-2); color: var(--mb-text-muted); }
input[aria-invalid="true"], .form-group.has-error input, .form-group.has-error select, .form-group.has-error textarea { border-color: var(--mb-danger); }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; min-height: 0; accent-color: var(--mb-primary); cursor: pointer; }
input[type="date"], input[type="time"], input[type="datetime-local"], input[type="number"] { direction: ltr; text-align: start; }
.form-hint { font-size: var(--mb-text-xs); color: var(--mb-text-muted); }
.form-error { font-size: var(--mb-text-xs); color: var(--mb-danger); font-weight: 500; }
.form-check { display: flex; align-items: center; gap: 0.5rem; font-size: var(--mb-text-sm); cursor: pointer; }
.form-actions, .modal-actions { display: flex; justify-content: flex-end; gap: var(--mb-space-2); margin-top: var(--mb-space-5); }
.section-label { font-size: var(--mb-text-xs); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--mb-primary); margin: var(--mb-space-5) 0 var(--mb-space-3); padding-bottom: 0.35rem; border-bottom: 1px solid var(--mb-border); }
[dir="rtl"] .section-label { letter-spacing: 0; text-transform: none; font-size: var(--mb-text-sm); }
.section-label:first-child { margin-top: 0; }
.input-group { display: flex; align-items: stretch; }
.input-group > * { border-radius: 0; }
.input-group > :first-child { border-start-start-radius: var(--mb-radius-md); border-end-start-radius: var(--mb-radius-md); }
.input-group > :last-child { border-start-end-radius: var(--mb-radius-md); border-end-end-radius: var(--mb-radius-md); }
.search-box { position: relative; }
.search-box input { padding-inline-start: 2.3rem; }
.search-box svg { position: absolute; inset-inline-start: 0.75rem; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--mb-text-subtle); pointer-events: none; }

.password-wrapper { position: relative; }
.password-wrapper input { padding-inline-end: 2.6rem; }
.password-toggle { position: absolute; inset-inline-end: 0.5rem; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; border-radius: var(--mb-radius-sm); display: grid; place-items: center; color: var(--mb-text-subtle); }
.password-toggle:hover { color: var(--mb-text); background: var(--mb-surface-2); }
.password-toggle svg { width: 18px; height: 18px; }
.password-requirements { list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 0.2rem 0.75rem; margin-top: 0.4rem; font-size: var(--mb-text-xs); color: var(--mb-text-muted); }
.password-requirements li { display: flex; align-items: center; gap: 0.35rem; }
.password-requirements li::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--mb-border-strong); flex-shrink: 0; }
.password-requirements li.met { color: var(--mb-success); }
.password-requirements li.met::before { background: var(--mb-success); }

.toggle-switch { width: 44px; height: 24px; border-radius: 12px; background: var(--mb-border-strong); position: relative; transition: background var(--mb-fast); flex-shrink: 0; }
.toggle-switch::after { content: ''; position: absolute; top: 3px; inset-inline-start: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--mb-shadow-sm); transition: transform var(--mb-fast); }
.toggle-switch.on, .toggle-switch.active, .toggle-switch[aria-checked="true"] { background: var(--mb-primary); }
.toggle-switch.on::after, .toggle-switch.active::after, .toggle-switch[aria-checked="true"]::after { transform: translateX(20px); }
[dir="rtl"] .toggle-switch.on::after, [dir="rtl"] .toggle-switch.active::after, [dir="rtl"] .toggle-switch[aria-checked="true"]::after { transform: translateX(-20px); }

/* --------------------------------------------------------------------------
   7. Badges, alerts, feedback
   -------------------------------------------------------------------------- */
.badge, .status-badge, .urgency-badge, .priority-badge, .role-badge {
    display: inline-flex; align-items: center; gap: 0.3rem;
    padding: 0.2rem 0.6rem; border-radius: var(--mb-radius-full);
    font-size: var(--mb-text-xs); font-weight: 600; line-height: 1.3; white-space: nowrap;
    background: var(--mb-surface-2); color: var(--mb-text-muted); border: 1px solid transparent;
}
.badge::before, .status-badge::before, .urgency-badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.8; }
.badge.no-dot::before, .role-badge::before, .priority-badge::before, .nav-item .badge::before { display: none; }
.nav-item .badge { background: var(--mb-primary); color: var(--mb-on-primary); padding: 0.1rem 0.5rem; min-width: 22px; justify-content: center; }
.badge-success, .badge.success, .status-badge.success, .status-badge.active, .status-badge.approved, .status-badge.completed, .status-badge.disbursed, .status-badge.paid, .status-badge.confirmed, .status-badge.status-active, .status-active, .urgency-badge.low, .priority-badge.low { background: var(--mb-success-soft); color: var(--mb-success-700); }
.badge-warning, .badge.warning, .status-badge.warning, .status-badge.pending, .status-badge.waiting, .status-badge.scheduled, .status-badge.on_hold, .status-badge.postponed, .status-badge.under_review, .urgency-badge.medium, .priority-badge.medium { background: var(--mb-warning-soft); color: var(--mb-warning-700); }
.badge-danger, .badge.danger, .status-badge.danger, .status-badge.rejected, .status-badge.cancelled, .status-badge.inactive, .status-badge.no_show, .status-badge.revoked, .status-badge.status-inactive, .status-inactive, .status-badge.overdue, .urgency-badge.high, .urgency-badge.emergency, .urgency-badge.urgent, .priority-badge.high, .priority-badge.urgent { background: var(--mb-danger-soft); color: var(--mb-danger-700); }
.badge-info, .badge.info, .status-badge.info, .status-badge.new, .status-badge.in_progress, .status-badge.in-progress, .status-badge.progress, .status-badge.submitted, .status-badge.open, .status-badge.routine { background: var(--mb-info-soft); color: var(--mb-info-700); }
.badge-primary, .badge.primary, .status-badge.primary, .role-badge { background: var(--mb-primary-soft-2); color: var(--mb-primary-800); }
.badge-neutral, .badge.neutral, .status-badge.neutral, .status-badge.draft { background: var(--mb-surface-2); color: var(--mb-text-muted); }
.badge-accent, .badge.accent { background: var(--mb-accent-soft); color: var(--mb-accent-700); }
[data-theme="dark"] .badge-success, [data-theme="dark"] .status-badge.success { color: #7BD9A4; }
[data-theme="dark"] .badge-warning, [data-theme="dark"] .status-badge.warning { color: #F0B36B; }
[data-theme="dark"] .badge-danger, [data-theme="dark"] .status-badge.danger { color: #F28B8B; }
[data-theme="dark"] .badge-info, [data-theme="dark"] .status-badge.info { color: #8FB4F2; }
[data-theme="dark"] .badge-primary, [data-theme="dark"] .role-badge { color: var(--mb-primary-200); }

.alert { display: flex; gap: var(--mb-space-3); align-items: flex-start; padding: var(--mb-space-3) var(--mb-space-4); border-radius: var(--mb-radius-md); border: 1px solid transparent; font-size: var(--mb-text-sm); margin-bottom: var(--mb-space-4); }
.alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.alert strong { display: block; margin-bottom: 0.1rem; }
.alert-info, .alert.info       { background: var(--mb-info-soft);    color: var(--mb-info-700);    border-color: rgba(31,95,191,0.2); }
.alert-success, .alert.success { background: var(--mb-success-soft); color: var(--mb-success-700); border-color: rgba(30,127,79,0.2); }
.alert-warning, .alert.warning { background: var(--mb-warning-soft); color: var(--mb-warning-700); border-color: rgba(176,98,11,0.2); }
.alert-danger, .alert.danger, .alert.error { background: var(--mb-danger-soft); color: var(--mb-danger-700); border-color: rgba(180,35,35,0.2); }
.setup-banner { background: var(--mb-primary-soft); border: 1px solid var(--mb-primary-200); border-radius: var(--mb-radius-lg); padding: var(--mb-space-4) var(--mb-space-5); margin-bottom: var(--mb-space-5); display: none; }
.setup-banner.show { display: block; }
.setup-banner h3 { font-size: var(--mb-text-md); margin-bottom: 0.25rem; color: var(--mb-primary-800); }
.setup-banner p { font-size: var(--mb-text-sm); color: var(--mb-text-muted); margin-bottom: var(--mb-space-3); }

/* Empty / loading states */
.empty-state { text-align: center; padding: var(--mb-space-10) var(--mb-space-4); color: var(--mb-text-muted); font-size: var(--mb-text-sm); display: flex; flex-direction: column; align-items: center; gap: var(--mb-space-2); }
.empty-state svg { width: 40px; height: 40px; color: var(--mb-text-subtle); margin-bottom: var(--mb-space-2); }
.empty-state .empty-title { font-weight: 600; color: var(--mb-text); font-size: var(--mb-text-base); }
.loading { text-align: center; padding: var(--mb-space-8); color: var(--mb-text-muted); font-size: var(--mb-text-sm); display: flex; flex-direction: column; align-items: center; gap: var(--mb-space-3); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--mb-border); border-top-color: var(--mb-primary); border-radius: 50%; animation: mb-spin 0.8s linear infinite; margin: var(--mb-space-6) auto; }
.spinner.sm { width: 16px; height: 16px; border-width: 2px; margin: 0; }
.spinner.inline { display: inline-block; margin: 0; vertical-align: middle; }
.skeleton { background: linear-gradient(90deg, var(--mb-surface-2) 25%, var(--mb-border) 50%, var(--mb-surface-2) 75%); background-size: 200% 100%; animation: mb-shimmer 1.4s infinite; border-radius: var(--mb-radius-sm); min-height: 1em; }
.progress-bar { height: 8px; background: var(--mb-surface-2); border-radius: var(--mb-radius-full); overflow: hidden; }
.progress-bar > span { display: block; height: 100%; background: var(--mb-primary); border-radius: inherit; transition: width var(--mb-slow); }
.progress-bar.success > span { background: var(--mb-success); }
.progress-bar.warning > span { background: var(--mb-warning); }
.progress-bar.danger > span { background: var(--mb-danger); }

/* Toasts */
.toast-container { position: fixed; top: var(--mb-space-4); inset-inline-end: var(--mb-space-4); z-index: 1000; display: flex; flex-direction: column; gap: var(--mb-space-2); max-width: min(380px, calc(100vw - 2rem)); pointer-events: none; }
.toast {
    display: flex; align-items: flex-start; gap: var(--mb-space-3);
    padding: 0.8rem var(--mb-space-4);
    background: var(--mb-neutral-900); color: #fff;
    border-radius: var(--mb-radius-md); box-shadow: var(--mb-shadow-lg);
    font-size: var(--mb-text-sm); font-weight: 500; line-height: 1.4;
    border-inline-start: 4px solid var(--mb-primary-300);
    animation: mb-toast-in var(--mb-base);
    pointer-events: auto;
}
[data-theme="dark"] .toast { background: var(--mb-surface-2); color: var(--mb-text); border: 1px solid var(--mb-border); border-inline-start: 4px solid var(--mb-primary-300); }
.toast.success { border-inline-start-color: #4ADE80; }
.toast.error, .toast.danger { border-inline-start-color: #F87171; }
.toast.warning { border-inline-start-color: #FBBF24; }
.toast.info { border-inline-start-color: #60A5FA; }
.toast svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.toast .toast-close { margin-inline-start: auto; opacity: 0.6; width: 20px; height: 20px; display: grid; place-items: center; border-radius: 4px; color: inherit; flex-shrink: 0; }
.toast .toast-close:hover { opacity: 1; background: rgba(255,255,255,0.12); }
.toast.removing { animation: mb-toast-out var(--mb-base) forwards; }

/* --------------------------------------------------------------------------
   8. Modals, dropdowns, tabs
   -------------------------------------------------------------------------- */
.modal-overlay, .confirm-modal {
    position: fixed; inset: 0; z-index: 900;
    background: var(--mb-overlay);
    display: none; align-items: center; justify-content: center;
    padding: var(--mb-space-4);
    backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
    overflow-y: auto;
}
.modal-overlay.open, .modal-overlay.active, .modal-overlay.show, .confirm-modal.open, .confirm-modal.active, .confirm-modal.show { display: flex; animation: mb-fade-in var(--mb-fast); }
.modal, .confirm-modal-content, .modal-content {
    background: var(--mb-surface); color: var(--mb-text);
    border-radius: var(--mb-radius-xl); box-shadow: var(--mb-shadow-lg);
    width: 100%; max-width: 560px; max-height: calc(100vh - 2rem);
    display: flex; flex-direction: column;
    animation: mb-scale-in var(--mb-base);
    border: 1px solid var(--mb-border);
}
.modal.modal-sm { max-width: 420px; }
.modal.modal-lg { max-width: 820px; }
.modal.modal-xl { max-width: 1080px; }
.modal > h2, .modal > h3 { padding: var(--mb-space-5) var(--mb-space-6) 0; }
.modal > .modal-subtitle { padding: 0.25rem var(--mb-space-6) 0; color: var(--mb-text-muted); font-size: var(--mb-text-sm); }
.modal > form { padding: var(--mb-space-5) var(--mb-space-6) var(--mb-space-6); overflow-y: auto; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: var(--mb-space-3); padding: var(--mb-space-5) var(--mb-space-6); border-bottom: 1px solid var(--mb-border); flex-shrink: 0; }
.modal-header h2, .modal-header h3 { font-size: var(--mb-text-lg); }
.modal-header .modal-sub { font-size: var(--mb-text-sm); color: var(--mb-text-muted); font-weight: 400; margin-top: 0.15rem; }
.modal-close { width: 34px; height: 34px; border-radius: var(--mb-radius-md); display: grid; place-items: center; color: var(--mb-text-muted); flex-shrink: 0; }
.modal-close:hover { background: var(--mb-surface-2); color: var(--mb-text); }
.modal-close svg { width: 18px; height: 18px; }
.modal-body { padding: var(--mb-space-5) var(--mb-space-6); overflow-y: auto; flex: 1; }
.modal-footer { display: flex; justify-content: flex-end; gap: var(--mb-space-2); padding: var(--mb-space-4) var(--mb-space-6); border-top: 1px solid var(--mb-border); background: var(--mb-surface-2); border-radius: 0 0 var(--mb-radius-xl) var(--mb-radius-xl); flex-shrink: 0; }
.confirm-modal-content { max-width: 440px; padding: var(--mb-space-6); gap: var(--mb-space-3); }
.confirm-modal-content h3 { font-size: var(--mb-text-lg); }
.confirm-modal-content p { color: var(--mb-text-muted); font-size: var(--mb-text-sm); }
.confirm-buttons { display: flex; justify-content: flex-end; gap: var(--mb-space-2); margin-top: var(--mb-space-3); }
body.modal-open { overflow: hidden; }

.dropdown { position: relative; }
.dropdown-menu, .notification-dropdown {
    position: absolute; top: calc(100% + 8px); inset-inline-end: 0;
    min-width: 220px; background: var(--mb-surface); border: 1px solid var(--mb-border);
    border-radius: var(--mb-radius-lg); box-shadow: var(--mb-shadow-lg); z-index: 200;
    animation: mb-scale-in var(--mb-fast); transform-origin: top; overflow: hidden;
}
.notification-dropdown { width: 360px; max-width: calc(100vw - 2rem); }
.notification-bell-wrapper { position: relative; }
.notification-bell { width: 38px; height: 38px; border-radius: var(--mb-radius-md); display: grid; place-items: center; color: var(--mb-text-muted); position: relative; }
.notification-bell:hover { background: var(--mb-surface-2); color: var(--mb-text); }
.notification-badge { position: absolute; top: 4px; inset-inline-end: 4px; min-width: 18px; height: 18px; padding-inline: 5px; border-radius: 9px; background: var(--mb-danger); color: #fff; font-size: 0.65rem; font-weight: 700; display: grid; place-items: center; border: 2px solid var(--mb-surface); direction: ltr; }
.notif-header { display: flex; align-items: center; justify-content: space-between; padding: var(--mb-space-3) var(--mb-space-4); border-bottom: 1px solid var(--mb-border); }
.notif-header h4 { font-size: var(--mb-text-base); }
.notif-mark-all { font-size: var(--mb-text-xs); font-weight: 600; color: var(--mb-primary); }
.notif-list { max-height: 380px; overflow-y: auto; }
.notif-item { display: flex; gap: var(--mb-space-3); padding: var(--mb-space-3) var(--mb-space-4); border-bottom: 1px solid var(--mb-border); cursor: pointer; transition: background var(--mb-fast); }
.notif-item:last-child { border-bottom: 0; }
.notif-item:hover { background: var(--mb-surface-hover); }
.notif-item.unread { background: var(--mb-primary-soft); }
.notif-item .notif-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mb-primary); margin-top: 6px; flex-shrink: 0; }
.notif-item.read .notif-dot { background: transparent; }
.notif-item .notif-title { font-size: var(--mb-text-sm); font-weight: 600; }
.notif-item .notif-msg { font-size: var(--mb-text-xs); color: var(--mb-text-muted); }
.notif-item .notif-time { font-size: 0.7rem; color: var(--mb-text-subtle); margin-top: 0.2rem; }
.notif-empty { padding: var(--mb-space-8); text-align: center; color: var(--mb-text-muted); font-size: var(--mb-text-sm); }
.dropdown-item { display: flex; align-items: center; gap: var(--mb-space-2); width: 100%; padding: 0.6rem var(--mb-space-4); font-size: var(--mb-text-sm); color: var(--mb-text); text-align: start; }
.dropdown-item:hover { background: var(--mb-surface-hover); }
.dropdown-item.danger { color: var(--mb-danger); }
.dropdown-divider { height: 1px; background: var(--mb-border); }

.tabs, .tabs-bar, .detail-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--mb-border); margin-bottom: var(--mb-space-5); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar, .tabs-bar::-webkit-scrollbar, .detail-tabs::-webkit-scrollbar { display: none; }
.tab-btn, .detail-tab {
    padding: 0.7rem 1rem; font-size: var(--mb-text-sm); font-weight: 600; color: var(--mb-text-muted);
    border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; transition: color var(--mb-fast), border-color var(--mb-fast);
    display: inline-flex; align-items: center; gap: 0.4rem;
}
.tab-btn:hover, .detail-tab:hover { color: var(--mb-text); }
.tab-btn.active, .detail-tab.active { color: var(--mb-primary); border-bottom-color: var(--mb-primary); }
.tab-btn .count { font-size: 0.7rem; padding: 0.05rem 0.4rem; border-radius: var(--mb-radius-full); background: var(--mb-surface-2); color: var(--mb-text-muted); }
.tab-btn.active .count { background: var(--mb-primary-soft-2); color: var(--mb-primary-800); }
.tab-panel { display: none; animation: mb-fade-in var(--mb-base); }
.tab-panel.active { display: block; }

/* --------------------------------------------------------------------------
   9. Auth layout (login / register)
   -------------------------------------------------------------------------- */
.auth-layout, .login-wrapper { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); min-height: 100vh; }
.auth-brand, .brand-panel {
    position: relative; overflow: hidden;
    background: linear-gradient(160deg, var(--mb-primary-800) 0%, var(--mb-primary-600) 60%, var(--mb-primary-500) 100%);
    color: #fff; padding: var(--mb-space-12) var(--mb-space-10);
    display: flex; flex-direction: column; justify-content: center; gap: var(--mb-space-6);
}
.auth-brand::before, .brand-panel::before {
    content: ''; position: absolute; inset: 0; pointer-events: none; opacity: 0.35;
    background-image: radial-gradient(circle at 20% 20%, rgba(255,255,255,0.18) 0, transparent 40%), radial-gradient(circle at 85% 75%, rgba(200,155,60,0.35) 0, transparent 45%);
}
.auth-brand::after, .brand-panel::after {
    content: ''; position: absolute; inset-inline-end: -120px; bottom: -120px; width: 360px; height: 360px; border-radius: 50%;
    border: 60px solid rgba(255,255,255,0.06); pointer-events: none;
}
.auth-brand > *, .brand-panel > * { position: relative; z-index: 1; }
.brand-logo { display: inline-flex; align-items: center; gap: var(--mb-space-3); font-weight: 700; font-size: var(--mb-text-lg); color: #fff; }
.brand-logo .logo-mark { background: rgba(255,255,255,0.16); color: #fff; }
.brand-headline { font-size: clamp(1.75rem, 3vw, 2.5rem); font-weight: 700; line-height: 1.15; color: #fff; letter-spacing: -0.02em; }
[dir="rtl"] .brand-headline { letter-spacing: 0; line-height: 1.35; }
.brand-subtitle { font-size: var(--mb-text-md); color: rgba(255,255,255,0.82); max-width: 44ch; line-height: 1.6; }
.brand-features { list-style: none; display: flex; flex-direction: column; gap: 0.7rem; }
.brand-features li { display: flex; align-items: center; gap: var(--mb-space-3); font-size: var(--mb-text-base); color: rgba(255,255,255,0.92); }
.brand-features li svg { width: 22px; height: 22px; padding: 3px; border-radius: 50%; background: rgba(255,255,255,0.15); flex-shrink: 0; }
.vision-badge { display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0.8rem; border-radius: var(--mb-radius-full); background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.22); font-size: var(--mb-text-xs); font-weight: 600; align-self: flex-start; color: #fff; }
.auth-panel, .form-panel { display: flex; align-items: center; justify-content: center; padding: var(--mb-space-10) var(--mb-space-6); background: var(--mb-bg); }
.form-container, .auth-card { width: 100%; max-width: 440px; }
.form-title { font-size: var(--mb-text-2xl); margin-bottom: 0.3rem; }
.form-subtitle { color: var(--mb-text-muted); font-size: var(--mb-text-base); margin-bottom: var(--mb-space-6); }
.back-home-link, .auth-link { display: inline-flex; align-items: center; gap: 0.4rem; font-size: var(--mb-text-sm); font-weight: 500; color: var(--mb-text-muted); margin-bottom: var(--mb-space-6); }
.back-home-link:hover, .auth-link:hover { color: var(--mb-primary); }
.back-home-link svg, .auth-link svg { width: 16px; height: 16px; flex-shrink: 0; }
[dir="rtl"] .back-home-link svg, [dir="rtl"] .icon-flip { transform: scaleX(-1); }
.auth-footer-links { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; margin-top: var(--mb-space-4); font-size: var(--mb-text-sm); }
.auth-footer-links a { font-weight: 500; }
.auth-panel .lang-switch, .form-panel .lang-switch { position: absolute; top: var(--mb-space-4); inset-inline-end: var(--mb-space-4); }
.auth-panel, .form-panel { position: relative; }
@media (max-width: 900px) {
    .auth-layout, .login-wrapper { grid-template-columns: 1fr; }
    .auth-brand, .brand-panel { padding: var(--mb-space-8) var(--mb-space-6); min-height: 0; }
    .brand-features { display: none; }
    .brand-headline { font-size: 1.5rem; }
}

/* --------------------------------------------------------------------------
   10. Marketing (homepage)
   -------------------------------------------------------------------------- */
.site-nav, nav.nav { position: sticky; top: 0; z-index: 100; height: 68px; display: flex; align-items: center; background: var(--mb-topbar-bg); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--mb-border); }
.site-nav .container, nav.nav .nav-inner { display: flex; align-items: center; justify-content: space-between; gap: var(--mb-space-4); }
.container { width: 100%; max-width: 1180px; margin-inline: auto; padding-inline: var(--mb-space-6); }
.nav-links { display: flex; align-items: center; gap: var(--mb-space-6); list-style: none; }
.nav-links a { font-size: var(--mb-text-sm); font-weight: 500; color: var(--mb-text-muted); }
.nav-links a:hover { color: var(--mb-text); }
.nav-actions { display: flex; align-items: center; gap: var(--mb-space-2); }
.hero { padding: clamp(3rem, 8vw, 6rem) 0; background: radial-gradient(ellipse at 15% 0%, var(--mb-primary-50) 0%, transparent 55%), radial-gradient(ellipse at 90% 20%, var(--mb-accent-100) 0%, transparent 45%), var(--mb-bg); }
.hero-inner { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: var(--mb-space-10); align-items: center; }
.hero h1 { font-size: clamp(2rem, 4.5vw, 3.25rem); line-height: 1.1; letter-spacing: -0.03em; margin-bottom: var(--mb-space-5); }
[dir="rtl"] .hero h1 { letter-spacing: 0; line-height: 1.3; }
.hero h1 .accent { color: var(--mb-primary); }
.hero p.lead, .hero-content > p { font-size: var(--mb-text-lg); color: var(--mb-text-muted); max-width: 52ch; margin-bottom: var(--mb-space-6); line-height: 1.6; }
.hero-actions { display: flex; gap: var(--mb-space-3); flex-wrap: wrap; }
.eyebrow { display: inline-flex; align-items: center; gap: 0.5rem; font-size: var(--mb-text-xs); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--mb-primary); margin-bottom: var(--mb-space-4); }
[dir="rtl"] .eyebrow { letter-spacing: 0; text-transform: none; font-size: var(--mb-text-sm); }
.section, section.features, section.stats, section.demo-section { padding: clamp(3rem, 7vw, 5.5rem) 0; }
.section-title, .section-heading { text-align: center; max-width: 640px; margin-inline: auto; margin-bottom: var(--mb-space-10); }
.section-title h2, .section-heading h2 { font-size: clamp(1.6rem, 3vw, 2.25rem); letter-spacing: -0.02em; margin-bottom: var(--mb-space-3); }
[dir="rtl"] .section-title h2, [dir="rtl"] .section-heading h2 { letter-spacing: 0; }
.section-title p, .section-heading p { color: var(--mb-text-muted); font-size: var(--mb-text-md); }
.features-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--mb-space-5); }
.feature-card { background: var(--mb-surface); border: 1px solid var(--mb-border); border-radius: var(--mb-radius-xl); padding: var(--mb-space-6); transition: transform var(--mb-base), box-shadow var(--mb-base), border-color var(--mb-base); }
.feature-card:hover { transform: translateY(-3px); box-shadow: var(--mb-shadow-md); border-color: var(--mb-primary-200); }
.feature-icon { width: 48px; height: 48px; border-radius: var(--mb-radius-md); background: var(--mb-primary-soft); color: var(--mb-primary); display: grid; place-items: center; margin-bottom: var(--mb-space-4); }
.feature-icon svg { width: 24px; height: 24px; }
.feature-card h3 { font-size: var(--mb-text-md); margin-bottom: var(--mb-space-2); }
.feature-card p { font-size: var(--mb-text-sm); color: var(--mb-text-muted); line-height: 1.6; }
.stats-band { background: var(--mb-primary-800); color: #fff; }
.stats-band .stat-item { text-align: center; }
.stats-band .stat-item .value { font-size: var(--mb-text-3xl); font-weight: 800; letter-spacing: -0.03em; direction: ltr; }
.stats-band .stat-item .label { font-size: var(--mb-text-sm); color: rgba(255,255,255,0.75); margin-top: 0.25rem; }
.demo-card { background: var(--mb-surface); border: 1px solid var(--mb-border); border-radius: var(--mb-radius-xl); padding: var(--mb-space-6); display: flex; flex-direction: column; gap: var(--mb-space-3); }
.demo-card-icon { width: 44px; height: 44px; border-radius: var(--mb-radius-md); display: grid; place-items: center; background: var(--mb-accent-soft); color: var(--mb-accent-700); }
.site-footer, footer.footer { background: var(--mb-neutral-900); color: rgba(255,255,255,0.7); padding: var(--mb-space-10) 0 var(--mb-space-6); font-size: var(--mb-text-sm); }
.site-footer a, footer.footer a { color: rgba(255,255,255,0.7); }
.site-footer a:hover, footer.footer a:hover { color: #fff; }
.footer-grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: var(--mb-space-8); margin-bottom: var(--mb-space-8); }
.footer-grid h4 { color: #fff; font-size: var(--mb-text-sm); margin-bottom: var(--mb-space-3); }
.footer-grid ul { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
.footer-bottom { border-top: 1px solid rgba(255,255,255,0.1); padding-top: var(--mb-space-5); display: flex; justify-content: space-between; gap: var(--mb-space-3); flex-wrap: wrap; font-size: var(--mb-text-xs); color: rgba(255,255,255,0.5); }
@media (max-width: 900px) {
    .hero-inner { grid-template-columns: 1fr; }
    .hero-illustration { display: none; }
    .nav-links { display: none; }
    .footer-grid { grid-template-columns: 1fr 1fr; }
}

/* --------------------------------------------------------------------------
   11. Utilities
   -------------------------------------------------------------------------- */
.flex { display: flex; } .inline-flex { display: inline-flex; } .grid { display: grid; } .block { display: block; }
.flex-col { flex-direction: column; } .flex-wrap { flex-wrap: wrap; } .flex-1 { flex: 1; min-width: 0; }
.items-center { align-items: center; } .items-start { align-items: flex-start; } .items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; } .justify-center { justify-content: center; } .justify-end { justify-content: flex-end; }
.gap-1 { gap: var(--mb-space-1); } .gap-2 { gap: var(--mb-space-2); } .gap-3 { gap: var(--mb-space-3); } .gap-4 { gap: var(--mb-space-4); } .gap-6 { gap: var(--mb-space-6); }
.mt-1 { margin-top: var(--mb-space-1); } .mt-2 { margin-top: var(--mb-space-2); } .mt-3 { margin-top: var(--mb-space-3); } .mt-4 { margin-top: var(--mb-space-4); } .mt-6 { margin-top: var(--mb-space-6); } .mt-8 { margin-top: var(--mb-space-8); }
.mb-1 { margin-bottom: var(--mb-space-1); } .mb-2 { margin-bottom: var(--mb-space-2); } .mb-3 { margin-bottom: var(--mb-space-3); } .mb-4 { margin-bottom: var(--mb-space-4); } .mb-6 { margin-bottom: var(--mb-space-6); }
.ms-auto { margin-inline-start: auto; } .me-auto { margin-inline-end: auto; } .mx-auto { margin-inline: auto; }
.p-0 { padding: 0; } .p-4 { padding: var(--mb-space-4); } .p-6 { padding: var(--mb-space-6); }
.w-full { width: 100%; } .w-auto { width: auto; } .min-w-0 { min-width: 0; }
.text-xs { font-size: var(--mb-text-xs); } .text-sm { font-size: var(--mb-text-sm); } .text-base { font-size: var(--mb-text-base); } .text-md { font-size: var(--mb-text-md); } .text-lg { font-size: var(--mb-text-lg); } .text-xl { font-size: var(--mb-text-xl); }
.text-muted { color: var(--mb-text-muted); } .text-subtle { color: var(--mb-text-subtle); } .text-primary { color: var(--mb-primary); } .text-success { color: var(--mb-success); } .text-warning { color: var(--mb-warning); } .text-danger { color: var(--mb-danger); } .text-info { color: var(--mb-info); }
.text-center { text-align: center; } .text-start { text-align: start; } .text-end { text-align: end; }
.fw-500 { font-weight: 500; } .fw-600 { font-weight: 600; } .fw-700 { font-weight: 700; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabular { font-variant-numeric: tabular-nums; }
.rounded { border-radius: var(--mb-radius-md); } .rounded-full { border-radius: var(--mb-radius-full); }
.border { border: 1px solid var(--mb-border); } .border-t { border-top: 1px solid var(--mb-border); } .border-b { border-bottom: 1px solid var(--mb-border); }
.bg-surface { background: var(--mb-surface); } .bg-surface-2 { background: var(--mb-surface-2); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.divider { height: 1px; background: var(--mb-border); margin: var(--mb-space-4) 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--mb-space-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--mb-space-4); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--mb-space-4); }
@media (max-width: 768px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } .hide-mobile { display: none !important; } }
@media (min-width: 769px) { .show-mobile { display: none !important; } }

/* Chart containers */
.chart-card { padding: var(--mb-space-5); }
.chart-wrap { position: relative; height: 280px; }
.chart-wrap canvas { width: 100% !important; height: 100% !important; }
.bar-chart { display: flex; flex-direction: column; gap: 0.6rem; }
.range-bar { display: grid; grid-template-columns: 120px 1fr 44px; align-items: center; gap: var(--mb-space-3); font-size: var(--mb-text-sm); }
.range-bar .lbl { color: var(--mb-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.range-bar .val { text-align: end; font-weight: 600; font-variant-numeric: tabular-nums; direction: ltr; }

/* Schedule grid (doctor) */
.schedule-grid { display: grid; grid-template-columns: 72px 1fr; border: 1px solid var(--mb-border); border-radius: var(--mb-radius-lg); overflow: hidden; background: var(--mb-surface); }
.schedule-slot-time { font-size: var(--mb-text-xs); color: var(--mb-text-muted); padding: 0.6rem; border-bottom: 1px solid var(--mb-border); border-inline-end: 1px solid var(--mb-border); background: var(--mb-surface-2); font-variant-numeric: tabular-nums; direction: ltr; text-align: center; }
.schedule-slot { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--mb-border); min-height: 44px; font-size: var(--mb-text-sm); }
.schedule-slot.booked { background: var(--mb-primary-soft); }
.schedule-slot.blocked { background: repeating-linear-gradient(45deg, var(--mb-surface-2) 0 6px, transparent 6px 12px); color: var(--mb-text-subtle); }
.schedule-header { display: flex; align-items: center; justify-content: space-between; gap: var(--mb-space-3); flex-wrap: wrap; margin-bottom: var(--mb-space-4); }
.schedule-nav { display: flex; align-items: center; gap: var(--mb-space-2); }
[dir="rtl"] .schedule-nav .icon-flip svg, [dir="rtl"] .icon-flip svg { transform: scaleX(-1); }

/* Timeline (clinical notes, audit) */
.timeline { position: relative; padding-inline-start: 1.5rem; }
.timeline::before { content: ''; position: absolute; inset-block: 0.5rem; inset-inline-start: 6px; width: 2px; background: var(--mb-border); }
.timeline-item { position: relative; padding-bottom: var(--mb-space-4); }
.timeline-item::before { content: ''; position: absolute; inset-inline-start: -1.5rem; top: 6px; width: 14px; height: 14px; border-radius: 50%; background: var(--mb-surface); border: 3px solid var(--mb-primary); }
.timeline-item .tl-time { font-size: var(--mb-text-xs); color: var(--mb-text-subtle); }
.timeline-item .tl-title { font-weight: 600; font-size: var(--mb-text-sm); }
.timeline-item .tl-body { font-size: var(--mb-text-sm); color: var(--mb-text-muted); }

/* Session timeout banner */
.session-warning { position: fixed; bottom: var(--mb-space-4); inset-inline-start: 50%; transform: translateX(-50%); z-index: 950; background: var(--mb-neutral-900); color: #fff; padding: var(--mb-space-3) var(--mb-space-5); border-radius: var(--mb-radius-lg); box-shadow: var(--mb-shadow-lg); display: flex; align-items: center; gap: var(--mb-space-4); font-size: var(--mb-text-sm); }
[dir="rtl"] .session-warning { transform: translateX(50%); }

/* --------------------------------------------------------------------------
   12. Animations
   -------------------------------------------------------------------------- */
@keyframes mb-spin { to { transform: rotate(360deg); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes mb-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes mb-scale-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes mb-toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes mb-toast-out { to { opacity: 0; transform: translateX(20px); } }
[dir="rtl"] .toast.removing { animation-name: mb-toast-out-rtl; }
@keyframes mb-toast-out-rtl { to { opacity: 0; transform: translateX(-20px); } }
@keyframes mb-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* --------------------------------------------------------------------------
   13. Print
   -------------------------------------------------------------------------- */
@media print {
    .sidebar, .topbar, .toast-container, .sidebar-backdrop, .no-print, .btn, .action-btn, .lang-switch { display: none !important; }
    .main-area { margin: 0 !important; }
    .main-content { padding: 0; max-width: none; }
    body { background: #fff; color: #000; }
    .card, .table-card, .stat-card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
    a { color: inherit; }
}
