:root {
  --bg: #f3f5f9;
  --flaeche: #ffffff;
  --flaeche2: #f8f9fc;
  --rand: #dde2ea;
  --text: #17202e;
  --text2: #5b6676;
  --blau: #123a6e;
  --blau2: #1d4f91;
  --akzent: #2563c9;
  --rot: #c62828;
  --rot-bg: #fdecec;
  --orange: #b25e00;
  --orange-bg: #fff3e0;
  --gruen: #217a46;
  --gruen-bg: #e7f5ec;
  --schatten: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c;
    --flaeche: #171e29;
    --flaeche2: #1c2532;
    --rand: #2a3546;
    --text: #e6ebf2;
    --text2: #9aa6b8;
    --blau: #0d2a52;
    --akzent: #5b93ec;
    --rot: #ff6b6b;
    --rot-bg: #3a1c1f;
    --orange: #f5a23d;
    --orange-bg: #3a2a14;
    --gruen: #4cc27e;
    --gruen-bg: #15301f;
    --schatten: 0 1px 3px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
.laden { padding: 40px; text-align: center; color: var(--text2); }

/* Kopf */
header.kopf {
  background: var(--blau);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  min-height: 56px;
  position: sticky;
  top: 0;
  z-index: 5;
  flex-wrap: wrap;
}
.marke { font-weight: 700; font-size: 17px; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.marke img { width: 26px; height: 26px; }
nav.reiter { display: flex; gap: 4px; flex: 1; }
nav.reiter button {
  background: none; border: 0; color: rgba(255, 255, 255, .75);
  padding: 8px 12px; border-radius: 8px; cursor: pointer; font-weight: 500;
}
nav.reiter button:hover { background: rgba(255, 255, 255, .1); color: #fff; }
nav.reiter button.an { background: rgba(255, 255, 255, .16); color: #fff; }
.ich { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.ich button { background: rgba(255, 255, 255, .12); border: 0; color: #fff; padding: 6px 10px; border-radius: 8px; cursor: pointer; }
.ich button:hover { background: rgba(255, 255, 255, .22); }

main { max-width: 1400px; margin: 0 auto; padding: 16px; }

/* Werkzeugleiste */
.leiste { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.leiste .suche { flex: 1 1 220px; min-width: 0; }
.leiste select, .leiste input, .feld input, .feld select, .feld textarea {
  background: var(--flaeche); border: 1px solid var(--rand); border-radius: 8px; padding: 8px 10px; min-width: 0;
}
.leiste select { max-width: 100%; }
.knopf {
  background: var(--flaeche); border: 1px solid var(--rand); border-radius: 8px; padding: 8px 14px;
  cursor: pointer; font-weight: 500; white-space: nowrap;
}
.knopf:hover { border-color: var(--akzent); }
.knopf.haupt { background: var(--akzent); border-color: var(--akzent); color: #fff; }
.knopf.haupt:hover { filter: brightness(1.08); }
.knopf.gefahr { color: var(--rot); }
.knopf.an { background: var(--akzent); color: #fff; border-color: var(--akzent); }
.knopf:disabled { opacity: .5; cursor: default; }

/* Spalten */
.spalten { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; align-items: start; }
.spalte { background: var(--flaeche2); border: 1px solid var(--rand); border-radius: var(--radius); padding: 10px; }
.spalte h2 { font-size: 14px; margin: 2px 4px 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.spalte h2 .zahl { color: var(--text2); font-weight: 500; }
.spalte .leer { color: var(--text2); font-size: 13px; padding: 6px 4px; }

.karte {
  background: var(--flaeche); border: 1px solid var(--rand); border-radius: 8px; padding: 10px 12px;
  margin-bottom: 8px; box-shadow: var(--schatten); cursor: pointer; display: flex; gap: 10px;
  border-left-width: 4px; width: 100%; text-align: left;
}
.karte:hover { border-color: var(--akzent); }
.karte:focus-visible { outline: 2px solid var(--akzent); outline-offset: 2px; }
.karte .haken { flex: none; width: 20px; height: 20px; margin-top: 1px; accent-color: var(--gruen); cursor: pointer; }
.karte .inhalt { flex: 1; min-width: 0; }
.karte .titel { font-weight: 600; overflow-wrap: anywhere; }
.karte.erledigt .titel { text-decoration: line-through; color: var(--text2); }

/* Ziehen & Ablegen */
@media (pointer: coarse) {
  .karte.ziehbar { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
}
body.zieht { -webkit-user-select: none; user-select: none; cursor: grabbing; }
body.zieht .karte { cursor: grabbing; }
.karte.platzhalter { opacity: .35; border-style: dashed; box-shadow: none; }
.karte.geist {
  position: fixed; left: 0; top: 0; z-index: 1000; margin: 0; pointer-events: none;
  box-shadow: 0 12px 28px rgba(16, 24, 40, .28); opacity: .96; border-color: var(--akzent);
}
.spalte { transition: background-color .12s, border-color .12s; }
.spalte.ziel { border: 2px dashed var(--akzent); padding: 9px; background: var(--flaeche); }
.spalte.ablage { display: none; border-style: dashed; }
body.zieht .spalte.ablage { display: block; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-top: 6px; font-size: 12.5px; color: var(--text2); align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 5px; }
.punkt { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.datum.ueber { color: var(--rot); font-weight: 600; }
.datum.bald { color: var(--orange); font-weight: 600; }
.prio-hoch { color: var(--rot); font-weight: 700; }
.marke-status { font-size: 11.5px; padding: 1px 7px; border-radius: 99px; background: var(--flaeche2); border: 1px solid var(--rand); }

/* Übersicht */
.kacheln { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kachel { background: var(--flaeche); border: 1px solid var(--rand); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--schatten); }
.kachel .wert { font-size: 30px; font-weight: 700; line-height: 1.1; }
.kachel .name { color: var(--text2); font-size: 13px; }
.kachel.rot .wert { color: var(--rot); }
.kachel.orange .wert { color: var(--orange); }
.kachel.gruen .wert { color: var(--gruen); }
.zwei { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.block { background: var(--flaeche); border: 1px solid var(--rand); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--schatten); min-width: 0; }
.block h2 { font-size: 15px; margin: 0 0 10px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--rand); vertical-align: middle; }
th { color: var(--text2); font-weight: 500; font-size: 12.5px; }
td.zahl, th.zahl { text-align: right; font-variant-numeric: tabular-nums; }
tr.klick { cursor: pointer; }
tr.klick:hover td { background: var(--flaeche2); }
.balken { height: 6px; background: var(--flaeche2); border-radius: 3px; overflow: hidden; min-width: 60px; }
.balken > span { display: block; height: 100%; background: var(--akzent); }
.tabelle-scroll { overflow-x: auto; }

/* Dialog */
dialog {
  border: 1px solid var(--rand); border-radius: 14px; padding: 0; width: min(720px, calc(100vw - 24px));
  max-height: calc(100vh - 24px); background: var(--flaeche); color: var(--text); box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(10, 16, 28, .5); }
.dlg-kopf { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--rand); position: sticky; top: 0; background: var(--flaeche); z-index: 1; }
.dlg-kopf h2 { margin: 0; font-size: 17px; }
.dlg-inhalt { padding: 16px 18px; }
.dlg-fuss { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--rand); flex-wrap: wrap; position: sticky; bottom: 0; background: var(--flaeche); }
.dlg-fuss .links { margin-right: auto; }
.x { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--text2); line-height: 1; padding: 4px 8px; }
.raster { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.feld { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.feld > span { font-size: 12.5px; color: var(--text2); font-weight: 500; }
.feld textarea { min-height: 90px; resize: vertical; }
.feld input:focus, .feld select:focus, .feld textarea:focus, .leiste input:focus, .leiste select:focus { outline: 2px solid var(--akzent); outline-offset: -1px; border-color: var(--akzent); }
.abschnitt { margin-top: 18px; }
.abschnitt h3 { font-size: 14px; margin: 0 0 8px; }
.kommentar { background: var(--flaeche2); border: 1px solid var(--rand); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.kommentar .wer { font-size: 12.5px; color: var(--text2); margin-bottom: 2px; }
.kommentar .was { white-space: pre-wrap; overflow-wrap: anywhere; }
.verlauf { font-size: 13px; color: var(--text2); margin: 0; padding-left: 18px; }
.verlauf li { margin-bottom: 3px; }
.zeile { display: flex; gap: 8px; align-items: flex-start; }
.zeile textarea { flex: 1; min-height: 44px; background: var(--flaeche); border: 1px solid var(--rand); border-radius: 8px; padding: 8px 10px; resize: vertical; }
.fehlertext { color: var(--rot); font-size: 14px; min-height: 1em; margin: 6px 0 0; }

/* Anhänge */
.knopf.klein { padding: 5px 10px; font-size: 14px; text-decoration: none; display: inline-flex; align-items: center; }
.dateiliste, .uploads { list-style: none; margin: 0 0 8px; padding: 0; }
.datei { display: flex; align-items: center; gap: 8px; padding: 6px; border: 1px solid var(--rand); border-radius: 8px; margin-bottom: 6px; background: var(--flaeche2); }
.datei-oeffnen { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 0; text-align: left; cursor: pointer; }
span.datei-oeffnen { cursor: default; }
.datei .mini, .datei .symbol { flex: none; width: 44px; height: 44px; border-radius: 6px; }
.datei .mini { object-fit: cover; background: var(--rand); }
.datei .symbol { display: grid; place-items: center; font-size: 24px; background: var(--flaeche); border: 1px solid var(--rand); }
.dname { display: flex; flex-direction: column; min-width: 0; }
.dname .n { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.datei-oeffnen:hover .n { color: var(--akzent); text-decoration: underline; }
.dname .hinweis { font-size: 12px; }
.anhang-knoepfe { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.upload { display: flex; align-items: center; gap: 10px; font-size: 13px; padding: 4px 2px; }
.upload .n { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 45%; }
.upload .balken { flex: 1; }
.upload .pz { font-variant-numeric: tabular-nums; color: var(--text2); min-width: 3.5em; text-align: right; }
.upload.fehler { color: var(--rot); }
.upload.fehler .x { font-size: 18px; margin-left: auto; }
.dlg-inhalt.datei-ziel { outline: 3px dashed var(--akzent); outline-offset: -8px; background: var(--flaeche2); }
@media (pointer: coarse) { .nur-maus { display: none; } }

/* Viewer */
dialog.viewer {
  width: 100vw; height: 100vh; height: 100dvh; max-width: none; max-height: none; margin: 0; border: 0; border-radius: 0;
  background: #0d1117; color: #e6ebf2; box-shadow: none;
}
dialog.viewer[open] { display: grid; grid-template-rows: auto 1fr; }
dialog.viewer::backdrop { background: rgba(0, 0, 0, .85); }
.v-kopf { display: flex; align-items: center; gap: 6px; padding: 8px 10px; background: #161b22; border-bottom: 1px solid #30363d; min-width: 0; }
.v-titel { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.v-zahl { color: #9aa4b2; font-size: 13px; white-space: nowrap; }
.v-luecke { flex: 1; }
.v-knopf {
  background: #21262d; border: 1px solid #30363d; color: #e6ebf2; border-radius: 8px; min-width: 38px; height: 36px;
  padding: 0 10px; cursor: pointer; font-size: 17px; display: inline-grid; place-items: center; text-decoration: none; flex: none;
}
.v-knopf:hover { background: #30363d; }
.v-knopf[hidden] { display: none; }
.v-buehne { overflow: auto; position: relative; min-height: 0; padding: 12px; -webkit-overflow-scrolling: touch; touch-action: pan-y pinch-zoom; }
.v-buehne.gezoomt { touch-action: auto; }  /* ungezoomt: waagerechtes Wischen = nächster Anhang */
.v-buehne.mitte { display: flex; }
.v-bild { margin: auto; max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in; display: block; }
.v-bild.gross { max-width: none; max-height: none; cursor: zoom-out; }
.v-seiten { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.v-seite { background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, .5); flex: none; }
.v-seite canvas { display: block; }
.v-text { white-space: pre-wrap; overflow-wrap: anywhere; background: #161b22; padding: 14px; border-radius: 8px; margin: 0 auto; max-width: 1000px; font: 13px/1.5 ui-monospace, Consolas, monospace; }
.v-laden { text-align: center; color: #9aa4b2; margin: 40px auto; }
.v-nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 64px; border: 0; border-radius: 10px;
  background: rgba(22, 27, 34, .7); color: #fff; font-size: 34px; cursor: pointer; z-index: 2;
}
.v-nav.links { left: 8px; }
.v-nav.rechts { right: 8px; }
.v-nav:hover { background: rgba(48, 54, 61, .9); }
@media (max-width: 640px) {
  .v-kopf { flex-wrap: wrap; }
  .v-titel { flex-basis: 100%; order: -1; }
  .v-buehne { padding: 6px; }
  .v-nav { width: 36px; height: 52px; font-size: 28px; }
}

/* Anmeldung */
.anmelden { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.anmelden form { background: var(--flaeche); border: 1px solid var(--rand); border-radius: 14px; padding: 28px; width: min(380px, 100%); box-shadow: var(--schatten); }
.anmelden h1 { font-size: 20px; margin: 10px 0 4px; }
.anmelden p.unter { color: var(--text2); margin: 0 0 20px; font-size: 14px; }
.anmelden img { width: 44px; height: 44px; }
.anmelden .knopf { width: 100%; padding: 10px; margin-top: 6px; }

/* Verwaltung */
.verw td input[type=text], .verw td select { width: 100%; background: var(--flaeche); border: 1px solid var(--rand); border-radius: 6px; padding: 5px 7px; min-width: 90px; }
.verw td input[type=color] { width: 40px; height: 30px; border: 1px solid var(--rand); border-radius: 6px; background: none; padding: 1px; }
.verw td input[type=number] { width: 64px; background: var(--flaeche); border: 1px solid var(--rand); border-radius: 6px; padding: 5px 7px; }
.hinweis { color: var(--text2); font-size: 13px; }
.verw td:last-child { white-space: nowrap; }
.verw .block, .block.verw { max-width: 100%; }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 10px; transition: .2s; pointer-events: none;
  z-index: 50; max-width: calc(100vw - 32px);
}
#toast.an { opacity: 1; transform: translateX(-50%); }
#toast.fehler { background: var(--rot); }

@media (max-width: 640px) {
  header.kopf { gap: 8px; padding: 8px 12px; }
  nav.reiter { order: 3; flex-basis: 100%; overflow-x: auto; }
  .ich .name { display: none; }
  main { padding: 12px; }
  .spalten { grid-template-columns: 1fr; }
  .leiste .knopf.haupt { flex: 1 1 100%; }
  .leiste select { flex: 1 1 45%; }
}
