/* ============================================================
   Organizations summary (#/app/organizations/summary)
   Lives in the same "Great Circle" world as the organization picker:
   it borrows the --ag-* tokens from css/auth.css (the root carries both
   .ag and .os) and adds only what a data page needs on top.
   Spacing scale: 4 8 12 16 20 24 32 40 48 64.
   ============================================================ */

.os {
  --os-card: rgba(255, 255, 255, 0.74);
  --os-card-line: rgba(12, 35, 64, 0.10);
  --os-track: rgba(12, 35, 64, 0.08);
  --os-income: #0369A1;
  --os-cost: #7F9DB8;
  --os-opex: #C2410C;
  --os-profit: #B27135;
  --os-profit-ink: #7A4A14; /* gold for text: 4.5:1+ on the light card */
  --os-pos: #15803D;
  --os-neg: #B3261E;
  --os-heat-rgb: 3, 105, 161;
  --os-focus: #0369A1;

  background: var(--ag-sky) fixed;
  overflow: visible;
}
html.dark .os {
  --os-card: rgba(6, 17, 36, 0.72);
  --os-card-line: rgba(163, 182, 201, 0.12);
  --os-track: rgba(163, 182, 201, 0.10);
  --os-income: #38BDF8;
  --os-cost: #5D7A9C;
  --os-opex: #FF8A65;
  --os-profit: #E2B568;
  --os-profit-ink: #E2B568;
  --os-pos: #4ADE80;
  --os-neg: #FF8A65;
  --os-heat-rgb: 56, 189, 248;
  --os-focus: #7DD3FC;
}

/* styles.css gives every <section> landing-page padding, a white background on even
   ones, and hides it until js/animations.js reveals it on scroll. None of that
   applies here; these selectors outrank `section:nth-of-type(even)`. */
.os section { opacity: 1; transform: none; transition: none; }
.os section.os-head { padding: 8px 0 0; background: none; }
.os section.os-filters,
.os section.os-hero,
.os section.os-card { background: var(--os-card); }

.os :focus-visible {
  outline: 2px solid var(--os-focus);
  outline-offset: 2px;
}
.os .ag-sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── Frame ───────────────────────────────────────────────── */
.os-back {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 16px 0 12px;
  border: 1px solid var(--ag-line); border-radius: 12px;
  background: var(--ag-field); color: var(--ag-ink);
  font: inherit; font-size: 14px; font-weight: 600; text-decoration: none;
  transition: border-color .15s ease-out;
}
.os-back:hover { border-color: var(--ag-line-hover); }
.os-back svg { width: 18px; height: 18px; }

.os-main {
  position: relative; z-index: 1;
  max-width: 1240px; margin: 0 auto;
  padding: 8px clamp(16px, 5vw, 64px) 64px;
  display: grid; gap: 24px;
}

.os-head { display: grid; gap: 12px; padding-top: 8px; }
.os-title {
  margin: 0;
  font-weight: 300;
  font-size: clamp(32px, 4.2vw, 52px);
  line-height: 1.05;
  letter-spacing: -0.02em;
}
.os-sub { margin: 0; color: var(--ag-muted); font-size: 16px; line-height: 1.55; max-width: 62ch; }

/* ── Filters ─────────────────────────────────────────────── */
.os-filters {
  display: grid; gap: 16px;
  padding: 20px;
  border: 1px solid var(--os-card-line); border-radius: 20px;
  background: var(--os-card);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.os-filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; }
.os-filter-label { font-size: 13px; color: var(--ag-muted); min-width: 64px; }

.os-seg {
  display: inline-flex; flex-wrap: wrap; gap: 4px;
  padding: 4px; border-radius: 12px; background: var(--os-track);
}
.os-seg button {
  min-height: 36px; padding: 0 12px;
  border: 0; border-radius: 8px; background: transparent;
  color: var(--ag-muted); font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: color .15s ease-out, background-color .15s ease-out;
}
.os-seg button:hover { color: var(--ag-ink); }
.os-seg button[aria-pressed="true"] { background: var(--ag-panel); color: var(--ag-ink); box-shadow: inset 0 0 0 1px var(--ag-line); }

.os-custom { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.os-custom label { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ag-muted); }
.os-date, .os-select {
  min-height: 36px; padding: 0 12px;
  border: 1px solid var(--ag-line); border-radius: 10px;
  background: var(--ag-field); color: var(--ag-ink);
  font: inherit; font-size: 13px; color-scheme: light;
}
html.dark .os-date, html.dark .os-select { color-scheme: dark; }

.os-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.os-chip {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 36px; padding: 0 16px;
  border: 1px solid var(--ag-line); border-radius: 999px;
  background: transparent; color: var(--ag-muted);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: color .15s ease-out, border-color .15s ease-out, background-color .15s ease-out;
}
.os-chip:hover { color: var(--ag-ink); border-color: var(--ag-line-hover); }
.os-chip[aria-pressed="true"] { color: var(--ag-ink); border-color: var(--os-income); background: var(--ag-mono-bg); }
.os-chip-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.os-chip-check {
  width: 14px; height: 14px; border-radius: 4px; flex: none;
  border: 1.5px solid currentColor; display: grid; place-items: center;
}
.os-chip[aria-pressed="true"] .os-chip-check { background: var(--os-income); border-color: var(--os-income); }
.os-chip-check svg { width: 10px; height: 10px; color: var(--ag-panel); opacity: 0; }
.os-chip[aria-pressed="true"] .os-chip-check svg { opacity: 1; }

.os-export { margin-left: auto; }

.os-note { margin: 0; font-size: 14px; color: var(--ag-muted); line-height: 1.5; }
.os-note:empty { display: none; }
.os-note.is-warn { color: var(--ag-warn); }

/* ── Hero: the P&L as one flight ─────────────────────────── */
.os-hero {
  display: grid; gap: 24px;
  padding: clamp(20px, 3vw, 32px);
  border: 1px solid var(--os-card-line); border-radius: 24px;
  background: var(--os-card);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.os-hero-top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.os-hero-label { margin: 0 0 8px; font-size: 14px; color: var(--ag-muted); }
.os-hero-value {
  margin: 0;
  font-size: clamp(40px, 6vw, 72px); font-weight: 300; line-height: 1;
  letter-spacing: -0.03em; font-variant-numeric: tabular-nums;
}
.os-hero-value.is-neg { color: var(--os-neg); }
.os-hero-meta { display: grid; justify-items: end; gap: 8px; text-align: right; }
.os-hero-margin { font-size: 14px; color: var(--ag-muted); }
.os-hero-margin b { color: var(--ag-ink); font-weight: 600; font-variant-numeric: tabular-nums; }

.os-delta {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums;
  background: var(--os-track); color: var(--ag-muted);
}
.os-delta.is-up { color: var(--os-pos); }
.os-delta.is-down { color: var(--os-neg); }
.os-delta svg { width: 12px; height: 12px; }

.os-flight { display: grid; gap: 12px; }
.os-flight-bar {
  position: relative; display: flex; height: 20px;
  border-radius: 999px; background: var(--os-track); overflow: hidden;
}
.os-seg-fill {
  height: 100%; flex: none;
  transform-origin: left center;
  animation: os-grow .2s ease-out both;
}
.os-seg-fill + .os-seg-fill { box-shadow: inset 2px 0 0 var(--ag-panel); }
.os-fill-cost { background: var(--os-cost); }
.os-fill-opex { background: var(--os-opex); }
.os-fill-profit { background: var(--os-profit); }
.os-flight-marker {
  position: absolute; top: -4px; bottom: -4px; width: 2px;
  background: var(--ag-ink); border-radius: 2px;
}
@keyframes os-grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.os-legend {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
.os-legend-item { display: grid; gap: 4px; }
.os-legend-name { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ag-muted); }
.os-legend-key { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.os-legend-val { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.os-legend-sub { font-size: 12px; color: var(--ag-muted); font-variant-numeric: tabular-nums; }
.os-legend-sub.is-up { color: var(--os-pos); }
.os-legend-sub.is-down { color: var(--os-neg); }

/* ── Findings ────────────────────────────────────────────── */
.os-findings { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin: 0; padding: 0; list-style: none; }
.os-finding {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 16px; border-radius: 16px;
  border: 1px solid var(--os-card-line); background: var(--os-card);
  font-size: 14px; line-height: 1.5;
}
.os-finding-ico {
  width: 32px; height: 32px; flex: none; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--ag-mono-bg); color: var(--os-income);
}
.os-finding-ico svg { width: 16px; height: 16px; }
.os-finding.is-warn .os-finding-ico { background: rgba(255, 138, 101, 0.14); color: var(--os-neg); }
.os-finding.is-good .os-finding-ico { background: rgba(226, 181, 104, 0.16); color: var(--os-profit-ink); }
.os-finding b { font-weight: 600; }

/* ── Cards ───────────────────────────────────────────────── */
.os-grid { display: grid; gap: 24px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); }
.os-card {
  display: grid; gap: 20px; align-content: start; min-width: 0;
  padding: clamp(16px, 2.4vw, 24px);
  border: 1px solid var(--os-card-line); border-radius: 20px;
  background: var(--os-card);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.os-card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.os-card-title { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.os-card-sub { margin: 4px 0 0; font-size: 13px; color: var(--ag-muted); line-height: 1.5; }
.os-empty { margin: 0; padding: 24px 0; text-align: center; color: var(--ag-muted); font-size: 14px; }

/* Standings */
.os-board { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
.os-board-row {
  display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: 4px 12px;
  padding: 12px; border-radius: 14px;
}
.os-board-row.is-lead { background: var(--ag-mono-bg); }
.os-rank { font-size: 14px; font-weight: 600; color: var(--ag-muted); font-variant-numeric: tabular-nums; text-align: center; }
.os-board-row.is-lead .os-rank { color: var(--os-profit-ink); }
.os-board-name { display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 600; font-size: 15px; }
.os-board-name span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.os-board-val { font-weight: 600; font-variant-numeric: tabular-nums; font-size: 15px; text-align: right; }
.os-board-val.is-neg { color: var(--os-neg); }
.os-board-bar { grid-column: 2 / 4; height: 6px; border-radius: 999px; background: var(--os-track); overflow: hidden; }
.os-board-bar i { display: block; height: 100%; border-radius: inherit; background: var(--os-income); transform-origin: left center; animation: os-grow .2s ease-out both; }
.os-board-bar i.is-neg { background: var(--os-neg); }
.os-board-meta { grid-column: 2 / 4; display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12px; color: var(--ag-muted); font-variant-numeric: tabular-nums; }
.os-tag {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: rgba(226, 181, 104, 0.18); color: var(--os-profit-ink);
}

/* Trend */
.os-trend-wrap { position: relative; height: 280px; }
.os-trend-wrap canvas { width: 100% !important; height: 100% !important; }

/* Service matrix */
.os-table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
.os-table { width: 100%; border-collapse: separate; border-spacing: 4px; font-size: 14px; }
.os-table th, .os-table td { padding: 12px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.os-table thead th { font-size: 12px; font-weight: 600; color: var(--ag-muted); padding-top: 0; padding-bottom: 4px; }
.os-table th:first-child, .os-table td:first-child { text-align: left; }
.os-table tbody td { border-radius: 10px; background: rgba(var(--os-heat-rgb), var(--heat, 0)); }
.os-table tbody td.is-zero { color: var(--ag-muted); background: transparent; }
.os-table tbody td.is-lead { box-shadow: inset 0 0 0 1.5px var(--os-profit); font-weight: 600; }
.os-table tbody td.is-neg { color: var(--os-neg); }
.os-table tbody tr.is-total td { background: transparent; font-weight: 600; border-top: 1px solid var(--os-card-line); }
.os-table .os-row-btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 32px; padding: 0 8px; margin-left: -8px;
  border: 0; border-radius: 8px; background: transparent; color: var(--ag-ink);
  font: inherit; font-weight: 600; cursor: pointer; text-align: left;
}
.os-table .os-row-btn:hover { background: var(--os-track); }
.os-table tr.is-active .os-row-btn { background: var(--ag-mono-bg); }
.os-table th.os-col-all, .os-table td.os-col-all { color: var(--ag-muted); }
.os-matrix-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; font-size: 12px; color: var(--ag-muted); }
.os-matrix-legend span { display: inline-flex; align-items: center; gap: 8px; }
.os-swatch-lead { width: 14px; height: 14px; border-radius: 4px; box-shadow: inset 0 0 0 1.5px var(--os-profit); }
.os-swatch-heat { width: 40px; height: 10px; border-radius: 4px; background: linear-gradient(90deg, rgba(var(--os-heat-rgb), .04), rgba(var(--os-heat-rgb), .5)); }

/* Expenses */
.os-bars { display: grid; gap: 16px; margin: 0; padding: 0; list-style: none; }
.os-bar-row { display: grid; gap: 8px; }
.os-bar-head { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.os-bar-head b { font-weight: 600; font-variant-numeric: tabular-nums; }
.os-bar-track { display: flex; height: 8px; border-radius: 999px; background: var(--os-track); overflow: hidden; }
.os-bar-track i { display: block; height: 100%; flex: none; transform-origin: left center; animation: os-grow .2s ease-out both; }
.os-bar-track i + i { box-shadow: inset 2px 0 0 var(--ag-panel); }
.os-branch-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 12px; color: var(--ag-muted); }
.os-branch-legend span { display: inline-flex; align-items: center; gap: 8px; }

/* Receivables */
.os-recv-total { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 24px; }
.os-recv-total strong { font-size: 32px; font-weight: 300; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.os-recv-total span { font-size: 13px; color: var(--ag-muted); }
.os-recv-total .is-warn { color: var(--os-neg); }
.os-recv-list { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
.os-recv-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center;
  padding: 12px; border-radius: 12px; font-size: 14px;
}
.os-recv-row:nth-child(odd) { background: var(--os-track); }
.os-recv-row b { font-weight: 600; font-variant-numeric: tabular-nums; }
.os-recv-row small { grid-column: 1 / -1; color: var(--ag-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.os-recv-row small .is-warn { color: var(--os-neg); }

/* Loading */
.os-skel { border-radius: 14px; background: var(--os-track); min-height: 20px; animation: os-pulse 1.2s ease-in-out infinite; }
@keyframes os-pulse { 50% { opacity: .5; } }
.os[aria-busy="true"] .os-hero, .os[aria-busy="true"] .os-card { opacity: .72; transition: opacity .15s ease-out; }

@media (max-width: 640px) {
  .os-filter-label { min-width: 0; width: 100%; }
  .os-export { margin-left: 0; width: 100%; }
  .os-hero-meta { justify-items: start; text-align: left; }
  .os-trend-wrap { height: 220px; }
}

@media (prefers-reduced-motion: reduce) {
  .os-seg-fill, .os-board-bar i, .os-bar-track i { animation: none; }
  .os-skel { animation: none; }
}

/* The picker's "Organizations summary" entry is a link styled as .ag-btn-ghost. */
a.ag-btn-ghost, a.ag-btn { text-decoration: none; }
.os .ag-btn-ghost:disabled { opacity: .5; cursor: not-allowed; }
