/* RAABIH Nexus CRM — one white sheet, ink, and a single accent.
   Tokens only; every text pair meets WCAG AA on its surface.
   Status is shown with a word and a dot, never with a coloured edge. */
:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface2: #f1f3f7; --ink: #171b26;
  --line: #e4e7ee; --line2: #cfd5e0;
  --text: #141821; --dim: #566070; --faint: #6f7a8c;
  --acc: #4f46c8; --acc-bg: #f3f2ff; --acc-line: #d6d3fb;
  --teal: #0b6b62;
  --red: #c2291c; --red-bg: #fef3f2; --red-line: #f9c6c1;
  --amber: #a14406; --amber-bg: #fff8eb; --amber-line: #f6d58a;
  --green: #05683f; --green-bg: #ecfdf3; --green-line: #a6e9c5;
  --r: 12px; --r-s: 9px;
  --sh1: 0 1px 2px rgba(16, 24, 40, .05);
  --sh2: 0 4px 16px rgba(16, 24, 40, .08), 0 1px 3px rgba(16, 24, 40, .05);
  --sh3: 0 16px 40px rgba(16, 24, 40, .16), 0 4px 10px rgba(16, 24, 40, .06);
  font-size: 15px;
}
* { box-sizing: border-box; margin: 0; }
html, body { min-height: 100%; }
body { font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', sans-serif; background: var(--bg); color: var(--text); line-height: 1.45; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
a { color: var(--acc); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; border-radius: 4px; }
::selection { background: rgba(79, 70, 200, .18); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- frame ---------- */
#app { display: none; min-height: 100vh; min-height: 100dvh; }
#app.on { display: grid; grid-template-columns: 224px minmax(0, 1fr); }
#nav { padding: 18px 12px; border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; gap: 2px; background: var(--surface); overflow-y: auto; }
.logo { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; }
.logo .orb { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, #5b4fd6, #0f9f8f); flex-shrink: 0; }
.logo b { font-size: 1rem; letter-spacing: .03em; }
.logo small { display: block; color: var(--faint); font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-btn { display: flex; align-items: center; gap: 11px; width: 100%; text-align: left; padding: 9px 11px; background: none; border: 1px solid transparent; border-radius: var(--r-s); color: var(--dim); font-weight: 520; font-size: .93rem; }
.nav-btn:hover { color: var(--text); background: var(--surface2); }
.nav-btn.active { color: var(--acc); background: var(--acc-bg); border-color: var(--acc-line); }
.nav-more { display: none; }
.ic { width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ic svg, .btn svg, .cmd-ic svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-spacer { flex: 1; }
.whoami { padding: 12px 11px 4px; border-top: 1px solid var(--line); font-size: .85rem; color: var(--dim); }
.whoami b { color: var(--text); display: block; }
.linkish { background: none; border: none; padding: 0; color: var(--acc); text-decoration: underline; font-size: inherit; }

#main { padding: 22px 28px 64px; width: 100%; max-width: 1320px; min-width: 0; }
.topbar { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 18px; }
.topbar h1 { font-size: 1.32rem; font-weight: 700; letter-spacing: -.01em; }
.topbar .sub { color: var(--dim); font-size: .86rem; margin-top: 2px; max-width: 62ch; }
.spacer { flex: 1; }
.cmdbar { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line2); border-radius: 10px; padding: 8px 12px; width: min(380px, 100%); box-shadow: var(--sh1); }
.cmdbar:focus-within { border-color: var(--acc); box-shadow: 0 0 0 3px rgba(79, 70, 200, .14); }
.cmdbar input { flex: 1; min-width: 0; background: none; border: none; outline: none; }
.cmdbar input::placeholder { color: var(--faint); }
.cmd-ic { display: inline-flex; color: var(--faint); }
.cmdbar kbd { font-size: .68rem; color: var(--faint); border: 1px solid var(--line2); background: var(--surface2); padding: 2px 6px; border-radius: 5px; font-family: inherit; }
#cmd-results { background: var(--surface); border: 1px solid var(--line2); border-radius: var(--r); box-shadow: var(--sh2); margin: -10px 0 16px auto; width: min(520px, 100%); overflow: hidden; }
.cmd-item { display: flex; gap: 10px; align-items: baseline; width: 100%; text-align: left; padding: 10px 14px; background: none; border: none; border-bottom: 1px solid var(--line); }
.cmd-item:last-child { border-bottom: none; }
.cmd-item:hover, .cmd-item:focus-visible { background: var(--acc-bg); }
.cmd-item span { color: var(--dim); font-size: .84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmd-ask b { color: var(--acc); }

.licbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; padding: 10px 14px; margin-bottom: 16px; border-radius: var(--r-s); background: var(--amber-bg); border: 1px solid var(--amber-line); color: #5c2c05; font-size: .9rem; }
.licbar.ended { background: var(--red-bg); border-color: var(--red-line); color: #7a1a12; }

/* ---------- surfaces ---------- */
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); margin-bottom: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; box-shadow: var(--sh1); min-width: 0; }
.card h3 { font-size: .76rem; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); margin-bottom: 10px; font-weight: 650; }
.card.warn { background: var(--amber-bg); border-color: var(--amber-line); }
.card.warn h3 { color: var(--amber); }
.kpi .v { font-size: 1.5rem; font-weight: 720; letter-spacing: -.02em; font-variant-numeric: tabular-nums; color: var(--ink); }
.kpi .v.bad, .bad { color: var(--red); }
.kpi .l { color: var(--dim); font-size: .82rem; margin-top: 2px; }
.two-col { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }
.briefing { padding: 14px 16px; background: var(--acc-bg); border: 1px solid var(--acc-line); border-radius: var(--r); margin-bottom: 16px; color: #2c2866; }
.flowstrip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 16px; }
.flowstep { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 13px; box-shadow: var(--sh1); min-height: 44px; }
.flowstep:hover { border-color: var(--acc); }
.flowstep b { display: block; font-size: .88rem; font-weight: 630; }
.flowstep span { display: block; color: var(--dim); font-size: .78rem; margin-top: 2px; }

.list { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; min-width: 0; }
.row.top { align-items: flex-start; }
.row .main { flex: 1; min-width: 0; text-align: left; }
.rowbtn { width: 100%; text-align: left; }
.rowbtn:hover, .rowmain:hover .t { border-color: var(--line2); }
.rowbtn:hover { box-shadow: var(--sh1); background: #fbfbfd; }
.rowmain { background: none; border: none; padding: 0; }
.rowmain:hover .t { text-decoration: underline; text-decoration-color: var(--line2); text-underline-offset: 3px; }
.row .t { font-weight: 570; overflow-wrap: anywhere; }
.row .s { color: var(--dim); font-size: .83rem; margin-top: 2px; overflow-wrap: anywhere; }
.row .s.pre { white-space: pre-wrap; color: var(--text); font-size: .9rem; margin-top: 6px; }
.row-acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; flex-shrink: 0; }
.row-acts.col { flex-direction: column; align-items: stretch; }
.num { text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.num b { display: block; color: var(--teal); }
.num span { font-size: .78rem; }
.struck { text-decoration: line-through; color: var(--faint); }
.tick { width: 20px; height: 20px; accent-color: var(--teal); flex-shrink: 0; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .72rem; font-weight: 650; border: 1px solid; white-space: nowrap; flex-shrink: 0; }
.badge.A, .badge.low { color: var(--green); border-color: var(--green-line); background: var(--green-bg); }
.badge.B { color: var(--teal); border-color: #99e3da; background: #effcfa; }
.badge.C, .badge.medium { color: var(--amber); border-color: var(--amber-line); background: var(--amber-bg); }
.badge.D, .badge.high { color: var(--red); border-color: var(--red-line); background: var(--red-bg); }
.badge.gray { color: var(--dim); border-color: var(--line2); background: var(--surface2); }
.badge.violet { color: var(--acc); border-color: var(--acc-line); background: var(--acc-bg); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.dot.high { background: #d92d20; }
.dot.medium { background: #dc8a00; }

/* ---------- buttons: brand-coloured or bordered, never pale on white ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 15px; min-height: 38px; border-radius: var(--r-s); border: 1px solid var(--line2); background: var(--surface); color: var(--text); font-weight: 570; font-size: .88rem; text-decoration: none; box-shadow: var(--sh1); white-space: nowrap; }
.btn:hover { background: var(--surface2); border-color: #b9c1cf; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #2b3142; border-color: #2b3142; }
.btn.danger { color: var(--red); border-color: var(--red-line); background: var(--red-bg); }
.btn.danger:hover { background: #fde3e0; }
.btn.good { color: var(--green); border-color: var(--green-line); background: var(--green-bg); }
.btn.good:hover { background: #d9f8e6; }
.btn.small { padding: 5px 11px; min-height: 32px; font-size: .8rem; border-radius: 8px; }
.btn.ghost { background: none; border-color: transparent; color: var(--dim); box-shadow: none; }
.btn.ghost:hover { color: var(--text); background: var(--surface2); }
.btn.block { width: 100%; }
.btn.icon-btn { padding: 6px; min-width: 36px; }
.btn:disabled, .btn.is-off, select.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn.is-busy { opacity: .7; }
select.btn { appearance: auto; padding-right: 6px; }

/* ---------- deal board ---------- */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(236px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.kcol { background: var(--surface2); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; min-height: 160px; }
.kcol.dragover { border-color: var(--acc); background: var(--acc-bg); }
.kcol h4 { font-size: .76rem; text-transform: uppercase; letter-spacing: .07em; color: var(--dim); display: flex; justify-content: space-between; gap: 8px; margin-bottom: 10px; font-variant-numeric: tabular-nums; }
.kcard { display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; margin-bottom: 9px; box-shadow: var(--sh1); cursor: grab; }
.kcard:hover { box-shadow: var(--sh2); }
.kcard .kt { font-weight: 570; font-size: .92rem; overflow-wrap: anywhere; }
.kcard .kv { color: var(--teal); font-weight: 680; font-size: .88rem; margin-top: 3px; font-variant-numeric: tabular-nums; }
.kcard .ks { color: var(--dim); font-size: .78rem; margin-top: 3px; }
.kempty { color: var(--faint); font-size: .82rem; text-align: center; padding: 18px 0; }
.stage-meter { display: flex; gap: 6px; margin: 12px 0; }
.stage-meter i { flex: 1; height: 6px; border-radius: 4px; background: var(--line); }
.stage-meter i.on { background: var(--teal); }

/* ---------- forms ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input[type=search], .toolbar select { background: var(--surface); border: 1px solid var(--line2); border-radius: var(--r-s); padding: 8px 12px; min-height: 38px; box-shadow: var(--sh1); min-width: 0; }
.toolbar input[type=search] { flex: 1 1 220px; max-width: 360px; }
.tabs { display: inline-flex; gap: 4px; padding: 4px; background: var(--surface2); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 16px; }
.tab { border: none; background: none; padding: 7px 16px; border-radius: 7px; font-weight: 570; color: var(--dim); min-height: 36px; }
.tab.on { background: var(--surface); color: var(--text); box-shadow: var(--sh1); }
.field { margin-bottom: 12px; min-width: 0; }
.field label { display: block; font-size: .8rem; color: var(--dim); margin-bottom: 5px; font-weight: 560; }
.field input, .field select, .field textarea { width: 100%; background: var(--surface); border: 1px solid var(--line2); border-radius: var(--r-s); padding: 9px 12px; min-height: 40px; }
.field input:focus, .field select:focus, .field textarea:focus, .toolbar input:focus, .toolbar select:focus { outline: none; border-color: var(--acc); box-shadow: 0 0 0 3px rgba(79, 70, 200, .14); }
.field textarea { min-height: 84px; resize: vertical; }
.field input:disabled, .field select:disabled, .field textarea:disabled { background: var(--surface2); color: var(--dim); }
.mono-in { font-family: ui-monospace, Consolas, monospace; font-size: .84rem; }
.frow { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.hint { color: var(--dim); font-size: .8rem; margin-top: 5px; }
.check { display: flex; gap: 9px; align-items: center; color: var(--text); font-size: .9rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--teal); }
.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline select { border: 1px solid var(--line2); border-radius: 8px; padding: 5px 8px; min-height: 32px; background: var(--surface); }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 5px 16px; font-size: .9rem; }
.kv dt { color: var(--dim); }
.kv dd { font-weight: 540; overflow-wrap: anywhere; }
.tl { display: grid; grid-template-columns: 78px minmax(0, 1fr); gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.tl:last-child { border-bottom: none; }
.tl-k { color: var(--dim); font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; padding-top: 2px; }
.reasons { padding-left: 18px; }
.reasons li { color: var(--text); font-size: .88rem; margin: 3px 0; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: .76rem; color: var(--text); word-break: break-all; background: var(--surface2); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; margin: 6px 0; user-select: all; }

/* ---------- windows ---------- */
.overlay, .sheet-back { position: fixed; inset: 0; background: rgba(16, 20, 30, .48); display: none; z-index: 50; }
.overlay.on { display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow: auto; background: var(--surface); border-radius: 16px; padding: 22px; box-shadow: var(--sh3); }
.modal.wide { width: min(860px, 100%); }
.win-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.win-head h2 { font-size: 1.1rem; font-weight: 700; overflow-wrap: anywhere; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.sticky-acts { position: sticky; bottom: -24px; background: var(--surface); padding: 12px 0 4px; margin-top: 16px; border-top: 1px solid var(--line); }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(500px, 100%); background: var(--surface); border-left: 1px solid var(--line); z-index: 40; padding: 22px 22px 24px; overflow-y: auto; transform: translateX(104%); transition: transform .2s ease-out; box-shadow: var(--sh3); visibility: hidden; }
.drawer.on { transform: none; visibility: visible; }
.acts-line { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.sheet-back.on { display: flex; align-items: flex-end; }
.sheet { width: 100%; background: var(--surface); border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); box-shadow: var(--sh3); max-height: 80dvh; overflow: auto; }
.sheet-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.sheet-who { margin-top: 14px; }

/* ---------- ask, settings, feedback ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 2px 0 16px; }
.chip { border: 1px solid var(--line2); border-radius: 999px; padding: 7px 14px; min-height: 36px; background: var(--surface); color: var(--text); font-size: .86rem; box-shadow: var(--sh1); }
.chip:hover { border-color: var(--acc); color: var(--acc); }
.answer { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; box-shadow: var(--sh1); }
.answer .via { color: var(--acc); font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 8px; font-weight: 650; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 14px; align-items: start; }
.muted { color: var(--dim); font-size: .86rem; }
.center { text-align: center; }
.gap-t { margin-top: 12px; }
.gap-b { margin-bottom: 12px; }
.section-gap { margin-top: 16px; }
.empty { text-align: center; color: var(--dim); padding: 34px 14px; border: 1px dashed var(--line2); border-radius: var(--r); background: var(--surface); }
.empty b { color: var(--text); }
.loading { color: var(--dim); padding: 24px 4px; }
#toasts { position: fixed; bottom: 20px; right: 20px; left: 20px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; z-index: 100; pointer-events: none; }
.toast { display: flex; align-items: flex-start; gap: 9px; background: var(--ink); color: #f4f6fa; border-radius: 10px; padding: 11px 15px; box-shadow: var(--sh3); font-size: .9rem; max-width: 380px; pointer-events: auto; }
.toast i { width: 8px; height: 8px; border-radius: 50%; background: #35d39a; margin-top: 7px; flex-shrink: 0; }
.toast.err i { background: #ff7b6e; }

/* ---------- sign-in ---------- */
#login { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: min(410px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 32px; box-shadow: var(--sh2); }
.login-card .logo { justify-content: center; padding-bottom: 8px; }
.login-card p.tag { text-align: center; color: var(--dim); font-size: .88rem; margin-bottom: 22px; }
.err-line { color: var(--red); font-size: .86rem; min-height: 1.3em; margin-top: 8px; text-align: center; }

@media (prefers-reduced-motion: reduce) { .drawer { transition: none; } }
@media (max-width: 980px) { .two-col { grid-template-columns: minmax(0, 1fr); } }

/* ---------- phones: four tabs and More at the bottom, controls a thumb can hit ---------- */
@media (max-width: 820px) {
  :root { font-size: 16px; }
  #app.on { grid-template-columns: minmax(0, 1fr); }
  #nav { position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; flex-direction: row; justify-content: space-around; padding: 4px 6px calc(4px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); border-right: none; z-index: 30; overflow: visible; }
  #nav .logo, #nav .nav-spacer, #nav .whoami, #nav .nav-extra { display: none; }
  #nav .nav-more { display: flex; }
  .nav-btn { flex-direction: column; gap: 2px; font-size: .68rem; padding: 6px 4px; min-height: 52px; justify-content: center; flex: 1; text-align: center; border: none; }
  .nav-btn.active { background: none; }
  .sheet .nav-btn { flex-direction: row; font-size: .95rem; padding: 12px; min-height: 48px; justify-content: flex-start; border: 1px solid var(--line); gap: 10px; }
  #main { padding: 14px 14px calc(88px + env(safe-area-inset-bottom)); }
  .topbar { flex-direction: column; gap: 10px; }
  .cmdbar { width: 100%; }
  .cmdbar kbd { display: none; }
  #cmd-results { margin-left: 0; width: 100%; }
  .frow { grid-template-columns: minmax(0, 1fr); }
  .flowstrip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row { flex-wrap: wrap; }
  .row-acts { width: 100%; justify-content: flex-start; }
  .row-acts.col { flex-direction: row; }
  .btn { min-height: 44px; }
  .btn.small { min-height: 40px; padding: 7px 13px; font-size: .85rem; }
  .tab, .chip { min-height: 44px; }
  .field input, .field select, .field textarea, .toolbar input[type=search], .toolbar select { min-height: 46px; }
  .drawer { padding: 18px 16px calc(24px + env(safe-area-inset-bottom)); }
  .overlay.on { align-items: flex-end; padding: 0; }
  .modal { width: 100%; border-radius: 18px 18px 0 0; max-height: 92dvh; padding-bottom: calc(22px + env(safe-area-inset-bottom)); }
  #toasts { bottom: calc(76px + env(safe-area-inset-bottom)); right: 12px; left: 12px; align-items: stretch; }
  .toast { max-width: none; }
  .kanban { grid-auto-columns: minmax(78vw, 1fr); }
}
