/*
  Spreadsheets lane — page-specific demo styles.
  Loaded after /main_style.css and /portfolio/portfolio.css.

  Contains: shared demo-chrome helpers (.ds-mini / .ds-seg / .ds-tooltip),
  .ds-* (data-prep tool), .pv-* (pivot builder),
  .inv-* (invoice tool — the intentionally LIGHT paper surface).

  The demos toggle a lot of panels with the `hidden` attribute, and several of
  those panels also carry a display value, so `hidden` is made authoritative
  inside every demo stage.
*/

.demo-stage [hidden] { display: none !important; }

/* ---- Micro-badge rhythm (dark demo chrome) ----
   .ds-badge and .ds-rule-act are the same tier — small uppercase status
   capsules on the dark demo surface — but carried different padding
   (0.1rem 0.45rem vs 0.1rem 0.4rem) and no line-height, so they rendered
   19.00px and 18.01px tall with mismatched left/right insets. One scale,
   matched to the automation and AI lanes so all four read as one system.

   NOTE: .inv-tag is deliberately NOT in this set. It lives on the LIGHT
   invoice paper — its own visual world, its own smaller type scale — and it is
   constrained by the line box of the table row it sits in. See the note on
   .inv-tag itself for the measurements; it is correct as-is. */
.ds-badge,
.ds-rule-act {
  padding: var(--badge-pad);
  line-height: var(--badge-lh);
}

/* ===================== Shared demo chrome ===================== */

.ds-mini {
  height: 28px;
  padding: 0 0.65rem;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.05);
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 750;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
  transition: color 180ms ease, border-color 180ms ease, background 180ms ease;
}
.ds-mini:hover:not(:disabled) {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 50%, rgba(255,255,255,0.14));
  background: color-mix(in srgb, var(--accent) 12%, rgba(255,255,255,0.05));
}
.ds-mini:disabled { opacity: 0.45; cursor: not-allowed; }
.ds-mini[aria-pressed="true"] {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 20%, rgba(255,255,255,0.05));
  border-color: color-mix(in srgb, var(--accent) 55%, rgba(255,255,255,0.14));
}

.ds-seg { display: inline-flex; gap: 0.3rem; flex-wrap: wrap; }
.ds-seg-btn {
  height: 30px;
  padding: 0 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.05);
  color: var(--muted);
  font: inherit;
  font-weight: 750;
  font-size: 0.78rem;
  cursor: pointer;
  transition: border-color 200ms ease, color 200ms ease, background 200ms ease;
}
.ds-seg-btn.active {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 22%, rgba(255,255,255,0.05));
  border-color: color-mix(in srgb, var(--accent) 55%, rgba(255,255,255,0.14));
}

.ds-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  max-width: min(260px, 70vw);
  background: #0b0e18;
  border: 1px solid rgba(255,255,255,0.16);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.4;
  text-align: left;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 3;
}
.ds-dl:hover .ds-tooltip,
.ds-dl:focus-visible .ds-tooltip,
.inv-export:hover .ds-tooltip,
.inv-export:focus-visible .ds-tooltip { opacity: 1; transform: translateY(0); }

.demo-stage :focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 80%, #fff);
  outline-offset: 2px;
}

/* ===================== DEMO 1: sheet-clean ===================== */

.demo-sheet { padding: 1.1rem 1.2rem 1.2rem; }

.ds-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-bottom: 0.9rem;
}

.dd-title { font-weight: 800; display: inline-flex; align-items: center; gap: 0.55rem; letter-spacing: 0.01em; flex-wrap: wrap; }
.dd-title i { color: color-mix(in srgb, var(--accent) 82%, #fff); }
.ds-file-meta { font-size: 0.74rem; font-weight: 650; color: var(--muted); letter-spacing: 0.02em; }

.ds-actions { display: inline-flex; gap: 0.5rem; flex-wrap: wrap; }
.mini-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.ds-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  align-items: start;
}
@media (min-width: 900px) { .ds-layout { grid-template-columns: 264px 1fr; } }

/* --- rules panel --- */

.ds-rules {
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.035);
  padding: 0.75rem 0.8rem 0.8rem;
}
.ds-rules-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.6rem; flex-wrap: wrap; }
.ds-rules-head h3 {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}
.ds-rules-head h3 i { color: color-mix(in srgb, var(--accent) 82%, #fff); }
.ds-bulk { display: inline-flex; gap: 0.3rem; }

.ds-rule-list { display: flex; flex-direction: column; gap: 0.3rem; }
.ds-rule {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.55rem;
  padding: 0.4rem 0.5rem;
  border-radius: 9px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}
.ds-rule:hover { background: rgba(255,255,255,0.05); border-color: rgba(255,255,255,0.08); }
.ds-rule input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; flex: none; }
.ds-rule-body { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.ds-rule-label { font-size: 0.79rem; font-weight: 700; color: var(--text); line-height: 1.25; }
.ds-rule input:not(:checked) ~ .ds-rule-body .ds-rule-label { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(255,255,255,0.28); }
.ds-rule-meta { display: flex; }
.ds-rule-act {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  border-radius: 999px; /* padding set by the micro-badge rhythm block above */
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--muted);
}
.ds-rule-act.fix  { color: #9ff0d3; border-color: rgba(70,230,168,0.32); background: rgba(70,230,168,0.10); }
.ds-rule-act.drop { color: #ffb3bb; border-color: rgba(255,95,107,0.30); background: rgba(255,95,107,0.10); }
.ds-rule-act.flag { color: #ffdca8; border-color: rgba(255,196,110,0.32); background: rgba(255,196,110,0.10); }
.ds-rule-count {
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  font-weight: 800;
  color: color-mix(in srgb, var(--accent) 80%, #fff);
  min-width: 1.5em;
  text-align: right;
}

.ds-remaining {
  margin-top: 0.7rem;
  padding-top: 0.7rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 0.1rem 0.5rem;
}
.ds-remaining-k { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.ds-remaining strong { font-size: 1.5rem; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; color: #ffd08a; grid-row: 1 / span 2; }
.ds-remaining.is-zero strong { color: #46e6a8; }
.ds-remaining-note { font-size: 0.7rem; color: var(--muted); grid-column: 1; }

.ds-hint { margin: 0.5rem 0 0; font-size: 0.74rem; color: #ffc46e; min-height: 1em; }

/* --- table --- */

.ds-main { min-width: 0; }
.ds-viewbar { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.ds-view-note { font-size: 0.73rem; color: var(--muted); }

.ds-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.10);
}

.ds-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  min-width: 860px;
}

.ds-table th {
  text-align: left;
  padding: 0.5rem 0.7rem;
  background: rgba(255,255,255,0.07);
  color: var(--muted);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-bottom: 1px solid rgba(255,255,255,0.10);
  white-space: nowrap;
}

.ds-table td {
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  white-space: nowrap;
  transition: background 300ms ease, color 300ms ease;
}

.ds-rownum { width: 2.4rem; color: rgba(255,255,255,0.32); font-variant-numeric: tabular-nums; text-align: right; }
.ds-calc { text-align: right; font-variant-numeric: tabular-nums; color: color-mix(in srgb, var(--accent) 60%, var(--text)); }
.ds-calc-out { color: rgba(255,255,255,0.28); text-decoration: line-through; }

.ds-sp {
  color: #ff9eaa;
  background: rgba(255,95,107,0.14);
  border-radius: 3px;
  letter-spacing: 0.12em;
}

.ds-table td.ds-issue { box-shadow: inset 0 -2px 0 rgba(255,158,170,0.5); }
.ds-table td.ds-changed { color: #bfffe3; }
.ds-was { color: rgba(255,255,255,0.35); margin-right: 0.35rem; text-decoration-color: rgba(255,158,170,0.7); }
.ds-now { color: #bfffe3; }

.ds-table tr.ds-r-flagged td { background: rgba(255,196,110,0.06); }
.ds-table tr.ds-r-removed td { color: rgba(255,255,255,0.3); text-decoration: line-through; background: rgba(255,95,107,0.05); }
.ds-table tr.ds-removing { transition: opacity 420ms ease; opacity: 0; }

.ds-table td.ds-fix { animation: dsFix 0.85s ease; }
@keyframes dsFix {
  0% { background: color-mix(in srgb, var(--accent) 32%, transparent); }
  100% { background: transparent; }
}

.ds-table tr.ds-totals td {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  font-weight: 800;
  color: var(--text);
  border-top: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
}

.ds-badge-cell { text-align: right; }
.ds-badge {
  display: inline-block;
  border-radius: 999px; /* padding set by the micro-badge rhythm block above */
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: 1px solid transparent;
  white-space: nowrap;
}
.ds-badge.clean   { color: rgba(255,255,255,0.42); border-color: rgba(255,255,255,0.14); }
.ds-badge.issue   { color: #ff9eaa; border-color: rgba(255,95,107,0.34); background: rgba(255,95,107,0.10); }
.ds-badge.fixed   { color: #7cf0c0; border-color: rgba(70,230,168,0.34); background: rgba(70,230,168,0.10); }
.ds-badge.removed { color: #ffb3bb; border-color: rgba(255,95,107,0.34); background: rgba(255,95,107,0.10); }
.ds-badge.flagged { color: #ffd08a; border-color: rgba(255,196,110,0.36); background: rgba(255,196,110,0.10); }

.ds-progress {
  margin-top: 0.55rem;
  height: 4px;
  border-radius: 999px;
  background: rgba(255,255,255,0.07);
  overflow: hidden;
}
.ds-progress i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 160ms linear;
}

.ds-status {
  margin-top: 0.6rem;
  min-height: 1.3em;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: right;
}
.ds-status .ok { color: #46e6a8; font-weight: 750; }
.ds-status .warn { color: #ffc46e; font-weight: 750; }

.ds-legend {
  margin: 0.55rem 0 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
  font-size: 0.72rem;
  color: var(--muted);
}

/* --- report --- */

.ds-report {
  margin-top: 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, rgba(255,255,255,0.10));
  background: color-mix(in srgb, var(--accent) 7%, rgba(255,255,255,0.03));
  padding: 0.95rem 1.05rem 1.05rem;
  animation: dsReportIn 420ms ease;
}

@keyframes dsReportIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.ds-report-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 800;
  font-size: 0.92rem;
  margin-bottom: 0.75rem;
}
.ds-report-head i { color: color-mix(in srgb, var(--accent) 82%, #fff); }

.ds-report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 0.7rem;
  margin-bottom: 0.9rem;
}

.ds-stat { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.ds-stat span { color: var(--muted); font-size: 0.68rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
.ds-stat strong { font-size: 1.02rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ds-report-bars { display: flex; flex-direction: column; gap: 0.4rem; }
.ds-bar-empty { font-size: 0.78rem; color: var(--muted); font-style: italic; }

.ds-bar-row {
  display: grid;
  grid-template-columns: 100px 1fr 84px;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.76rem;
  color: var(--muted);
}
.ds-bar-row > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ds-bar-row strong { color: var(--text); text-align: right; font-size: 0.76rem; font-variant-numeric: tabular-nums; }

.ds-bar { height: 8px; border-radius: 999px; background: rgba(255,255,255,0.07); overflow: hidden; }
.ds-bar i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 85%, transparent), color-mix(in srgb, var(--accent2) 70%, transparent));
  width: 0;
  transition: width 700ms cubic-bezier(.2,.9,.2,1);
}

/* --- CSV preview --- */

.ds-csv {
  margin-top: 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(0,0,0,0.28);
  padding: 0.85rem 0.95rem 0.95rem;
}
.ds-csv-head { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.ds-csv-head h3 {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}
.ds-csv-head h3 i { color: color-mix(in srgb, var(--accent) 82%, #fff); }
.ds-csv-meta { font-size: 0.72rem; color: var(--muted); }
.ds-dl {
  position: relative;
  margin-left: auto;
  height: 30px;
  padding: 0 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  color: rgba(255,255,255,0.42);
  font: inherit;
  font-size: 0.74rem;
  font-weight: 750;
  cursor: not-allowed;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.ds-csv-pre {
  margin: 0;
  max-height: 190px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  line-height: 1.65;
  color: #c9f2ff;
  white-space: pre;
  tab-size: 2;
}

/* ===================== DEMO 2: sheet-pivot ===================== */

.pv { padding: 1.1rem 1.2rem 1.2rem; }

.pv-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem 1.2rem;
  margin-bottom: 0.9rem;
}
.pv-ctl { display: flex; flex-direction: column; gap: 0.4rem; min-width: 0; }
.pv-ctl-label { font-size: 0.7rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.pv-seg { display: inline-flex; gap: 0.3rem; flex-wrap: wrap; }
.pv-seg-btn {
  height: 32px; padding: 0 0.8rem;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.05);
  color: var(--muted);
  font: inherit;
  font-weight: 750; font-size: 0.8rem; cursor: pointer;
  display: inline-flex; align-items: center; gap: 0.4rem;
  transition: border-color 200ms ease, color 200ms ease, background 200ms ease;
}
.pv-seg-btn.active {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 22%, rgba(255,255,255,0.05));
  border-color: color-mix(in srgb, var(--accent) 55%, rgba(255,255,255,0.14));
}
.pv-seg-btn:disabled { opacity: 0.32; cursor: not-allowed; }

.pv-filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem 1.2rem;
  padding: 0.8rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.09);
  background: rgba(255,255,255,0.035);
  margin-bottom: 0.7rem;
}
@media (min-width: 760px) { .pv-filters { grid-template-columns: auto 1fr auto; align-items: center; } }
.pv-filter { display: flex; flex-direction: column; gap: 0.4rem; min-width: 0; }

.pv-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.pv-chip {
  height: 28px; padding: 0 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.04);
  color: var(--muted);
  font: inherit; font-size: 0.76rem; font-weight: 750;
  cursor: pointer;
  transition: border-color 180ms ease, color 180ms ease, background 180ms ease;
}
.pv-chip.active {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 20%, rgba(255,255,255,0.04));
  border-color: color-mix(in srgb, var(--accent) 52%, rgba(255,255,255,0.14));
}

.pv-range { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.pv-range input[type="range"] { flex: 1 1 auto; min-width: 0; width: 100%; accent-color: var(--accent); cursor: pointer; }
.pv-range-out {
  font-size: 0.78rem; font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: color-mix(in srgb, var(--accent) 80%, #fff);
  min-width: 4.2em; text-align: right;
}

.pv-toggles { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 0.5rem 0.9rem; }
.pv-check { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.78rem; font-weight: 650; color: var(--muted); cursor: pointer; }
.pv-check input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }
.pv-check.is-off { opacity: 0.42; cursor: not-allowed; }
.pv-check.is-off input { cursor: not-allowed; }

.pv-matchline { margin: 0 0 0.7rem; font-size: 0.78rem; color: var(--muted); }
.pv-matchline i { color: color-mix(in srgb, var(--accent) 70%, var(--muted)); margin-right: 0.25rem; }
.pv-matchline strong { color: var(--text); }

.pv-body {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  align-items: start;
}
@media (min-width: 900px) { .pv-body { grid-template-columns: 1.35fr 1fr; } }

.pv-table-wrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid rgba(255,255,255,0.10); align-self: start; }
.pv-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; min-width: 380px; }
.pv-table th {
  text-align: left;
  padding: 0;
  background: rgba(255,255,255,0.07);
  color: var(--muted);
  font-size: 0.72rem; letter-spacing: 0.04em; text-transform: uppercase;
  border-bottom: 1px solid rgba(255,255,255,0.10);
  white-space: nowrap;
}
.pv-table tbody th {
  padding: 0.45rem 0.7rem;
  background: rgba(255,255,255,0.03);
  color: var(--text);
  font-size: 0.8rem;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 750;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.pv-sort {
  width: 100%;
  padding: 0.5rem 0.7rem;
  background: none; border: 0;
  color: inherit; font: inherit;
  font-size: 0.72rem; letter-spacing: 0.04em; text-transform: uppercase; font-weight: 800;
  text-align: left;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 0.35rem; justify-content: flex-start;
}
.pv-table th.pv-num .pv-sort { justify-content: flex-end; text-align: right; }
.pv-sort:hover { color: var(--text); }
.pv-si { font-size: 0.7em; opacity: 0.4; }
.pv-si.on { opacity: 1; color: color-mix(in srgb, var(--accent) 85%, #fff); }

.pv-table th.pv-num, .pv-table td.pv-num { text-align: right; font-variant-numeric: tabular-nums; }
.pv-table td {
  position: relative;
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  white-space: nowrap;
}
.pv-cell { cursor: pointer; }
.pv-cell:hover { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent); }
.pv-cell.is-drill { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 85%, #fff); }
.pv-table tbody tr.hi th, .pv-table tbody tr.hi td { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.pv-tot-col { font-weight: 800; border-left: 1px solid rgba(255,255,255,0.10); }
.pv-table tfoot .pv-total th,
.pv-table tfoot .pv-total td {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  font-weight: 800; color: var(--text);
  border-top: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  padding: 0.5rem 0.7rem;
  text-transform: none; font-size: 0.82rem; letter-spacing: 0;
}

.pv-side { display: flex; flex-direction: column; gap: 0.9rem; min-width: 0; }
.pv-chart { display: flex; flex-direction: column; gap: 0.5rem; }
.pv-brow { display: grid; grid-template-columns: 84px 1fr auto; align-items: center; gap: 0.6rem; font-size: 0.78rem; color: var(--muted); }
.pv-brow-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pv-brow strong { color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.pv-btrack { height: 12px; border-radius: 999px; background: rgba(255,255,255,0.07); overflow: hidden; }
.pv-bfill {
  display: block; height: 100%; width: 0; border-radius: 999px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 88%, transparent), color-mix(in srgb, var(--accent2) 72%, transparent));
  transition: width 500ms cubic-bezier(.2,.9,.2,1);
}
.pv-brow.hi .pv-btrack { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 45%, transparent); }
.pv-brow.hi .pv-brow-label, .pv-brow.hi strong { color: color-mix(in srgb, var(--accent) 85%, #fff); }

.pv-drill {
  border-radius: var(--radius-sm);
  border: 1px solid color-mix(in srgb, var(--accent) 32%, rgba(255,255,255,0.10));
  background: color-mix(in srgb, var(--accent) 6%, rgba(255,255,255,0.03));
  padding: 0.7rem 0.8rem 0.8rem;
  animation: dsReportIn 300ms ease;
}
.pv-drill-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.5rem; }
.pv-drill-head h4 { margin: 0; font-size: 0.84rem; font-weight: 800; display: inline-flex; align-items: center; gap: 0.4rem; }
.pv-drill-head h4 i { color: color-mix(in srgb, var(--accent) 82%, #fff); }
.pv-drill-x {
  flex: none;
  width: 24px; height: 24px;
  border-radius: 7px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.05);
  color: var(--muted);
  font-size: 0.72rem; cursor: pointer; line-height: 1;
}
.pv-drill-x:hover { color: var(--text); border-color: color-mix(in srgb, var(--accent) 50%, rgba(255,255,255,0.14)); }
.pv-drill-sum { font-size: 0.74rem; color: var(--muted); margin: 0.3rem 0 0.55rem; }
.pv-drill-wrap { overflow: auto; max-height: 210px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.08); }
.pv-drill-table { width: 100%; border-collapse: collapse; font-size: 0.74rem; min-width: 300px; }
.pv-drill-table th { text-align: left; padding: 0.35rem 0.55rem; background: rgba(255,255,255,0.05); color: var(--muted); font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em; position: sticky; top: 0; }
.pv-drill-table td { padding: 0.3rem 0.55rem; border-bottom: 1px solid rgba(255,255,255,0.05); white-space: nowrap; }
.pv-drill-table .pv-num { text-align: right; font-variant-numeric: tabular-nums; }
.pv-drill-empty { color: var(--muted); font-style: italic; text-align: center; padding: 0.8rem; }

.pv-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  text-align: center;
  padding: 2rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px dashed rgba(255,255,255,0.16);
  background: rgba(255,255,255,0.02);
}
.pv-empty i { font-size: 1.5rem; color: color-mix(in srgb, var(--accent) 55%, var(--muted)); }
.pv-empty strong { font-size: 0.95rem; }
.pv-empty span { font-size: 0.8rem; color: var(--muted); max-width: 42ch; }
.pv-empty .ds-mini { margin-top: 0.4rem; }

.pv-note { margin: 0.75rem 0 0; font-size: 0.74rem; color: var(--muted); font-style: italic; }

.pv-source { margin-top: 0.85rem; font-size: 0.82rem; }
.pv-source summary { cursor: pointer; color: var(--muted); font-weight: 700; padding: 0.3rem 0; }
.pv-source summary:hover { color: var(--text); }
.pv-source-wrap { overflow: auto; max-height: 260px; margin-top: 0.5rem; border-radius: var(--radius-sm); border: 1px solid rgba(255,255,255,0.08); }
.pv-source-table { width: 100%; border-collapse: collapse; font-size: 0.76rem; min-width: 520px; }
.pv-source-table th { text-align: left; padding: 0.4rem 0.7rem; background: #10131f; color: var(--muted); font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.05em; position: sticky; top: 0; }
.pv-source-table td { padding: 0.32rem 0.7rem; border-bottom: 1px solid rgba(255,255,255,0.05); white-space: nowrap; }
.pv-source-table .pv-num { text-align: right; font-variant-numeric: tabular-nums; }
.pv-source-table tr.hi td { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--text); }

/* ===================== DEMO 3: sheet-invoice (LIGHT paper) ===================== */

.inv {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  padding: 1.2rem;
}
@media (min-width: 860px) { .inv { grid-template-columns: 0.95fr 1.05fr; align-items: start; } }

.inv-print-bar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  flex-wrap: wrap;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid color-mix(in srgb, var(--accent) 34%, rgba(255,255,255,0.10));
  background: color-mix(in srgb, var(--accent) 9%, rgba(255,255,255,0.03));
  font-size: 0.78rem;
  color: var(--muted);
}
.inv-print-bar i { color: color-mix(in srgb, var(--accent) 80%, #fff); }
.inv-print-actions { display: inline-flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.inv-export {
  position: relative;
  height: 30px; padding: 0 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  color: rgba(255,255,255,0.42);
  font: inherit; font-size: 0.74rem; font-weight: 750;
  cursor: not-allowed;
  display: inline-flex; align-items: center; gap: 0.4rem;
}

.inv.inv-print { grid-template-columns: 1fr; }
.inv.inv-print .inv-editor { display: none; }
.inv.inv-print .inv-paper { max-width: 700px; margin: 0 auto; padding: 2rem 2.1rem; width: 100%; }

.inv-editor {
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.10);
  padding: 0.9rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-width: 0;
}
.inv-editor-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; font-weight: 750; font-size: 0.85rem; color: var(--muted); }
.inv-editor-head > span:first-child i { color: color-mix(in srgb, var(--accent) 82%, #fff); margin-right: 0.3rem; }
.inv-head-actions { display: inline-flex; gap: 0.4rem; flex-wrap: wrap; }

.inv-group { display: flex; flex-direction: column; gap: 0.5rem; padding-top: 0.75rem; border-top: 1px solid rgba(255,255,255,0.08); }
.inv-group-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; }
.inv-group-title {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--accent) 62%, var(--muted));
}

.inv-fields { display: grid; grid-template-columns: 1fr; gap: 0.5rem; }
@media (min-width: 480px) { .inv-fields { grid-template-columns: 1fr 1fr; } }
.inv-field { display: flex; flex-direction: column; gap: 0.22rem; min-width: 0; }
.inv-field > span { font-size: 0.68rem; font-weight: 750; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }

.inv-editor input[type="text"],
.inv-editor input[type="date"],
.inv-editor input[type="number"],
.inv-editor select,
.inv-textarea {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 0 0.55rem;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.05);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
}
.inv-editor select { cursor: pointer; }
.inv-textarea { height: auto; padding: 0.45rem 0.55rem; resize: vertical; line-height: 1.5; }
.inv-editor input.invalid { border-color: rgba(255,95,107,0.6); background: rgba(255,95,107,0.08); }
.inv-editor input::placeholder { color: rgba(255,255,255,0.3); }

.inv-note { margin: 0; font-size: 0.7rem; color: var(--muted); font-style: italic; }

.inv-rows { display: flex; flex-direction: column; gap: 0.5rem; }
.inv-rows-empty {
  padding: 0.9rem;
  text-align: center;
  border-radius: 10px;
  border: 1px dashed rgba(255,255,255,0.16);
  color: var(--muted);
  font-size: 0.8rem;
  font-style: italic;
}
.inv-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "desc del" "meta meta";
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem;
  border-radius: 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  overflow: hidden;
  transition: opacity 240ms ease, height 240ms ease, padding 240ms ease, margin 240ms ease;
}
.inv-row.removing { opacity: 0; height: 0 !important; padding-top: 0; padding-bottom: 0; margin: 0; }
.inv-desc { grid-area: desc; }
.inv-del { grid-area: del; }
.inv-row-meta { grid-area: meta; display: flex; align-items: center; flex-wrap: wrap; gap: 0.4rem 0.5rem; }

.inv-qty { display: inline-flex; align-items: center; gap: 0.2rem; }
.inv-qty-btn {
  width: 24px; height: 26px; border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(255,255,255,0.06); color: var(--text);
  cursor: pointer; font-weight: 800; line-height: 1; font-size: 0.9rem;
  flex: none;
}
.inv-qty-btn:hover { border-color: color-mix(in srgb, var(--accent) 55%, rgba(255,255,255,0.16)); }
.inv-editor input.inv-qty-n { width: 44px; height: 26px; text-align: center; padding: 0 0.2rem; font-size: 0.78rem; }
.inv-rate-wrap { display: inline-flex; align-items: center; gap: 0.2rem; }
.inv-cur { font-size: 0.78rem; font-weight: 800; color: var(--muted); }
.inv-editor input.inv-rate { width: 78px; height: 26px; padding: 0 0.35rem; font-size: 0.78rem; }
.inv-ex { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.72rem; font-weight: 700; color: var(--muted); cursor: pointer; }
.inv-ex input { accent-color: var(--accent); width: 14px; height: 14px; cursor: pointer; }
.inv-line-amt { margin-left: auto; font-size: 0.8rem; font-weight: 800; font-variant-numeric: tabular-nums; color: color-mix(in srgb, var(--accent) 70%, var(--text)); }
.inv-del {
  width: 26px; height: 26px; border-radius: 7px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.05); color: var(--muted);
  cursor: pointer; font-size: 0.72rem;
  transition: color 160ms ease, border-color 160ms ease;
  flex: none;
}
.inv-del:hover { color: #ff8b95; border-color: rgba(255,95,107,0.4); }

.inv-opts { display: flex; flex-direction: column; gap: 0.55rem; }
.inv-opt { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; font-size: 0.8rem; color: var(--muted); font-weight: 650; flex-wrap: wrap; }
.inv-opt select { max-width: 62%; }
.inv-disc-ctl { display: inline-flex; align-items: center; gap: 0.4rem; }
.inv-seg { display: inline-flex; gap: 0.2rem; }
.inv-seg-btn {
  height: 28px; min-width: 34px; padding: 0 0.5rem;
  border-radius: 7px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.05);
  color: var(--muted); font: inherit; font-size: 0.75rem; font-weight: 800; cursor: pointer;
}
.inv-seg-btn.active {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 22%, rgba(255,255,255,0.05));
  border-color: color-mix(in srgb, var(--accent) 55%, rgba(255,255,255,0.14));
}
.inv-disc-input { display: inline-flex; align-items: center; gap: 0.25rem; }
.inv-editor input#inv-disc-val { width: 78px; text-align: right; }
.inv-disc-unit { font-size: 0.78rem; font-weight: 800; color: var(--muted); min-width: 1em; }

.inv-hint { margin: 0; font-size: 0.75rem; color: #ffc46e; }

/* --- The paper — intentionally a light surface --- */
.inv-paper {
  --pt: #1c2230;
  --pmut: #5b6478;
  --pline: #e3e7ef;
  background: #fbfcfe;
  color: var(--pt);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 18px 50px rgba(0,0,0,0.4), inset 0 0 0 1px rgba(255,255,255,0.6);
  padding: 1.3rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-width: 0;
}
.inv-paper-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.inv-brand { font-size: 1.12rem; font-weight: 900; letter-spacing: 0.01em; color: #101623; }
.inv-brand-sub { font-size: 0.72rem; color: var(--pmut); margin-top: 0.15rem; max-width: 34ch; }
.inv-meta { text-align: right; margin-left: auto; }
.inv-doc { font-size: 0.62rem; font-weight: 900; letter-spacing: 0.22em; color: var(--pmut); }
.inv-no { font-weight: 800; font-size: 0.95rem; color: color-mix(in srgb, var(--accent) 45%, #101623); }
.inv-date { font-size: 0.72rem; color: var(--pmut); margin-top: 0.1rem; }

.inv-billto { display: flex; flex-direction: column; gap: 0.1rem; font-size: 0.8rem; color: var(--pmut); }
.inv-billto-k { font-size: 0.62rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.inv-billto strong { color: var(--pt); font-size: 0.92rem; }

.inv-lines-wrap { overflow-x: auto; }
.inv-lines { width: 100%; border-collapse: collapse; font-size: 0.8rem; min-width: 300px; }
.inv-lines th {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 2px solid var(--pline);
  color: var(--pmut);
  font-size: 0.64rem; letter-spacing: 0.05em; text-transform: uppercase;
  white-space: nowrap;
}
.inv-lines th.inv-r, .inv-lines td.inv-r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.inv-lines td { padding: 0.42rem 0.5rem; border-bottom: 1px solid var(--pline); }
.inv-lines .inv-line-name { color: var(--pt); font-weight: 600; }
/* Paper-scale micro badge. `padding: 0` on the block axis looks alarming but is
   correct here and was measured before being left alone: `line-height: normal`
   supplies ~2.47px of leading above and below the cap, against 5.12px of
   horizontal padding — a 2.07 ratio, i.e. MORE square than the dark-chrome
   badges (2.75) or the base .pill (3.67). Adding block padding also pushes this
   inline-block past the 17.68px line box of .inv-lines td, which makes the one
   tagged invoice row 1-3px taller than every other row. Do not "fix" it. */
.inv-tag {
  display: inline-block;
  margin-left: 0.3rem;
  padding: 0 0.32rem;
  border-radius: 999px;
  font-size: 0.6rem; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase;
  color: #1d6b9d; background: #e6f2fa; border: 1px solid #cbe2f2;
}
.inv-lines .inv-empty td { color: var(--pmut); text-align: center; padding: 1rem; font-style: italic; }

.inv-totals { display: flex; flex-direction: column; gap: 0.28rem; margin-left: auto; width: min(250px, 100%); }
.inv-total-row { display: flex; justify-content: space-between; gap: 0.8rem; font-size: 0.84rem; color: var(--pmut); font-variant-numeric: tabular-nums; }
.inv-total-row span:last-child.flash { animation: invNumFlash 0.7s ease; border-radius: 4px; }
@keyframes invNumFlash { 0% { background: color-mix(in srgb, var(--accent) 30%, transparent); } 100% { background: transparent; } }
.inv-disc-row { color: #1d9d6b; }
.inv-grand { color: var(--pt); font-weight: 800; font-size: 1rem; padding-top: 0.35rem; border-top: 1px solid var(--pline); margin-top: 0.15rem; }

.inv-taxsum { border-top: 1px solid var(--pline); padding-top: 0.6rem; }
.inv-taxsum h4 { margin: 0 0 0.35rem; font-size: 0.62rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--pmut); }
.inv-taxsum-table { width: 100%; border-collapse: collapse; font-size: 0.76rem; color: var(--pmut); }
.inv-taxsum-table th { text-align: left; padding: 0.22rem 0.4rem; font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.05em; color: #8b93a5; font-weight: 800; }
.inv-taxsum-table th.inv-r, .inv-taxsum-table td.inv-r { text-align: right; font-variant-numeric: tabular-nums; }
.inv-taxsum-table td { padding: 0.22rem 0.4rem; border-top: 1px solid var(--pline); }
.inv-taxsum-table .inv-taxsum-total td { font-weight: 800; color: var(--pt); border-top: 1px solid #c9d0dd; }

.inv-notes-block { display: flex; flex-direction: column; gap: 0.15rem; border-top: 1px solid var(--pline); padding-top: 0.6rem; }
.inv-notes-k { font-size: 0.62rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--pmut); }
.inv-notes-block > span:last-child { font-size: 0.76rem; color: var(--pmut); line-height: 1.5; }

.inv-foot { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-top: 0.2rem; padding-top: 0.65rem; border-top: 1px solid var(--pline); }
.inv-foot > span { font-size: 0.72rem; color: var(--pmut); font-style: italic; }
.inv-foot b { font-style: normal; color: var(--pt); }
.inv-download {
  position: relative;
  height: 34px; padding: 0 0.85rem;
  border-radius: 9px;
  border: 1px solid rgba(0,0,0,0.12);
  background: #eef1f7;
  color: #8a91a2;
  font: inherit;
  font-weight: 750; font-size: 0.78rem;
  cursor: not-allowed;
  display: inline-flex; align-items: center; gap: 0.45rem;
}
.inv-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  max-width: min(240px, 66vw);
  background: #0b0e18;
  border: 1px solid rgba(255,255,255,0.14);
  color: #fff;
  font-size: 0.72rem; font-weight: 600; line-height: 1.4; text-align: left;
  padding: 0.4rem 0.6rem; /* matches .ds-tooltip — same tier, same page */
  border-radius: 8px;
  opacity: 0; pointer-events: none;
  transform: translateY(4px);
  transition: opacity 180ms ease, transform 180ms ease;
}
.inv-download:hover .inv-tooltip, .inv-download:focus-visible .inv-tooltip { opacity: 1; transform: translateY(0); }

/* ===================== RESPONSIVE ===================== */

@media (max-width: 600px) {
  .demo-sheet, .pv { padding: 0.85rem 0.9rem 1rem; }
  .inv { padding: 0.9rem; }
  .ds-bar-row { grid-template-columns: 84px 1fr 72px; }
  .pv-brow { grid-template-columns: 70px 1fr auto; }
  .ds-report, .ds-csv { padding: 0.8rem 0.85rem 0.9rem; }
  .ds-remaining strong { font-size: 1.25rem; }
  .inv-paper { padding: 1rem 1rem; }
  .inv-opt select { max-width: 100%; width: 100%; }
  .inv-opt { justify-content: flex-start; }
  .inv.inv-print .inv-paper { padding: 1.1rem 1.05rem; }
}

/* ===================== REDUCED MOTION ===================== */

@media (prefers-reduced-motion: reduce) {
  .ds-table td.ds-fix { animation: none; }
  .ds-report, .pv-drill { animation: none; }
  .ds-bar i { transition: none; }
  .ds-progress i { transition: none; }
  .pv-bfill { transition: none; }
  .inv-row { transition: none; }
  .inv-total-row span:last-child.flash { animation: none; }
}
