/* =======================================================
   Orchestrator — application shell + §4 design language
   Layers on top of layouts-base.css (.layout-host tokens).
   Global chrome: top bar + two-layer left nav + page frame.
   ======================================================= */

.orch {
  --topbar-h: 54px;
  --nav-w: 180px;
  --gap: 16px;
  --r-lg: 9px; --r-md: 8px; --r-sm: 6px; --r-xs: 5px;
  --card-shadow: 0 1px 2px rgba(30,20,80,0.04), 0 12px 32px rgba(40,28,110,0.07);
  --card-border: 1px solid color-mix(in oklch, var(--border) 60%, transparent);

  position: fixed; inset: 0;
  display: grid;
  grid-template-columns: var(--nav-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas: "brand topbar" "nav main";
  background: var(--canvas);
  color: var(--fg);
  font-family: var(--font);
}
.orch.orch-corners-medium { --r-lg: 15px; --r-md: 12px; --r-sm: 9px; --r-xs: 7px; }
.orch.orch-corners-round  { --r-lg: 22px; --r-md: 17px; --r-sm: 13px; --r-xs: 9px; }
.orch.orch-flat {
  --card-shadow: none;
  --card-border: 1px solid var(--border);
}

/* ---------- brand corner ---------- */
.orch-brand {
  grid-area: brand;
  display: flex; align-items: center; gap: 9px;
  padding: 0 14px 0 18px;
  border-bottom: 1px solid var(--hairline);
  min-width: 0;
}
.orch-brand .name { flex-shrink: 0; }
.orch-brand .logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--brand); border: 1px solid var(--brand-border, transparent);
  color: var(--brand-fg); display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 16px;
  box-shadow: 0 4px 12px color-mix(in oklch, var(--brand) 30%, transparent);
}
.orch-brand .name { font-size: 15px; font-weight: 700; letter-spacing: -0.02em; color: var(--fg-strong); }
.orch-brand .ws {
  margin-left: 4px; font-size: 11px; font-weight: 600; color: var(--muted);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px 4px 8px; border-radius: 999px; background: var(--sunken);
  border: 2px solid var(--surface); position: relative; z-index: 2;
}
.orch-brand .ws svg { color: var(--brand); }

/* ---------- top bar ---------- */
.orch-topbar {
  grid-area: topbar;
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px;
  border-bottom: 1px solid var(--hairline);
  background: color-mix(in oklch, var(--surface) 70%, transparent);
  backdrop-filter: blur(8px);
}
.orch-crumbs { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.orch-crumbs .sec { color: var(--muted); font-weight: 500; }
.orch-crumbs .sep { color: var(--faint); }
.orch-crumbs .page { color: var(--fg-strong); font-weight: 600; }
.orch-cmdk {
  margin-left: 18px; flex: 1; max-width: 420px;
  height: 34px; border-radius: var(--r-sm);
  background: var(--surface); border: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; padding: 0 12px;
  color: var(--muted); font-size: 12.5px; cursor: text;
}
.orch-cmdk .kbd { margin-left: auto; font-family: var(--mono); font-size: 10.5px; padding: 1px 6px; background: var(--sunken); border-radius: var(--r-xs); }
.orch-topbar .spacer { flex: 1; }
.orch-tb-btn {
  width: 34px; height: 34px; border-radius: var(--r-sm);
  border: 1px solid transparent; background: transparent; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); position: relative;
}
.orch-tb-btn:hover { background: var(--sunken); color: var(--fg); }
.orch-tb-btn .ping {
  position: absolute; top: 6px; right: 7px; width: 7px; height: 7px; border-radius: 50%;
  background: var(--alert); border: 2px solid var(--surface);
}
.orch-tb-user {
  display: flex; align-items: center; gap: 8px; padding: 4px 6px 4px 4px;
  border-radius: 999px; cursor: pointer; border: 1px solid var(--border); background: var(--surface);
}
.orch-tb-user .who { font-size: 12px; font-weight: 600; color: var(--fg-strong); line-height: 1.1; }
.orch-tb-user .role { font-size: 10px; color: var(--muted); }

/* ---------- two-layer nav ---------- */
.orch-nav {
  grid-area: nav;
  display: flex; flex-direction: column;
  padding: 12px 10px;
  border-right: 1px solid var(--hairline);
  min-height: 0; overflow-y: auto;
}
.orch-nav-back {
  display: flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 10px; margin-bottom: 6px;
  border: none; background: transparent; cursor: pointer;
  color: var(--muted); font-family: inherit; font-size: 12px; font-weight: 600;
  border-radius: var(--r-sm);
}
.orch-nav-back:hover { background: var(--sunken); color: var(--fg); }
.orch-nav-secname {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--dim); padding: 4px 10px 8px;
}
.orch-navitem {
  display: flex; align-items: center; gap: 11px;
  height: 38px; padding: 0 11px; margin-bottom: 2px;
  border-radius: var(--r-md);
  color: var(--fg); cursor: pointer; position: relative;
  font-size: 13px; font-weight: 500;
}
.orch-navitem:hover { background: var(--sunken); }
.orch-navitem .ico { flex: 0 0 18px; display: inline-flex; color: var(--muted); }
.orch-navitem .lbl { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.orch-navitem .badge {
  font-size: 10px; font-weight: 700; font-family: var(--mono);
  padding: 1px 6px; border-radius: 999px; background: var(--sunken); color: var(--muted);
}
.orch-navitem.is-active {
  background: var(--surface); color: var(--brand-strong); font-weight: 600;
  box-shadow: var(--card-shadow); border: var(--card-border);
}
.orch-navitem.is-active .ico { color: var(--brand); }
.orch-navitem.is-active::before {
  content: ""; position: absolute; left: -10px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; border-radius: 2px; background: var(--brand);
}
.orch-navitem.is-active .badge { background: var(--brand-soft); color: var(--brand-strong); }
.orch-nav .spacer { flex: 1; }
.orch-nav-foot {
  border-top: 1px solid var(--hairline); margin-top: 6px; padding-top: 8px;
}

/* ---- Views sidebar panel (lifecycle + flags) ---- */
.orch-views-divider {
  margin: 10px 0 8px;
  border: none; border-top: 1.5px solid oklch(0.30 0.02 270);
  opacity: 0.22;
}
.orch-views-title {
  font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--dim); padding: 2px 10px 6px;
}
.orch-views-group-label {
  font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--dim); padding: 8px 10px 4px;
}
.orch-nav-divider {
  margin: 10px 0 8px;
  border: none; border-top: 1.5px solid oklch(0.30 0.02 270);
  opacity: 0.22;
}
.orch-nav-group-label {
  font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--dim); padding: 8px 10px 4px;
}
.orch-views-item {
  display: flex; align-items: center; gap: 9px;
  height: 30px; padding: 0 10px; border-radius: var(--r-sm);
  font-size: 12px; font-weight: 500; color: var(--muted); cursor: pointer;
  margin-bottom: 1px;
}
.orch-views-item:hover { background: var(--sunken); color: var(--fg); }
.orch-views-item.is-active { background: var(--sunken); color: var(--fg-strong); font-weight: 600; }
.orch-views-item .vi-ico { flex-shrink: 0; opacity: 0.55; display: inline-flex; }
.orch-views-item .vi-lbl { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.orch-views-item .vi-cnt {
  font-family: var(--mono); font-size: 11px; font-weight: 600; color: var(--dim);
  min-width: 18px; text-align: right;
}
.orch-views-item.is-active .vi-cnt { color: var(--brand); font-weight: 700; }
.orch-main { grid-area: main; min-width: 0; min-height: 0; overflow: hidden; position: relative; }
.orch-page { position: absolute; inset: 0; display: flex; flex-direction: column; overflow: hidden; }
.orch-page-head {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 22px 14px;
}
.orch-page-head h1 { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; margin: 0; color: var(--fg-strong); }
.orch-page-head .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.orch-page-head .spacer { flex: 1; }
.orch-page-body { flex: 1; min-height: 0; overflow: auto; padding: 0 22px 22px; }

/* shared card */
.orch-card {
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--card-shadow); border: var(--card-border);
}

/* shared button */
.orch-btn {
  height: 32px; padding: 0 13px; border-radius: var(--r-sm);
  background: var(--surface); border: 1px solid var(--border);
  color: var(--fg); font-size: 12.5px; font-weight: 500; font-family: inherit; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.orch-btn:hover { background: var(--sunken); }
.orch-btn.primary {
  background: var(--brand);
  border-color: var(--brand-border, transparent); color: var(--brand-fg); font-weight: 600;
}
.orch-btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.orch-btn.ghost:hover { background: var(--sunken); color: var(--fg); }
.orch-btn.ok { color: var(--ok); border-color: color-mix(in oklch, var(--ok) 35%, var(--border)); background: var(--ok-bg); }
.orch-btn.danger { color: var(--alert); border-color: color-mix(in oklch, var(--alert) 35%, var(--border)); background: var(--alert-bg); }
.orch-btn.sm { height: 27px; padding: 0 9px; font-size: 11.5px; }
.ld-tabs { margin-top: 10px; }

/* segmented control (page-level view toggles / filter views) */
.orch-seg { display: inline-flex; background: var(--sunken); border-radius: var(--r-sm); padding: 2px; gap: 2px; }
.orch-seg button {
  height: 28px; padding: 0 12px; border: none; background: transparent; cursor: pointer;
  border-radius: max(3px, calc(var(--r-sm) - 2px));
  font-family: inherit; font-size: 12px; font-weight: 600; color: var(--muted);
  display: inline-flex; align-items: center; gap: 6px;
}
.orch-seg button.is-active { background: var(--surface); color: var(--fg-strong); box-shadow: 0 1px 2px rgba(0,0,0,0.06); }

/* =======================================================
   §4 DESIGN LANGUAGE — locked recurring elements
   ======================================================= */

/* ---- AI mark + grounding receipt ---- */
.ai-mark {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px; font-weight: 700; color: var(--ai);
  letter-spacing: 0.01em;
}
.ai-mark .spk { font-size: 11px; line-height: 1; }
.ai-receipt {
  display: flex; align-items: flex-start; gap: 7px;
  padding: 8px 11px; border-radius: var(--r-sm);
  background: var(--ai-bg);
  border: 1px solid color-mix(in oklch, var(--ai) 18%, white);
  font-size: 11.5px; color: var(--fg); line-height: 1.45;
}
.ai-receipt .spk { color: var(--ai); flex-shrink: 0; font-weight: 700; }
.ai-receipt b { color: var(--ai); font-weight: 700; }
.ai-colhead { display: inline-flex; align-items: center; gap: 4px; color: var(--ai); font-weight: 700; }
.ai-colhead .spk { font-size: 10px; }

/* ---- temperature (amber family ONLY) ---- */
.temp { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.temp .swatch { width: 22px; height: 6px; border-radius: 3px; background: var(--faint); position: relative; overflow: hidden; }
.temp .swatch i { position: absolute; inset: 0; border-radius: 3px; }
.temp.hot  { color: oklch(0.52 0.15 65); }
.temp.hot  .swatch i { background: oklch(0.66 0.17 62); width: 100%; }
.temp.warm { color: oklch(0.58 0.10 72); }
.temp.warm .swatch i { background: oklch(0.78 0.12 75); width: 62%; }
.temp.cold { color: var(--muted); }
.temp.cold .swatch i { background: var(--dim); width: 30%; }

/* ---- lifecycle pill (pastel + bold) ---- */
.life {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.005em; white-space: nowrap;
}
.life-active    { background: oklch(0.93 0.05 245); color: oklch(0.42 0.14 250); }
.life-booked    { background: oklch(0.93 0.06 285); color: oklch(0.42 0.17 290); }
.life-postmtg   { background: oklch(0.93 0.05 200); color: oklch(0.40 0.10 210); }
.life-noshow    { background: oklch(0.93 0.05 75);  color: oklch(0.46 0.13 65); }
.life-handoff   { background: oklch(0.92 0.05 330); color: oklch(0.44 0.15 335); }
.life-won       { background: oklch(0.90 0.03 260); color: oklch(0.30 0.04 260); }
.life-disq      { background: oklch(0.93 0.012 260); color: oklch(0.50 0.01 260); }
.life-invited   { background: var(--warn-bg); color: var(--warn); }
.life-suspended { background: var(--alert-bg); color: var(--alert); }
.life-dnc       { color: oklch(0.46 0.012 260); border: 1px solid oklch(0.84 0.01 260);
  background: repeating-linear-gradient(45deg, oklch(0.95 0.008 260), oklch(0.95 0.008 260) 4px, oklch(0.92 0.008 260) 4px, oklch(0.92 0.008 260) 8px); }

/* ---- intent pill + direction ---- */
.intent { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; background: var(--sunken); color: var(--fg); white-space: nowrap; }
.intent .arw { font-size: 10px; font-weight: 700; }
.intent .arw.up { color: oklch(0.50 0.13 250); }
.intent .arw.dn { color: var(--muted); }
.intent .arw.flat { color: var(--dim); }

/* ---- sentiment trajectory (cool monochrome only) ---- */
.sent { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.sent b { color: oklch(0.34 0.03 255); font-weight: 600; }
.sent .arrow { color: var(--dim); }

/* ---- contact role pill ---- */
.role-pill { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
  background: oklch(0.94 0.03 255); color: oklch(0.40 0.08 255); }

/* ---- generic chips ---- */
.ch { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: var(--r-xs);
  font-size: 10.5px; font-weight: 600; white-space: nowrap; background: var(--sunken); color: var(--fg); }
.ch .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.ch.needs-review { background: var(--warn-bg); color: var(--warn); }
.ch.overdue { background: var(--alert-bg); color: var(--alert); }
.ch.ok { background: var(--ok-bg); color: var(--ok); }
.ch.warn { background: var(--warn-bg); color: var(--warn); }
.ch.info { background: var(--info-bg); color: var(--info); }
.ch.ai { background: var(--ai-bg); color: var(--ai); }
.ch.src-inbound { background: var(--info-bg); color: var(--info); }
.ch.src-calendar { background: oklch(0.95 0.04 200); color: oklch(0.42 0.10 200); }
.ch.src-outbound { background: var(--sunken); color: var(--muted); }

/* ---- guardrail "always escalates" (slate/indigo, never red/amber) ---- */
.guardrail { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: var(--r-xs);
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.01em; white-space: nowrap;
  background: oklch(0.93 0.035 275); color: oklch(0.38 0.11 278); }

/* ---- connection status (neutral-positive, never green; auth-expired amber; error amber) ---- */
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.conn .dot { width: 7px; height: 7px; border-radius: 50%; }
.conn.connected { color: var(--info); } .conn.connected .dot { background: var(--info); }
.conn.syncing   { color: var(--info); } .conn.syncing .dot { background: var(--info); animation: connpulse 1.4s ease-in-out infinite; }
.conn.off       { color: var(--muted); } .conn.off .dot { background: var(--dim); }
.conn.expired   { color: var(--warn); } .conn.expired .dot { background: var(--warn); }
.conn.error     { color: var(--alert); } .conn.error .dot { background: var(--alert); }
@keyframes connpulse { 0%,100%{opacity:1} 50%{opacity:0.35} }

/* ---- fit score (out of 200) ---- */
.fit { display: inline-flex; align-items: baseline; gap: 4px; font-family: var(--mono); white-space: nowrap; }
.fit .n { font-size: 13px; font-weight: 700; color: var(--fg-strong); }
.fit .d { font-size: 10.5px; color: var(--dim); }
.fit-label { font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: var(--r-xs); }
.fit-strong { background: oklch(0.93 0.04 250); color: oklch(0.40 0.12 250); }
.fit-mixed  { background: oklch(0.95 0.06 80);  color: oklch(0.47 0.12 70); }
.fit-weak   { background: var(--sunken); color: var(--muted); }
.risk-band { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.risk-band.low { color: var(--muted); }
.risk-band.med { color: oklch(0.50 0.12 70); }
.risk-band.high { color: var(--alert); }

/* ---- propose-only confirm card (distinct chrome) ---- */
.confirm-card {
  border-radius: var(--r-md);
  border: 1.5px dashed oklch(0.62 0.10 245);
  background: oklch(0.975 0.012 245);
  padding: 13px 15px;
}
.confirm-card .ch-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.confirm-card .ch-head .tag { display: inline-flex; align-items: center; gap: 5px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em; color: oklch(0.42 0.11 245);
  background: oklch(0.92 0.04 245); padding: 2px 8px; border-radius: 999px; }
.confirm-card .ch-title { font-size: 13px; font-weight: 600; color: var(--fg-strong); }
.confirm-card .ch-ev { font-size: 11.5px; color: var(--muted); line-height: 1.5; margin-bottom: 11px; }
.confirm-card .ch-ev b { color: var(--fg); font-weight: 600; }
.confirm-card .ch-acts { display: flex; align-items: center; gap: 8px; }
.confirm-card .ch-target { margin-left: auto; font-size: 10.5px; color: var(--muted); font-family: var(--mono); }

/* ---- undo toast ---- */
.orch-toast {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px;
  padding: 10px 14px; border-radius: 10px;
  background: oklch(0.18 0.02 270); color: #fff;
  box-shadow: 0 14px 40px rgba(20,12,50,0.35); font-size: 12.5px; z-index: 50;
}
.orch-toast button { background: transparent; border: none; color: oklch(0.82 0.06 250); font-weight: 700; font-size: 12.5px; cursor: pointer; font-family: inherit; }
.orch-toast .x { color: var(--dim); }

/* CRM posture banner */
.crm-banner {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 14px; border-radius: var(--r-sm);
  background: oklch(0.96 0.02 245); border: 1px solid oklch(0.88 0.04 245);
  font-size: 12px; color: oklch(0.38 0.08 245);
}
.crm-banner b { font-weight: 700; }
.crm-banner .spk { font-weight: 700; }

/* clickable name → opens the lead mini-dashboard (Leads page) */
.lead-link { cursor: pointer; }
.lead-link:hover { color: var(--brand-strong); text-decoration: underline; text-underline-offset: 2px; }

/* ---- Qualification gauge (circular score + labeled bars) ---- */
.qual-gauge { display: flex; align-items: center; gap: 16px; }
.qg-ring { position: relative; width: 72px; height: 72px; flex-shrink: 0; }
.qg-ring svg { display: block; }
.qg-track-c { fill: none; stroke: color-mix(in oklch, var(--brand) 16%, var(--sunken)); stroke-width: 4; }
.qg-prog { fill: none; stroke-width: 4; stroke-linecap: round; transition: stroke-dasharray .5s cubic-bezier(.4,0,.2,1); }
.qg-num { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.qg-num b { font-size: 20px; font-weight: 800; color: var(--fg-strong); letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.qg-num span { font-size: 9px; color: var(--muted); margin-top: 1px; }
.qg-bars { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 7px; }
.qg-row { display: grid; grid-template-columns: 100px 1fr auto; align-items: center; gap: 10px; }
.qg-k { font-size: 11.5px; font-weight: 600; color: var(--fg); white-space: nowrap; }
.qg-v { font-size: 11px; font-weight: 700; color: var(--brand-strong); white-space: nowrap; text-align: right; }
.qg-v em { font-style: normal; font-weight: 600; color: var(--muted); }
.qg-v.good { color: oklch(0.46 0.13 150); } .qg-v.good em { color: color-mix(in oklch, oklch(0.46 0.13 150) 70%, var(--muted)); }
.qg-v.warn { color: oklch(0.52 0.13 70); } .qg-v.warn em { color: color-mix(in oklch, oklch(0.52 0.13 70) 70%, var(--muted)); }
.qg-v.bad { color: var(--alert); } .qg-v.bad em { color: color-mix(in oklch, var(--alert) 70%, var(--muted)); }
.qg-track { height: 7px; border-radius: 4px; background: var(--sunken); overflow: hidden; }
.qg-track i { display: block; height: 100%; border-radius: 4px; background: var(--brand); transition: width .5s cubic-bezier(.4,0,.2,1); }
.qg-track i.good { background: oklch(0.66 0.16 150); }
.qg-track i.warn { background: oklch(0.76 0.15 78); }
.qg-track i.bad { background: oklch(0.64 0.19 25); }
.qual-gauge.compact { gap: 12px; }
.qual-gauge.compact .qg-ring { width: 58px; height: 58px; }
.qual-gauge.compact .qg-ring svg { width: 58px; height: 58px; }
.qual-gauge.compact .qg-num b { font-size: 16px; }
