:root {
  color-scheme: light dark;
  font-family: Arial, sans-serif;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #0f172a;
  --text-muted: #475569;
  --border: #e2e8f0;
  --border-strong: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #dbeafe;
  --primary-soft-hover: #bfdbfe;
  --primary-contrast: #ffffff;
  --focus-ring: #2563eb;
  --success-bg: #dcfce7;
  --success-text: #166534;
  --info-bg: #dbeafe;
  --info-text: #1e3a8a;
  --error-text: #991b1b;
  --header-bg: #0f172a;
  --header-text: #ffffff;
  --table-head-bg: #e2e8f0;
  --table-head-text: #0f172a;
  --sheet-section-bg: #dbeafe;
  --sheet-subtotal-bg: #cfe2ff;
  --sheet-total-bg: #bfdbfe;
  --sheet-zebra-bg: #f1f5f9;
}
body { margin: 0; background: var(--bg); color: var(--text); }
.page-header { padding: 1rem 1.25rem; background: var(--header-bg); color: var(--header-text); }
.page-header h1 { margin: 0 0 0.35rem; font-size: 1.5rem; }
.page-header p { margin: 0; opacity: 0.9; }
.layout { padding: 1rem; display: grid; gap: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1.1rem 1rem; }
.card h2 { margin-top: 0; }
.grid { display: grid; gap: 0.75rem; }
.two-col { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.split-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0.8rem; }
label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.82rem; text-transform: uppercase; color: var(--text-muted); }
.toggle-label { flex-direction: row; align-items: center; gap: 0.5rem; text-transform: none; color: var(--text); }
input, button, select { font: inherit; }
input, select { padding: 0.48rem 0.56rem; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 0.92rem; text-transform: none; }
select { min-height: 2.1rem; }
.tabs { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }
.sub-card { border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem; background: var(--surface-soft); }
.sub-card h3 { margin: 0 0 0.6rem; font-size: 0.95rem; }
.tab-btn { background: var(--primary-soft); border: 1px solid var(--primary-soft-hover); color: var(--text); border-radius: 6px; padding: 0.42rem 0.7rem; cursor: pointer; }
.tab-btn.is-active { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
table { width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid var(--border); padding: 0.44rem 0.56rem; text-align: left; font-size: 0.92rem; line-height: 1.25; }
th { background: var(--table-head-bg); color: var(--table-head-text); font-size: 0.85rem; text-transform: uppercase; font-weight: 700; }
.money-col, .money-cell { text-align: right; font-variant-numeric: tabular-nums; }
th:nth-child(3), td:nth-child(3) { border-left: 1px solid var(--border-strong); }
.sheet-section-row td { background: var(--sheet-section-bg); font-weight: 700; border-top: 1px solid var(--border-strong); font-size: 0.84rem; text-transform: uppercase; }
.sheet-total-row td { font-weight: 800; border-top: 3px solid var(--primary); border-bottom: 1px solid var(--border-strong); background: var(--sheet-total-bg); }
.sheet-subtotal-row td { font-weight: 700; border-top: 1px solid var(--border-strong); border-bottom: 1px solid var(--border-strong); background: var(--sheet-subtotal-bg); }
.sheet-line-row td:first-child { color: var(--text-muted); }
.factor-label { cursor: help; border-bottom: 1px dotted color-mix(in srgb, var(--text-muted) 55%, transparent 45%); }
.sheet-line-row.is-alt td { background: var(--sheet-zebra-bg); }
.money-zero { color: var(--text-muted); }
.kpi-grid { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.kpi { border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem; background: var(--surface-soft); }
.kpi h3 { margin: 0 0 0.4rem; font-size: 0.9rem; }
.kpi p { margin: 0; font-size: 1.2rem; font-weight: 700; }
.winner-banner { margin-bottom: 0.75rem; padding: 0.7rem 0.8rem; border-radius: 8px; font-weight: 700; }
.winner-banner.win-bch { background: var(--success-bg); color: var(--success-text); }
.winner-banner.win-used { background: var(--info-bg); color: var(--info-text); }
.validation { color: var(--error-text); min-height: 1.2rem; margin: 0.55rem 0 0; font-size: 0.86rem; }
.is-hidden { display: none !important; }
.helper-note { margin: 0.05rem 0 0.35rem; font-size: 0.68rem; color: color-mix(in srgb, var(--text-muted) 78%, transparent 22%); text-transform: none; letter-spacing: normal; line-height: 1.2; }

@media (max-width: 768px) {
  .page-header h1 { font-size: 1.25rem; }
  .tabs { gap: 0.4rem; }
  .tab-btn { font-size: 0.84rem; padding: 0.36rem 0.52rem; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #111827;
    --surface-soft: #1f2937;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #334155;
    --border-strong: #64748b;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-soft: #1e3a8a;
    --primary-soft-hover: #1d4ed8;
    --primary-contrast: #ffffff;
    --focus-ring: #60a5fa;
    --success-bg: #14532d;
    --success-text: #bbf7d0;
    --info-bg: #1e3a8a;
    --info-text: #dbeafe;
    --error-text: #fca5a5;
    --table-head-bg: #0f172a;
    --table-head-text: #cbd5e1;
    --sheet-section-bg: #1e293b;
    --sheet-subtotal-bg: #223658;
    --sheet-total-bg: #1d3a63;
    --sheet-zebra-bg: #172235;
  }
  input, select, button { border-color: var(--border-strong); }
}
