:root {
  --bg: #eef0f4;
  --flaeche: #ffffff;
  --flaeche-2: #e6e9f0;
  --text: #1d2130;
  --leise: #6b6f7d;
  --linie: #d6dae3;
  --akzent: #1f2a44;
  --akzent-text: #ffffff;
  --tisch: #8a5a35;
  --tisch-rand: #6e4426;
  --gruen: #2f9e5a;
  --gelb: #d9a400;
  --rot: #d0453a;
  --grau: #9aa0ab;
  --schatten: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151d;
    --flaeche: #1b1f2a;
    --flaeche-2: #242a37;
    --text: #e9e7e1;
    --leise: #9ba1af;
    --linie: #2f3646;
    --akzent: #c9a86a;
    --akzent-text: #12151d;
    --tisch: #6b4528;
    --tisch-rand: #4f321c;
    --schatten: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #12151d;
    --flaeche: #1b1f2a;
    --flaeche-2: #242a37;
    --text: #e9e7e1;
    --leise: #9ba1af;
    --linie: #2f3646;
    --akzent: #c9a86a;
    --akzent-text: #12151d;
    --tisch: #6b4528;
    --tisch-rand: #4f321c;
    --schatten: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }
.leise { color: var(--leise); font-size: 13px; }

.kopf {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px));
  background: var(--akzent); color: var(--akzent-text);
}
.kopf .leise { color: inherit; opacity: .75; }
.kopf-titel { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: .2px; }
.kopf-titel img { border-radius: 7px; }
.kopf-rechts { display: flex; align-items: center; gap: 4px; }
.icon-knopf {
  border: 0; background: transparent; width: 40px; height: 40px; border-radius: 10px;
  font-size: 20px; line-height: 1; display: inline-grid; place-items: center;
}
.icon-knopf:active { background: rgba(127,127,127,.2); }

main { max-width: 980px; margin: 0 auto; padding: 16px; }
h2 { font-size: 20px; margin: 22px 0 10px; }
h2:first-child { margin-top: 4px; }

.karte {
  background: var(--flaeche); border: 1px solid var(--linie); border-radius: 14px;
  box-shadow: var(--schatten); padding: 14px;
}
.raster { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

/* Kennzahlen */
.zahlen { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0 6px; }
.zahl { text-align: center; padding: 12px 6px; border: 0; width: 100%; }
.zahl b { display: block; font-size: 28px; line-height: 1.1; }
.zahl span { font-size: 13px; color: var(--leise); }

/* Runder Tisch */
.tisch-wrap { display: flex; justify-content: center; }
.tisch-svg { width: 100%; max-width: 460px; height: auto; display: block; overflow: visible; }
.tisch-svg .sitz { cursor: pointer; }
.tisch-svg .sitz:focus { outline: none; }
.tisch-svg .sitz:focus .ring, .tisch-svg .sitz:hover .ring { stroke-width: 7; }
.tisch-svg text { fill: var(--text); font-family: inherit; }
.tisch-svg .platte { fill: var(--tisch); stroke: var(--tisch-rand); stroke-width: 6; }
.tisch-svg .platte-text { fill: #f6ead9; font-weight: 700; }
.tisch-svg .platte-klein { fill: #f6ead9; opacity: .85; }
.legende { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; font-size: 13px; color: var(--leise); margin-top: 6px; }
.punkt { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.p-gruen { background: var(--gruen); } .p-gelb { background: var(--gelb); } .p-rot { background: var(--rot); } .p-grau { background: var(--grau); }

/* KI-Liste */
.ki { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; text-align: left; width: 100%; }
.avatar {
  flex: 0 0 auto; width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 16px;
  box-shadow: 0 0 0 3px var(--flaeche), 0 0 0 6px var(--ring, var(--grau));
  margin: 6px;
}
.ki-name { font-weight: 650; }
.ki-text { font-size: 14px; color: var(--leise); }

/* Aufträge */
.spalten { display: grid; gap: 14px; grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) { .spalten { grid-template-columns: 1fr; } }
.spalte-kopf { display: flex; align-items: center; justify-content: space-between; margin: 4px 2px 8px; font-weight: 650; }
.zaehler { background: var(--flaeche-2); border-radius: 999px; padding: 1px 9px; font-size: 13px; font-weight: 600; }
.auftrag { display: block; width: 100%; text-align: left; margin-bottom: 10px; }
.auftrag-titel { font-weight: 650; margin-bottom: 4px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 13px; color: var(--leise); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px;
  background: var(--flaeche-2); border-radius: 999px; padding: 2px 10px 2px 3px;
}
.chip .mini { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 10px; font-weight: 700; }
.stufe-1 { border-left: 4px solid #5b7bd5; }
.stufe-2 { border-left: 4px solid var(--gelb); }
.stufe-3 { border-left: 4px solid var(--gruen); }
.leer { color: var(--leise); font-size: 14px; padding: 10px 2px; }

/* Listen */
.liste { display: flex; flex-direction: column; gap: 8px; }
.zeile { display: flex; justify-content: space-between; gap: 12px; align-items: center; width: 100%; text-align: left; }
.zeile b { font-weight: 600; word-break: break-word; }

/* Leiste unten */
.leiste {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--flaeche); border-top: 1px solid var(--linie);
  padding-bottom: env(safe-area-inset-bottom);
}
.leiste button { border: 0; background: transparent; padding: 8px 0 9px; display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 12px; color: var(--leise); }
.leiste .sym { font-size: 20px; line-height: 1.1; }
.leiste button.aktiv { color: var(--text); font-weight: 650; }
.fab {
  position: fixed; right: 16px; bottom: calc(78px + env(safe-area-inset-bottom)); z-index: 11;
  border: 0; border-radius: 999px; padding: 12px 18px; font-weight: 650;
  background: var(--akzent); color: var(--akzent-text); box-shadow: 0 6px 18px rgba(0,0,0,.25);
}

/* Blatt (Detailansicht) */
.blatt-hintergrund { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }
.blatt {
  position: fixed; z-index: 21; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto;
  background: var(--flaeche); border-radius: 18px 18px 0 0; padding: 10px 16px calc(24px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0,0,0,.25); -webkit-overflow-scrolling: touch;
}
@media (min-width: 760px) {
  .blatt { left: 50%; right: auto; width: 720px; transform: translateX(-50%); bottom: auto; top: 6vh; border-radius: 18px; max-height: 88vh; }
}
.blatt-griff { width: 40px; height: 5px; border-radius: 3px; background: var(--linie); margin: 0 auto 6px; }
.blatt-zu { position: sticky; top: 0; float: right; margin-right: -6px; }

/* Markdown */
.md { overflow-wrap: anywhere; }
.md h1 { font-size: 21px; margin: 6px 0 12px; }
.md h2 { font-size: 18px; margin: 18px 0 8px; }
.md h3 { font-size: 16px; margin: 14px 0 6px; }
.md p, .md ul, .md ol { margin: 0 0 10px; }
.md ul, .md ol { padding-left: 22px; }
.md code { background: var(--flaeche-2); padding: 1px 5px; border-radius: 5px; font-size: 14px; }
.md pre { background: var(--flaeche-2); padding: 10px; border-radius: 8px; overflow-x: auto; }
.md pre code { background: transparent; padding: 0; }
.md .tab-wrap { overflow-x: auto; margin-bottom: 12px; }
.md table { border-collapse: collapse; font-size: 14px; min-width: 100%; }
.md th, .md td { border: 1px solid var(--linie); padding: 5px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--flaeche-2); }
.md blockquote { margin: 0 0 10px; padding-left: 12px; border-left: 3px solid var(--linie); color: var(--leise); }

/* Formulare */
.feld { display: block; margin-bottom: 12px; }
.feld span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.feld input, .feld textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--linie); border-radius: 10px; padding: 10px 12px;
}
.feld textarea { min-height: 96px; resize: vertical; }
.knopf {
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 650;
  background: var(--akzent); color: var(--akzent-text);
}
.knopf.zweit { background: var(--flaeche-2); color: var(--text); }
.knopf:disabled { opacity: .55; }
.knopfreihe { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.ampel-wahl { display: flex; gap: 8px; margin: 8px 0 4px; }
.ampel-wahl button { flex: 1; border: 2px solid transparent; border-radius: 10px; padding: 9px 4px; background: var(--flaeche-2); font-weight: 600; }
.ampel-wahl button.an { border-color: var(--text); }
.fehler { background: color-mix(in srgb, var(--rot) 14%, var(--flaeche)); border: 1px solid var(--rot); border-radius: 12px; padding: 12px; }
.hinweis { background: var(--flaeche-2); border-radius: 12px; padding: 12px; font-size: 14px; }

/* Anmeldung */
.anmelden { max-width: 420px; margin: 8vh auto 0; text-align: center; }
.anmelden img { width: 84px; height: 84px; border-radius: 20px; }
.anmelden h1 { font-size: 24px; margin: 14px 0 6px; }
.anmelden p { color: var(--leise); }

.laden { text-align: center; color: var(--leise); padding: 40px 0; }

/* Dateiknöpfe im Auftrag */
#auftrag-dateien .knopf { padding: 7px 12px; font-size: 14px; border-radius: 999px; }
#auftrag-dateien .knopf.an { background: var(--akzent); color: var(--akzent-text); }
