:root {
  --paper: #f0f0ee; --card: #fff; --soft: #f5f5f4; --line: #e2e2de;
  --red: #eb3924; --ink: #1b1b1b; --muted: #5a5a56;
  --good: #1f7a3f; --bad: #c0392b; --amber: #b8860b;
}
* { box-sizing: border-box; }
html, body { margin: 0; font-family: 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif; background: var(--paper); color: var(--ink); font-size: 14px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.pos { color: var(--good); } .neg { color: var(--bad); }
svg.vi { width: 15px; height: 15px; vertical-align: -2px; flex: none; }
h1 svg.vi { width: 20px; height: 20px; vertical-align: -3px; }
button { font-family: inherit; cursor: pointer; }

/* Auth */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 4px 20px rgba(0,0,0,.06); padding: 30px; width: 340px; display: flex; flex-direction: column; gap: 12px; }
.auth-card h1 { margin: 0 0 6px; font-size: 22px; }
.auth-card input { padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px; font-size: 15px; }
.auth-card button { background: var(--red); color: #fff; border: none; border-radius: 9px; padding: 12px; font-weight: 700; }
.auth-err { color: var(--bad); font-size: 13px; }

/* Topbar */
.topbar { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 14px; background: #fff; border-bottom: 1px solid var(--line); padding: 10px 16px; }
.brand { font-weight: 800; font-size: 17px; display: flex; align-items: center; gap: 7px; }
.brand i { color: var(--red); font-style: normal; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs button { background: transparent; border: 1px solid transparent; border-radius: 999px; padding: 8px 15px; color: #444; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.tabs button:hover { background: #f1f1ef; }
.tabs button.active { background: var(--red); color: #fff; }
.tabs .badge { background: var(--red); color: #fff; border-radius: 999px; font-size: 10px; padding: 1px 6px; margin-left: 4px; }
.tabs button.active .badge { background: #fff; color: var(--red); }
.userchip { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.logout { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.burger { display: none; background: transparent; border: none; padding: 4px; }
.burger svg.vi { width: 22px; height: 22px; }

main { max-width: 1100px; margin: 0 auto; padding: 18px 16px 60px; }
h1 { font-size: 22px; margin: 4px 0 16px; display: flex; align-items: center; gap: 8px; }
h2 { font-size: 16px; margin: 22px 0 10px; }

/* KPI-Karten */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 15px 16px; }
.kpi .lbl { font-size: 12px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.kpi .val { font-size: 24px; font-weight: 800; margin-top: 4px; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.accent { border-color: var(--red); }
.kpi.accent .val { color: var(--red); }

/* Tabellen */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 0; overflow: hidden; }
/* Breite Tabellen mobil horizontal scrollen statt stauchen */
.card:has(table) { overflow-x: auto; }
@media (max-width: 720px) { .card table { min-width: 600px; } }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
th { background: var(--soft); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.chip { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 11px; font-weight: 700; }
.chip.offen { background: #fff3e0; color: var(--amber); }
.chip.bezahlt { background: #e7f6ec; color: var(--good); }
.chip.review { background: #fdecea; color: var(--red); }

.btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.btn.primary { background: var(--red); color: #fff; border-color: var(--red); }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
input, select, textarea { font-family: inherit; font-size: 14px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; }
label.fld { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); font-weight: 600; }
.note-box { background: #fffbe6; border: 1px solid #f0e2a8; border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 14px; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(20,20,20,.4); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: 14px; padding: 20px; width: 100%; max-width: 480px; max-height: 88vh; overflow-y: auto; }
.modal h3 { margin: 0 0 14px; display: flex; align-items: center; gap: 8px; }
.modal .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn { flex: 1; justify-content: center; }

/* Mobile-Menü */
.mnav-bg { position: fixed; inset: 0; background: rgba(20,20,20,.35); z-index: 90; }
.mnav { position: absolute; top: 0; left: 0; right: 0; background: #fff; padding: 60px 14px 14px; display: flex; flex-direction: column; gap: 3px; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.mnav button { display: flex; align-items: center; gap: 10px; background: transparent; border: none; border-radius: 10px; padding: 13px 12px; font-weight: 700; color: var(--ink); text-align: left; }
.mnav button.active { background: var(--red); color: #fff; }

@media (max-width: 820px) {
  .burger { display: inline-flex; }
  .topbar .tabs { display: none; }
  .userchip { display: none; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  table { display: block; overflow-x: auto; white-space: nowrap; }
  .modal .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 480px) { .kpi-grid { grid-template-columns: 1fr; } }


/* ===== Charts + mehr Farbe (Dashboard) ===== */
.chart-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-top: 16px; }
.chart-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: 0 1px 3px rgba(27,27,27,.05); }
.chart-card.wide { grid-column: 1 / -1; }
.chart-head { font-weight: 700; font-size: 14px; margin-bottom: 12px; }
@media (max-width: 820px) { .chart-grid { grid-template-columns: 1fr; } }
/* KPI-Karten farbige Akzentkante je Rolle */
.kpi { border-left: 4px solid var(--line); }
.kpi:nth-child(1) { border-left-color: #eb3924; }
.kpi:nth-child(2) { border-left-color: #1f9d57; }
.kpi:nth-child(3) { border-left-color: #e08a1e; }
.kpi:nth-child(4) { border-left-color: #7b3fa0; }
.kpi:nth-child(5) { border-left-color: #0072b2; }
.kpi:nth-child(6) { border-left-color: #0f9bb0; }
h1 { border-bottom: 3px solid var(--red); padding-bottom: 8px; display: inline-flex; }

.chart-box { position: relative; height: 260px; }
.chart-card.wide .chart-box { height: 300px; }

.chart-box canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
.subtabs { display: inline-flex; gap: 3px; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 4px; margin-bottom: 16px; flex-wrap: wrap; }
.subtabs button { background: transparent; border: none; border-radius: 999px; padding: 8px 14px; color: #444; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.subtabs button.active { background: var(--red); color: #fff; }
.subtabs .badge { background: var(--red); color:#fff; border-radius:999px; font-size:10px; padding:1px 6px; }
.subtabs button.active .badge { background:#fff; color:var(--red); }
@media (max-width:820px){ .subtabs{ display:flex; overflow-x:auto; } }

/* ===== Produktionskosten: Hero + Kostenbalken ===== */
.calc-hero { display: grid; grid-template-columns: 300px 1fr; gap: 18px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 20px; box-shadow: 0 1px 3px rgba(27,27,27,.05); }
.calc-hero-main { border-right: 1px solid var(--line); padding-right: 18px; }
.calc-hero-row { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 0; font-size: 14px; }
.calc-hero-row.big { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 12px; font-size: 16px; }
.calc-hero-row.big b { font-size: 28px; font-weight: 800; }
.calc-marge { margin-top: 10px; font-size: 12px; color: var(--muted); }
.calc-bar-title { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.calc-bar { display: flex; height: 30px; border-radius: 8px; overflow: hidden; background: #eee; }
.calc-seg { height: 100%; transition: width .3s; min-width: 2px; border-right: 2px solid #fff; }
.calc-legend { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 12px; }
.calc-leg { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.calc-leg b { color: var(--ink); }
.calc-leg i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.calc-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 8px; vertical-align: 0; }
.calc-sum td { background: var(--soft); }
@media (max-width: 820px) { .calc-hero { grid-template-columns: 1fr; } .calc-hero-main { border-right: none; border-bottom: 1px solid var(--line); padding-right: 0; padding-bottom: 12px; } }

/* Produktionskosten kompakter */
.calc-hero { padding: 16px; }
#app section:has(.calc-hero) table td, #app section:has(.calc-hero) table th { padding: 6px 12px; }
.calc-dot { width: 12px; height: 12px; }
.calc-seg { border-right-width: 1px; }


/* Buchhaltung Übersicht (Tages-Ledger) */
.ledger-day { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; overflow: hidden; }
.ledger-day-head { display: flex; justify-content: space-between; align-items: center; padding: 9px 14px; background: var(--soft); font-size: 13px; }
.ledger-sums { font-variant-numeric: tabular-nums; font-weight: 700; }
.ledger-sums .neg { margin-left: 10px; }
.ledger-item { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-top: 1px solid var(--line); font-size: 13px; }
.ledger-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.ledger-sub { font-weight: 700; min-width: 120px; }
.ledger-party { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ledger-beleg { color: var(--muted); }
.ledger-amt { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 90px; text-align: right; }
@media (max-width: 820px) { .ledger-sub { min-width: 84px; } .ledger-party { font-size: 12px; } }
.btn.disabled { opacity: .5; pointer-events: none; }

/* Programmierer-Verdict-Hero */
.prog-hero { display:flex; flex-wrap:wrap; gap:16px; justify-content:space-between; align-items:center;
  border:1px solid var(--line,#e6e6e2); border-radius:14px; padding:16px 18px; margin-bottom:12px; background:#fff; }
.prog-hero.ok { border-left:5px solid #1f9d57; background:linear-gradient(90deg,rgba(31,157,87,.06),#fff 40%); }
.prog-hero.gap { border-left:5px solid #c0392b; background:linear-gradient(90deg,rgba(192,57,43,.06),#fff 40%); }
.prog-hero-badge { display:inline-flex; align-items:center; gap:8px; font-size:1.35rem; font-weight:700; }
.prog-hero.ok .prog-hero-badge { color:#1f9d57; }
.prog-hero.gap .prog-hero-badge { color:#c0392b; }
.prog-hero-badge svg { width:22px; height:22px; }
.prog-hero-sub { color:#5a5a56; font-size:.9rem; margin-top:4px; }
.prog-hero-stats { display:flex; gap:22px; }
.prog-hero-stats > div { display:flex; flex-direction:column; }
.prog-hero-stats .lbl { font-size:.72rem; text-transform:uppercase; letter-spacing:.04em; color:#8a8f98; }
.prog-hero-stats b { font-size:1.1rem; }
@media (max-width:640px){ .prog-hero-stats { gap:16px; width:100%; } }

/* Übersicht: erste Zeile = 4 Kern-Gruppen */
.kpi-grid.g4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 860px){ .kpi-grid.g4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 480px){ .kpi-grid.g4 { grid-template-columns: 1fr; } }

/* Bestandswert-Rechner (nutzt calc-hero-Grid) */
.calc-hero-in { display:flex; flex-direction:column; gap:12px; justify-content:center; border-right:1px solid var(--line); padding-right:18px; }
.calc-quick { display:flex; flex-wrap:wrap; gap:6px; }
.calc-hero-out { display:flex; flex-direction:column; justify-content:center; }
.calc-hero-out .lbl { font-size:12px; text-transform:uppercase; letter-spacing:.04em; color:#8a8f98; }
.calc-hero-out .big { font-size:34px; font-weight:800; line-height:1.1; margin:4px 0 8px; }
@media (max-width:820px){ .calc-hero-in { border-right:none; border-bottom:1px solid var(--line); padding-right:0; padding-bottom:12px; } }

/* Bestandswert-Rechner Aufschlüsselung */
.calc-break { display:flex; flex-direction:column; gap:2px; margin-top:8px; max-width:340px; }
.calc-break > div { display:flex; justify-content:space-between; gap:12px; }
.calc-break-total { border-top:1px solid var(--line); margin-top:4px; padding-top:5px; font-weight:700; color:var(--ink,#1b1b1b); }

/* Länderstatistiken */
.geo-split { display:grid; grid-template-columns: 1fr 340px; gap:14px; }
.geo-map-card { padding:0; overflow:hidden; }
.geo-map { height:440px; width:100%; }
.geo-rank { max-height:440px; overflow-y:auto; }
.geo-rank tr.active { background:rgba(192,57,43,.10); }
.leaflet-container { font-family:inherit; border-radius:12px; }
@media (max-width:820px){ .geo-split { grid-template-columns:1fr; } .geo-map { height:320px; } .geo-rank { max-height:none; } }
