:root {
  --bg: #f4f5f3;
  --surface: #ffffff;
  --ink: #1f2a2e;
  --muted: #5d6b70;
  --line: #d9ddd8;
  --accent: #0f6e64;
  --accent-dark: #0b524a;
  --warn-bg: #fdf6e3;
  --warn-ink: #8a6d00;
  --err-bg: #fdeceb;
  --err-ink: #a3261c;
  --ok-bg: #ecf6ee;
  --ok-ink: #1f6b35;
  --num: #243b53;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.7rem 1.4rem;
  background: var(--accent-dark);
  color: #fff;
}
header .brand { font-weight: 700; font-size: 1.1rem; color: #fff; text-decoration: none; letter-spacing: .02em; }
header nav { display: flex; gap: 1rem; }
header nav a { color: #cfe6e2; text-decoration: none; font-size: .95rem; }
header nav a:hover { color: #fff; }
header .phase { margin-left: auto; font-size: .8rem; color: #9ec7c1; }

main { max-width: 1200px; margin: 0 auto; padding: 1.6rem 1.4rem 3rem; }

h1 { font-size: 1.45rem; margin: .2rem 0 1rem; }
h1 .tname, h1 + .hint { font-weight: 400; }
.tname { font-size: .8rem; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: .1rem .4rem; vertical-align: middle; }

.hint { color: var(--muted); margin-top: 0; }
.crumb { font-size: .85rem; color: var(--muted); margin: 0 0 .3rem; }
.crumb a { color: var(--accent); text-decoration: none; }

code { background: #eceeea; padding: .1rem .35rem; border-radius: 4px; font-size: .85em; }

/* Karten-Übersicht */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  text-decoration: none;
  color: inherit;
  display: block;
}
a.card { transition: border-color .15s, transform .15s; }
a.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.cardtitle { font-weight: 600; font-size: 1.05rem; }
.cardsub { font-size: .78rem; color: var(--muted); letter-spacing: .03em; }
.cardnum { font-size: 1.7rem; font-weight: 700; color: var(--accent); margin: .5rem 0 .1rem; }
.cardnum span { font-size: .8rem; font-weight: 400; color: var(--muted); }
.cardmeta { font-size: .78rem; color: var(--muted); }

/* Formular / Buttons */
form.card { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; max-width: 640px; }
select, button, .btn {
  font: inherit;
  padding: .45rem .8rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
}
button, .btn {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button:hover, .btn:hover { background: var(--accent-dark); }

/* Hinweise */
.alert { padding: .7rem 1rem; border-radius: 8px; margin: 1rem 0; }
.alert.warn { background: var(--warn-bg); color: var(--warn-ink); }
.alert.error { background: var(--err-bg); color: var(--err-ink); }
.alert.ok { background: var(--ok-bg); color: var(--ok-ink); }
.alert a { color: inherit; font-weight: 600; }

/* Datentabellen */
.scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table.data { border-collapse: collapse; width: 100%; background: var(--surface); font-size: .85rem; }
table.data th, table.data td { padding: .4rem .6rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.data thead th { position: sticky; top: 0; background: #eef1ed; vertical-align: bottom; }
table.data th .coldesc { display: block; font-weight: 400; font-size: .72rem; color: var(--muted); max-width: 160px; white-space: normal; }
table.data th.pk { background: #e0ebe8; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; color: var(--num); }
table.data tbody tr:hover { background: #f6f8f5; }

/* Pagination */
.pager { display: flex; gap: 1rem; align-items: center; margin-top: 1rem; }
.pager a { color: var(--accent); text-decoration: none; }
.pager span { color: var(--muted); font-size: .9rem; }

footer { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1.4rem; color: var(--muted); font-size: .8rem; border-top: 1px solid var(--line); }

/* ===================== Phase 2: Login & Benutzer ===================== */

/* Kopf: Benutzerbox rechts */
header .userbox { margin-left: auto; display: flex; align-items: center; gap: 1rem; font-size: .9rem; }
header .userbox .who { color: #d7ece8; }
header .userbox .who em { color: #9ec7c1; font-style: normal; }
header .userbox a { color: #cfe6e2; text-decoration: none; }
header .userbox a:hover { color: #fff; }
header .userbox a.logout { background: rgba(255,255,255,.12); padding: .25rem .7rem; border-radius: 6px; }

/* Alert-Alias (PHP nutzt .err) */
.alert.err { background: var(--err-bg); color: var(--err-ink); }

/* Login-Box */
.loginwrap { max-width: 360px; margin: 2rem auto; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: 1.6rem 1.8rem; }
.loginwrap h1 { margin-top: 0; }

/* Allgemeine Formulare (Spalten-Layout) */
form.form { display: flex; flex-direction: column; gap: .8rem; max-width: 460px; }
form.form.grid { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem 1.1rem; max-width: 720px; align-items: end; }
form.form label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
form.form input, form.form select { font: inherit; padding: .5rem .6rem; border: 1px solid var(--line);
  border-radius: 6px; background: #fff; color: var(--ink); }
form.form button { justify-self: start; }
form.form.grid button { grid-column: 1 / -1; justify-self: start; }

/* Button-Varianten */
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-dark); }
.btn.small { padding: .3rem .55rem; font-size: .78rem; }

/* Dashboard-Kacheln (deaktiviert = ausgegraut) */
.dashcard.disabled { opacity: .55; cursor: default; }
.dashcard.disabled:hover { transform: none; border-color: var(--line); }

/* Status-Pillen */
.pill { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; }
.pill.ok { background: var(--ok-bg); color: var(--ok-ink); }
.pill.off { background: var(--err-bg); color: var(--err-ink); }

/* Aktionsspalte in der Benutzertabelle */
table.data td.actions { white-space: nowrap; }
form.inline { display: inline-flex; gap: .3rem; align-items: center; margin: .1rem .4rem .1rem 0; }
form.inline input[type=password] { width: 8.5rem; padding: .25rem .4rem; border: 1px solid var(--line); border-radius: 5px; }

/* ===================== Phase 3: Spielverwaltung ===================== */

/* Buttons-Varianten */
.btn.small { padding: .25rem .6rem; font-size: .8rem; }
.btn.ghost { background: var(--surface); color: var(--accent); border-color: var(--line); }
.btn.ghost:hover { background: var(--bg); }
.btn.danger { background: var(--err-ink); border-color: var(--err-ink); }
.btn.danger:hover { background: #861d15; }
.actions { white-space: nowrap; }
.actions .btn { margin-bottom: .15rem; }

/* Spiele-Tabelle */
table.grid { border-collapse: collapse; width: 100%; background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
table.grid th, table.grid td { padding: .5rem .7rem; border-bottom: 1px solid var(--line); text-align: left; }
table.grid thead th { background: var(--bg); font-size: .82rem; color: var(--muted); }
table.grid tbody tr:last-child td { border-bottom: none; }

/* Inline-Löschen */
details.del { display: inline-block; }
details.del > summary { list-style: none; cursor: pointer; display: inline-block; }
details.del > summary::-webkit-details-marker { display: none; }
.delform { margin-top: .5rem; padding: .6rem; border: 1px solid var(--err-ink);
  border-radius: 8px; background: var(--err-bg); max-width: 320px; }
.delform p { margin: 0 0 .4rem; font-size: .85rem; }
.delform input { width: 100%; margin-bottom: .5rem; padding: .4rem .5rem;
  border: 1px solid var(--line); border-radius: 6px; }

/* Formulare (überschreibt die Flex-Zeile von form.card) */
form.form, form.firma { display: block; max-width: 760px; }
form.form .fld, form.firma .fld { display: flex; flex-direction: column; gap: .25rem; margin: .6rem 0; }
.fld > span { font-size: .85rem; color: var(--muted); }
.fld input, .fld select { padding: .45rem .55rem; border: 1px solid var(--line);
  border-radius: 6px; background: var(--surface); font: inherit; }
.radio-row { display: flex; gap: 1.4rem; flex-wrap: wrap; margin-bottom: .8rem; }
.radio-row label { font-weight: 600; }
.check { display: flex; align-items: center; gap: .5rem; margin: .5rem 0; }
.subblock { border: 1px solid var(--line); border-radius: 8px; padding: .8rem 1rem; margin: .6rem 0; }
.subblock legend { font-weight: 600; padding: 0 .4rem; }
.form-actions { margin-top: 1rem; display: flex; gap: .6rem; align-items: center; }

/* Firmen */
form.firma { margin-bottom: 1rem; }
.firma-head { font-weight: 700; font-size: 1.05rem; margin-bottom: .4rem; color: var(--accent); }
.emailgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px,1fr)); gap: .5rem .9rem; }

/* Basiswerte-Editor */
.tabs { display: flex; flex-wrap: wrap; gap: .3rem; border-bottom: 2px solid var(--line);
  margin-bottom: 1rem; position: sticky; top: 0; background: var(--bg); padding-top: .3rem; z-index: 5; }
.tabs .tab { background: transparent; color: var(--muted); border: 1px solid transparent;
  border-bottom: none; border-radius: 8px 8px 0 0; padding: .5rem .9rem; cursor: pointer; font-size: .9rem; }
.tabs .tab:hover { background: var(--surface); color: var(--ink); }
.tabs .tab.active { background: var(--surface); color: var(--accent); font-weight: 600;
  border-color: var(--line); border-bottom: 2px solid var(--surface); margin-bottom: -2px; }
.tabpane { animation: fade .15s ease; }
@keyframes fade { from { opacity: .4; } to { opacity: 1; } }
fieldset.grp { border: 1px solid var(--line); border-radius: 8px; padding: .7rem 1rem 1rem; margin: 0 0 1rem; }
fieldset.grp legend { font-weight: 600; color: var(--accent); padding: 0 .4rem; }
.fieldgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .55rem .9rem; }
.bf { display: grid; grid-template-columns: 1fr 110px; align-items: center; gap: .5rem; }
.bf-label { font-size: .82rem; color: var(--ink); line-height: 1.2; }
.bf-in { padding: .35rem .45rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); font: inherit; width: 100%; }
.bf-in.num { text-align: right; font-variant-numeric: tabular-nums; }
.bf-ro { padding: .35rem .45rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--ink); text-align: right; font-variant-numeric: tabular-nums;
  font-size: .85rem; min-height: 1.2rem; }
.form-actions.sticky { position: sticky; bottom: 0; background: var(--bg);
  padding: .8rem 0; border-top: 1px solid var(--line); margin-top: 1rem; }

@media (max-width: 560px) {
  .bf { grid-template-columns: 1fr; }
  .bf-in { width: 100%; }
}

/* ---------- Phase 4: Entscheidungen ---------- */

/* Inline-Auswahlformulare (Spiel-/Periodenwahl) */
.inline-form { margin: 0 0 1rem; display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.inline-form select { padding: .35rem .45rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--ink); }

/* Status-Badges (offen / abgegeben) */
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem;
  font-weight: 600; line-height: 1.5; }
.badge.ok   { background: var(--ok-bg);   color: var(--ok-ink); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }

/* Maschinen-Matrix */
.matrix-wrap { overflow-x: auto; }
table.matrix { border-collapse: collapse; width: 100%; font-size: .85rem; }
table.matrix th, table.matrix td { border: 1px solid var(--line); padding: .3rem .4rem; }
table.matrix thead th { background: var(--bg); color: var(--accent); text-align: center; font-weight: 600; }
table.matrix th.rowhead { background: var(--bg); text-align: left; white-space: nowrap; font-weight: 600; color: var(--ink); }
table.matrix td .bf-in { width: 100%; box-sizing: border-box; }

/* Auswahl-Selects in den Feldgittern wie Zahlenfelder ausrichten */
.decisions .bf select.bf-in { width: 110px; }

/* Gesperrte Eingaben (Firma nach Abgabe) */
.decisions input:disabled, .decisions select:disabled {
  background: var(--bg); color: var(--muted); cursor: not-allowed; }

@media (max-width: 640px) {
  .decisions .bf select.bf-in { width: 100%; }
}

/* Periode-Reset (calc.php): Bestaetigungs-Panel */
.confirm-box {
  border: 1px solid var(--err-ink);
  background: #fdf3f1;
  border-radius: 6px;
  padding: .8rem 1rem;
  margin: .6rem 0;
}
.confirm-box p { margin: .3rem 0 .6rem; }
.mt { margin-top: .8rem; }

/* ---- Ergebnisanzeige (ergebnisse.php) ---- */
.mb { margin-bottom: 1rem; }

/* Schluessel-Wert-Tabelle (Marktdaten) */
table.kv { max-width: 540px; }
table.kv td:last-child { text-align: right; white-space: nowrap; }

/* GuV / Bilanz */
table.guv { width: 100%; max-width: 560px; border-collapse: collapse; }
table.guv td, table.guv th { padding: .28rem .5rem; border-bottom: 1px solid var(--line); }
table.guv th { text-align: left; background: var(--bg); }
table.guv .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.guv .neg { color: var(--err-ink); }
td.neg { color: var(--err-ink); }
table.guv tr.row-sub td { font-weight: 600; border-top: 1px solid var(--line); }
table.guv tr.row-strong td { font-weight: 700; }
table.guv tr.row-result td { border-top: 2px solid var(--accent); border-bottom: 2px solid var(--accent); background: var(--ok-bg); }

/* Bilanz: Aktiva und Passiva nebeneinander */
.bilanz { display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: flex-start; }
.bilanz table.guv { flex: 1 1 320px; }

/* Reiter als Links (ergebnisse.php) – nutzt vorhandene .tabs/.tab-Stile */
.tabs a.tab { text-decoration: none; display: inline-block; }
.tabs a.tab.active { text-decoration: none; }

/* ---- Verlaufs-Charts (ergebnisse.php, Tab "Verlauf") ---- */
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 1rem; }
.chart-card { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .6rem .7rem; }
.chart-card figcaption { font-weight: 600; color: var(--ink); margin-bottom: .35rem; font-size: .92rem; }
.chart { width: 100%; }
.chart-svg { width: 100%; height: auto; display: block; }
.chart-axis { font-size: 12px; }
.chart-axis-label { font-size: 12px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; margin: .2rem 0 1rem; }
.chart-legend-item { display: inline-flex; align-items: center; gap: .35rem; font-size: .85rem; color: var(--ink); }
.chart-swatch { width: 14px; height: 14px; border-radius: 3px; display: inline-block; flex: none; }

/* ---- Chart-Vergroesserung (Modal) + Export ---- */
.chart { cursor: zoom-in; border-radius: 6px; }
.chart:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chart-zoom-hint { font-weight: 400; font-size: .78rem; color: var(--muted); }

.chart-modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.chart-modal[hidden] { display: none; }
.chart-modal-backdrop { position: absolute; inset: 0; background: rgba(20, 30, 33, .55); }
.chart-modal-box { position: relative; background: var(--surface); border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,.3); width: min(1100px, 94vw); max-height: 92vh;
  display: flex; flex-direction: column; padding: 1rem 1.1rem 1.2rem; }
.chart-modal-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .6rem; }
.chart-modal-head h3 { margin: 0; font-size: 1.05rem; color: var(--ink); }
.chart-modal-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.chart-modal-body { overflow: auto; }
.chart-modal-body svg { width: 100%; height: auto; max-height: 82vh; display: block; }

/* PERDATEN-Editor: Periodenstatus-Leiste */
.period-status { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; }
.period-status .ps { display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; border-radius: 6px; text-decoration: none;
  border: 1px solid var(--line); font-weight: 600; font-size: .85rem; color: var(--ink); }
.period-status .ps.ok   { background: #d7e8e4; color: #0f6e64; border-color: #9fc7be; }
.period-status .ps.part { background: #fff4e0; color: #8a5300; border-color: #e6c07a; }
.period-status .ps.none { background: var(--surface); color: var(--muted); }
.period-status .ps.cur  { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ===== Kontextleiste (globaler Spiel-Selektor unter der Navigation) ===== */
.ctxbar { background: #0e4842; border-bottom: 1px solid rgba(255,255,255,.08); }
.ctxbar-inner { max-width: 1200px; margin: 0 auto; padding: .5rem 1.4rem;
  display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; }
.ctxbar-lbl { color: #9ec7c1; font-size: .8rem; text-transform: uppercase;
  letter-spacing: .06em; }
.ctxbar-form { margin: 0; display: inline-flex; align-items: center; gap: .4rem; }
.ctxbar-form select { padding: .3rem .5rem; border-radius: 6px;
  border: 1px solid rgba(255,255,255,.25); background: #fff; color: var(--ink);
  font-size: .92rem; min-width: 14rem; }
.ctxbar-cur { color: #fff; font-size: 1rem; }
.ctxbar-hint { color: #9ec7c1; font-size: .82rem; }

/* ===== Firmen-Buttonleiste (Look an die Periodenleiste angelehnt) ===== */
.firm-bar { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.firm-bar .fb { display: inline-flex; align-items: baseline; gap: .4rem;
  padding: .35rem .7rem; border-radius: 6px; text-decoration: none;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-size: .9rem; line-height: 1.2; }
.firm-bar .fb:hover { border-color: var(--accent); }
.firm-bar .fb .fb-no { font-weight: 700; color: var(--accent); }
.firm-bar .fb .fb-name { color: var(--muted); }
.firm-bar .fb.cur { background: #d7e8e4; border-color: var(--accent);
  outline: 2px solid var(--accent); outline-offset: 1px; }
.firm-bar .fb.cur .fb-name { color: var(--ink); }

/* Beschriftung vor einer Buttonleiste */
.bar-lbl { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin-right: .2rem; }

/* Perioden-Chips als POST-Buttons (z. B. „Periode zurücksetzen") */
.period-status .ps-form { margin: 0; display: inline-flex; }
.period-status button.ps { cursor: pointer; font-family: inherit; padding: 0; }
.period-status button.ps:hover { border-color: var(--accent); }

/* Stufenweise Deckungsbeitragsrechnung (Ergebnisse > Kosten-Reiter) */
table.db-staffel { width: 100%; max-width: 760px; border-collapse: collapse; font-size: .9rem; margin: .25rem 0 1.25rem; }
table.db-staffel th, table.db-staffel td { padding: .28rem .5rem; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.db-staffel thead th { background: var(--accent); color: #fff; text-align: center; font-weight: 600; }
table.db-staffel th:first-child, table.db-staffel td:first-child { text-align: left; white-space: normal; }
table.db-staffel td.num { font-variant-numeric: tabular-nums; color: var(--num); }
table.db-staffel tbody tr.row-strong td { font-weight: 700; background: var(--ok-bg); }

/* Ergebnis-Kurzübersicht (calc.php) */
.ov-wrap { overflow-x: auto; margin-bottom: .5rem; }
table.ov-table thead th { background: var(--accent); color: #fff; white-space: nowrap; }
table.ov-table thead th.num { color: #fff; }
table.ov-table th.coldesc, table.ov-table .coldesc { color: rgba(255,255,255,.75); }
table.ov-table th.ov-grp, table.ov-table td.ov-grp { border-left: 2px solid var(--accent-dark); }
table.ov-table thead th.ov-grp { border-left-color: rgba(255,255,255,.35); }
table.ov-table tbody td.num { font-variant-numeric: tabular-nums; color: var(--num); }
table.ov-table tbody td.neg { color: var(--err-ink); }
table.ov-table tbody tr:hover td { background: #f0f5f3; }
.ov-dot-cell { width: 6px; padding-right: 0 !important; }
.ov-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%;
           vertical-align: middle; }
.ov-name { white-space: nowrap; }
.ov-fname { font-weight: 400; color: var(--muted); margin-left: .25rem; font-size: .82em; }
