:root {
  --bg: #f4f5f7;
  --flaeche: #ffffff;
  --text: #1b1f24;
  --gedaempft: #5c6570;
  --rand: #d9dde3;
  --primaer: #1565c0;
  --primaer-text: #ffffff;
  --erfolg: #2e7d32;
  --gefahr: #c62828;
  --warnung-bg: #fff4e0;
  --warnung-rand: #f0b450;
  --fehler-bg: #fdecec;
  --fehler-rand: #e57373;
  --info-bg: #e8f1fc;
  --schalter-aus: #b5bcc5;
  --zellen-rand: #c4c9d0;
  --fokus: #1565c0;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121417;
    --flaeche: #1c1f24;
    --text: #e8eaed;
    --gedaempft: #9aa3ad;
    --rand: #343941;
    --primaer: #64a8f0;
    --primaer-text: #0b1a2b;
    --erfolg: #66bb6a;
    --gefahr: #ef5350;
    --warnung-bg: #3a2c12;
    --warnung-rand: #a07020;
    --fehler-bg: #3a1a1a;
    --fehler-rand: #a04040;
    --info-bg: #17283c;
    --schalter-aus: #4a515b;
    --zellen-rand: #8a929c;
    --fokus: #64a8f0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body.beschaeftigt { cursor: progress; }

[hidden] { display: none !important; }

h1 { font-size: 1.5rem; margin: 0; }
h3 { font-size: 1rem; margin: 0; }
h4 { font-size: .8rem; margin: 1rem 0 .4rem; color: var(--gedaempft); text-transform: uppercase; letter-spacing: .04em; }

a { color: var(--primaer); }

:focus-visible { outline: 2px solid var(--fokus); outline-offset: 2px; }

.gedaempft { color: var(--gedaempft); margin: .25rem 0 0; }

/* ---------- Kopf ---------- */

.kopf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem 16px;
  background: var(--flaeche);
  border-bottom: 1px solid var(--rand);
  position: sticky;
  top: 0;
  z-index: 10;
}

.marke { display: flex; flex-direction: column; }
.marke strong { font-size: 1.05rem; }
.marke span { font-size: .8rem; color: var(--gedaempft); }

main { max-width: 1000px; margin: 0 auto; padding: 1.25rem 16px 4rem; }

/* ---------- Bausteine ---------- */

.karte {
  background: var(--flaeche);
  border: 1px solid var(--rand);
  border-radius: var(--radius);
  padding: 1rem 1.25rem 1.25rem;
  margin: 0 0 1rem;
  min-width: 0;
}

fieldset.karte legend {
  font-weight: 600;
  padding: 0 .4rem;
  margin-left: -.4rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  min-height: 38px;
  padding: .4rem .9rem;
  border: 1px solid var(--rand);
  border-radius: 8px;
  background: var(--flaeche);
  color: var(--text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--gedaempft); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primaer { background: var(--primaer); border-color: var(--primaer); color: var(--primaer-text); font-weight: 600; }
.btn-primaer:hover { filter: brightness(1.08); border-color: var(--primaer); }
.btn-gefahr { color: var(--gefahr); }
.btn-gefahr:hover { border-color: var(--gefahr); }
.btn-leise { border-color: transparent; background: transparent; }

.feld { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.feld > span { font-size: .85rem; font-weight: 600; }

input:not([type=checkbox]):not([type=color]) {
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--rand);
  border-radius: 8px;
  padding: .5rem .65rem;
  min-height: 40px;
  width: 100%;
}
input:not([type=checkbox]):focus { outline: 2px solid var(--fokus); outline-offset: 0; border-color: var(--fokus); }

.hinweis { color: var(--gedaempft); font-size: .8rem; min-height: 1em; }
.hinweis.warnung { color: var(--text); background: var(--warnung-bg); border: 1px solid var(--warnung-rand); border-radius: 6px; padding: .4rem .6rem; margin: .75rem 0 0; }

.fehlertext { color: var(--gefahr); margin: 0; }

.raster { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }

/* ---------- Schalter ---------- */

.schalter { position: relative; display: inline-flex; align-items: center; gap: .55rem; cursor: pointer; user-select: none; min-height: 40px; }
.schalter input { position: absolute; opacity: 0; width: 44px; height: 26px; margin: 0; cursor: pointer; }
.schalter-bahn {
  flex: none;
  position: relative;
  width: 44px;
  height: 26px;
  border-radius: 13px;
  background: var(--schalter-aus);
  transition: background .15s;
}
.schalter-bahn::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
  transition: transform .15s;
}
.schalter input:checked + .schalter-bahn { background: var(--erfolg); }
.schalter input:checked + .schalter-bahn-gefahr { background: var(--gefahr); }
.schalter input:checked + .schalter-bahn::after { transform: translateX(18px); }
.schalter input:focus-visible + .schalter-bahn { outline: 2px solid var(--fokus); outline-offset: 2px; }
.schalter input:disabled + .schalter-bahn { opacity: .5; }
.schalter input:disabled { cursor: progress; }

/* ---------- Meldungen ---------- */

.meldung { border-radius: var(--radius); padding: .75rem 1rem; margin: 0 0 1rem; border: 1px solid; }
.meldung p { margin: 0; }
.meldung ul { margin: .5rem 0 0; padding-left: 1.25rem; }
.meldung-fehler { background: var(--fehler-bg); border-color: var(--fehler-rand); }
.meldung-warnung { background: var(--warnung-bg); border-color: var(--warnung-rand); }
.meldung-info { background: var(--info-bg); border-color: var(--rand); }
.meldung-aktionen { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: .7rem 1.1rem;
  border-radius: 8px;
  color: #fff;
  background: #2b3036;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
  z-index: 20;
}
.toast-erfolg { background: #2e7d32; }
.toast-fehler { background: #c62828; }

/* ---------- Login ---------- */

.login { max-width: 380px; margin: 3rem auto 0; }
.login form { display: flex; flex-direction: column; gap: 1rem; }

/* ---------- Liste ---------- */

.leiste { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.leiste-aktionen { display: flex; gap: .5rem; flex-wrap: wrap; }

.schirmliste { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }

.schirm {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto 150px auto;
  grid-template-areas: "nr info streifen schalter aktionen";
  align-items: center;
  gap: .5rem 1rem;
  background: var(--flaeche);
  border: 1px solid var(--rand);
  border-radius: var(--radius);
  padding: .6rem .9rem;
}
.schirm .nr {
  grid-area: nr;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  background: var(--bg);
  border: 1px solid var(--rand);
}
.schirm .info { grid-area: info; min-width: 0; }
.schirm .titel { font-weight: 600; }
.schirm .details { font-size: .82rem; color: var(--gedaempft); display: flex; flex-wrap: wrap; column-gap: 1rem; }
.schirm .details .gesperrt { color: var(--gefahr); font-weight: 600; }
.schirm > .farb-streifen { grid-area: streifen; }
.schirm > .schalter { grid-area: schalter; }
.schirm .zeilen-aktionen { grid-area: aktionen; display: flex; gap: .4rem; }

.schirm.inaktiv { background: var(--bg); border-style: dashed; }
.schirm.inaktiv .info, .schirm.inaktiv > .farb-streifen, .schirm.inaktiv .nr { opacity: .55; }
.schirm.inaktiv .schalter-text { color: var(--gefahr); font-weight: 600; }

@media (max-width: 760px) {
  .schirm {
    grid-template-columns: 44px minmax(0, 1fr);
    grid-template-areas:
      "nr info"
      ". streifen"
      ". schalter"
      ". aktionen";
  }
}

/* ---------- Farbstreifen ---------- */

.farb-streifen { display: flex; gap: 3px; }
.farb-streifen .zelle {
  display: block;
  /* Graue Umrandung, damit auch schwarze oder weiße Zellen erkennbar bleiben */
  border: 1px solid var(--zellen-rand);
  border-radius: 3px;
}
.farb-streifen .zelle.leer { border-color: transparent; background: transparent; }
.farb-streifen.klein .zelle { width: 14px; height: 14px; }

.farb-streifen.gross { flex-wrap: wrap; gap: 6px; margin: .75rem 0 0; }
.zellen-knopf {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .25rem;
  padding: 4px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.zellen-knopf .zelle { width: 44px; height: 44px; border-radius: 4px; }
.zellen-knopf .zelle.leer { border: 1px dashed var(--zellen-rand); }
.zellen-knopf.gewaehlt { border-color: var(--primaer); background: var(--info-bg); }
.zellen-nr { font-size: .75rem; color: var(--gedaempft); }

.zellen-editor { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--rand); }
.zellen-kopf { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem; }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  border: 1px solid var(--zellen-rand);
  cursor: pointer;
  padding: 0;
}
.swatch.gewaehlt { outline: 3px solid var(--primaer); outline-offset: 2px; }

.freie-farbe { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.freie-farbe input[type=color] {
  width: 52px;
  height: 40px;
  padding: 2px;
  border: 1px solid var(--rand);
  border-radius: 8px;
  background: var(--flaeche);
  cursor: pointer;
}
.hex-eingabe { max-width: 120px; font-family: ui-monospace, Consolas, monospace !important; text-transform: uppercase; }
.hex-eingabe.ungueltig { border-color: var(--gefahr) !important; }

/* ---------- Limits ---------- */

.limits { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; margin-top: .75rem; }
.limit { border: 1px solid var(--rand); border-radius: 8px; padding: .75rem 1rem 1rem; }
.limit-kopf { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.limit-felder { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.limit-gesperrt-text { margin: .25rem 0 0; color: var(--gefahr); font-weight: 600; }

/* ---------- Formular-Aktionen ---------- */

.zurueck { display: inline-block; margin-bottom: .35rem; font-size: .9rem; }

.form-aktionen {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  padding: .75rem 0;
  background: linear-gradient(to bottom, transparent, var(--bg) 30%);
}
.form-aktionen .btn { min-width: 120px; }
