/* Embrace Finance Portal — professional, investor-grade.
   Keep colors restrained, plenty of whitespace, sans-serif. */

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

:root {
  --bg:        #f5f7fa;
  --surface:   #ffffff;
  --border:    #e3e8ef;
  --text:      #1a2238;
  --muted:     #677489;
  --primary:   #1a237e;
  --primary-h: #283593;
  --accent:    #00897b;
  --danger:    #c62828;
  --warning:   #ef6c00;
  --success:   #2e7d32;
  --sidebar:   #1a2238;
  --sidebar-h: #2a3553;
}

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.view { display: block; }
.view[hidden] { display: none !important; }

/* ============ LOGIN ============ */

#login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a237e 0%, #283593 100%);
}
.login-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 40px 36px;
  width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  text-align: center;
}
.login-card .login-logo { max-width: 220px; height: auto; margin-bottom: 16px; }
.login-card h1 { font-size: 20px; font-weight: 600; margin-bottom: 6px; color: var(--primary); }
.login-card .sub { color: var(--muted); margin-bottom: 26px; }
.login-card form { text-align: left; }
.login-card label { display: block; font-size: 12px; color: var(--muted); margin-top: 14px; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.login-card input {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--primary); }
.login-card button {
  width: 100%; margin-top: 24px;
  padding: 12px;
  background: var(--primary); color: #fff;
  border: none; border-radius: 6px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.login-card button:hover { background: var(--primary-h); }
.login-card .err {
  margin-top: 16px; padding: 10px;
  background: #fde7e7; color: var(--danger);
  border-radius: 6px; font-size: 13px;
}

/* ============ APP SHELL ============ */

#app { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: var(--sidebar);
  color: #c8d2e6;
  display: flex; flex-direction: column;
  padding: 0;
  flex-shrink: 0;
  /* Sticky: stays in view as the main content scrolls. Pinned at top of
     viewport; the sidebar itself scrolls internally if it ever exceeds the
     viewport height (e.g. when the BU picker is open with all 13 BUs). */
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  padding: 14px 22px 12px;
  border-bottom: 1px solid var(--sidebar-h);
  text-align: center;
}
.sidebar .brand .brand-logo { max-width: 110px; height: auto; display: block; margin: 0 auto 4px; }
.sidebar .brand .brand-sub  { font-size: 11px; color: #c8d2e6; text-transform: uppercase; letter-spacing: 1px; font-weight: 500; }

.sidebar-filter {
  padding: 10px 22px;
  border-bottom: 1px solid var(--sidebar-h);
}
.sidebar-filter label {
  display: block;
  font-size: 10px; color: #c8d2e6;
  text-transform: uppercase; letter-spacing: 0.6px;
  margin-bottom: 4px;
}
.sidebar-filter select {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--sidebar-h);
  background: #2a3553;
  color: #fff;
  border-radius: 5px;
  font-size: 13px;
}
.sidebar-filter select:focus { outline: none; border-color: var(--accent); }
.sidebar-filter select option { background: var(--surface); color: var(--text); }
.sidebar-filter select optgroup { background: #f0f4ff; color: var(--text); font-style: normal; font-weight: 600; }

.sidebar nav { flex: 1; padding: 6px 0; }
.sidebar .nav-link {
  display: block;
  padding: 7px 22px;
  color: #c8d2e6;
  text-decoration: none;
  font-size: 13px;
  border-left: 3px solid transparent;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.sidebar .nav-link:hover { background: var(--sidebar-h); color: #fff; }
.sidebar .nav-link.active {
  background: var(--sidebar-h);
  color: #fff;
  border-left-color: var(--accent);
  font-weight: 600;
}

/* Per-sub logo shown below the picker. White pill background so dark-on-light
   logos remain readable on the navy sidebar. Hidden until a sub is selected. */
.sub-logo-wrap {
  margin-top: 8px;
  background: #fff;
  border-radius: 5px;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
}
.sub-logo-wrap img { max-width: 100%; max-height: 28px; height: auto; display: block; }
/* Aggregate-selection badge: replaces the per-BU image with a text label
   ("Embrace" / "Industrial" / etc.) using the same pill chrome. Hide the
   inner img entirely so no broken-image icon leaks through. */
.sub-logo-wrap.agg { background: var(--primary); color: #fff; font-weight: 700; font-size: 16px; letter-spacing: 0.5px; }
.sub-logo-wrap.agg img { display: none !important; }
.sub-logo-wrap.agg::before { content: attr(data-label); }

.user-box {
  padding: 10px 22px;
  border-top: 1px solid var(--sidebar-h);
  font-size: 11px;
}
.user-email { color: #fff; font-weight: 500; word-break: break-all; }
.user-role  { color: var(--muted); margin-top: 1px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; }
.user-box .logout {
  margin-top: 8px; width: 100%;
  padding: 6px;
  background: transparent; color: #c8d2e6;
  border: 1px solid var(--sidebar-h);
  border-radius: 4px;
  cursor: pointer; font-size: 11px;
}
.user-box .logout:hover { background: var(--sidebar-h); color: #fff; }

.main { flex: 1; padding: 0; min-width: 0; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; z-index: 10;
}
.topbar-title { font-size: 16px; font-weight: 600; color: var(--text); }
.topbar-sub { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; flex: 1; }
.topbar-sub-label    { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }
.topbar-sub-name     { font-size: 18px; font-weight: 700; color: var(--primary); margin-top: 2px; }
.topbar-sub-vertical { font-size: 11px; color: var(--muted); margin-top: 1px; }
.meta { color: var(--muted); font-size: 12px; }

/* ============ DIAGNOSIS BOX (top of AR Trend) ============ */

.diag-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 14px 18px;
  margin-bottom: 18px;
}
.diag-box.warn    { border-left-color: var(--warning); }
.diag-box.danger  { border-left-color: var(--danger); }
.diag-box.success { border-left-color: var(--success); }
/* AI Commentary header pill — colored amber badge so readers always see this
   is AI-generated narrative, not ground truth. The amber "caution" tone is
   intentional: nudges the reader to verify before acting on the narrative. */
.diag-label {
  display: inline-block;
  font-size: 11px;
  color: #6b4d00;
  background: #fff3cd;
  border: 1px solid #ffe69c;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 6px;
}
.diag-title { font-size: 16px; font-weight: 700; margin-top: 4px; color: var(--text); }
.diag-explain { font-size: 13px; color: #444; margin-top: 6px; line-height: 1.5; }
.diag-deltas { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 16px; font-size: 12px; }
.diag-delta { color: var(--muted); }
.diag-delta b { color: var(--text); font-weight: 600; }
.diag-delta.up      b { color: var(--danger);  }   /* days getting worse */
.diag-delta.up.good b { color: var(--success); }   /* days getting better when up = good */
.diag-delta.down    b { color: var(--success); }   /* days getting better when down = good */
.diag-delta.flat    b { color: var(--muted); }

.diag-bullets { margin: 12px 0 0 18px; padding: 0; font-size: 13px; color: #444; line-height: 1.55; }
.diag-bullets li { margin: 2px 0; }
.diag-bullets b.risk { color: var(--danger); }
.diag-bullets b.warn { color: var(--warning); }
.diag-bullets b.good { color: var(--success); }
.diag-bullets b.bad  { color: var(--danger); }

/* ============ METRIC DEFINITIONS (bottom of AR Trend) ============ */

.metric-defs {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  margin-top: 24px;
}
.metric-defs > summary {
  font-size: 13px; font-weight: 600;
  color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  cursor: pointer;
  list-style: none;
}
.metric-defs > summary::-webkit-details-marker { display: none; }
.metric-defs > summary::before { content: '▸ '; color: var(--primary); display: inline-block; transition: transform 0.15s; }
.metric-defs[open] > summary::before { content: '▾ '; }
.metric-defs dl { margin-top: 14px; }
.metric-defs dt {
  font-weight: 700; color: var(--primary);
  margin-top: 14px;
  font-size: 13px;
}
.metric-defs dt:first-child { margin-top: 0; }
.metric-defs dd { margin: 4px 0 0 0; font-size: 13px; color: #444; line-height: 1.5; }
.metric-defs dd b { color: var(--text); font-weight: 600; }
.metric-defs dd code { background: #f5f7fa; padding: 1px 5px; border-radius: 3px; font-size: 12px; font-family: 'SF Mono', Menlo, Consolas, monospace; }

.page { padding: 24px 28px; max-width: 1400px; min-width: 0; }
/* Wide tables (Profitability Monthly Detail, Recurring LTM matrix) shouldn't
   push the page layout sideways — they scroll inside their own bordered
   container. Keeps every tab the same outer width as Dashboard. */
.pm-wrap { overflow-x: auto; }
.loading { color: var(--muted); padding: 40px; text-align: center; }

.section-h {
  font-size: 13px; font-weight: 600;
  color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.6px;
  margin: 28px 0 12px 0;
}
.section-h:first-child { margin-top: 0; }

/* ============ TILES ============ */

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.tile-grid.tiles-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); max-width: 700px; }
.tile-grid.tiles-3 { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); max-width: 1100px; }
.tile-grid.tiles-4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.tile-grid.tiles-5 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
@media (min-width: 1000px) {
  .tile-grid.tiles-5 { grid-template-columns: repeat(5, 1fr); }
  .tile-grid.tiles-4 { grid-template-columns: repeat(4, 1fr); }
  .tile-grid.tiles-3 { grid-template-columns: repeat(3, 1fr); }
  .tile-grid.tiles-2 { grid-template-columns: repeat(2, 1fr); }
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}
.tile .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.tile .value { font-size: 24px; font-weight: 700; margin-top: 6px; color: var(--text); }
.tile .sub   { font-size: 11px; color: var(--muted); margin-top: 4px; }
.tile.danger  .value { color: var(--danger); }
.tile.warning .value { color: var(--warning); }
.tile.success .value { color: var(--success); }
.tile.primary .value { color: var(--primary); }

/* ============ CHARTS ============ */

.chart-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  height: 320px;
}
.chart-wrap.big { height: 420px; }

/* ============ TABLES ============ */

.data-table {
  width: 100%;
  background: var(--surface);
  border-collapse: collapse;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  font-size: 13px;
  margin-top: 8px;
}
.data-table th {
  background: #f8fafc;
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.4px;
}
.data-table td {
  padding: 9px 14px;
  border-bottom: 1px solid #eef1f5;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ============ PAGE HEAD (refresh button + status) ============ */

.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.page-head-actions { display: flex; align-items: center; gap: 12px; }
.refresh-status { font-size: 12px; color: var(--muted); }
.refresh-status .who { color: var(--text); font-weight: 500; }
.refresh-status .when { color: var(--muted); }
.refresh-status.running { color: var(--warning); }
.refresh-btn {
  background: var(--primary); color: #fff;
  border: none; border-radius: 5px;
  padding: 7px 14px;
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.refresh-btn:hover { background: var(--primary-h); }
.refresh-btn:disabled { background: #b0b8c8; cursor: not-allowed; }

/* ============ CASHFLOW PAGE ============ */

.page-note { color: var(--muted); font-size: 13px; margin: -6px 0 14px 0; }

.cf-table {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.cf-table thead th {
  background: #f8fafc;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-size: 11px;
  padding: 10px 14px;
  border-bottom: 2px solid var(--border);
  text-align: left;
}
.cf-table thead th.num { text-align: right; }
.cf-table th.col-ytd, .cf-table td.col-ytd { background: #f0f4ff; font-weight: 700; }
.cf-table td { padding: 8px 14px; border-bottom: 1px solid #eef1f5; }
.cf-table td.num { text-align: right; }
.cf-table tr.section-header td {
  background: var(--primary); color: #fff;
  font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px;
  padding: 7px 14px;
}
.cf-table tr.cat-row td.cat-name { padding-left: 26px; color: #333; }
.cf-table tr.subtotal-row td { background: #eef3fb; font-weight: 700; color: var(--primary); border-top: 2px solid var(--primary); }
.cf-table tr.net-row td { background: #1a237e; color: #fff; font-weight: 800; font-size: 14px; padding: 11px 14px; }
.section-sub { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 6px; }

/* WIP badge inside nav links — marks tabs that aren't built yet */
.nav-link .nav-badge {
  display: inline-block;
  font-size: 9px;
  background: #ff9800;
  color: #fff;
  padding: 1px 6px;
  border-radius: 999px;
  margin-left: 6px;
  font-weight: 700;
  letter-spacing: 0.5px;
  vertical-align: middle;
}
/* Honor the [hidden] attribute — explicit display rule above would otherwise
   override the UA default `display: none`, leaving the badge visible even
   when JS tries to hide it. */
.nav-link .nav-badge[hidden] { display: none; }
/* Under-construction placeholder block (Sales + Support tabs) */
.wip-block {
  background: var(--surface);
  border: 2px dashed #ff9800;
  border-radius: 12px;
  padding: 48px 32px;
  text-align: center;
  max-width: 640px;
  margin: 48px auto;
}
.wip-icon { font-size: 56px; margin-bottom: 12px; }
.wip-title { font-size: 22px; font-weight: 700; color: var(--primary); margin-bottom: 12px; }
.wip-sub { font-size: 14px; color: #555; line-height: 1.55; margin-bottom: 24px; }
.wip-sub code { background: #f0f4ff; padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.wip-list {
  text-align: left;
  display: inline-block;
  margin: 0 auto;
  padding-left: 20px;
  font-size: 13px;
  color: #444;
  line-height: 1.7;
}
.wip-list li { margin: 4px 0; }

/* Sales tab status chips (Bellwether HubSpot view) */
.sales-chip {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: #eef1f5;
  color: #555;
  margin-right: 6px;
  margin-bottom: 6px;
}
.sales-chip.good { background: #e8f5e9; color: #1b5e20; }
.sales-chip.warn { background: #fff8e1; color: #6b4d00; }
.sales-chip.bad  { background: #ffebee; color: #b71c1c; }
.sales-chip b { color: var(--text); font-weight: 700; margin-right: 4px; }

/* Zoho Opportunities row tinting — mirrors generate_isl_ar.js Opportunities tab */
.data-table tr.opp-needs-inv td { background: #ffebee; }
.data-table tr.opp-paid td       { background: #e8f5e9; }
.data-table tr.opp-lost td       { background: #fff8e1; color: #6b4d00; }

/* Per-section data-source note — rendered as a `?` icon next to the section
   heading that pops a tooltip bubble on hover. Replaces the inline block
   variant so source info is available but not visually noisy. */
.src-help {
  display: inline-block;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #e0e3eb;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  line-height: 16px;
  margin-left: 8px;
  cursor: help;
  font-weight: 600;
  position: relative;
  vertical-align: middle;
  transition: background 0.15s, color 0.15s;
  /* Reset inherited text-transform/letter-spacing from section-h */
  text-transform: none;
  letter-spacing: normal;
}
.src-help:hover { background: var(--primary); color: #fff; }
.src-help:hover::after {
  content: attr(data-src);
  position: absolute;
  left: 26px;
  top: -6px;
  background: #2a2a35;
  color: #fff;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-style: normal;
  font-weight: 400;
  line-height: 1.5;
  width: 380px;
  max-width: 380px;
  z-index: 1000;
  box-shadow: 0 4px 14px rgba(0,0,0,0.22);
  white-space: normal;
  pointer-events: none;
}
.src-help:hover::before {
  content: '';
  position: absolute;
  left: 18px;
  top: 4px;
  border: 7px solid transparent;
  border-right-color: #2a2a35;
  z-index: 1001;
  pointer-events: none;
}

/* Legacy class kept as alias in case any inline notes remain — hide them. */
.section-src { display: none; }

/* Dashboard insight cards — 2x2 grid summarizing one tab each. Each card is
   a clickable navigation link styled with a colored left border by severity
   (success / warn / danger / neutral) — the user can read the whole dashboard
   at a glance and click in for detail. */
.insight-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 14px; }
.insight-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 14px 18px;
  text-decoration: none;
  color: inherit;
  display: flex; flex-direction: column; gap: 6px;
  transition: transform 0.1s, box-shadow 0.1s;
  cursor: pointer;
}
.insight-card:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.insight-card.success { border-left-color: var(--success); }
.insight-card.warn    { border-left-color: var(--warning); }
.insight-card.danger  { border-left-color: var(--danger); }
.insight-card.neutral { border-left-color: var(--muted); }
.insight-header { display: flex; justify-content: space-between; align-items: center; }
.insight-tab { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; font-weight: 600; }
.insight-icon { font-size: 18px; }
.insight-headline { font-size: 16px; font-weight: 600; color: var(--text); line-height: 1.35; }
.insight-headline b { color: var(--primary); font-weight: 700; }
.insight-body { font-size: 13px; color: #555; line-height: 1.45; }
.insight-footer { font-size: 11px; color: var(--primary); margin-top: 4px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.4px; }

/* Collapsible wrapper around the Profitability monthly detail. Click summary
   to expand/close — the table is large, summary tiles above are usually
   enough. */
.pm-wrap { margin-top: 18px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.pm-wrap > .pm-summary { cursor: pointer; padding: 12px 16px; font-size: 14px; font-weight: 600; color: var(--primary); user-select: none; list-style: none; }
.pm-wrap > .pm-summary::-webkit-details-marker { display: none; }
.pm-wrap > .pm-summary::before { content: '▶ '; display: inline-block; transition: transform 0.15s; color: var(--muted); margin-right: 4px; }
.pm-wrap[open] > .pm-summary::before { transform: rotate(90deg); }
.pm-wrap[open] > .pm-summary { border-bottom: 1px solid var(--border); }

/* Profitability monthly P&L table — wide layout with N actual month columns
   on the left and YTD/Annualized/FY comparisons on the right. Inside the
   collapsible wrapper above. */
.pm-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 0; background: var(--surface); }
.pm-table td.num.neg { color: var(--danger); }
.pm-table thead th { background: #f5f6fa; color: #455a64; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: right; font-weight: 600; }
.pm-table thead th.lbl { text-align: left; min-width: 220px; }
.pm-table thead th.grp-start { border-left: 2px solid #cfd8dc; }
.pm-table td { padding: 6px 10px; border-bottom: 1px solid #eef1f5; }
.pm-table td.lbl { color: #444; font-weight: 500; }
.pm-table td.num { text-align: right; font-variant-numeric: tabular-nums; color: #333; }
.pm-table tr.pm-section td { background: #e8eaf6; color: var(--primary); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; padding: 6px 12px; }
/* Subgroup header row — click to expand its account-level children. */
.pm-table tr.pm-subgroup { cursor: pointer; }
.pm-table tr.pm-subgroup td { background: #fafbfd; font-weight: 600; color: #333; border-top: 1px solid #eef1f5; }
.pm-table tr.pm-subgroup:hover td { background: #f0f4ff; }
.pm-table tr.pm-subgroup td.lbl { padding-left: 16px; }
.pm-table tr.pm-subgroup .pm-caret { display: inline-block; font-size: 9px; color: var(--muted); margin-right: 6px; transition: transform 0.15s; }
.pm-table tr.pm-subgroup.open .pm-caret { transform: rotate(90deg); }
.pm-table tr.pm-row td.lbl { padding-left: 42px; color: #666; font-weight: 400; font-size: 11px; }
.pm-table tr.pm-row td { background: #fff; color: #666; font-size: 11px; }
.pm-table tr.pm-subtotal td { background: #f0f4ff; font-weight: 700; color: var(--primary); border-top: 1px solid var(--primary); }

/* Variance cell shading — 6 bands: ≤10%, ≤20%, ≤30%, ≤40%, ≤50%, >50%.
   Green for positive variance (actual > budget), red for negative. The
   .var-cell class is included in every selector to bump specificity above
   the row-level background rules (.pm-row td, .pm-subgroup td, etc.) which
   would otherwise win and paint the cell white. */
.pm-table td.var-cell { transition: background 0.15s; }
.pm-table td.var-cell.var-pos-10  { background: #e8f5e9; }
.pm-table td.var-cell.var-pos-20  { background: #c8e6c9; }
.pm-table td.var-cell.var-pos-30  { background: #a5d6a7; }
.pm-table td.var-cell.var-pos-40  { background: #81c784; }
.pm-table td.var-cell.var-pos-50  { background: #66bb6a; }
.pm-table td.var-cell.var-pos-50p { background: #43a047; }
.pm-table td.var-cell.var-neg-10  { background: #ffebee; }
.pm-table td.var-cell.var-neg-20  { background: #ffcdd2; }
.pm-table td.var-cell.var-neg-30  { background: #ef9a9a; }
.pm-table td.var-cell.var-neg-40  { background: #e57373; }
.pm-table td.var-cell.var-neg-50  { background: #ef5350; }
.pm-table td.var-cell.var-neg-50p { background: #d32f2f; }
/* On darker shades, deepen delta text color (or invert to white on the
   darkest band) so the value stays readable. */
.pm-table td.var-cell.var-pos-40 .delta,
.pm-table td.var-cell.var-pos-50 .delta  { color: #1b5e20; font-weight: 700; }
.pm-table td.var-cell.var-pos-50p .delta { color: #fff;    font-weight: 700; }
.pm-table td.var-cell.var-neg-40 .delta,
.pm-table td.var-cell.var-neg-50 .delta  { color: #b71c1c; font-weight: 700; }
.pm-table td.var-cell.var-neg-50p .delta { color: #fff;    font-weight: 700; }

.pm-table tr.pm-ebitda td { background: var(--primary); color: #fff; font-weight: 800; font-size: 13px; padding: 10px; }
.pm-table tr.pm-ebitda td .delta.pos { color: #b9f6ca; }
.pm-table tr.pm-ebitda td .delta.neg { color: #ffcdd2; }
.pm-table .grp-start { border-left: 2px solid #cfd8dc; }
/* Delta colors inside the .sub line of comparison tiles — green for positive
   variance, red for negative. Used on the Profitability tab YTD-vs-Budget
   and Annualized-vs-Budget sections. */
.tile .sub .delta { font-weight: 600; }
.tile .sub .delta.pos { color: var(--success); }
.tile .sub .delta.neg { color: var(--danger); }
.cf-table tr.unrec-row td { background: #fff8e1; color: #6d4c41; font-style: italic; border-top: 1px dashed #d4a017; }
.cf-table tr.unrec-row td.cat-name { padding-left: 26px; }
.cf-table tr.bal-row td  { background: #fafbfd; color: #555; font-style: italic; }
.cf-table tr.bal-row.tot-row td { background: #e8eaf6; color: var(--primary); font-weight: 700; font-style: normal; }
.cf-table tr.memo-header td { background: #f5f5f5; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; padding: 6px 14px; padding-top: 14px; }
.cf-table tr.memo-row td { background: #fafafa; color: #777; font-size: 12px; }
.cf-table td.num.neg { color: var(--danger); }

/* iframe wrapping the canonical AR report (loaded from /api/ar-report-html).
   Full-width, tall enough to show several customers without scroll-in-scroll
   confusion. Single border to mark the embedded boundary clearly. */
.ar-report-frame {
  display: block;
  width: 100%;
  height: 1200px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}

.cf-source-note {
  margin-top: 12px;
  padding: 10px 14px;
  background: #fafbfd;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-size: 12px; color: var(--muted);
  font-style: italic;
}

.cf-not-avail {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 48px 20px;
  text-align: center;
}
.cf-not-avail-icon { font-size: 48px; opacity: 0.4; margin-bottom: 12px; }
.cf-not-avail-title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.cf-not-avail-sub { font-size: 13px; color: var(--muted); max-width: 520px; margin: 0 auto; line-height: 1.5; }

/* ============ CEO-DASHBOARD DRILLDOWN STYLING ============ */
/* Subset of generate_ceo_dashboard.js styles needed so the embedded
   <details> blocks (Profitability fc48 forecast detail + Recurring Revenue
   customer-level tables) render exactly as in the canonical report. */

table.aging { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 13px; }
table.aging th, table.aging td { padding: 6px 10px; text-align: right; border-bottom: 1px solid #eee; }
table.aging th { background: #f8f9fa; font-weight: 600; color: #455a64; font-size: 11px; text-transform: uppercase; }
table.aging th.cust-name, table.aging td.cust-name { text-align: left; min-width: 180px; }
table.aging td.warn-cell { background: #fff3e0; }
table.aging td.severe-cell { background: #ffebee; color: #b71c1c; font-weight: 600; }
table.aging td.tot-cell { font-weight: 700; background: #e8eaf6; }
table.aging tr.agg-row td { font-weight: 700; background: #f5f5f5; }
table.aging tr.agg-row td.warn-cell { background: #ffe0b2; }
table.aging tr.agg-row td.severe-cell { background: #ffcdd2; }
table.aging tr.agg-row td.tot-cell { background: #c5cae9; }
table.aging tr.top-header td { background: #fff8e1; font-weight: 600; color: #6d4c41; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; padding: 4px 10px; text-align: left; border-top: 2px solid #ffd54f; }
table.aging tr.top-cust td { font-size: 12px; }
table.aging tr.top-cust td.cust-name { font-weight: 600; color: var(--primary); }
table.aging tr.all-cust td { font-size: 12px; }
table.aging tr.all-cust td.cust-name { color: #333; }

details.all-cust-details { margin-top: 14px; border: 1px solid var(--border); border-radius: 6px; background: #fafbfc; }
details.all-cust-details > summary { cursor: pointer; padding: 10px 14px; font-size: 12px; font-weight: 600; color: #455a64; text-transform: uppercase; letter-spacing: 0.4px; user-select: none; }
details.all-cust-details[open] > summary { border-bottom: 1px solid var(--border); }
details.all-cust-details > table.aging { margin-top: 0; }

details.fc48-details > .fc48-scroll { overflow-x: auto; padding: 0 0 4px; }
table.fc48 { font-size: 11px; min-width: 1200px; }
table.fc48 th, table.fc48 td { padding: 5px 8px; }
table.fc48 th.actual { background: #eceff1; }
table.fc48 th.budget { background: #f3e5f5; color: #6a1b9a; }
table.fc48 td.actual { background: #fafbfc; }
table.fc48 td.budget { background: #faf3fb; }
table.fc48 tr.ni-row td { font-weight: 700; background: #fff3e0 !important; border-top: 2px solid #e65100; }
table.fc48 tr.ni-row td.actual, table.fc48 tr.ni-row td.budget { background: #fff3e0 !important; }
table.fc48 tr.addback-row td { font-size: 11px; color: #6d4c41; background: #fffde7; }
table.fc48 tr.addback-row td.actual, table.fc48 tr.addback-row td.budget { background: #fffde7; }
table.fc48 tr.addback-row td.addback-name { padding-left: 22px; font-weight: 500; }
table.fc48 tr.ebitda-row td { font-weight: 700; background: #e8eaf6 !important; border-top: 2px solid #3949ab; }
table.fc48 tr.ebitda-row td.actual, table.fc48 tr.ebitda-row td.budget { background: #e8eaf6 !important; }
table.fc48 tr.fc48-parent td.cust-name { font-weight: 600; }
table.fc48 td.fc48-toggle { cursor: pointer; user-select: none; }
table.fc48 td.fc48-toggle:hover { background: #eceff1; }
table.fc48 .fc48-icon { display: inline-block; width: 14px; color: #607d8b; font-weight: 600; }
table.fc48 tr.fc48-child.collapsed { display: none; }
table.fc48 tr.fc48-subgroup td { font-size: 11px; color: #455a64; background: #fafbfc; }
table.fc48 tr.fc48-subgroup td.subgroup-name { padding-left: 22px; font-weight: 600; }
table.fc48 tr.fc48-child td { font-size: 11px; color: #555; }
table.fc48 tr.fc48-child td.acct-name { padding-left: 44px; font-weight: 400; color: #455a64; }

/* ============ MOBILE ============ */

@media (max-width: 760px) {
  #app { flex-direction: column; }
  .sidebar { width: 100%; padding: 0; }
  .sidebar nav { display: flex; flex-wrap: wrap; }
  .sidebar .nav-link { flex: 1; min-width: 140px; text-align: center; border-left: none; border-bottom: 3px solid transparent; }
  .sidebar .nav-link.active { border-left: none; border-bottom-color: var(--accent); }
  .user-box { display: flex; align-items: center; gap: 12px; }
  .user-box .logout { width: auto; margin-top: 0; margin-left: auto; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 10px; }
  .page { padding: 16px; }
  .chart-wrap.big { height: 320px; }
}

/* --- Billing Readiness heatmap (Bellwether Sales/Billing) --- */
.bw-legend { display: flex; gap: 18px; flex-wrap: wrap; margin: 12px 0; font-size: 12px; color: #555; align-items: center; }
.bw-legend .swatch { display: inline-block; width: 16px; height: 12px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.bw-legend span { display: inline-flex; align-items: center; gap: 5px; }
.bw-match    { color: #155724; font-weight: 600; }
.bw-hs-higher { color: #856404; font-weight: 600; }
.bw-ns-higher { color: #0c5460; font-weight: 600; }
.bw-table-wrap { overflow: auto; max-height: 70vh; background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); margin-top: 6px; }
.bw-table { border-collapse: separate; border-spacing: 0; font-size: 12px; white-space: nowrap; width: max-content; }
.bw-table th { background: #f8f9fa; text-align: left; padding: 8px 10px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: #666; border-bottom: 2px solid #dee2e6; position: sticky; top: 0; z-index: 2; }
.bw-table td { padding: 6px 10px; border-bottom: 1px solid #f0f0f0; }
.bw-table .bw-fc { position: sticky; z-index: 3; background: #fff; }
.bw-table th.bw-fc { z-index: 4; background: #f8f9fa; }
.bw-table .bw-fc-3 { border-right: 2px solid #dee2e6; }
.bw-table .bw-ns-name { font-size: 10px; color: #888; margin-top: 2px; }
.bw-table td a { color: #0366d6; text-decoration: none; font-weight: 500; }
.bw-table td a:hover { text-decoration: underline; }
.bw-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.bw-table .mrr-cell { text-align: right; font-size: 10px; padding: 4px 6px; min-width: 65px; font-variant-numeric: tabular-nums; }
.bw-table .mrr-cell.empty { background: #fafafa; }
.bw-table .month-th { min-width: 65px; text-align: right; font-size: 9px; }
.bw-table tr:hover td { background: #f0f7ff !important; }
.bw-table tr:hover td.bw-fc { background: #e4eef8 !important; }
.bw-table tr:hover .mrr-cell.empty { background: #e8f0fe !important; }
.bw-var-note { font-size: 9px; font-weight: 400; color: #888; }
.bw-company-detail { background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); margin-bottom: 10px; }
.bw-company-detail summary { padding: 10px 14px; cursor: pointer; display: flex; align-items: center; gap: 12px; font-size: 13px; }
.bw-company-detail summary:hover { background: #f8f9fa; }
.bw-company-detail[open] summary { border-bottom: 1px solid #eee; }
.bw-co-name { font-weight: 600; }
.bw-co-tags { font-size: 11px; color: #888; }
.bw-li-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.bw-li-table th { background: #f8f9fa; padding: 8px 12px; text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: #666; border-bottom: 1px solid #dee2e6; }
.bw-li-table td { padding: 8px 12px; border-bottom: 1px solid #f0f0f0; }
.bw-li-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.bw-li-table .bw-total-row { background: #f8f9fa; }
.bw-src-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 600; }
.bw-src-hs { background: #fff3e0; color: #e65100; }
.bw-src-ns { background: #e3f2fd; color: #1565c0; }

/* --- CC/Expense person cards --- */
.cce-person { background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); margin-bottom: 8px; }
.cce-person > summary { padding: 12px 16px; cursor: pointer; display: grid; grid-template-columns: 1fr auto auto; gap: 16px; align-items: center; font-size: 13px; list-style: none; }
.cce-person > summary::-webkit-details-marker { display: none; }
.cce-person > summary::before { content: '▸'; color: #888; margin-right: 8px; display: inline-block; transition: transform .15s; }
.cce-person[open] > summary::before { transform: rotate(90deg); }
.cce-person > summary:hover { background: #f8f9fa; }
.cce-person[open] > summary { border-bottom: 1px solid #eee; }
.cce-name { font-weight: 600; }
.cce-total { font-weight: 700; font-variant-numeric: tabular-nums; }
.cce-breakdown { font-size: 11px; color: #888; }
.cce-table { width: 100%; margin: 0; border-radius: 0; box-shadow: none; }
.cce-src-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 600; min-width: 60px; text-align: center; }
.cce-src-cc { background: #e3f2fd; color: #0d47a1; }
.cce-src-reimb { background: #fff3e0; color: #bf360c; }

/* --- AR Trend: Recommended Actions box --- */
.actions-box { background: #fff; border: 1px solid #e0e3eb; border-radius: 8px; padding: 14px 18px; margin: 14px 0; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.actions-label { font-size: 12px; color: #455a64; text-transform: uppercase; letter-spacing: 0.4px; font-weight: 600; margin-bottom: 10px; display: flex; align-items: center; gap: 6px; }
.actions-list { list-style: none; padding: 0; margin: 0; }
.action-item { padding: 10px 12px; border-radius: 6px; border-left: 4px solid #cfd8dc; margin-bottom: 8px; background: #fafbfc; }
.action-item.pri-high { border-left-color: #c62828; background: #fff5f5; }
.action-item.pri-med  { border-left-color: #f57c00; background: #fff8e1; }
.action-item.pri-low  { border-left-color: #388e3c; background: #f1f8e9; }
.action-head { display: flex; align-items: center; gap: 10px; font-size: 13px; margin-bottom: 4px; }
.action-pri { font-size: 11px; font-weight: 700; min-width: 70px; }
.action-verb { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 10px; background: #eceff1; color: #37474f; letter-spacing: 0.5px; }
.action-item.pri-high .action-verb { background: #ffebee; color: #b71c1c; }
.action-item.pri-med  .action-verb { background: #fff3e0; color: #e65100; }
.action-item.pri-low  .action-verb { background: #e8f5e9; color: #1b5e20; }
.action-title { font-weight: 600; color: #263238; }
.action-detail { font-size: 12px; color: #455a64; margin: 2px 0 4px 80px; }
.action-do { font-size: 12px; color: #1a237e; margin-left: 80px; font-style: italic; }
