/* ============================================================================
 * O2C Recon — Theme & Components  (styles.css)
 * Dark mode is the DEFAULT (tokens on :root). Light mode is applied when
 * <html data-theme="light"> is set by the toggle. All colours are driven by
 * CSS variables so the theme switch is instant and complete.
 * ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ---- LIGHT (default) — crisp, airy slate + indigo --------------------------- */
:root {
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  --app:        #f8fafc;   /* main workspace canvas (alabaster) */
  --elev:       #f1f5f9;   /* left sidebar / header             */
  --surface:    #ffffff;   /* KPI & data cards                  */
  --surface-2:  #f1f5f9;   /* inset panels / table head         */
  --line:       #e2e8f0;   /* borders                           */
  --line-strong:#cbd5e1;

  --ink:        #0f172a;   /* primary text / bold figures       */
  --sub:        #475569;   /* secondary text                    */
  --faint:      #64748b;   /* micro muted labels                */

  --brand:      #6366f1;   /* indigo accent                     */
  --brand-ink:  #4338ca;
  --brand-soft: #eef2ff;   /* RESULT card surface               */
  --brand-line: #a5b4fc;   /* RESULT card border                */

  --blue:       #2563eb;   /* cobalt progress bars              */
  --pos:        #16a34a;
  --pos-soft:   #dcfce7;
  --neg:        #ef4444;   /* coral — overdue / risk            */
  --neg-soft:   #fee2e2;
  --warn:       #d97706;
  --warn-soft:  #fef3c7;

  --shadow:     0 1px 2px rgba(15,23,42,0.05);
  --heat:       99, 102, 241;   /* indigo rgb for heatmap shading */
}

/* ---- DARK (matte obsidian-charcoal) --------------------------------------- */
:root[data-theme="dark"] {
  --app:        #0e1015;   /* deep matte obsidian canvas */
  --elev:       #12141c;   /* sidebar / header           */
  --surface:    #161922;   /* cards                      */
  --surface-2:  #13161f;   /* table head / inset         */
  --line:       #1f2430;   /* dividers / borders         */
  --line-strong:#2e3545;   /* input / strong borders     */

  --ink:        #f8fafc;
  --sub:        #94a3b8;
  --faint:      #8b95a5;

  --brand:      #60a5fa;   /* active icon accent         */
  --brand-ink:  #818cf8;   /* result / pill text         */
  --brand-soft: #1e243b;   /* indigo soft fill (results, pills, active) */
  --brand-line: #3b4371;   /* indigo border              */

  --blue:       #3b82f6;   /* cobalt progress bars       */
  --pos:        #34d399;
  --pos-soft:   rgba(52, 211, 153, 0.15);
  --neg:        #f87171;
  --neg-soft:   rgba(248, 113, 113, 0.16);
  --warn:       #fbbf24;
  --warn-soft:  rgba(251, 191, 36, 0.15);

  --shadow:     0 1px 2px rgba(0,0,0,0.5), 0 1px 3px rgba(0,0,0,0.35);
  --heat:       129, 140, 248;
}
/* Dark-only fine surface tweaks (match screenshot exactly) */
:root[data-theme="dark"] .bar-bg { background-color: #222736; }
:root[data-theme="dark"] .tbl tbody tr:hover { background-color: #1b202c; }
:root[data-theme="dark"] .field { background-color: #181c26; }
:root[data-theme="dark"] #btn-theme { background-color: #1e222d; border-color: #2e3545; }
:root[data-theme="dark"] .pill-result { background-color: #252b4d; }

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { background-color: var(--app); }
body {
  font-family: var(--font-family);
  color: var(--ink);
  min-height: 100vh;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
}

/* ---- Layout -------------------------------------------------------------- */
.app-sidebar {
  width: 222px; background-color: var(--elev); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 30; overflow-y: auto;
}
.app-main { margin-left: 222px; min-height: 100vh; display: flex; flex-direction: column; }
@media (max-width: 860px) {
  .app-sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .app-sidebar.open { transform: translateX(0); }
  .app-main { margin-left: 0; }
}

/* ---- Cards & primitives -------------------------------------------------- */
.card {
  background-color: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow);
}
.op-circle {
  width: 22px; height: 22px; border-radius: 50%; background-color: var(--surface-2);
  border: 1px solid var(--line-strong); color: var(--sub);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; line-height: 1; flex-shrink: 0;
}
.result-box {
  background-color: var(--brand-soft); border: 1px solid var(--brand-line);
  border-radius: 8px; padding: 6px 14px;
}
.pill-result {
  background-color: var(--brand-soft); color: var(--brand-ink); font-size: 9px; font-weight: 700;
  padding: 1px 5px; border-radius: 4px; text-transform: uppercase; letter-spacing: .05em; margin-left: 6px;
}

/* ---- Sidebar nav --------------------------------------------------------- */
.sidebar-category {
  font-size: 10px; font-weight: 700; color: var(--faint); text-transform: uppercase; letter-spacing: .05em;
  padding: 14px 14px 4px; display: flex; align-items: center; justify-content: space-between; cursor: pointer;
}
.sidebar-category:hover { color: var(--sub); }
.sidebar-category.active-channel { color: var(--brand-ink); }
.sidebar-category .cat-chevron { transition: transform .2s ease; }

/* Executive Overview top-level nav item */
.exec-nav-item {
  display: flex; align-items: center; gap: 9px; margin: 8px 8px 4px; padding: 8px 10px;
  border-radius: 8px; cursor: pointer; color: var(--sub); border: 1px solid var(--line);
  background: var(--surface); transition: all .12s ease;
}
.exec-nav-item:hover { color: var(--ink); border-color: var(--brand-line); }
.exec-nav-item.active { background: var(--brand-soft); border-color: var(--brand-line); color: var(--ink); }
.exec-nav-item.active .ico { color: var(--brand); }

/* Collapsible channel accordion (open by default, smooth transition) */
.channel-links { overflow: hidden; max-height: 360px; transition: max-height .25s ease, opacity .2s ease; }
.channel-group.collapsed .channel-links { max-height: 0; opacity: 0; }
.sidebar-nav-link {
  display: flex; align-items: center; gap: 9px; padding: 6px 14px; font-size: 12.5px; color: var(--sub);
  text-decoration: none; font-weight: 500; border-radius: 7px; margin: 1px 8px; transition: all .12s ease; cursor: pointer;
}
.sidebar-nav-link:hover { background-color: var(--surface-2); color: var(--ink); }
.sidebar-nav-link.active { background-color: var(--brand-soft); color: var(--ink); font-weight: 600; }
.sidebar-nav-link.active .ico { color: var(--brand); }
.ico { width: 15px; height: 15px; flex-shrink: 0; color: var(--faint); display: inline-flex; }
.ico svg { width: 100%; height: 100%; }

/* ---- Filter pills & sub-tabs --------------------------------------------- */
.period-pill {
  padding: 3px 9px; font-size: 11px; font-weight: 500; color: var(--sub); background-color: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 6px; cursor: pointer; transition: all .12s ease;
}
.period-pill:hover { background-color: var(--surface-2); color: var(--ink); }
.period-pill.active { background-color: var(--brand); color: #fff; border-color: var(--brand); font-weight: 600; }

.sub-tab-btn {
  padding: 6px 12px; font-size: 12px; font-weight: 500; color: var(--faint);
  border-bottom: 2px solid transparent; cursor: pointer; transition: all .12s ease; background: none;
}
.sub-tab-btn:hover { color: var(--ink); }
.sub-tab-btn.active { color: var(--ink); font-weight: 600; border-bottom-color: var(--brand); }

/* ---- Inputs / selects / buttons ------------------------------------------ */
.field {
  background-color: var(--surface); border: 1px solid var(--line-strong); border-radius: 6px;
  font-size: 11.5px; color: var(--ink); padding: 4px 10px; outline: none;
}
.field::placeholder { color: var(--faint); }
.field:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(59,130,246,.2); }
select.field { cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600;
  padding: 6px 12px; border-radius: 7px; cursor: pointer; border: 1px solid transparent; transition: all .12s ease;
}
.btn-primary { background-color: var(--blue); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-brand { background-color: var(--brand); color: #fff; }
.btn-brand:hover { filter: brightness(1.08); }
.btn-ghost { background-color: var(--surface); color: var(--sub); border-color: var(--line-strong); }
.btn-ghost:hover { background-color: var(--surface-2); color: var(--ink); }
.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 500; color: var(--sub);
  border: 1px solid var(--line-strong); background-color: var(--surface); border-radius: 999px; padding: 3px 10px; cursor: pointer;
}
.chip:hover { color: var(--ink); border-color: var(--brand-line); }

/* ---- Tables -------------------------------------------------------------- */
.tbl { width: 100%; text-align: left; border-collapse: collapse; font-size: 12px; }
.tbl thead { background-color: var(--surface-2); color: var(--sub); }
.tbl thead th { padding: 7px 8px; font-size: 10px; text-transform: uppercase; font-weight: 600; letter-spacing: .03em; border-bottom: 1px solid var(--line); }
.tbl tbody td { padding: 7px 8px; border-bottom: 1px solid var(--line); color: var(--ink); }
.tbl tbody tr:hover { background-color: var(--surface-2); }
.tbl tbody tr.is-total td { background-color: var(--surface-2); font-weight: 700; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }

/* ---- Status badges ------------------------------------------------------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-recon      { background: var(--pos-soft);  color: var(--pos); }
.badge-tolerance  { background: var(--brand-soft); color: var(--brand-ink); }
.badge-pending    { background: var(--warn-soft); color: var(--warn); }
.badge-return     { background: rgba(59,130,246,.14); color: var(--blue); }
.badge-exception  { background: var(--neg-soft);  color: var(--neg); }
.badge-soft       { background: var(--surface-2); color: var(--sub); border: 1px solid var(--line); }

/* ---- Progress bars ------------------------------------------------------- */
.bar-bg { background-color: var(--line); border-radius: 999px; height: 6px; overflow: hidden; }
.bar-fill { background-color: var(--blue); height: 100%; border-radius: 999px; }   /* cobalt */
.bar-fill.bar-neg { background-color: var(--neg); }                                /* coral — overdue/risk */

/* ---- Heatmap cells (Category x Reason) ----------------------------------- */
.heat-1 { background-color: rgba(var(--heat), .10); }
.heat-2 { background-color: rgba(var(--heat), .22); font-weight: 600; }
.heat-3 { background-color: rgba(var(--heat), .40); font-weight: 700; }
.heat-rate { background-color: rgba(var(--heat), .28); font-weight: 600; color: var(--brand-ink); }

/* ---- P&L % heatmap ------------------------------------------------------- */
.pnl-danger  { background-color: var(--neg-soft); color: var(--neg); font-weight: 600; }
.pnl-safe    { background-color: var(--pos-soft); color: var(--pos); font-weight: 500; }
.pnl-neutral { background-color: var(--warn-soft); color: var(--warn); }

/* ---- Modal drawer -------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; background-color: rgba(0,0,0,.5); backdrop-filter: blur(2px);
  z-index: 50; opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.modal-backdrop.active { opacity: 1; pointer-events: auto; }
.modal-drawer {
  position: fixed; inset: 0 0 0 auto; width: 100%; max-width: 640px; background-color: var(--surface);
  border-left: 1px solid var(--line); z-index: 51; transform: translateX(100%);
  transition: transform .25s cubic-bezier(.16,1,.3,1); overflow-y: auto; box-shadow: -8px 0 24px rgba(0,0,0,.35);
}
.modal-backdrop.active .modal-drawer { transform: translateX(0); }

/* ---- Portfolio banner ---------------------------------------------------- */
.demo-banner {
  display: flex; align-items: center; gap: 8px; justify-content: center; text-align: center;
  background: var(--brand-soft); color: var(--brand-ink); border-bottom: 1px solid var(--brand-line);
  font-size: 11px; font-weight: 500; padding: 5px 14px;
}
.demo-footer { color: var(--faint); font-size: 10.5px; text-align: center; padding: 18px 10px 26px; }

/* ---- Filter bar (timeline pills + calendar + dropdowns) ------------------ */
.filterbar { display: flex; flex-direction: column; gap: 10px; }
.pillbar { display: flex; flex-wrap: wrap; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
:root[data-theme="dark"] .pillbar { background: #141418; }
.pillbar .seg { padding: 4px 10px; font-size: 11px; font-weight: 600; color: var(--sub); border-radius: 7px; cursor: pointer; border: none; background: transparent; transition: all .12s ease; }
.pillbar .seg:hover { color: var(--ink); }
.pillbar .seg.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.fb-row2 { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.fb-label { font-size: 10px; font-weight: 700; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; }
.date-field { position: relative; }
.date-field input { padding-right: 28px; }
.date-field .cal-ic { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 13px; height: 13px; color: var(--faint); pointer-events: none; }
input[type="date"].field::-webkit-calendar-picker-indicator { filter: var(--cal-filter, none); opacity: .7; cursor: pointer; }
:root[data-theme="dark"] { --cal-filter: invert(1) brightness(1.4); }

/* ---- Segmented metric switcher ------------------------------------------- */
.segswitch { display: inline-flex; gap: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 3px; }
.segswitch button { padding: 4px 9px; font-size: 10.5px; font-weight: 600; color: var(--sub); border: none; background: transparent; border-radius: 6px; cursor: pointer; transition: all .12s ease; }
.segswitch button:hover { color: var(--ink); }
.segswitch button.active { background: var(--brand); color: #fff; }

/* ---- Trend legend pills --------------------------------------------------- */
.legendpills { display: flex; flex-wrap: wrap; gap: 8px; }
.legpill { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; color: var(--ink); border: 1px solid var(--line-strong); background: var(--surface); border-radius: 999px; padding: 4px 11px; cursor: pointer; transition: all .12s ease; user-select: none; }
.legpill:hover { border-color: var(--brand-line); }
.legpill .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.legpill .val { color: var(--sub); font-weight: 500; font-variant-numeric: tabular-nums; }
.legpill.off { opacity: .42; }
.legpill.off .val { text-decoration: line-through; }
.trend-cap { font-size: 10.5px; color: var(--faint); line-height: 1.5; }

/* ---- Utility ------------------------------------------------------------- */
.view-panel.hidden, .hidden { display: none !important; }
.text-pos { color: var(--pos); } .text-neg { color: var(--neg); } .text-warn { color: var(--warn); }
.text-brand { color: var(--brand-ink); } .text-sub { color: var(--sub); } .text-faint { color: var(--faint); }
.scrollbar-thin::-webkit-scrollbar { height: 8px; width: 8px; }
.scrollbar-thin::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 8px; }

/* ---- Orders reconciliation strip ---------------------------------------- */
.recon-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); }
.recon-cell { padding: 10px 12px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.recon-lbl { font-size: 9.5px; font-weight: 700; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.recon-val { font-size: 15px; font-weight: 700; color: var(--ink); margin-top: 2px; white-space: nowrap; }

/* ---- Status filter pills ------------------------------------------------- */
.status-pillbar { display: flex; gap: 6px; flex-wrap: wrap; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--sub); font-size: 11.5px; font-weight: 600; cursor: pointer; transition: all .12s; }
.status-pill:hover { border-color: var(--brand); color: var(--ink); }
.status-pill.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.status-pill .pill-count { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: var(--surface-2); color: var(--faint); }
.status-pill.active .pill-count { background: rgba(255,255,255,.22); color: #fff; }

/* ---- Sortable table headers --------------------------------------------- */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--brand-ink); }
th.sortable[data-dir]:not([data-dir=""])::after { content: " " attr(data-dir); color: var(--brand-ink); font-size: 9px; }
th.sort-on { color: var(--brand-ink); }
.sku-tbl tfoot .is-total td { border-top: 2px solid var(--brand); background: var(--surface-2); }
