/* Check-Mate — mobile-first, hell/dunkel automatisch */
:root {
  --bg: #eef0f5;
  --surface: #e6e8ef;
  --col-bg: #f7f8fa;
  --card-bg: #ffffff;
  --text: #1c2340;
  --muted: #6b7280;
  --border: #dcdfe8;
  --accent: #e96220;
  --navy: #1c2340;
  --navy-text: #f2f4fa;
  --danger: #d64541;
  --ok: #2e9e5b;
  --shadow: 0 1px 2px rgba(20, 25, 50, .12);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c;
    --surface: #171a24;
    --col-bg: #1d2130;
    --card-bg: #272c3d;
    --text: #e8eaf2;
    --muted: #9aa0b4;
    --border: #343a4e;
    --navy: #171a24;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }

#app { display: flex; flex-direction: column; height: 100dvh; }

/* ---------- Header ---------- */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--navy);
  color: var(--navy-text);
}
.brand { font-weight: 700; font-size: 18px; white-space: nowrap; }
.brand .knight { font-size: 22px; }
.board-switch {
  border: 0; background: rgba(255, 255, 255, .12); color: inherit;
  padding: 8px 12px; border-radius: 8px; cursor: pointer;
  max-width: 45vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-height: 44px;
}
.topbar .spacer { flex: 1; }
.iconbtn {
  border: 0; background: transparent; color: inherit; cursor: pointer;
  font-size: 20px; min-width: 44px; min-height: 44px; border-radius: 8px;
}
.iconbtn:active, .board-switch:active { background: rgba(255, 255, 255, .22); }

/* ---------- Board ---------- */
.board { flex: 1; overflow: hidden; }
.lists {
  display: flex; gap: 12px; align-items: flex-start;
  height: 100%;
  overflow-x: auto; overflow-y: hidden;
  padding: 12px;
  scroll-snap-type: x proximity;
}
.list {
  flex: none;
  width: min(86vw, 300px);
  max-height: 100%;
  display: flex; flex-direction: column;
  background: var(--col-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  scroll-snap-align: start;
}
.list-head {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 8px 6px 14px;
  cursor: grab;
}
.list-head h2 {
  margin: 0; font-size: 15px; font-weight: 600; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.list-head .count { color: var(--muted); font-size: 13px; }
.list-head .iconbtn { color: var(--muted); font-size: 18px; min-width: 44px; min-height: 44px; }

.cards {
  flex: 1; overflow-y: auto;
  padding: 4px 8px;
  display: flex; flex-direction: column; gap: 8px;
  min-height: 8px;
}
.card {
  background: var(--card-bg);
  border-radius: 8px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  cursor: pointer;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
.card.ghost { opacity: .4; }
.card .cover { width: 100%; max-height: 140px; object-fit: cover; display: block; }
.card .inner { padding: 8px 10px; }
.card .labelbar { display: flex; gap: 4px; margin-bottom: 6px; }
.card .labelbar span { height: 6px; width: 32px; border-radius: 3px; }
.card .title { font-size: 14.5px; line-height: 1.35; word-break: break-word; }
.card .badges {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px;
  font-size: 12px; color: var(--muted);
}
.badge { display: inline-flex; align-items: center; gap: 3px; padding: 2px 6px; border-radius: 6px; background: var(--surface); }
.badge.due-over { background: var(--danger); color: #fff; }
.badge.due-today { background: var(--accent); color: #fff; }
.badge.check-done { background: var(--ok); color: #fff; }

.composer { padding: 6px 8px 10px; }
.composer > button {
  width: 100%; text-align: left; border: 0; background: transparent;
  color: var(--muted); padding: 10px 8px; border-radius: 8px; cursor: pointer; min-height: 44px;
}
.composer > button:active { background: var(--surface); }
.composer textarea {
  width: 100%; resize: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; font: inherit; background: var(--card-bg); color: var(--text);
}
.composer .row { display: flex; gap: 8px; margin-top: 6px; }

/* Ablage-Zonen beim Karten-Ziehen (Archivieren/Löschen), Trello-Muster */
.dragzones {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
  display: flex; gap: 2px;
  padding-bottom: env(safe-area-inset-bottom);
  transform: translateY(110%);
  transition: transform .18s ease;
  pointer-events: none;
}
body.dragging-card .dragzones { transform: translateY(0); pointer-events: auto; }
.dragzone {
  flex: 1; min-height: 78px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 15.5px; color: #fff;
  user-select: none;
}
.dragzone.archive { background: var(--navy); }
.dragzone.delete { background: var(--danger); }
.dragzone:has(.card) { filter: brightness(1.35); }
.dragzone .card { display: none; } /* hineingezogene Karte nicht in der Zone rendern */

/* Datei-Drop-Ziel (Desktop-Drag): Spalte oder offener Karten-Dialog leuchtet orange */
.list.drop-target,
dialog.drop-target {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
  background: color-mix(in srgb, var(--accent) 8%, var(--col-bg));
}
dialog.drop-target { background: color-mix(in srgb, var(--accent) 6%, var(--bg)); }

.add-list {
  flex: none; width: min(70vw, 260px);
  border: 1px dashed var(--border); border-radius: var(--radius);
  background: transparent; color: var(--muted);
  padding: 14px; cursor: pointer; min-height: 52px;
}

/* ---------- Buttons ---------- */
.btn {
  border: 0; border-radius: 8px; padding: 10px 16px; cursor: pointer;
  background: var(--surface); color: var(--text); min-height: 44px;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: transparent; color: var(--danger); }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: 13px; }

/* ---------- Menü (Dropdown) ---------- */
.menu {
  position: fixed; z-index: 60;
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .25);
  min-width: 210px; padding: 6px; max-height: 70dvh; overflow-y: auto;
}
.menu button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 12px; border-radius: 8px; cursor: pointer; font-size: 15px;
}
.menu button:active { background: var(--surface); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.menu-backdrop { position: fixed; inset: 0; z-index: 55; }

/* ---------- Dialoge ---------- */
dialog {
  border: 0; border-radius: 14px 14px 0 0; padding: 0;
  background: var(--bg); color: var(--text);
  width: 100%; max-width: none;
  margin: auto 0 0 0;
  max-height: 94dvh;
}
dialog::backdrop { background: rgba(10, 12, 24, .55); }
@media (min-width: 640px) {
  dialog { border-radius: 14px; margin: auto; width: 580px; max-height: 88dvh; }
}
.dlg-head {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 14px 10px 8px 16px;
  position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.dlg-head .iconbtn { color: var(--muted); }
.dlg-body { padding: 0 16px 24px; overflow-y: auto; }
.dlg-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 8px; }

.title-input {
  width: 100%; border: 0; background: transparent; color: var(--text);
  font-size: 19px; font-weight: 600; resize: none; font-family: inherit; line-height: 1.3;
  padding: 4px 0;
}
.meta-line { color: var(--muted); font-size: 13.5px; margin: 0 0 4px; }
.meta-line select {
  font: inherit; border: 1px solid var(--border); background: var(--card-bg);
  color: var(--text); border-radius: 6px; padding: 4px 6px;
}

.due-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.due-row input {
  font: inherit; padding: 9px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--card-bg); color: var(--text);
}
.hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 2px solid transparent; border-radius: 8px; padding: 8px 14px;
  cursor: pointer; font-size: 13.5px; color: #fff; opacity: .45; min-height: 40px;
}
.chip.on { opacity: 1; border-color: var(--text); }

.desc-input {
  width: 100%; min-height: 90px; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; font: inherit; background: var(--card-bg); color: var(--text); resize: vertical;
}

.checklist { display: flex; flex-direction: column; gap: 2px; }
.check-item { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.check-item input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.check-item .txt { flex: 1; word-break: break-word; padding: 6px 0; }
.check-item .txt.done { text-decoration: line-through; color: var(--muted); }
.check-add { display: flex; gap: 8px; margin-top: 8px; }
.check-add input {
  flex: 1; font: inherit; padding: 10px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--card-bg); color: var(--text);
}

.attach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.attach {
  position: relative; border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
  background: var(--card-bg); cursor: pointer; min-height: 84px;
  display: flex; align-items: center; justify-content: center; text-align: center;
}
.attach img { width: 100%; height: 96px; object-fit: cover; display: block; }
.attach .fname { font-size: 11.5px; color: var(--muted); padding: 8px 6px; word-break: break-all; }
.attach .del {
  position: absolute; top: 4px; right: 4px;
  border: 0; border-radius: 6px; background: rgba(0, 0, 0, .55); color: #fff;
  width: 28px; height: 28px; cursor: pointer;
}

.dlg-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }

/* Archiv & Suche */
.plain-list { display: flex; flex-direction: column; gap: 8px; }
.plain-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
}
.plain-row .grow { flex: 1; min-width: 0; word-break: break-word; }
.plain-row .sub { display: block; font-size: 12px; color: var(--muted); }
.search-input {
  width: 100%; font: inherit; font-size: 16px; padding: 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--card-bg); color: var(--text); margin-bottom: 12px;
}

/* ---------- Login ---------- */
.login-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--card-bg);
  border: 1px solid var(--border); border-radius: 16px; padding: 28px;
  display: flex; flex-direction: column; gap: 14px; text-align: center;
}
.login-card .knight { font-size: 52px; line-height: 1; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card input {
  font: inherit; font-size: 16px; padding: 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--bg); color: var(--text); text-align: center;
}
.login-card .err { color: var(--danger); font-size: 14px; min-height: 18px; margin: 0; }

/* ---------- Toast / Offline ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--navy); color: var(--navy-text);
  padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow);
  z-index: 100; max-width: 90vw; text-align: center;
}
#offline {
  position: fixed; top: 0; left: 0; right: 0; z-index: 99;
  background: var(--danger); color: #fff; text-align: center;
  padding: 6px 10px; padding-top: calc(6px + env(safe-area-inset-top)); font-size: 13.5px;
}
