:root {
  --ink: #161a14;
  --ink-soft: #262c22;
  --paper: #f5f2ea;
  --panel: #fffdf8;
  --line: #e2dccb;
  --text: #22261f;
  --text-muted: #6f6a58;
  --accent: #8a4a2f;
  --accent-soft: #f1e2d4;
  --positive: #3c6e4f;
  --negative: #a13d2c;

  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */

.sidebar {
  background: var(--ink);
  color: #ece7da;
  display: flex;
  flex-direction: column;
  padding: 28px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 40px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.02em;
}

.brand-name {
  font-family: var(--font-serif);
  font-size: 15px;
  line-height: 1.2;
}

.brand-sub {
  font-size: 11px;
  color: #a9a290;
  letter-spacing: 0.03em;
  margin-top: 2px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-item {
  all: unset;
  cursor: pointer;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 14px;
  color: #cfc9ba;
  border-left: 2px solid transparent;
}

.nav-item:hover {
  background: rgba(255,255,255,0.05);
  color: #fff;
}

.nav-item.is-active {
  background: rgba(138,74,47,0.25);
  border-left: 2px solid var(--accent);
  color: #fff;
}

.sidebar-foot {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.user-card {
  padding: 10px 0;
}

.user-name {
  font-size: 13px;
  color: #ece7da;
}

.user-role {
  display: inline-block;
  margin-top: 4px;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 100px;
  background: rgba(255,255,255,0.1);
  color: #cfc9ba;
}

.user-role.admin { background: var(--accent); color: #fff; }

.dev-panel {
  margin-top: 14px;
  font-size: 12px;
  color: #a9a290;
}

.dev-panel summary {
  cursor: pointer;
  color: #cfc9ba;
}

.dev-panel p {
  line-height: 1.4;
  margin: 8px 0;
}

.dev-panel input {
  width: 100%;
  padding: 6px 8px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.06);
  color: #fff;
  font-size: 12px;
  margin-bottom: 6px;
}

.dev-panel button {
  width: 100%;
  padding: 6px 8px;
  border-radius: 4px;
  border: none;
  background: rgba(255,255,255,0.12);
  color: #fff;
  cursor: pointer;
  font-size: 12px;
}

.dev-panel button:hover { background: rgba(255,255,255,0.2); }

/* ---------- Main ---------- */

.main {
  padding: 40px 48px;
  max-width: 1180px;
}

.view { display: none; }
.view.is-active { display: block; }

.view-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 20px;
}

.view-header h1 {
  font-family: var(--font-serif);
  font-size: 28px;
  margin: 0 0 6px 0;
  font-weight: 500;
}

.section-subhead {
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 500;
  margin: 32px 0 4px 0;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.view-sub {
  margin: 0;
  color: var(--text-muted);
  font-size: 13.5px;
}

select, input[type="text"], input[type="number"], input[type="month"], input[type="email"] {
  font-family: var(--font-sans);
  font-size: 13.5px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
}

#dashboard-year {
  height: fit-content;
}

.header-controls {
  display: flex;
  gap: 10px;
}

.warning-banner {
  background: #fbeee7;
  border: 1px solid #e8c4a8;
  color: #7a3a1a;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12.5px;
  margin-bottom: 20px;
}

/* ---------- KPI cards ---------- */

.card-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.kpi-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 20px;
}

.kpi-label {
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
}

/* ---------- Charts ---------- */

.chart-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px 22px;
}

.panel h2 {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 500;
  margin: 0 0 16px 0;
}

.panel canvas {
  max-height: 300px;
}

.poc-note {
  margin-top: 24px;
  font-size: 12px;
  color: var(--text-muted);
  border-left: 2px solid var(--accent-soft);
  padding-left: 12px;
}

/* ---------- Forms ---------- */

.input-form {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 24px;
  margin-bottom: 28px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 18px;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.form-grid label.span-2 {
  grid-column: span 2;
}

.form-grid .optional, .matrix-filters .optional {
  font-weight: 400;
  opacity: 0.7;
}

.btn-primary {
  all: unset;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 13.5px;
}

.btn-primary:hover { background: #723c25; }

.form-status {
  margin-left: 14px;
  font-size: 12.5px;
  color: var(--positive);
}

.form-status.error { color: var(--negative); }

/* ---------- Tables ---------- */

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  font-size: 13px;
}

.data-table th, .data-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

.data-table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: var(--paper);
}

.data-table td.num {
  font-family: var(--font-mono);
}

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

.opex-overview-section td, .opex-overview-section th {
  background: var(--paper);
  color: var(--accent);
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 500;
}

.opex-overview-subtotal td, .opex-overview-subtotal th {
  background: var(--accent-soft);
  font-family: var(--font-mono);
  font-weight: 500;
}

.opex-overview-subtotal td.matrix-sticky-col, .opex-overview-subtotal th.matrix-sticky-col {
  background: var(--accent-soft);
}

td.positive, th.positive { color: var(--positive); }
td.negative, th.negative { color: var(--negative); }

.growth-cell {
  font-size: 11px;
  font-style: italic;
}

/* ---------- Sales-Mengen-Matrix ---------- */

.matrix-filters {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.matrix-filters label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.matrix-filters-actions {
  display: flex;
  gap: 10px;
  margin-left: auto;
}

.btn-secondary {
  all: unset;
  cursor: pointer;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 13px;
}

.btn-secondary:hover { background: var(--accent-soft); border-color: var(--accent); }

.matrix-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  margin-bottom: 20px;
}

.matrix-table {
  border-collapse: collapse;
  font-size: 13px;
  width: 100%;
}

.matrix-table th, .matrix-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  text-align: center;
  white-space: nowrap;
}

.matrix-table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: var(--paper);
}

.matrix-table tbody tr:last-child td { border-bottom: none; }
.matrix-table th:last-child, .matrix-table td:last-child { border-right: none; }

.matrix-year-head {
  border-left: 2px solid var(--accent-soft);
  font-size: 13px;
  color: var(--accent);
  font-family: var(--font-serif);
  letter-spacing: normal;
  text-transform: none;
}

.matrix-total-head, .matrix-growth-head {
  border-left: 1px dashed var(--line);
}

/* Dicke Trennlinie zwischen Spaltengruppen (z.B. "Actual Month" | "YTD"
   im Ist/Soll-Vergleich) - deutlich staerker als die duennen
   Jahres-/Total-Trennlinien oben, damit die Gruppierung sofort auffaellt. */
.matrix-group-divider {
  border-left: 3px solid var(--ink);
}

/* GL-Detailkonto-Zeilen im "Details"-Modus (Ist/Soll-Vergleich) - kleiner,
   eingerueckt, gedaempfte Farbe, damit sie sich klar vom eigentlichen
   Planungskonto-Total darueber abheben. */
.avb-detail-row td {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--paper);
}

.avb-detail-row td.matrix-sticky-col {
  padding-left: 24px;
  font-weight: 400;
}

/* ".matrix-table td/th" (Zeile ~476) setzt text-align:center mit hoeherer
   Spezifitaet (Element+Klasse) als eine blosse ".matrix-sticky-col"-Regel
   (nur Klasse) - deshalb hier als td/th-Kombination, sonst gewinnt centered
   trotz spaeterer Position im Stylesheet. */
td.matrix-sticky-col, th.matrix-sticky-col {
  text-align: left;
}

.matrix-sticky-col {
  position: sticky;
  left: 0;
  background: var(--panel);
  z-index: 1;
  font-weight: 500;
  min-width: 130px;
  border-right: 2px solid var(--line);
}

th.matrix-sticky-col { background: var(--paper); z-index: 2; }

.matrix-cell {
  width: 60px;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  text-align: right;
  font-family: var(--font-mono);
  background: transparent;
}

.matrix-cell:focus {
  border-color: var(--accent);
  outline: none;
  background: var(--accent-soft);
}

.matrix-row-total, .matrix-row-growth, .matrix-table tfoot th {
  font-family: var(--font-mono);
}

.matrix-row-total {
  border-left: 1px dashed var(--line);
}

.matrix-row-growth {
  border-left: 1px dashed var(--line);
  color: var(--text-muted);
}

/* Bewusst NICHT im Jahres-Header-Stil (kein Accent/Serif) - sonst liest man
   diese Spalte optisch als zusaetzliches "Jahr" neben 2026, statt als
   eigenstaendigen Anker vor dem Planungshorizont. */
.matrix-opening-col {
  background: var(--line);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  line-height: 1.3;
  border-right: 3px double var(--ink-soft);
  white-space: nowrap;
}

.matrix-opening-cell {
  background: var(--paper);
  color: var(--text-muted);
  font-style: italic;
  border-right: 3px double var(--ink-soft);
}

.matrix-row-growth.positive, .matrix-table tfoot th.positive { color: var(--positive); }
.matrix-row-growth.negative, .matrix-table tfoot th.negative { color: var(--negative); }

.matrix-table tfoot th {
  background: var(--paper);
  color: var(--text);
}

.matrix-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* ---------- Sales & COGS Annahmen-Matrix (Feld x Halbjahr) ---------- */

.matrix-table-fields .matrix-sticky-col {
  min-width: 260px;
  white-space: normal;
}

.matrix-table-fields .matrix-cell {
  width: 76px;
}

.as-field-fixed {
  background: var(--accent-soft);
  color: var(--text-muted);
  cursor: not-allowed;
}

.as-field-fixed:focus {
  background: var(--accent-soft);
}

.matrix-field-hint {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}

.matrix-section-row {
  background: var(--paper);
  color: var(--accent);
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  position: sticky;
  left: 0;
}

.matrix-summary-row th, .matrix-summary-row td {
  background: var(--accent-soft);
  font-family: var(--font-mono);
  color: var(--text);
}

.matrix-summary-row th.matrix-sticky-col, .matrix-summary-row td.matrix-sticky-col {
  background: var(--accent-soft);
}

.pm-remove-btn {
  all: unset;
  cursor: pointer;
  color: var(--negative);
  font-size: 16px;
  line-height: 1;
  padding: 2px 8px;
  border-radius: 4px;
}

.pm-remove-btn:hover {
  background: var(--accent-soft);
}

.opex-line-sticky {
  display: flex;
  align-items: center;
  gap: 4px;
}

.opex-line-description {
  flex: 1;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 4px 6px;
  background: transparent;
  font-family: var(--font-sans);
}

.opex-line-description:focus {
  border-color: var(--accent);
  outline: none;
  background: var(--accent-soft);
}

.matrix-warning {
  color: var(--negative);
  font-weight: 600;
}

.matrix-ok {
  color: var(--positive);
}

.pm-spacer-row td {
  border: none;
  padding: 6px 0;
  background: var(--paper);
}

.matrix-empty-note {
  padding: 20px 14px;
  color: var(--text-muted);
  text-align: center;
  font-style: italic;
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .card-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr 1fr; }
}
