/* ============================================================
   FlightBarN — Design Token System
   All visual decisions are expressed as CSS custom properties.
   Never hard-code colour or spacing values outside this file.
   ============================================================ */

:root {
  /* ── Brand Palette — "Ramp": aviation instrument panel.
     Graphite structure + teal signal + amber caution. ──── */
  --color-primary-50:  #e6f6f7;
  --color-primary-100: #c2e9ec;
  --color-primary-200: #8ed6dc;
  --color-primary-300: #4fbcc6;
  --color-primary-400: #21a0ad;
  --color-primary-500: #0f7b8a;
  --color-primary-600: #0b6472;
  --color-primary-700: #0a505c;
  --color-primary-800: #093f49;
  --color-primary-900: #072f37;
  --color-primary-950: #051f24;
  /* RGB triplet of --color-primary-500, for rgba() glows/overlays. */
  --color-primary-rgb: 15, 123, 138;

  --color-accent-400:  #f5a524;
  --color-accent-500:  #d8860c;
  --color-accent-600:  #a96707;

  /* ── Semantic Colours ───────────────────────────────────── */
  --color-success-50:  #e7f7ef;
  --color-success-500: #17915d;
  --color-success-600: #0f7349;
  --color-success-700: #0b5738;

  --color-warning-50:  #fff6e5;
  --color-warning-400: #fabf4f;
  --color-warning-500: #d8860c;
  --color-warning-600: #a96707;

  --color-danger-50:   #fdecec;
  --color-danger-500:  #cf3b3b;
  --color-danger-600:  #a92c2c;
  --color-danger-700:  #7f2222;

  --color-info-50:     #ecefff;
  --color-info-500:    #4f5ed1;
  --color-info-600:    #3d49ab;

  /* Intermediate steps — referenced by alerts, status dots and attachment
     cards but never defined before, so those borders silently fell back to
     currentColor. */
  --color-success-100: #c9ecd9;
  --color-success-200: #9fdcbc;
  --color-success-300: #5fc493;
  --color-warning-700: #7f4d05;
  --color-danger-200:  #f4b9b9;
  --color-info-200:    #c3cafa;
  --color-info-700:    #2f3884;
  --color-neutral-300: #c3ccd7;
  --color-neutral-400: #8b97a6;

  /* ── Light Theme (Default) ──────────────────────────────── */
  --bg-app:            #f5f7f9;
  --bg-surface:        #ffffff;
  --bg-surface-raised: #ffffff;
  --bg-surface-sunken: #eceff3;
  --bg-sidebar:        #0c1116;
  --bg-sidebar-hover:  #1b242e;
  --bg-sidebar-active: #0f7b8a;
  --bg-topbar:         #ffffff;
  --bg-overlay:        rgba(0, 0, 0, 0.45);
  --bg-code:           #eceff3;

  --text-primary:      #131a22;
  --text-secondary:    #4d5967;
  --text-tertiary:     #6b7889;
  --text-disabled:     #c3ccd7;
  --text-inverse:      #ffffff;
  --text-link:         #0f7b8a;
  --text-link-hover:   #0b6472;
  --text-sidebar:      #c3ccd7;
  --text-sidebar-hover:#eceff3;
  --text-sidebar-active:#ffffff;

  --border-default:    #dde2e9;
  --border-strong:     #c3ccd7;
  --border-focus:      #21a0ad;
  --border-input:      #c3ccd7;

  /* ── Typography ─────────────────────────────────────────── */
  --font-sans:         'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono:         'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --font-fa:           'Vazirmatn', 'Tahoma', sans-serif;
  --font-ar:           'Noto Sans Arabic', 'Vazirmatn', 'Tahoma', sans-serif;

  --text-xs:    0.75rem;    /* 12px */
  --text-sm:    0.8125rem;  /* 13px */
  --text-base:  0.875rem;   /* 14px */
  --text-md:    1rem;       /* 16px */
  --text-lg:    1.125rem;   /* 18px */
  --text-xl:    1.25rem;    /* 20px */
  --text-2xl:   1.5rem;     /* 24px */
  --text-3xl:   1.875rem;   /* 30px */
  --text-4xl:   2.25rem;    /* 36px */

  --font-normal:  400;
  --font-medium:  500;
  --font-semibold:600;
  --font-bold:    700;

  --leading-tight:  1.25;
  --leading-snug:   1.375;
  --leading-normal: 1.5;
  --leading-relaxed:1.625;

  /* ── Spacing Scale ──────────────────────────────────────── */
  --space-0:   0;
  --space-1:   0.25rem;   /* 4px */
  --space-2:   0.5rem;    /* 8px */
  --space-3:   0.75rem;   /* 12px */
  --space-4:   1rem;      /* 16px */
  --space-5:   1.25rem;   /* 20px */
  --space-6:   1.5rem;    /* 24px */
  --space-8:   2rem;      /* 32px */
  --space-10:  2.5rem;    /* 40px */
  --space-12:  3rem;      /* 48px */
  --space-16:  4rem;      /* 64px */
  --space-20:  5rem;      /* 80px */

  /* ── Radius ─────────────────────────────────────────────── */
  --radius-none: 0;
  --radius-sm:   0.25rem;
  --radius-md:   0.375rem;
  --radius-lg:   0.5rem;
  --radius-xl:   0.75rem;
  --radius-2xl:  1rem;
  --radius-full: 9999px;

  /* ── Shadows / Elevation ────────────────────────────────── */
  --shadow-xs:  0 1px 2px 0 rgba(0,0,0,.05);
  --shadow-sm:  0 1px 3px 0 rgba(0,0,0,.10), 0 1px 2px -1px rgba(0,0,0,.10);
  --shadow-md:  0 4px 6px -1px rgba(0,0,0,.10), 0 2px 4px -2px rgba(0,0,0,.10);
  --shadow-lg:  0 10px 15px -3px rgba(0,0,0,.10), 0 4px 6px -4px rgba(0,0,0,.10);
  --shadow-xl:  0 20px 25px -5px rgba(0,0,0,.10), 0 8px 10px -6px rgba(0,0,0,.10);
  --shadow-2xl: 0 25px 50px -12px rgba(0,0,0,.25);
  --shadow-inner:inset 0 2px 4px 0 rgba(0,0,0,.05);

  /* ── Sidebar dimensions ─────────────────────────────────── */
  --sidebar-width:         240px;
  --sidebar-collapsed-width: 64px;
  --topbar-height:         60px;
  --footer-height:         44px;
  --bottom-nav-height:     58px;

  /* ── Motion ─────────────────────────────────────────────────
     Custom curves: the built-in CSS keywords are too weak and make the UI
     feel sluggish. Rules used throughout app.css:
       enter / exit / press feedback → --ease-out    (instant response, soft landing)
       on-screen movement            → --ease-in-out (sidebar collapse, switches)
       drawers / bottom sheets       → --ease-drawer (iOS-like)
     Exits are faster than entries. Keyboard-initiated UI (the Ctrl+K command
     palette) is deliberately NOT animated — it is opened dozens of times a day.
     Everything here is neutralised under prefers-reduced-motion (app.css). */
  --ease-out:     cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out:  cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer:  cubic-bezier(0.32, 0.72, 0, 1);

  --duration-press:  120ms;   /* button / tile press feedback     */
  --duration-fast:   150ms;   /* hover colour, tooltips           */
  --duration-normal: 200ms;   /* dropdowns, popovers, toast exit  */
  --duration-slow:   260ms;   /* modals, sidebar, drawers         */

  /* Shorthands kept for the existing call sites — now on the strong ease-out
     curve instead of generic `ease`, so every existing transition in the app
     is upgraded from this one place. */
  --transition-fast:   var(--duration-fast) var(--ease-out);
  --transition-normal: var(--duration-normal) var(--ease-out);
  --transition-slow:   var(--duration-slow) var(--ease-out);

  /* One focus ring for every focusable control. */
  --focus-ring: 0 0 0 3px rgba(var(--color-primary-rgb), .22);

  /* ── Z-index layers ─────────────────────────────────────── */
  --z-dropdown:  100;
  --z-sticky:    200;
  --z-drawer:    300;
  --z-modal:     400;
  --z-toast:     500;
  --z-tooltip:   600;
  --z-overlay:   700;
}

/* ── Dark Theme — first-class, independently tuned, not an inversion:
   cooler graphite base, luminous teal at 400, softer foreground (never
   pure white), borders carried by translucent light. ─────────────── */
[data-theme="dark"] {
  --color-primary-300: #4fbcc6;
  --color-primary-400: #21a0ad;
  --color-primary-500: #21a0ad;
  --color-primary-600: #4fbcc6;
  --color-primary-700: #7fdbe4;
  --color-primary-rgb: 33, 160, 173;

  --color-success-500: #2fae76;
  --color-warning-500: #f5a524;
  --color-danger-500:  #e35d5d;
  --color-info-500:    #6b7ae8;

  /* Tint steps (50-200) were light pastels in both themes, so every chip,
     icon tile, alert and selected row without its own dark override showed
     up as a glaring bright block on the dark surface. As translucent tints
     they sit on whatever surface is underneath. The matching "on-tint" text
     steps are lifted so text placed on those tints stays readable. */
  --color-primary-50:  rgba(33, 160, 173, .12);
  --color-primary-100: rgba(33, 160, 173, .20);
  --color-primary-200: rgba(33, 160, 173, .32);
  --color-success-50:  rgba(47, 174, 118, .14);
  --color-success-100: rgba(47, 174, 118, .22);
  --color-success-200: rgba(47, 174, 118, .32);
  --color-success-300: rgba(47, 174, 118, .45);
  --color-success-700: #86dcb4;
  --color-warning-50:  rgba(245, 165, 36, .14);
  --color-warning-600: #ffd485;
  --color-warning-700: #ffd485;
  --color-danger-50:   rgba(227, 93, 93, .14);
  --color-danger-200:  rgba(227, 93, 93, .32);
  --color-danger-700:  #f4a9a9;
  --color-info-50:     rgba(107, 122, 232, .14);
  --color-info-200:    rgba(107, 122, 232, .32);
  --color-info-600:    #aab4ff;
  --color-info-700:    #aab4ff;
  --color-neutral-300: rgba(226, 240, 255, .18);
  --color-neutral-400: #6b7889;

  --bg-app:            #0b1015;
  --bg-surface:        #131b23;
  --bg-surface-raised: #18222b;
  --bg-surface-sunken: #0e151b;
  --bg-sidebar:        #090d12;
  --bg-sidebar-hover:  rgba(226, 240, 255, 0.06);
  --bg-sidebar-active: #21a0ad;
  --bg-topbar:         #131b23;

  --text-primary:      #e4eaf0;
  --text-secondary:    #8b9aa9;
  --text-tertiary:     #6b7889;
  --text-disabled:     #3a4552;
  --text-inverse:      #04171a;
  --text-link:         #21a0ad;
  --text-link-hover:   #4fbcc6;
  --text-sidebar:      #63707e;
  --text-sidebar-hover:#d7e4f0;

  --border-default:    rgba(226, 240, 255, 0.1);
  --border-strong:     rgba(226, 240, 255, 0.18);
  --border-focus:      #4fbcc6;
  --border-input:      rgba(226, 240, 255, 0.16);

  --bg-code:           #18222b;

  --shadow-xs:  0 1px 2px rgba(0,0,0,.5);
  --shadow-sm:  0 1px 2px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.03);
  --shadow-md:  0 4px 14px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,.04);
  --shadow-lg:  0 12px 32px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.05);
  --shadow-xl:  0 32px 72px rgba(0,0,0,.7), inset 0 1px 0 rgba(255,255,255,.06);
  --shadow-2xl: 0 32px 72px rgba(0,0,0,.75);

  --focus-ring: 0 0 0 3px rgba(var(--color-primary-rgb), .35);
}

/* ── Legacy / alias tokens ─────────────────────────────────────────
   Pages and older CSS blocks reference these names, but none of them were
   ever defined — so every border, background and text colour using them
   silently fell back to currentColor / transparent (e.g. SearchableSelect's
   focus border, the rate-import dropzone, step circles, many inline
   `border: 1px solid var(--border-color)` dividers). Mapping them onto the
   real tokens fixes all of those call sites at once and keeps them correct
   in both themes. New code should use the canonical names on the right. */
:root {
  --color-primary:        var(--color-primary-600);
  --color-success:        var(--color-success-600);
  --color-success-light:  var(--color-success-50);
  --color-secondary-400:  var(--color-neutral-400);
  --color-border:         var(--border-default);
  --color-bg-secondary:   var(--bg-surface-sunken);
  --color-text-muted:     var(--text-tertiary);

  --border-color:         var(--border-default);
  --border-1:             var(--border-default);
  --border-subtle:        var(--border-default);
  --border-accent:        var(--color-primary-300);

  --bg-1:                 var(--bg-surface);
  --bg-2:                 var(--bg-surface-sunken);
  --bg-secondary:         var(--bg-surface-sunken);
  --bg-input:             var(--bg-surface);
  --bg-surface-hover:     var(--bg-surface-sunken);
  --bg-accent-soft:       var(--color-primary-50);
  --surface-2:            var(--bg-surface-sunken);
  --warning-subtle:       var(--color-warning-50);

  --text-muted:           var(--text-tertiary);
  --text-placeholder:     var(--text-tertiary);

  --input-height:         38px;
}

/* ── RTL overrides — layout direction only ─────────────────────── */
[dir="rtl"] {
  font-family: var(--font-fa), var(--font-sans);
  /* Persian/Arabic letterforms carry diacritics and taller ascenders/
     descenders than Latin — the Latin-tuned 1.5 base line-height reads
     cramped for them. */
  line-height: var(--leading-relaxed);
}

/* Arabic gets its own face — Vazirmatn is Persian-optimized and renders Arabic text
   noticeably worse than a font built for it. */
[dir="rtl"]:lang(ar) {
  font-family: var(--font-ar), var(--font-sans);
}

/* Negative tracking (e.g. .btn's -0.005em) is a Latin-typography trick for
   tightening large geometric sans faces — it has no equivalent benefit on
   Arabic/Persian's connected, cursive-style letterforms and just cramps
   them, so neutralize any tracking on RTL text.
   `html[dir="rtl"] *` (attribute + type + universal) is deliberately more
   specific than the single-class rules it needs to beat (.btn, .modal-title,
   etc. are all (0,1,0)) — plain `[dir="rtl"] *` would tie on specificity
   and lose to them on source order, since this file loads before app.css. */
html[dir="rtl"] * {
  letter-spacing: normal;
}

/* Numerics/identifiers isolated via <Ltr> must never inherit the RTL page font — Western
   digits and Latin codes look correct in the base sans stack, not the Arabic/Persian one. */
.ltr-isolate {
  font-family: var(--font-sans);
  unicode-bidi: isolate;
}
