/* =====================================================================
 * Selinka SWM Rechner — precious-metals dark theme (v2)
 * Plan §7.2. Card gradient borders, larger typography, richer feel.
 * ===================================================================== */

:root {
  --bg:            #0d0d0f;
  --bg-2:          #111114;
  --surface:       #17171b;
  --surface-2:     #1e1e23;
  --surface-3:     #24242a;
  --border-start:  #e8c547;
  --border-end:    #c8cdd4;
  --accent-gold:     #e8c547;
  --accent-gold-2:   #f7d968;
  --accent-silver:   #c8cdd4;
  --accent-platinum: #5b9bd5;
  --accent-palladium:#e85d75;
  --accent-green:    #6bbf6b;
  --accent-copper:   #c8744a;
  --accent-bronze:   #b87333;
  --text-primary:  #f3f3f5;
  --text-muted:    #b0b0b8;
  --text-subtle:   #7a7a84;
  --danger:        #e85d75;
  --radius-card:   20px;
  --radius-input:  10px;
  --glow:          0 0 12px rgba(232, 197, 71, 0.35);
  --font-heading:  "Inter", system-ui, sans-serif;
  --font-body:     system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono:     ui-monospace, "SF Mono", Consolas, "Courier New", monospace;
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    radial-gradient(ellipse at top, rgba(232, 197, 71, 0.04), transparent 60%),
    radial-gradient(ellipse at bottom, rgba(91, 155, 213, 0.03), transparent 50%),
    var(--bg);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 .5em 0;
}

a { color: var(--accent-gold); text-decoration: none; }
a:hover, a:focus { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent-gold);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* =====================================================================
 *  Gradient-border card helper (precious-metals rim)
 *  Uses background-clip: padding-box / border-box instead of a
 *  pseudo-element + mask-composite — renders cleanly on every browser
 *  and doesn't produce stray edges at sub-pixel widths.
 * ===================================================================== */
.metal-card {
  border: 1px solid transparent;
  border-radius: var(--radius-card);
  background:
    linear-gradient(180deg, var(--surface), var(--surface-2)) padding-box,
    linear-gradient(160deg,
      var(--border-start) 0%,
      rgba(232,197,71,0.15) 35%,
      rgba(200,205,212,0.15) 55%,
      var(--border-end) 100%) border-box;
  box-shadow: 0 6px 20px rgba(0,0,0,0.35);
}

/* =====================================================================
 *  LOGIN
 * ===================================================================== */
.login-body {
  display: flex; flex-direction: column; min-height: 100vh;
  align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 440px;
  padding: 36px 32px;
  border: 1px solid transparent;
  border-radius: var(--radius-card);
  background:
    linear-gradient(180deg, var(--surface), var(--surface-2)) padding-box,
    linear-gradient(160deg,
      var(--border-start) 0%,
      rgba(232,197,71,0.15) 35%,
      rgba(200,205,212,0.15) 55%,
      var(--border-end) 100%) border-box;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45), var(--glow);
}
.login-card h1 {
  font-size: 24px;
  margin-bottom: 20px;
  background: linear-gradient(90deg, var(--border-start), var(--border-end));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card label { font-size: 14px; color: var(--text-muted); }
.login-card input[type="password"] {
  background: var(--surface-2);
  border: 1px solid var(--surface-3);
  border-radius: var(--radius-input);
  padding: 12px 14px;
  color: var(--text-primary);
  font-size: 16px;
}
.login-card input[type="password"]:focus { border-color: var(--accent-gold); outline: none; }

.login-card button[type="submit"] {
  margin-top: 6px;
  background: linear-gradient(135deg, var(--accent-gold-2), var(--accent-bronze));
  color: #17170b;
  font-weight: 700;
  border: 0;
  border-radius: var(--radius-input);
  padding: 13px 16px;
  font-size: 16px;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .15s ease;
  box-shadow: 0 4px 14px rgba(232,197,71,0.25);
}
.login-card button[type="submit"]:hover  {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(232,197,71,0.4);
}

.error {
  color: var(--danger);
  background: rgba(232, 93, 117, 0.08);
  border: 1px solid rgba(232, 93, 117, 0.35);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  margin: 0 0 8px 0;
}

/* Login page footer — width-matched to the card */
.login-body .footer-disclaimer {
  max-width: 440px;
  width: 100%;
  margin-top: 24px;
  padding: 16px 4px;
  border-top: 1px solid #1a1a1e;
  font-size: 13px;
  line-height: 1.55;
}

/* =====================================================================
 *  DASHBOARD
 * ===================================================================== */
.dashboard-body {
  display: flex; flex-direction: column;
  min-height: 100vh;
  padding: 0 0 40px 0;
}

.dashboard-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 32px;
  border-bottom: 1px solid #212126;
  background: linear-gradient(180deg, rgba(232,197,71,0.04), transparent);
}
.dashboard-header h1 {
  font-size: 22px;
  background: linear-gradient(90deg, var(--border-start), var(--border-end));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.logout-form button {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--surface-3);
  border-radius: var(--radius-input);
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.logout-form button:hover { border-color: var(--accent-gold); color: var(--text-primary); }

.dashboard-main {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  max-width: 1400px;
  width: 100%;
  margin: 24px auto;
  padding: 0 32px;
}

/* ---------- Input bar ---------- */
.input-bar { padding: 22px 26px; position: sticky; top: 16px; z-index: 10; }
.input-bar h2 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.input-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px 22px;
}
.input-field { display: flex; flex-direction: column; gap: 4px; }
.input-field[hidden] { display: none; }
.input-field label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}
.input-field input,
.input-field select {
  background: var(--surface-2);
  border: 1px solid var(--surface-3);
  border-radius: var(--radius-input);
  padding: 10px 12px;
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--font-body);
  width: 100%;
}
.input-field input:focus,
.input-field select:focus { border-color: var(--accent-gold); outline: none; }
.input-field select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--accent-gold) 50%),
    linear-gradient(135deg, var(--accent-gold) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}
.input-field .hint {
  font-size: 12px;
  color: var(--text-subtle);
}
.input-field.error input,
.input-field.error select { border-color: var(--danger); }
.input-field .field-error {
  font-size: 12px;
  color: var(--danger);
  min-height: 14px;
}

/* Warnings — now subtle and placed below the form inside the input bar */
.input-bar .warnings {
  margin-top: 14px;
  background: rgba(91, 155, 213, 0.08);
  border: 1px solid rgba(91, 155, 213, 0.3);
  color: var(--accent-platinum);
  border-radius: var(--radius-input);
  padding: 10px 14px;
  font-size: 13px;
}
.input-bar .warnings ul { margin: 0; padding-left: 18px; }

/* ---------- KPI row — 4 cards, roomier ---------- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}
.kpi-card {
  padding: 22px 24px;
  min-width: 0;
}
.kpi-card .kpi-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 600;
}
.kpi-card .kpi-value {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 26px;
  letter-spacing: -0.01em;
  line-height: 1.15;
  word-break: break-word;
}
.kpi-card .kpi-sub {
  font-size: 13px;
  color: var(--text-subtle);
  margin-top: 6px;
}
.kpi-card[data-tone="gold"]     .kpi-value { color: var(--accent-gold); }
.kpi-card[data-tone="silver"]   .kpi-value { color: var(--accent-silver); }
.kpi-card[data-tone="green"]    .kpi-value { color: var(--accent-green); }
.kpi-card[data-tone="platinum"] .kpi-value { color: var(--accent-platinum); }
.kpi-card[data-tone="palladium"].kpi-value { color: var(--accent-palladium); }

/* ---------- Summary (2-col) + Parameters (3-col) panels ---------- */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.params-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.summary-card { padding: 22px 26px; }
.summary-card h3 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.summary-table td {
  padding: 7px 0;
  border-bottom: 1px solid #1f1f24;
}
.summary-table td:last-child {
  text-align: right;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}
.summary-table td:first-child { color: var(--text-muted); }
.summary-table tr.highlight td {
  /* Small padding-top so the border-top line sits directly above the text */
  padding-top: 4px;
  border-top: 2px solid var(--accent-gold);
  border-bottom: 0;
  color: var(--accent-gold);
  font-weight: 700;
  font-size: 16px;
}
/* Extra space before a highlight row — pushes the line away from the preceding row */
.summary-table tr.highlight td { padding-bottom: 6px; }
.summary-table tr:not(.highlight) + tr.highlight td { /* already handled by tr preceding */
  /* no-op — kept for clarity */
}
/* Colour overrides — higher specificity than `tr.highlight td` and the default
   first/last-child color rules, so Kosten / Erträge / Endstand each get their
   own distinct colour. */
.summary-card .summary-table tr.highlight-neg td,
.summary-card .summary-table tr.highlight-neg td:first-child,
.summary-card .summary-table tr.highlight-neg td:last-child {
  border-top-color: var(--accent-palladium);
  color: var(--accent-palladium);
}
.summary-card .summary-table tr.highlight-pos td,
.summary-card .summary-table tr.highlight-pos td:first-child,
.summary-card .summary-table tr.highlight-pos td:last-child {
  border-top-color: var(--accent-green);
  color: var(--accent-green);
}
.summary-card .summary-table tr.highlight-final td,
.summary-card .summary-table tr.highlight-final td:first-child,
.summary-card .summary-table tr.highlight-final td:last-child {
  border-top-color: var(--accent-gold);
  color: var(--accent-gold);
  font-size: 18px;
  padding-top: 6px;
}
/* Give the row preceding a highlight row more breathing room */
.summary-table tr.has-post-line td { padding-bottom: 10px; }
.summary-table tr.section-label td {
  padding-top: 14px; padding-bottom: 4px;
  border-bottom: 0;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.summary-table tr.section-spacer td { border: 0; height: 4px; padding: 0; }
.summary-table .minus { color: var(--accent-palladium); }
.summary-table .plus  { color: var(--accent-green); }

/* ---------- Charts ---------- */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.chart-card { padding: 20px 22px 14px; min-width: 0; }
.chart-card h3 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.chart-card .chart-sub {
  font-size: 12px;
  color: var(--text-subtle);
  margin-bottom: 10px;
}
.chart-card canvas {
  width: 100% !important;
  height: 280px !important;
  display: block;
}
.chart-card.full-width { grid-column: 1 / -1; }

/* ---------- Mobile info banner (shown only on small screens) ---------- */
.mobile-hint {
  display: none;
  background: linear-gradient(135deg, rgba(232,197,71,0.1), rgba(232,197,71,0.03));
  border: 1px solid rgba(232,197,71,0.3);
  color: var(--accent-gold);
  border-radius: var(--radius-input);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.45;
}
.mobile-hint strong { color: var(--text-primary); }

/* ---------- Detail table ---------- */
.detail-section { padding: 22px 26px; }
.detail-table-wrap {
  /* Horizontal scroll fallback on narrow viewports */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.detail-section h2 {
  font-size: 18px;
  margin-bottom: 6px;
  color: var(--text-primary);
}
.detail-section .detail-legend {
  color: var(--text-subtle);
  font-size: 13px;
  margin-bottom: 14px;
}
.detail-section .detail-legend .plus  { color: var(--accent-green); font-weight: 600; }
.detail-section .detail-legend .minus { color: var(--accent-palladium); font-weight: 600; }

.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.detail-table th, .detail-table td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid #1f1f24;
}
.detail-table th {
  text-align: right;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.detail-table th:first-child, .detail-table td:first-child { text-align: left; }
.detail-table td.pos { color: var(--accent-green); }
.detail-table td.neg { color: var(--accent-palladium); }
.detail-table .year-row { cursor: pointer; background: var(--surface-2); }
.detail-table .year-row td {
  font-weight: 700;
  color: var(--accent-gold);
  border-top: 1px solid #28282e;
  border-bottom: 1px solid #28282e;
  font-size: 15px;
}
.detail-table .year-row td.pos { color: var(--accent-green); }
.detail-table .year-row td.neg { color: var(--accent-palladium); }
.detail-table .year-row .chevron {
  display: inline-block;
  transition: transform .15s;
  margin-right: 8px;
  color: var(--text-muted);
}
.detail-table .year-row.open .chevron { transform: rotate(90deg); }
.detail-table .month-row { display: none; }
.detail-table .month-row.visible { display: table-row; }
.detail-table .month-row td { color: var(--text-primary); }

/* ---------- Footer disclaimer ---------- */
.footer-disclaimer {
  max-width: 1400px;
  margin: 36px auto 0;
  padding: 18px 32px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
  border-top: 1px solid #1a1a1e;
}
.footer-disclaimer small { font-size: inherit; }
.footer-disclaimer .math-note {
  display: block;
  margin-top: 8px;
  color: var(--text-subtle);
  font-size: 13px;
}

/* =====================================================================
 *  Breakpoints — plan §7.1
 * ===================================================================== */
@media (max-width: 1199px) {
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .params-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1023px) {
  /* Tablet */
  .charts-grid { grid-template-columns: 1fr; }
  .chart-card.full-width { grid-column: 1; }
  .summary-grid { grid-template-columns: 1fr; }
  .params-grid { grid-template-columns: 1fr; }
}

@media (max-width: 767px) {
  /* Mobile — show the advisory banner */
  .mobile-hint { display: block; }
  html, body { overflow-x: hidden; }
  body { font-size: 15px; }
  .dashboard-header { padding: 14px 16px; }
  .dashboard-header h1 { font-size: 16px; }
  .dashboard-main {
    padding: 0 14px;
    gap: 14px;
    margin-top: 14px;
    max-width: 100%;
  }
  .metal-card { box-shadow: 0 4px 12px rgba(0,0,0,0.3); }
  .input-bar {
    position: static;
    padding: 16px;
  }
  .input-grid { grid-template-columns: 1fr; gap: 12px; }
  .kpi-row { grid-template-columns: 1fr; gap: 10px; }
  .kpi-card { padding: 14px 16px; }
  .kpi-card .kpi-value { font-size: 22px; }
  .summary-card { padding: 16px; }
  .summary-card h3 { font-size: 13px; }
  .summary-table { font-size: 14px; }
  .chart-card { padding: 16px 14px 10px; }
  .chart-card canvas { height: 220px !important; }
  .detail-section { padding: 16px 12px; }
  /* Reduced detail table on mobile — only essentials per plan §7.1.
     Hide Honorar / Einrichtung / Agio / Vergütung columns.
     Keep Zeitraum / Einzahlung / Restzins / Unkosten / Kontostand. */
  .detail-table th:nth-child(4),  .detail-table td:nth-child(4),
  .detail-table th:nth-child(6),  .detail-table td:nth-child(6),
  .detail-table th:nth-child(7),  .detail-table td:nth-child(7),
  .detail-table th:nth-child(8),  .detail-table td:nth-child(8) {
    display: none;
  }
  .detail-table { font-size: 13px; }
  .detail-table th, .detail-table td {
    padding: 6px 4px;
    white-space: nowrap;
  }
  .detail-table .year-row td { font-size: 13px; }
  .detail-table .month-row { display: none !important; }
  .detail-table .month-row.visible { display: none !important; }
  .footer-disclaimer { padding: 18px 14px; font-size: 13px; }
}

@media (max-width: 500px) {
  /* Very narrow phones — drop two more columns, keep only the
     essentials: Zeitraum, Einzahlung, Restzins, Kontostand. */
  .detail-table th:nth-child(5),  .detail-table td:nth-child(5) { display: none; }
  .kpi-card .kpi-value { font-size: 20px; }
  .detail-section h2 { font-size: 15px; }
  .detail-section .detail-legend { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* =====================================================================
 * Utility classes — replace inline styles so CSP can drop unsafe-inline.
 * ===================================================================== */

/* Hide row without inline style="display:none" (used in params panels
   that toggle onetime/monthly rows based on programm). */
.is-hidden { display: none !important; }

/* Month-row label cell — replaces style="padding-left:32px" on the
   first <td> of the SSR/JS-built detail-table month rows. */
.detail-table .month-label { padding-left: 32px; }

/* Error-toast bottom-center — replaces setAttribute('style', ...). */
.swm-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1c1c20;
  border: 1px solid var(--accent-palladium);
  color: var(--text-primary);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 1000;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
  display: none;
}
.swm-toast.is-visible { display: block; }
