/* ============================================================
   AGENT FLOW — Design Tokens v1.0
   Powered by wijdan AI · Wajdan CRM AI
   Single source of truth for color, type, space, radius,
   elevation and motion. Drop this in before any other CSS.

   Brand primary is derived from the Agent Flow logo waveform
   (indigo / periwinkle), NOT from the legacy sky-blue scale.
   ============================================================ */

:root {
  /* ── Brand · Flow Indigo ─────────────────────────────────
     Sampled from the logo mark. 500 is the literal logo
     mid-tone. 600 is the default interactive colour because
     white-on-500 is 4.40:1 (large text only).               */
  --primary-50:  #f2f2fe;
  --primary-100: #e5e5fd;
  --primary-200: #cdcdfa;
  --primary-300: #adadf6;
  --primary-400: #8b8bee;
  --primary-500: #6c6cd8;  /* logo core */
  --primary-600: #5555c2;  /* default action */
  --primary-700: #4444a8;  /* hover / strong */
  --primary-800: #34348f;
  --primary-900: #24247e;
  --primary-950: #10104f;
  --primary-color: var(--primary-500);

  /* ── Ink · indigo-leaning deep neutral (sidebar, nav) ──── */
  --ink-700: #26263d;
  --ink-800: #1a1a2e;
  --ink-900: #12121f;

  /* ── Slate · text, borders, dividers ────────────────────── */
  --slate-50:  #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;

  /* ── Gray · surfaces ────────────────────────────────────── */
  --gray-50:  #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* ── Semantic ───────────────────────────────────────────── */
  --success-50:  #ecfdf5;
  --success-100: #d1fae5;
  --success-200: #a7f3d0;
  --success-500: #10b981;
  --success-600: #059669;
  --success-700: #047857;
  --success-color: var(--success-500);

  --warning-50:  #fffbeb;
  --warning-100: #fef3c7;
  --warning-200: #fde68a;
  --warning-500: #f59e0b;
  --warning-600: #d97706;
  --warning-color: var(--warning-500);

  --error-50:  #fef2f2;
  --error-100: #fee2e2;
  --error-200: #fecaca;
  --error-500: #ef4444;
  --error-600: #dc2626;
  --error-700: #b91c1c;
  --error-color: var(--error-500);

  /* Info stays sky-blue so it never reads as a brand action */
  --info-50:  #eff6ff;
  --info-100: #dbeafe;
  --info-200: #bfdbfe;
  --info-500: #3b82f6;
  --info-600: #2563eb;

  /* ── Foreground / surfaces ──────────────────────────────── */
  --fg1: #0f172a;
  --fg2: #374151;
  --fg-muted: #64748b;
  --fg-on-primary: #ffffff;

  --bg-page: #f8f8fc;
  --bg-card: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-sidebar: var(--ink-800);

  --border-color: #e5e7eb;
  --border-strong: #d1d5db;
  --border-subtle: #f1f5f9;

  /* ── Type ───────────────────────────────────────────────── */
  --app-font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-family: var(--app-font);
  --font-arabic: "IBM Plex Sans Arabic", "Noto Sans Arabic", var(--app-font);
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --fs-xs:   0.75rem;    /* 12 */
  --fs-sm:   0.8125rem;  /* 13 */
  --fs-base: 0.875rem;   /* 14 — body default */
  --fs-md:   0.9375rem;  /* 15 */
  --fs-lg:   1rem;       /* 16 */
  --fs-xl:   1.125rem;   /* 18 */
  --fs-2xl:  1.25rem;    /* 20 */
  --fs-3xl:  1.5rem;     /* 24 — page title */
  --fs-4xl:  1.875rem;   /* 30 */
  --fs-5xl:  2.25rem;    /* 36 — hero stat */

  --fw-light: 300;
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  --lh-tight: 1.2;
  --lh-snug: 1.4;
  --lh-base: 1.5;
  --lh-relaxed: 1.6;

  --tracking-tight: -0.02em;
  --tracking-wide: 0.05em;
  --tracking-wider: 0.08em;

  /* ── Spacing (4pt grid) ─────────────────────────────────── */
  --spacing-xs: 0.25rem;  /*  4 */
  --spacing-sm: 0.5rem;   /*  8 */
  --spacing-md: 1rem;     /* 16 */
  --spacing-lg: 1.5rem;   /* 24 */
  --spacing-xl: 2rem;     /* 32 */
  --spacing-2xl: 3rem;    /* 48 */

  /* ── Radius ─────────────────────────────────────────────── */
  --radius-sm: 0.375rem;  /*  6 */
  --radius-md: 0.5rem;    /*  8 */
  --radius-button: 10px;
  --radius-lg: 0.75rem;   /* 12 — cards */
  --radius-xl: 1rem;      /* 16 — analytics */
  --radius-2xl: 1.25rem;  /* 20 — hero */
  --radius-pill: 9999px;

  /* ── Elevation ──────────────────────────────────────────── */
  --shadow-sm: 0 1px 2px 0 rgba(16,16,79,.06);
  --shadow-md: 0 4px 6px -1px rgba(16,16,79,.10), 0 2px 4px -1px rgba(16,16,79,.06);
  --shadow-lg: 0 10px 15px -3px rgba(16,16,79,.10), 0 4px 6px -2px rgba(16,16,79,.05);
  --shadow-xl: 0 20px 25px -5px rgba(16,16,79,.12), 0 10px 10px -5px rgba(16,16,79,.04);
  --shadow-header: 0 1px 3px 0 rgba(16,16,79,.06);
  --shadow-sidebar: 4px 0 20px rgba(16,16,79,.14);

  --glow-primary: 0 4px 14px 0 rgba(108,108,216,.40);
  --glow-primary-hover: 0 6px 20px 0 rgba(108,108,216,.52);
  --ring-focus: 0 0 0 3px rgba(108,108,216,.28);

  /* ── Gradients ──────────────────────────────────────────── */
  --grad-primary: linear-gradient(135deg, var(--primary-500), var(--primary-600));
  --grad-primary-strong: linear-gradient(135deg, var(--primary-600), var(--primary-700));
  --grad-brand-wave: linear-gradient(135deg, #adadf6 0%, #6c6cd8 45%, #24247e 100%);
  --grad-sidebar: linear-gradient(180deg, var(--ink-800) 0%, var(--ink-900) 100%);
  --grad-surface: linear-gradient(135deg, #f8fafc 0%, #ffffff 100%);
  /* There is no coloured modal-header gradient. Modal headers are white
     with a 1px --border-color rule. One gradient per screen, max. */

  /* ── Motion ─────────────────────────────────────────────── */
  --ease-out: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-emphasized: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 150ms;
  --dur-base: 200ms;
  --dur-slow: 300ms;

  /* ── Layout ─────────────────────────────────────────────── */
  --sidebar-width: 280px;
  --sidebar-width-collapsed: 76px;
  --topbar-height: 70px;
  --content-max: 85rem;
  --page-pad-x: 2rem;

  /* ── Data-viz series (use in order) ─────────────────────── */
  --chart-1: #5555c2;
  --chart-2: #8b8bee;
  --chart-3: #3b82f6;
  --chart-4: #10b981;
  --chart-5: #f59e0b;
  --chart-6: #24247e;
  --chart-7: #94a3b8;
  --chart-8: #adadf6;
  --chart-grid: #eef0f6;
  --chart-axis: #94a3b8;

  /* ── Role identity (monochrome ladder — never new hues) ── */
  --role-admin:     var(--primary-900);
  --role-sales-admin: var(--primary-700);
  --role-sales-rep: var(--primary-500);
  --role-marketing: var(--primary-400);

  --white: #ffffff;
  --black: #000000;
}

/* ============================================================
   Base
   ============================================================ */
html, body {
  font-family: var(--app-font);
  font-weight: var(--fw-regular);
  font-size: var(--fs-base);
  line-height: var(--lh-relaxed);
  color: var(--fg1);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
[dir="rtl"] body { font-family: var(--font-arabic); }

/* ============================================================
   Type roles
   ============================================================ */
.t-display       { font-size: var(--fs-5xl); font-weight: var(--fw-bold); line-height: var(--lh-tight); letter-spacing: var(--tracking-tight); color: var(--fg1); }
.t-h1            { font-size: var(--fs-4xl); font-weight: var(--fw-bold); line-height: var(--lh-tight); letter-spacing: var(--tracking-tight); color: var(--fg1); }
.t-h2            { font-size: var(--fs-3xl); font-weight: var(--fw-bold); line-height: var(--lh-tight); color: var(--fg1); }
.t-h3            { font-size: var(--fs-2xl); font-weight: var(--fw-semibold); line-height: var(--lh-snug); color: var(--fg1); }
.t-card-title    { font-size: var(--fs-xl);  font-weight: var(--fw-semibold); color: var(--fg1); }
.t-section-title { font-size: var(--fs-lg);  font-weight: var(--fw-semibold); color: var(--fg1); }
.t-body          { font-size: var(--fs-base); color: var(--fg2); line-height: var(--lh-relaxed); }
.t-small         { font-size: var(--fs-sm);  color: var(--fg-muted); }
.t-micro         { font-size: var(--fs-xs);  color: var(--fg-muted); }
.t-eyebrow       { font-size: var(--fs-xs);  font-weight: var(--fw-semibold); text-transform: uppercase; letter-spacing: var(--tracking-wider); color: var(--fg-muted); }
.t-stat          { font-size: 2rem; font-weight: var(--fw-bold); line-height: 1; color: var(--fg1); font-variant-numeric: tabular-nums; }
.t-mono          { font-family: var(--font-mono); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.t-link          { color: var(--primary-600); font-weight: var(--fw-medium); text-decoration: none; }
.t-link:hover    { color: var(--primary-700); text-decoration: underline; }
.t-gradient-title{
  font-size: var(--fs-5xl); font-weight: var(--fw-bold); letter-spacing: var(--tracking-tight);
  background: linear-gradient(135deg, var(--primary-600), var(--primary-900));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  height: 40px; padding: 0 1rem;
  font: var(--fw-semibold) var(--fs-base)/1 var(--app-font);
  border-radius: var(--radius-button); border: 1px solid transparent;
  cursor: pointer; white-space: nowrap;
  transition: all var(--dur-base) var(--ease-out);
}
.btn .material-symbols-outlined { font-size: 1.125rem; }
.btn:focus-visible { outline: none; box-shadow: var(--ring-focus); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

.btn-primary   { background: var(--grad-primary-strong); color: #fff; box-shadow: var(--glow-primary); }
.btn-primary:hover { background: linear-gradient(135deg, var(--primary-700), var(--primary-800)); box-shadow: var(--glow-primary-hover); transform: translateY(-1px); }
.btn-primary:active{ transform: translateY(0); box-shadow: var(--shadow-sm); }

.btn-secondary { background: #fff; color: var(--fg2); border-color: var(--border-color); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--gray-50); border-color: var(--gray-400); }

.btn-tonal     { background: var(--primary-50); color: var(--primary-700); border-color: var(--primary-100); }
.btn-tonal:hover { background: var(--primary-100); border-color: var(--primary-200); }

.btn-ghost     { background: transparent; color: var(--fg2); }
.btn-ghost:hover { background: var(--gray-100); color: var(--fg1); }

.btn-danger    { background: var(--error-600); color: #fff; }
.btn-danger:hover { background: var(--error-700); transform: translateY(-1px); }

.btn-sm { height: 32px; padding: 0 .75rem; font-size: var(--fs-sm); border-radius: var(--radius-md); }
.btn-lg { height: 48px; padding: 0 1.5rem; font-size: var(--fs-md); }
.btn-icon { width: 40px; padding: 0; }

/* ============================================================
   Form controls
   ============================================================ */
.form-label { display:block; font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--fg2); margin-bottom: .375rem; }
.form-input, .form-select, .form-textarea {
  width: 100%; height: 44px; padding: 0 .875rem;
  font: var(--fw-regular) var(--fs-base)/1.5 var(--app-font); color: var(--fg1);
  background: #fff; border: 2px solid var(--border-color); border-radius: var(--radius-lg);
  transition: border-color var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out);
}
.form-textarea { height: auto; padding: .75rem .875rem; resize: vertical; }
.form-input::placeholder { color: var(--gray-400); }
.form-input:hover, .form-select:hover { border-color: var(--border-strong); box-shadow: 0 2px 6px rgba(16,16,79,.06); }
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--primary-500); box-shadow: var(--ring-focus);
}
.form-input[aria-invalid="true"] { border-color: var(--error-500); box-shadow: 0 0 0 3px rgba(239,68,68,.15); }
.form-input:disabled { background: var(--gray-100); color: var(--gray-400); cursor: not-allowed; }
.form-hint  { font-size: var(--fs-xs); color: var(--fg-muted); margin-top: .375rem; }
.form-error { font-size: var(--fs-xs); color: var(--error-600); margin-top: .375rem; }

/* ============================================================
   Cards
   Colour restraint: the accent bar is indigo. Semantic variants
   exist for cards reporting an ACTUAL state (SLA breach, failed
   sync) — at most one semantic card per row. Icon tiles default
   to a flat --slate-100 fill with a --slate-600 icon.
   ============================================================ */
.card {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); padding: var(--spacing-lg); box-shadow: var(--shadow-sm);
}
.card-interactive { transition: transform var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out); }
.card-interactive:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.stat-card { position: relative; overflow: hidden; }
.stat-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--grad-primary);
}
.stat-card.is-success::before { background: linear-gradient(135deg, var(--success-500), var(--success-600)); }
.stat-card.is-warning::before { background: linear-gradient(135deg, var(--warning-500), var(--warning-600)); }
.stat-card.is-error::before   { background: linear-gradient(135deg, var(--error-500), var(--error-600)); }

.icon-tile {
  width: 44px; height: 44px; border-radius: var(--radius-lg);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--slate-100); color: var(--slate-600); flex: none;
}
.icon-tile.is-ai      { background: var(--primary-50); color: var(--primary-700); }
.icon-tile.is-warning { background: var(--warning-50); color: #b45309; }
.icon-tile.is-error   { background: var(--error-50);   color: var(--error-700); }

/* Modal header — white, never a coloured banner */
.modal-header {
  padding: var(--spacing-lg) var(--spacing-lg);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
}

/* ============================================================
   Badges & status pills
   Reserved for real state. A row carries at most one pill.
   ============================================================ */
.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  height: 22px; padding: 0 .5rem; border-radius: var(--radius-pill);
  font-size: 11px; font-weight: var(--fw-semibold); text-transform: uppercase; letter-spacing: var(--tracking-wide);
}
.badge-new       { background: var(--primary-50); color: var(--primary-700); }
.badge-contacted { background: var(--info-50);    color: var(--info-600); }
.badge-qualified { background: var(--warning-50); color: var(--warning-600); }
.badge-converted { background: var(--success-50); color: var(--success-700); }
.badge-lost      { background: var(--gray-100);   color: var(--gray-600); }
.badge-hot       { background: var(--error-50);   color: var(--error-600); }

/* ============================================================
   Table
   ============================================================ */
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-base); }
.table th {
  text-align: left; padding: .75rem 1rem; font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  text-transform: uppercase; letter-spacing: var(--tracking-wide); color: var(--fg-muted);
  background: var(--gray-50); border-bottom: 1px solid var(--border-color); white-space: nowrap;
}
.table td { padding: .875rem 1rem; border-bottom: 1px solid var(--border-subtle); color: var(--fg2); vertical-align: middle; }
.table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr { transition: background var(--dur-fast) var(--ease-out); }
.table tbody tr:hover { background: var(--gray-50); }
.table tbody tr[aria-selected="true"] { background: var(--primary-50); }

/* ============================================================
   App shell
   ============================================================ */
.app-sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-width);
  background: var(--grad-sidebar); box-shadow: var(--shadow-sidebar);
  transition: transform var(--dur-slow) var(--ease-out); z-index: 40;
}
.app-topbar {
  position: fixed; top: 0; left: var(--sidebar-width); right: 0; height: var(--topbar-height);
  background: #fff; border-bottom: 1px solid var(--border-color); box-shadow: var(--shadow-header); z-index: 30;
}
.app-main { margin-left: var(--sidebar-width); margin-top: var(--topbar-height); padding: var(--spacing-xl) var(--page-pad-x); }
.app-content { max-width: var(--content-max); margin-inline: auto; }

.nav-link {
  display: flex; align-items: center; gap: .75rem; position: relative;
  height: 44px; padding: 0 1.25rem; border-radius: var(--radius-md); margin: 2px .75rem;
  color: var(--slate-300); font-size: var(--fs-base); font-weight: var(--fw-medium); text-decoration: none;
  transition: all var(--dur-base) var(--ease-out);
}
.nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-link[aria-current="page"] { background: rgba(108,108,216,.22); color: #fff; font-weight: var(--fw-semibold); }
.nav-link[aria-current="page"]::before {
  content: ""; position: absolute; inset-inline-start: 0; top: 8px; bottom: 8px;
  width: 3px; border-radius: var(--radius-pill); background: var(--primary-400);
}

/* ============================================================
   RTL
   ============================================================ */
[dir="rtl"] .app-sidebar { inset: 0 0 0 auto; }
[dir="rtl"] .app-topbar  { left: 0; right: var(--sidebar-width); }
[dir="rtl"] .app-main    { margin-left: 0; margin-right: var(--sidebar-width); }
[dir="rtl"] .table th, [dir="rtl"] .table td { text-align: right; }
[dir="rtl"] .table td.num { text-align: left; }
[dir="rtl"] .icon-directional { transform: scaleX(-1); }

/* ============================================================
   Motion utilities
   ============================================================ */
@keyframes af-fade-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes af-slide-in-left { from { opacity: 0; transform: translateX(-16px); } to { opacity: 1; transform: none; } }
.anim-fade-up { animation: af-fade-up var(--dur-slow) var(--ease-emphasized) both; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
