/* ============================================================================
   Intelligence - the leadership "Value Cockpit" (Sentinel).
   Strict LIGHT theme · blue (#2563eb / var(--acc)) · NO gradients · NO glows.
   Reuses styles.css tokens (--acc, --t-*, --line, --surface, --green/amber/red,
   --fs-*, --shadow-*). Frosted chrome only on the header (inherited from .topbar).
   Standalone admin page - mirrors swarm.css conventions.
   ============================================================================ */

body { background: var(--bg); }

.intel-topbar { z-index: 40; }
.intel-back-link { gap: 6px; }
.intel-run-btn { gap: 6px; height: 32px; }

/* Last-swept pill (flat, no glow) */
.intel-swept-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 0 11px; height: 28px;
  background: var(--acc-soft); color: var(--acc-ink);
  border: 1px solid var(--acc-tint); border-radius: 999px;
  font-size: var(--fs-12); font-weight: 700; white-space: nowrap;
}
.isp-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--acc); flex-shrink: 0; }

/* ── Shell ─────────────────────────────────────────────────────────────────── */
.intel-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 18px 40px;
  min-height: calc(100vh - 52px - 30px);
  box-sizing: border-box;
}

.intel-loading {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 80px 16px; color: var(--t-4); font-size: var(--fs-13); font-weight: 500;
}

.intel-content { display: flex; flex-direction: column; gap: 18px; }

/* Spinner + ghost button (styles.css doesn't ship these standalone) */
.dl-spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--acc-tint); border-top-color: var(--acc);
  display: inline-block; animation: intel-spin 0.7s linear infinite;
}
@keyframes intel-spin { to { transform: rotate(360deg); } }
.btn-ghost {
  background: var(--surface); color: var(--t-2);
  border: 1px solid var(--line);
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-ghost:not(:disabled):hover { color: var(--acc-ink); background: var(--acc-soft); border-color: var(--acc-tint); }
.btn.is-busy { opacity: 0.65; pointer-events: none; }

/* ── (1) HERO ROW - three metric cards ───────────────────────────────────────── */
.intel-hero {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px;
}
.intel-metric {
  display: flex; align-items: flex-start; gap: 14px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 18px 18px; box-shadow: var(--shadow-sm);
  position: relative; overflow: hidden;
}
.intel-metric::before {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 4px; border-radius: 4px 0 0 4px;
}
.intel-metric-danger::before  { background: var(--red); }
.intel-metric-success::before { background: var(--green); }
.intel-metric-blue::before    { background: var(--acc); }

.im-icon {
  flex-shrink: 0; width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center;
}
.intel-metric-danger  .im-icon { background: var(--red-soft);   color: var(--red); }
.intel-metric-success .im-icon { background: var(--green-soft); color: var(--green); }
.intel-metric-blue    .im-icon { background: var(--acc-soft);   color: var(--acc); }

.im-body { min-width: 0; }
.im-label { font-size: var(--fs-12); font-weight: 700; color: var(--t-3); text-transform: uppercase; letter-spacing: 0.04em; }
.im-value { font-size: 26px; font-weight: 800; color: var(--t-1); line-height: 1.15; margin-top: 4px; letter-spacing: -0.02em; }
.im-cur { font-size: var(--fs-13); font-weight: 700; color: var(--t-3); margin-right: 2px; }
.intel-metric-danger  .im-value { color: #b91c1c; }
.intel-metric-success .im-value { color: #047857; }
.im-sub { font-size: var(--fs-12); color: var(--t-4); margin-top: 4px; }

/* ── (2) VALUE LEDGER BANNER ─────────────────────────────────────────────────── */
.intel-ledger {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow-sm); overflow: hidden;
}
.il-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px 12px;
}
.il-title { font-size: var(--fs-16); font-weight: 800; color: var(--t-1); margin: 0; letter-spacing: -0.01em; }
.il-sub { font-size: var(--fs-12); color: var(--t-3); margin: 3px 0 0; }
.il-auditable {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-11); font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--green); background: var(--green-soft);
  border: 1px solid color-mix(in srgb, var(--green) 28%, transparent);
  border-radius: 8px; padding: 5px 9px;
}
.il-buckets {
  display: grid; grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
}
.il-bucket { padding: 16px 18px; border-right: 1px solid var(--line); }
.il-bucket:last-child { border-right: 0; }
.ilb-label { font-size: var(--fs-12); font-weight: 700; color: var(--t-3); text-transform: uppercase; letter-spacing: 0.04em; }
.ilb-value { font-size: 22px; font-weight: 800; color: var(--t-1); margin-top: 4px; letter-spacing: -0.02em; }
.ilb-cur { font-size: var(--fs-12); font-weight: 700; color: var(--t-3); margin-right: 2px; }
.il-bucket-realized .ilb-value { color: #047857; }
.il-bucket-potential .ilb-value { color: var(--acc-ink); }
.il-bucket-risk .ilb-value { color: #b45309; }

/* ── Section heads (depts + findings) ───────────────────────────────────────── */
.intel-section { display: flex; flex-direction: column; gap: 12px; }
.is-head { display: flex; align-items: center; gap: 9px; }
.is-title { font-size: var(--fs-15); font-weight: 800; color: var(--t-1); margin: 0; letter-spacing: -0.01em; }
.is-count {
  min-width: 20px; height: 20px; padding: 0 6px;
  display: inline-grid; place-items: center;
  background: var(--acc-soft); color: var(--acc-ink);
  border: 1px solid var(--acc-tint); border-radius: 999px;
  font-size: var(--fs-11); font-weight: 800;
}
.intel-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 9px; padding: 30px 16px; text-align: center;
  color: var(--t-4); font-size: var(--fs-12); font-weight: 500;
  background: var(--surface); border: 1px dashed var(--line); border-radius: 14px;
}

/* ── (3) DEPARTMENT SCORECARDS ──────────────────────────────────────────────── */
.intel-dept-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px;
}
.intel-dept-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px 15px; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 8px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.intel-dept-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow-md, var(--shadow-sm)); }
.idc-head { display: flex; align-items: baseline; gap: 8px; }
.idc-name { font-size: var(--fs-14); font-weight: 700; color: var(--t-1); }
.idc-score {
  margin-left: auto; font-size: var(--fs-12); font-weight: 800; color: var(--acc-ink);
  background: var(--acc-soft); border: 1px solid var(--acc-tint);
  border-radius: 7px; padding: 2px 8px;
}
.idc-stars { display: inline-flex; gap: 2px; }
.idc-star path { fill: var(--line-strong); }
.idc-star-full path { fill: #f59e0b; }
/* Half star: keep the base path muted, overlay a clipped amber half via CSS mask. */
.idc-star-half { position: relative; }
.idc-star-half path { fill: var(--line-strong); }
.idc-star-half::after {
  content: ''; position: absolute; inset: 0; width: 50%; overflow: hidden;
  background: #f59e0b;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3.5l2.5 5.6 6.1.6-4.6 4.1 1.4 6L12 16.9 6.6 19.8l1.4-6L3.4 9.7l6.1-.6z'/%3E%3C/svg%3E") left center / 28px 14px no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3.5l2.5 5.6 6.1.6-4.6 4.1 1.4 6L12 16.9 6.6 19.8l1.4-6L3.4 9.7l6.1-.6z'/%3E%3C/svg%3E") left center / 28px 14px no-repeat;
}
.idc-issue { font-size: var(--fs-12); color: var(--t-2); line-height: 1.4; min-height: 18px; }
.idc-issue-none { color: var(--t-4); }
.idc-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.idc-chip {
  font-size: var(--fs-11); font-weight: 700; border-radius: 7px; padding: 3px 8px;
  border: 1px solid var(--line);
}
.idc-chip-danger  { color: var(--red);   background: var(--red-soft);   border-color: color-mix(in srgb, var(--red) 22%, transparent); }
.idc-chip-success { color: var(--green); background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 22%, transparent); }
.idc-chip-blue    { color: var(--acc-ink); background: var(--acc-soft); border-color: var(--acc-tint); }
.idc-chip-amber   { color: var(--amber); background: var(--amber-soft); border-color: color-mix(in srgb, var(--amber) 22%, transparent); }

/* ── (4) FINDINGS LIST ──────────────────────────────────────────────────────── */
.intel-findings { display: flex; flex-direction: column; gap: 10px; }
.intel-finding {
  display: flex; gap: 0;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow-sm); overflow: hidden;
}
.if-rail { width: 4px; flex-shrink: 0; background: var(--line-strong); }
.intel-finding-high   .if-rail { background: var(--red); }
.intel-finding-medium .if-rail { background: var(--amber); }
.intel-finding-low    .if-rail { background: var(--acc); }
.intel-finding-directional { border-style: dashed; }

.if-main { flex: 1 1 auto; min-width: 0; padding: 13px 15px; display: flex; flex-direction: column; gap: 9px; }
.if-top { display: flex; align-items: center; gap: 9px; }
.if-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: var(--t-4); }
.if-dot-high   { background: var(--red); }
.if-dot-medium { background: var(--amber); }
.if-dot-low    { background: var(--acc); }
.if-title { font-size: var(--fs-14); font-weight: 700; color: var(--t-1); line-height: 1.35; }

.if-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.if-chip {
  font-size: var(--fs-11); font-weight: 700; border-radius: 7px; padding: 3px 8px;
  border: 1px solid var(--line); color: var(--t-2); background: var(--surface-2, #fafbfd);
}
.if-chip-dept { color: var(--t-1); }
.if-chip-type-bottleneck { color: var(--acc-ink); background: var(--acc-soft); border-color: var(--acc-tint); }
.if-chip-type-leakage    { color: var(--red);   background: var(--red-soft);   border-color: color-mix(in srgb, var(--red) 22%, transparent); }
.if-chip-type-conflict   { color: var(--amber); background: var(--amber-soft); border-color: color-mix(in srgb, var(--amber) 22%, transparent); }
.if-chip-type-sla        { color: var(--amber); background: var(--amber-soft); border-color: color-mix(in srgb, var(--amber) 22%, transparent); }

.if-impact {
  font-size: var(--fs-12); font-weight: 800; border-radius: 7px; padding: 3px 9px;
  margin-left: auto;
}
.if-impact-aed   { color: #b91c1c; background: var(--red-soft); border: 1px solid color-mix(in srgb, var(--red) 22%, transparent); }
.if-impact-days  { color: var(--amber); background: var(--amber-soft); border: 1px solid color-mix(in srgb, var(--amber) 22%, transparent); }
.if-impact-count { color: var(--acc-ink); background: var(--acc-soft); border: 1px solid var(--acc-tint); }
/* Directional impact → muted, honest, never money-coloured */
.if-impact-directional,
.if-directional {
  color: var(--t-3); background: var(--surface-3, #f1f3f8); border: 1px solid var(--line-strong);
  font-size: var(--fs-11); font-weight: 700; border-radius: 7px; padding: 3px 8px;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.if-impact-directional { margin-left: auto; }

.if-actions { display: flex; align-items: center; gap: 10px; margin-top: 2px; }
.if-expander {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: 0; cursor: pointer;
  font-size: var(--fs-12); font-weight: 700; color: var(--acc-ink);
  padding: 4px 4px; border-radius: 7px;
}
.if-expander:hover { background: var(--acc-soft); }
.ife-chev { transition: transform 0.15s ease; }
.if-expander.is-open .ife-chev { transform: rotate(90deg); }
.if-action { margin-left: auto; height: 30px; font-size: var(--fs-12); }
.if-action-gated { gap: 6px; }

.if-evidence {
  border-top: 1px solid var(--line); margin-top: 4px; padding-top: 11px;
  display: flex; flex-direction: column; gap: 9px;
}
.ife-row { display: flex; align-items: baseline; gap: 10px; }
.ife-row-block { flex-direction: column; gap: 5px; }
.ife-k { font-size: var(--fs-11); font-weight: 800; color: var(--t-3); text-transform: uppercase; letter-spacing: 0.05em; flex-shrink: 0; }
.ife-cap {
  font-family: 'JetBrains Mono', monospace; font-size: var(--fs-12); font-weight: 600;
  color: var(--acc-ink); background: var(--acc-soft); border: 1px solid var(--acc-tint);
  border-radius: 6px; padding: 2px 7px;
}
.ife-json {
  font-family: 'JetBrains Mono', monospace; font-size: var(--fs-11); line-height: 1.55;
  color: var(--t-2); background: var(--surface-3, #f1f3f8); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; margin: 0; max-height: 260px; overflow: auto;
  white-space: pre; word-break: normal;
}

/* ── Confirm-gated DRAFT modal ──────────────────────────────────────────────── */
.intel-modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(15, 23, 42, 0.32);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.intel-modal {
  width: min(560px, 100%); max-height: 88vh; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; box-shadow: 0 20px 50px rgba(15, 23, 42, 0.22);
  display: flex; flex-direction: column;
}
.intel-modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 18px 12px; }
.intel-modal-title { font-size: var(--fs-16); font-weight: 800; color: var(--t-1); margin: 0; }
.intel-modal-sub { font-size: var(--fs-12); color: var(--t-3); margin: 4px 0 0; }
.intel-modal-close { margin-left: auto; width: 30px; height: 30px; padding: 0; justify-content: center; border-radius: 8px; }
.intel-gate-note {
  display: flex; gap: 9px; align-items: flex-start;
  margin: 0 18px 14px; padding: 11px 13px;
  background: var(--acc-soft); border: 1px solid var(--acc-tint); border-radius: 11px;
  color: var(--acc-ink); font-size: var(--fs-12); line-height: 1.5;
}
.intel-gate-note svg { flex-shrink: 0; margin-top: 1px; color: var(--acc); }
.intel-modal-body { padding: 0 18px 6px; overflow: auto; }
.idr-summary { font-size: var(--fs-13); color: var(--t-1); line-height: 1.5; margin-bottom: 12px; }
.idr-grid { margin: 0; display: flex; flex-direction: column; gap: 0; border: 1px solid var(--line); border-radius: 11px; overflow: hidden; }
.idr-row { display: flex; gap: 12px; padding: 9px 13px; border-bottom: 1px solid var(--line); }
.idr-row:last-child { border-bottom: 0; }
.idr-row dt { font-size: var(--fs-12); font-weight: 700; color: var(--t-3); width: 110px; flex-shrink: 0; margin: 0; }
.idr-row dd { font-size: var(--fs-13); color: var(--t-1); margin: 0; word-break: break-word; }
.idr-row dd code { font-family: 'JetBrains Mono', monospace; font-size: var(--fs-12); color: var(--acc-ink); }
.idr-no-move {
  display: flex; align-items: center; gap: 8px; margin-top: 12px;
  font-size: var(--fs-12); font-weight: 700; color: var(--green);
}
.idr-no-move svg { color: var(--green); flex-shrink: 0; }
.idr-routed {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px;
  font-size: var(--fs-12); font-weight: 650; color: var(--t-2);
}
.idr-routed-link { color: var(--acc); font-weight: 700; text-decoration: none; }
.idr-routed-link:hover { text-decoration: underline; }
/* Inline routed-to-Approvals confirmation that replaces the action button */
.if-routed {
  display: inline-flex; align-items: center; gap: 7px; margin-left: auto;
  font-size: var(--fs-12); font-weight: 650; color: var(--acc);
  background: var(--acc-soft); border: 1px solid var(--acc-tint);
  border-radius: 8px; padding: 5px 10px; max-width: 100%; flex-wrap: wrap;
}
.if-routed.fin { color: var(--amber); background: var(--amber-soft, #fef3c7); border-color: #fde68a; }
.if-routed svg { flex-shrink: 0; }
.if-routed-text { color: inherit; }
.if-routed-link { color: var(--acc); font-weight: 700; text-decoration: none; white-space: nowrap; }
.if-routed-link:hover { text-decoration: underline; }
[dir="rtl"] .if-routed { margin-left: 0; margin-right: auto; }
.intel-modal-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding: 14px 18px 18px; border-top: 1px solid var(--line); margin-top: 12px;
}

/* ── Fail-closed ────────────────────────────────────────────────────────────── */
.intel-forbidden {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 70px 20px; text-align: center;
}
.ifb-orb {
  width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center;
  background: var(--acc-soft); border: 1px solid var(--acc-tint);
}
.ifb-h { font-size: var(--fs-18); font-weight: 800; color: var(--t-1); margin: 4px 0 0; }
.ifb-p { font-size: var(--fs-13); color: var(--t-3); margin: 0 0 6px; max-width: 360px; }

/* ── Status footer ──────────────────────────────────────────────────────────── */
.intel-status-footer .sf-dot { background: var(--green); }
.intel-status-footer .sf-dot.err { background: var(--red); }

/* ── RTL niceties (mirror the swarm/desk approach) ──────────────────────────── */
[dir="rtl"] .intel-metric::before { inset: 0 0 0 auto; border-radius: 0 4px 4px 0; }
[dir="rtl"] .im-cur, [dir="rtl"] .ilb-cur { margin-right: 0; margin-left: 2px; }
[dir="rtl"] .il-auditable { margin-left: 0; margin-right: auto; }
[dir="rtl"] .idc-score { margin-left: 0; margin-right: auto; }
[dir="rtl"] .if-impact, [dir="rtl"] .if-impact-directional { margin-left: 0; margin-right: auto; }
[dir="rtl"] .if-action { margin-left: 0; margin-right: auto; }
[dir="rtl"] .intel-modal-close { margin-left: 0; margin-right: auto; }
[dir="rtl"] .if-expander.is-open .ife-chev { transform: rotate(-90deg); }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 820px) {
  .intel-hero { grid-template-columns: 1fr; }
  .il-buckets { grid-template-columns: 1fr; }
  .il-bucket { border-right: 0; border-bottom: 1px solid var(--line); }
  .il-bucket:last-child { border-bottom: 0; }
}
