:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --border: #e4e8ef;
  --border-strong: #d2d8e2;
  --text: #0f172a;
  --text-muted: #5b6478;
  --text-soft: #8590a4;
  --accent: #1d4ed8;
  --accent-soft: #eef4ff;
  --accent-border: #bdcffb;
  --positive: #047857;
  --negative: #b91c1c;
  --row-total: #f5f7fb;
  --row-result: #eef4ff;
  --row-positive: #ecfdf5;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
  --radius: 14px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Layout */
.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

@media (max-width: 640px) {
  .page { padding: 20px 16px 60px; }
}

/* Header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.page-header h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text);
}

.subtitle {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 15px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.15s ease;
}

.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-ghost:hover {
  background: var(--surface);
}

/* KPI Strip */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 28px;
}

@media (max-width: 900px) {
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 460px) {
  .kpi-strip { grid-template-columns: 1fr; }
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease;
}

.kpi-label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-soft);
  font-weight: 600;
  margin-bottom: 4px;
}

.kpi-value {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.kpi-highlight {
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.kpi-highlight .kpi-value { color: var(--accent); }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.card-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.card-total {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.card-total strong {
  color: var(--text);
  font-weight: 700;
  margin-left: 4px;
}

.card-body {
  padding: 18px 22px 20px;
}

/* Grid layouts */
.grid {
  display: grid;
  gap: 14px;
}

.grid-2 { grid-template-columns: 1fr 1fr; }

@media (max-width: 640px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* Fields */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.field input[type="text"],
.field input[type="number"] {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font: inherit;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus,
.calc-table input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.15);
}

/* Tables */
.table-wrap {
  margin: -4px -6px 0;
  overflow-x: auto;
}

.calc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 560px;
}

.calc-table thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-soft);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: transparent;
}

.calc-table thead .col-pct,
.calc-table thead .col-chf { text-align: right; }
.calc-table thead .col-basis { text-align: left; color: var(--text-soft); }

.calc-table tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

.calc-table tbody tr:last-child td {
  border-bottom: none;
}

.calc-table td small {
  color: var(--text-soft);
  font-weight: 400;
  font-size: 12px;
  margin-left: 4px;
}

.calc-table .col-label { width: 38%; }
.calc-table .col-pct { width: 14%; text-align: right; }
.calc-table .col-basis { width: 18%; color: var(--text-soft); font-size: 13px; }
.calc-table .col-chf { width: 30%; text-align: right; }

.calc-table td:nth-child(2),
.calc-table td:nth-child(4) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.calc-table input[type="number"] {
  width: 100%;
  max-width: 140px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 6px 10px;
  font: inherit;
  font-size: 14px;
  text-align: right;
  background: var(--surface);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Hide spin buttons */
.calc-table input[type="number"]::-webkit-inner-spin-button,
.calc-table input[type="number"]::-webkit-outer-spin-button,
.field input[type="number"]::-webkit-inner-spin-button,
.field input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.calc-table input[type="number"],
.field input[type="number"] { -moz-appearance: textfield; }

.calc-table output {
  display: inline-block;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.calc-table .col-chf input,
.calc-table .col-chf output {
  margin-left: auto;
}

/* Special row styles */
.row-positive td {
  background: var(--row-positive);
}

.row-positive td:nth-child(4) {
  font-weight: 600;
  color: var(--positive);
}

.row-subhead td {
  background: var(--bg);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-soft);
  padding: 6px 12px !important;
}

.row-total td {
  background: var(--row-total);
  font-weight: 700;
  border-top: 2px solid var(--border-strong);
}

.row-result td {
  background: var(--row-result);
  font-weight: 700;
  color: var(--accent);
}

.row-result td output {
  color: var(--accent);
}

/* Metrics grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.metric {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.metric-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-soft);
  font-weight: 600;
}

.metric-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.metric-formula {
  font-size: 12px;
  color: var(--text-soft);
}

.metric-highlight {
  background: var(--accent-soft);
  border-color: var(--accent-border);
}
.metric-highlight .metric-value { color: var(--accent); }

/* Hints */
.hint {
  margin: 12px 4px 0;
  font-size: 13px;
  color: var(--text-soft);
}

/* Footer */
.page-footer {
  margin-top: 32px;
  text-align: center;
  color: var(--text-soft);
  font-size: 12px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: white;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 1000;
  box-shadow: var(--shadow);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Negative values */
.is-negative { color: var(--negative) !important; }

/* Print */
@media print {
  body { background: white; }
  .header-actions, .toast { display: none; }
  .card { box-shadow: none; break-inside: avoid; }
  .kpi-strip { break-inside: avoid; }
}
