/* Nibras sales dashboard — RTL, light/dark. Chart colours follow the validated reference palette. */
:root {
  color-scheme: light;
  --page: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #fcfcfb;
  --surface-sunken: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6c6a64;
  --hairline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.12);
  --accent: #1c5cab;
  --accent-hover: #184f95;
  --accent-ink: #ffffff;
  --accent-soft: #e6effb;
  --series-1: #2a78d6;
  --track: #eceae4;
  --prio-a: #1c5cab; --prio-a-ink: #ffffff;
  --prio-b: #3987e5; --prio-b-ink: #ffffff;
  --prio-c: #86b6ef; --prio-c-ink: #0b0b0b;
  --good: #0ca30c; --good-text: #006300; --good-soft: #e3f4e3;
  --warn-soft: #fff4d9; --warn-text: #7a5300;
  --critical: #d03b3b; --critical-soft: #fbe7e7; --critical-text: #a32626;
  --wa: #0f7a3d; --wa-hover: #0b6532;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 2px 8px rgba(11, 11, 11, 0.04);
  --font: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #1a1a19;
    --surface-sunken: #232321;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #9a988f;
    --hairline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #5598e7;
    --accent-hover: #6da7ec;
    --accent-ink: #0b0b0b;
    --accent-soft: #1b2c44;
    --series-1: #3987e5;
    --track: #2a2a28;
    --prio-a: #9ec5f4; --prio-a-ink: #0b0b0b;
    --prio-b: #5598e7; --prio-b-ink: #0b0b0b;
    --prio-c: #256abf; --prio-c-ink: #ffffff;
    --good-text: #0ca30c; --good-soft: #15301a;
    --warn-soft: #3a2f12; --warn-text: #f5c86a;
    --critical-soft: #3a1a1a; --critical-text: #f08a8a;
    --wa: #1a9c55; --wa-hover: #21b263;
    --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.6 var(--font);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.55rem; line-height: 1.3; margin: 0 0 4px; font-weight: 700; }
h2 { font-size: 1.05rem; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 0.95rem; margin: 18px 0 6px; font-weight: 600; color: var(--ink-2); }
p { margin: 0 0 8px; }
.mt { margin-top: 20px; }
.muted { color: var(--muted); }
.small, small { font-size: 0.82rem; }
.err { color: var(--critical-text); display: block; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ------------------------------------------------------------ layout */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand-sub { color: var(--muted); font-weight: 500; }
.brand-mark { width: 22px; height: 22px; border-radius: 7px; background: radial-gradient(circle at 35% 35%, #ffd36e 0 30%, #eda100 31% 55%, transparent 56%), var(--accent); }
.mainnav { display: flex; gap: 4px; flex: 1; }
.mainnav a { padding: 6px 12px; border-radius: 8px; color: var(--ink-2); font-weight: 500; }
.mainnav a:hover { background: var(--surface-sunken); text-decoration: none; }
.mainnav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.userbox { display: flex; align-items: center; gap: 12px; }
.userbox form { margin: 0; }
.user-name { display: flex; flex-direction: column; line-height: 1.2; font-weight: 600; }
.user-name small { color: var(--muted); font-weight: 400; }
.link-subtle { color: var(--muted); font-size: 0.85rem; }

.page { max-width: 1280px; margin: 0 auto; padding: 24px; }
.page-center { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 + * { margin-top: 16px; }
.empty { text-align: center; padding: 40px 20px; }

/* ------------------------------------------------------------ forms */
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--ink-2); font-weight: 500; }
input, select, textarea {
  font: inherit; font-size: 0.95rem; color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 38px;
  width: 100%;
}
textarea { resize: vertical; line-height: 1.7; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; color: var(--ink); }
label.inline { flex-direction: row; align-items: center; gap: 8px; }
label.inline select { width: auto; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-size: 0.85rem; color: var(--ink-2); font-weight: 500; margin-bottom: 6px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 12px; align-items: flex-end; }
.row.wrap { flex-wrap: wrap; }
.row > label { flex: 1 1 140px; }
.f-grow { flex: 2 1 220px !important; }
.inline-form { display: inline; margin: 0; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 0.88rem; }
.settings-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.settings-form .field:has(textarea) { grid-column: 1 / -1; }
.settings-form .f-actions { grid-column: 1 / -1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: 0.92rem;
  padding: 8px 16px; min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none !important;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-sunken); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 12px; min-height: 32px; font-size: 0.85rem; }
.btn-wa { background: var(--wa); border-color: var(--wa); color: #fff; }
.btn-wa:hover { background: var(--wa-hover); }
.link-btn { background: none; border: 0; padding: 0; font: inherit; font-size: 0.85rem; color: var(--accent); cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.f-actions { display: flex; gap: 8px; align-items: flex-end; }

.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; }
.flash ul { margin: 6px 0 0; padding-inline-start: 20px; }
.flash-ok { background: var(--good-soft); color: var(--good-text); }
.flash-warn { background: var(--warn-soft); color: var(--warn-text); }
.notice { border-color: var(--accent); }
code.secret { font-size: 1.1rem; padding: 4px 10px; border-radius: 6px; background: var(--surface-sunken); letter-spacing: 0.04em; }

/* ------------------------------------------------------------ auth */
.auth-card { width: min(420px, 100%); padding: 28px; }
.auth-card h1 { margin-bottom: 16px; }
.auth-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-bottom: 18px; }

/* ------------------------------------------------------------ badges & chips */
.prio, .stage, .chip, .run {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 999px;
  font-size: 0.82rem; font-weight: 600; line-height: 1.6; white-space: nowrap;
}
.prio small { font-weight: 500; opacity: 0.85; font-size: 0.75rem; }
.prio-A { background: var(--prio-a); color: var(--prio-a-ink); }
.prio-B { background: var(--prio-b); color: var(--prio-b-ink); }
.prio-C { background: var(--prio-c); color: var(--prio-c-ink); }
.prio-none { background: var(--surface-sunken); color: var(--muted); font-weight: 500; }
.stage { background: var(--surface-sunken); color: var(--ink-2); }
.stage-contacted, .stage-replied, .stage-meeting, .stage-proposal { background: var(--accent-soft); color: var(--accent); }
.stage-won { background: var(--good-soft); color: var(--good-text); }
.stage-lost { background: var(--critical-soft); color: var(--critical-text); }
.chip { background: var(--surface-sunken); color: var(--ink-2); font-weight: 500; }
.chip:hover { text-decoration: none; filter: brightness(0.97); }
.chip-due { background: var(--warn-soft); color: var(--warn-text); font-weight: 600; padding: 6px 14px; }
.due { color: var(--warn-text); font-weight: 600; }
.run-running { background: var(--accent-soft); color: var(--accent); }
.run-finished { background: var(--good-soft); color: var(--good-text); }
.run-failed { background: var(--critical-soft); color: var(--critical-text); }
.run-stale { background: var(--warn-soft); color: var(--warn-text); }

/* ------------------------------------------------------------ filters & tables */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filters > label { flex: 1 1 130px; }
.filters > label.check { flex: 0 0 auto; padding-bottom: 8px; }
.bulkbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 10px 16px; }
.table-wrap { overflow-x: auto; }
.table-wrap.card { padding: 0; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: start; font-size: 0.8rem; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--hairline); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--hairline); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
.num { text-align: end; }
.col-check { width: 36px; }
.col-name a { font-weight: 600; color: var(--ink); }
.col-name small { display: block; }
table.users input, table.users select { min-height: 32px; padding: 4px 8px; }
table.users td:first-child small { display: block; margin-top: 2px; }
.actions-cell { white-space: nowrap; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 12px 0 24px; }

/* ------------------------------------------------------------ overview tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); }
.tile-label { font-size: 0.82rem; color: var(--ink-2); }
.tile-value { font-size: 1.9rem; font-weight: 700; line-height: 1.2; }
.tile-sub { font-size: 0.78rem; color: var(--muted); }

/* ------------------------------------------------------------ charts */
.viz { margin: 0; }
.hbars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.hbars li { display: grid; grid-template-columns: 110px 1fr 120px; gap: 10px; align-items: center; }
.hb-label { font-size: 0.85rem; color: var(--ink-2); }
.hb-track { height: 14px; background: var(--track); border-radius: 4px; overflow: hidden; }
.hb-bar { display: block; height: 100%; background: var(--series-1); border-radius: 4px; }
.hb-val { font-weight: 600; font-variant-numeric: tabular-nums; }
.hb-val small { display: block; font-weight: 400; color: var(--muted); font-size: 0.75rem; }
.cols { display: flex; align-items: stretch; gap: 6px; height: 150px; padding-top: 4px; border-bottom: 1px solid var(--hairline); }
.col { flex: 1; display: flex; flex-direction: column; align-items: center; min-width: 0; cursor: default; }
.col-val { font-size: 0.75rem; font-weight: 600; height: 18px; font-variant-numeric: tabular-nums; }
.col-plot { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.col-bar { width: min(28px, 70%); background: var(--series-1); border-radius: 4px 4px 0 0; }
.col-label { font-size: 0.72rem; color: var(--muted); padding: 4px 0 2px; font-variant-numeric: tabular-nums; }
.col:hover .col-bar, .col:focus-visible .col-bar, .hb-bar:hover, .hb-bar:focus-visible { filter: brightness(1.12); }
.seg { display: flex; gap: 2px; height: 18px; border-radius: 4px; overflow: hidden; margin: 6px 0 12px; }
.seg-part { min-width: 4px; }
.prio-fill-A { background: var(--prio-a); }
.prio-fill-B { background: var(--prio-b); }
.prio-fill-C { background: var(--prio-c); }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 0.88rem; }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.tip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--ink); color: var(--page);
  padding: 6px 10px; border-radius: 8px; font-size: 0.82rem; font-weight: 500;
  max-width: 280px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { padding: 8px 0; border-bottom: 1px solid var(--hairline); }
.feed li:last-child { border-bottom: 0; }

/* ------------------------------------------------------------ lead page */
.crumbs { margin-bottom: 8px; font-size: 0.88rem; }
.lead-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.lead-badges { display: flex; gap: 8px; align-items: center; }
.lead-badges .prio, .lead-badges .stage { font-size: 0.95rem; padding: 4px 14px; }
.lead-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(300px, 1fr); gap: 16px; align-items: start; }
.message-card textarea { font-size: 1rem; background: var(--surface-2); }
.prose { white-space: pre-line; color: var(--ink); line-height: 1.85; }
.report h3 { color: var(--ink); font-size: 1rem; border-top: 1px solid var(--hairline); padding-top: 14px; margin-top: 14px; }
.limits { margin-top: 16px; }
details summary { cursor: pointer; color: var(--ink-2); font-weight: 500; }
.inline-h { display: inline; font-size: 1.05rem; }
.meters { list-style: none; padding: 0; margin: 4px 0 6px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 24px; }
.meters li { display: grid; grid-template-columns: 1fr 90px 32px; gap: 8px; align-items: center; font-size: 0.85rem; }
.meter { height: 8px; background: var(--track); border-radius: 4px; overflow: hidden; display: block; }
.meter-fill { display: block; height: 100%; background: var(--series-1); border-radius: 4px; }
.meter-val { font-weight: 600; text-align: end; font-variant-numeric: tabular-nums; }
.pipe-now { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.lead-side form + form { margin-top: 14px; }
.facts { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 8px 12px; margin: 0; font-size: 0.9rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.links { display: flex; flex-wrap: wrap; gap: 6px; }
.psi { list-style: none; padding: 0; margin: 0 0 12px; display: flex; gap: 10px; }
.psi li { flex: 1; background: var(--surface-sunken); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; font-size: 0.8rem; color: var(--ink-2); }
.psi strong { font-size: 1.3rem; color: var(--ink); }
.psi strong small { font-weight: 400; color: var(--muted); }
.timeline { list-style: none; padding: 0; margin: 14px 0 0; }
.timeline li { padding: 10px 0 10px; border-top: 1px solid var(--hairline); }
.timeline p { margin: 2px 0 0; white-space: pre-line; }
.tl-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 0.82rem; }
.tl-meta time { color: var(--muted); }
.tl-stage p, .tl-assigned p, .tl-sent p, .tl-reanalyze p { color: var(--ink-2); font-size: 0.88rem; }
.run-buttons { display: flex; flex-wrap: wrap; gap: 16px; }
.run-buttons form { display: flex; flex-direction: column; gap: 4px; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1000px) {
  .lead-grid, .grid-2 { grid-template-columns: 1fr; }
  .grid-2 > .card { margin-bottom: 16px; }
  .settings-form { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 8px 16px; padding: 10px 16px; }
  .mainnav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .userbox .link-subtle { display: none; }
  .page { padding: 16px; }
  h1 { font-size: 1.3rem; }
  .card { padding: 14px 16px; }
  .meters { grid-template-columns: 1fr; }
  .hbars li { grid-template-columns: 84px 1fr 86px; }
  .row { flex-direction: column; align-items: stretch; }
  /* lead list becomes cards */
  .leads-table thead { display: none; }
  .leads-table, .leads-table tbody, .leads-table tr, .leads-table td { display: block; width: 100%; }
  .leads-table tr { padding: 12px 14px; border-bottom: 1px solid var(--hairline); position: relative; }
  .leads-table td { border: 0; padding: 3px 0; }
  .leads-table td[data-label] { display: flex; justify-content: space-between; gap: 12px; }
  .leads-table td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 0.82rem; }
  .leads-table .col-check { position: absolute; inset-inline-end: 14px; top: 12px; width: auto; }
  .leads-table .num { text-align: start; }
  .facts { grid-template-columns: 90px minmax(0, 1fr); }
}
@media (forced-colors: active) {
  .hb-bar, .col-bar, .meter-fill, .seg-part, .swatch { forced-color-adjust: none; background: CanvasText; }
}
@media print {
  .topbar, .filters, .bulkbar, .actions, form { display: none !important; }
  .card { box-shadow: none; break-inside: avoid; }
}
