:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --list: #f1f2f4;
  --text: #172b4d;
  --text-2: #44546f;
  --muted: #626f86;
  --line: #dcdfe4;
  --hover: #e9ebee;
  --accent: #0c66e4;
  --accent-text: #ffffff;
  --danger: #c9372c;
  --shadow: 0 1px 1px rgba(9, 30, 66, .25), 0 0 1px rgba(9, 30, 66, .31);
  --radius: 8px;
  --topbar: #1d2125;

  --l-green: #4bce97; --l-yellow: #f5cd47; --l-orange: #fea362; --l-red: #f87168;
  --l-purple: #9f8fef; --l-blue: #579dff; --l-sky: #6cc3e0; --l-lime: #94c748;
  --l-pink: #e774bb; --l-black: #8590a2;

  --b-blue: #0c66e4; --b-green: #1f845a; --b-orange: #c25100; --b-red: #ae2e24;
  --b-purple: #6e5dc6; --b-pink: #ae4787; --b-lime: #4c6b1f; --b-sky: #206a83; --b-grey: #626f86;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.43 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.spacer { flex: 1; }

/* ---------- Grundbausteine ---------- */
.btn {
  border: 0; border-radius: 4px; padding: 6px 12px; background: var(--hover);
  color: var(--text); font-weight: 500; line-height: 20px;
}
.btn:hover { background: #dcdfe4; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: #0055cc; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.subtle { background: transparent; }
.btn.subtle:hover { background: var(--hover); }
.btn.block { display: block; width: 100%; text-align: left; margin-bottom: 6px; }
.input, textarea.input, select.input {
  width: 100%; border: 1px solid #8590a2; border-radius: 4px; padding: 6px 8px; background: #fff;
}
.input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea.input { resize: vertical; min-height: 36px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 8px; }
h3.sec { font-size: 14px; margin: 20px 0 8px; color: var(--text-2); }

/* ---------- Login ---------- */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-box {
  background: var(--surface); border-radius: 12px; padding: 32px; width: 100%; max-width: 360px;
  box-shadow: var(--shadow); text-align: center;
}
.login-logo { font-size: 28px; font-weight: 700; letter-spacing: -.5px; margin-bottom: 4px; }
#google-btn { display: flex; justify-content: center; min-height: 44px; align-items: center; margin-top: 16px; }

/* ---------- Kopfzeile ---------- */
#app { height: 100%; height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--topbar); color: #fff;
  flex: none; position: relative; z-index: 20;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right));
}
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 17px; margin-right: 4px; }
.tb-btn {
  border: 0; background: rgba(255, 255, 255, .12); color: #fff; border-radius: 4px; padding: 6px 10px;
  font-weight: 500;
}
.tb-btn:hover { background: rgba(255, 255, 255, .22); }
.search-wrap { position: relative; flex: 0 1 320px; min-width: 120px; }
#search {
  width: 100%; border: 1px solid rgba(255, 255, 255, .25); background: rgba(255, 255, 255, .12); color: #fff;
  border-radius: 4px; padding: 5px 10px;
}
#search::placeholder { color: rgba(255, 255, 255, .7); }
#search:focus { background: #fff; color: var(--text); outline: none; }
.search-results {
  position: absolute; top: 38px; left: 0; width: min(420px, 92vw); background: #fff; color: var(--text);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(9, 30, 66, .3); max-height: 60vh; overflow: auto;
  padding: 6px;
}
.sr-item { padding: 8px; border-radius: 4px; cursor: pointer; }
.sr-item:hover, .sr-item.active { background: var(--hover); }
.sr-item small { display: block; color: var(--muted); }

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---------- Startseite ---------- */
.home { padding: 24px 16px; max-width: 1100px; margin: 0 auto; width: 100%; overflow: auto; }
.home h2 { font-size: 16px; margin: 24px 0 12px; color: var(--text-2); }
.board-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.board-tile {
  height: 96px; border-radius: var(--radius); padding: 10px 12px; color: #fff; font-weight: 700;
  border: 0; text-align: left; position: relative; display: flex; align-items: flex-start;
  box-shadow: var(--shadow); word-break: break-word;
}
.board-tile:hover { filter: brightness(.92); }
.board-tile .star { position: absolute; right: 8px; bottom: 6px; font-weight: 400; opacity: .9; font-size: 12px; }
.board-tile.new { background: var(--hover); color: var(--text-2); font-weight: 500; align-items: center; justify-content: center; }

/* ---------- Board ---------- */
.board { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.board-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: rgba(0, 0, 0, .24); color: #fff;
  flex-wrap: wrap;
}
.board-title {
  font-size: 18px; font-weight: 700; padding: 2px 8px; border-radius: 4px; border: 0; background: transparent;
  color: #fff; max-width: 60vw;
}
.board-title:hover { background: rgba(255, 255, 255, .2); }
input.board-title { background: #fff; color: var(--text); }
.hb { border: 0; background: rgba(255, 255, 255, .2); color: #fff; border-radius: 4px; padding: 5px 10px; font-weight: 500; }
.hb:hover { background: rgba(255, 255, 255, .32); }
.hb.on { background: #fff; color: var(--text); }
.lists {
  flex: 1; min-height: 0; display: flex; align-items: flex-start; gap: 12px; padding: 12px;
  overflow-x: auto; overflow-y: hidden;
}
.list {
  flex: none; width: 272px; max-height: 100%; display: flex; flex-direction: column; background: var(--list);
  border-radius: 12px; box-shadow: var(--shadow);
}
.list-head { display: flex; align-items: center; gap: 4px; padding: 8px 8px 4px 12px; cursor: grab; }
.list-name { flex: 1; font-weight: 600; padding: 4px 0; border: 0; background: transparent; text-align: left; min-width: 0; overflow-wrap: anywhere; }
input.list-name { background: #fff; padding: 4px 6px; border-radius: 4px; }
.list-count { color: var(--muted); font-size: 12px; }
.icon-btn { border: 0; background: transparent; border-radius: 4px; padding: 2px 8px; color: var(--text-2); font-weight: 700; }
.icon-btn:hover { background: #dcdfe4; }
.cards { flex: 1 1 auto; min-height: 4px; overflow-y: auto; padding: 4px 8px; display: flex; flex-direction: column; gap: 8px; }
.list-foot { padding: 4px 8px 8px; }
.add-btn { width: 100%; text-align: left; border: 0; background: transparent; padding: 6px 8px; border-radius: 6px; color: var(--text-2); font-weight: 500; }
.add-btn:hover { background: #dcdfe4; color: var(--text); }
.add-list { flex: none; width: 272px; background: rgba(255, 255, 255, .24); border-radius: 12px; color: #fff; }
.add-list > .add-btn { color: #fff; padding: 10px 12px; }
.add-list > .add-btn:hover { background: rgba(255, 255, 255, .16); }
.add-list.open { background: var(--list); padding: 8px; color: var(--text); }

.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px 10px;
  cursor: pointer; position: relative; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  outline: 2px solid transparent;
}
.card:hover { outline-color: #388bff55; }
.card.sel { outline-color: var(--accent); }
.card .title { overflow-wrap: anywhere; white-space: pre-wrap; }
.card .lbls { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px; }
.lbl { display: inline-block; min-width: 40px; height: 8px; border-radius: 4px; }
.show-label-text .card .lbl { height: auto; padding: 0 8px; font-size: 12px; font-weight: 600; line-height: 16px; color: #172b4d; }
.badges { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; font-size: 12px; color: var(--muted); }
.badge-due { padding: 0 6px; border-radius: 3px; }
.badge-due.soon { background: #f5cd47; color: #172b4d; }
.badge-due.over { background: #c9372c; color: #fff; }
.badge-due.done { background: #1f845a; color: #fff; }
.badge-done { color: #1f845a; font-weight: 600; }
.composer textarea { width: 100%; border: 0; border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px 10px; resize: none; min-height: 56px; background: #fff; }
.composer textarea:focus { outline: 2px solid var(--accent); }
.composer .row { margin-top: 8px; }
.card-quick textarea { width: 100%; min-height: 72px; border: 0; padding: 0; resize: none; background: transparent; outline: none; }

/* Ziehen */
.drag-ghost {
  position: fixed; z-index: 1000; pointer-events: none; transform: rotate(3deg);
  box-shadow: 0 12px 24px rgba(9, 30, 66, .35); opacity: .95;
}
.placeholder { background: rgba(9, 30, 66, .08); border-radius: var(--radius); flex: none; }
.list.placeholder { background: rgba(0, 0, 0, .18); box-shadow: none; }
body.dragging, body.dragging * { cursor: grabbing !important; }
body.dragging .lists { scroll-snap-type: none; }
.archive-zone {
  position: fixed; z-index: 900; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(420px, calc(100vw - 32px)); padding: 18px 12px; text-align: center; font-weight: 600;
  background: var(--surface); color: var(--text-2); border: 2px dashed var(--muted); border-radius: var(--radius);
  box-shadow: 0 8px 20px rgba(9, 30, 66, .25); animation: zone-in .15s ease-out;
}
.archive-zone.over { background: var(--danger); border-color: var(--danger); color: #fff; }
@keyframes zone-in { from { opacity: 0; transform: translate(-50%, 12px); } }

/* Farben */
.c-green { background: var(--l-green); } .c-yellow { background: var(--l-yellow); } .c-orange { background: var(--l-orange); }
.c-red { background: var(--l-red); } .c-purple { background: var(--l-purple); } .c-blue { background: var(--l-blue); }
.c-sky { background: var(--l-sky); } .c-lime { background: var(--l-lime); } .c-pink { background: var(--l-pink); }
.c-black { background: var(--l-black); }
.bg-blue { background: var(--b-blue); } .bg-green { background: var(--b-green); } .bg-orange { background: var(--b-orange); }
.bg-red { background: var(--b-red); } .bg-purple { background: var(--b-purple); } .bg-pink { background: var(--b-pink); }
.bg-lime { background: var(--b-lime); } .bg-sky { background: var(--b-sky); } .bg-grey { background: var(--b-grey); }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(9, 30, 66, .55); z-index: 100; display: flex;
  justify-content: center; align-items: flex-start; overflow-y: auto; padding: 48px 16px;
}
.dialog {
  background: var(--list); border-radius: 12px; width: 100%; max-width: 768px; position: relative;
  padding: 20px 20px 24px; box-shadow: 0 8px 32px rgba(9, 30, 66, .4);
}
.dialog.narrow { max-width: 520px; background: var(--surface); }
.dialog-close {
  position: absolute; right: 10px; top: 10px; border: 0; background: transparent; border-radius: 50%;
  width: 36px; height: 36px; font-size: 22px; line-height: 1; color: var(--text-2);
}
.dialog-close:hover { background: var(--hover); }
.cd-title {
  width: calc(100% - 40px); font-size: 20px; font-weight: 600; border: 0; background: transparent; resize: none;
  padding: 4px 6px; margin-left: -6px; border-radius: 4px; overflow: hidden;
}
.cd-title:focus { background: #fff; }
.cd-sub { color: var(--muted); margin: 2px 0 12px; }
.cd-sub button { border: 0; background: none; padding: 0; color: var(--text-2); text-decoration: underline; }
.cd-grid { display: grid; grid-template-columns: 1fr 180px; gap: 24px; }
.cd-side h4 { font-size: 12px; color: var(--muted); margin: 0 0 6px; font-weight: 600; }
.cd-side .btn { display: block; width: 100%; text-align: left; margin-bottom: 8px; }
.cd-meta { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 8px; }
.cd-meta h4 { font-size: 12px; color: var(--muted); margin: 0 0 4px; font-weight: 600; }
.chip { display: inline-block; border-radius: 4px; padding: 4px 10px; min-width: 40px; min-height: 28px; font-weight: 600; color: #172b4d; border: 0; margin: 0 4px 4px 0; }
.desc-view { white-space: pre-wrap; overflow-wrap: anywhere; background: #fff; border-radius: 6px; padding: 8px 10px; min-height: 40px; cursor: text; }
.desc-view.empty { color: var(--muted); background: var(--hover); }
.cl { margin-top: 16px; }
.cl-head { display: flex; align-items: center; gap: 8px; }
.cl-head strong { flex: 1; }
.progress { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: 12px; color: var(--muted); }
.progress .bar { flex: 1; height: 8px; border-radius: 4px; background: var(--hover); overflow: hidden; }
.progress .bar i { display: block; height: 100%; background: var(--accent); }
.progress .bar i.full { background: #1f845a; }
.item { display: flex; align-items: flex-start; gap: 8px; padding: 4px 6px; border-radius: 4px; }
.item:hover { background: var(--hover); }
.item input[type=checkbox] { margin-top: 3px; width: 16px; height: 16px; }
.item span { flex: 1; overflow-wrap: anywhere; cursor: text; }
.item.done span { text-decoration: line-through; color: var(--muted); }
.item .x { visibility: hidden; }
.item:hover .x { visibility: visible; }
.comment { margin-top: 10px; }
.comment .meta { font-size: 12px; color: var(--muted); }
.comment .body { background: #fff; border-radius: 6px; padding: 8px 10px; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: var(--shadow); }
.comment .acts button { border: 0; background: none; padding: 0; margin-right: 10px; font-size: 12px; color: var(--muted); text-decoration: underline; }
.act { font-size: 13px; color: var(--text-2); padding: 3px 0; }
.act small { color: var(--muted); margin-left: 6px; }
.archived-note { background: #fff7d6; padding: 8px 12px; border-radius: 6px; margin-bottom: 12px; }

.popover {
  position: fixed; z-index: 200; background: #fff; border-radius: var(--radius); width: 304px;
  box-shadow: 0 8px 24px rgba(9, 30, 66, .3); padding: 12px; max-height: 80vh; overflow: auto;
}
.popover h4 { margin: 0 0 10px; text-align: center; font-size: 14px; color: var(--text-2); }
.pop-label { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.pop-label .chip { flex: 1; margin: 0; text-align: left; cursor: pointer; }
.pop-label input { width: 16px; height: 16px; }
.swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 8px 0; }
.swatch { height: 32px; border-radius: 4px; border: 0; }
.swatch.on { outline: 2px solid var(--accent); outline-offset: 2px; }
.menu-item { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 4px; }
.menu-item:hover { background: var(--hover); }
.menu-item.danger { color: var(--danger); }

.side-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(360px, 100vw); background: #fff; z-index: 150;
  box-shadow: -8px 0 24px rgba(9, 30, 66, .25); padding: 16px; overflow-y: auto;
}
.side-panel h3 { margin: 0 0 12px; text-align: center; font-size: 16px; }
.side-panel h3.sec { text-align: left; font-size: 14px; margin: 20px 0 8px; }
.check-row { display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; cursor: pointer; }
.check-row input { margin-top: 3px; flex: none; width: 18px; height: 18px; }
.mail-addr { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; background: var(--hover); padding: 8px; border-radius: 4px; word-break: break-all; }
.kbd-table { width: 100%; border-collapse: collapse; }
.kbd-table td { padding: 4px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
kbd { display: inline-block; min-width: 22px; text-align: center; padding: 1px 6px; border-radius: 4px; background: var(--hover); border: 1px solid var(--line); font: 12px ui-monospace, Menlo, Consolas, monospace; margin-right: 2px; }
.log-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.log-table td { padding: 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ok { color: #1f845a; font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #172b4d; color: #fff;
  padding: 10px 16px; border-radius: 6px; z-index: 300; box-shadow: var(--shadow); max-width: 90vw;
}
.toast button { margin-left: 12px; border: 0; background: none; color: #85b8ff; text-decoration: underline; padding: 0; }

/* ---------- Touch-Geräte (kein Hover) ---------- */
@media (hover: none) {
  .item .x { visibility: visible; }
  .card:hover { outline-color: transparent; }
  .card.sel { outline-color: var(--accent); }
  .icon-btn { min-width: 40px; min-height: 40px; }
  .item input[type=checkbox], .pop-label input, .cd-meta input[type=checkbox] { width: 22px; height: 22px; }
  .add-btn, .menu-item { padding-top: 10px; padding-bottom: 10px; }
}

/* ---------- Tablet ---------- */
@media (max-width: 1024px) {
  .dialog { max-width: 680px; }
  .cd-grid { grid-template-columns: 1fr 160px; gap: 16px; }
}

/* ---------- Handy ---------- */
@media (max-width: 700px) {
  body { font-size: 15px; }
  /* 16px verhindert das automatische Hineinzoomen von iOS beim Tippen */
  input, select, textarea, .input, #search, .composer textarea { font-size: 16px; }
  .topbar { gap: 6px; padding-bottom: 8px; padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  #btn-help { display: none; }
  .tb-btn { padding: 8px 10px; }
  .search-wrap { flex: 1 1 auto; min-width: 0; }
  .search-results { position: fixed; left: 8px; right: 8px; top: calc(52px + env(safe-area-inset-top)); width: auto; }
  .home { padding: 16px 12px calc(16px + env(safe-area-inset-bottom)); }
  .board-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .board-tile { height: 84px; }
  .board-head { padding: 8px 10px; gap: 6px; }
  .board-title { font-size: 17px; max-width: 100%; }
  .hb { padding: 8px 10px; }
  .lists { scroll-snap-type: x mandatory; padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); gap: 10px; }
  .list, .add-list { width: calc(100vw - 44px); max-width: 360px; scroll-snap-align: center; }
  .card { padding: 10px 12px; }
  .overlay { padding: 0; align-items: stretch; }
  .dialog { border-radius: 0; min-height: 100%; max-width: none; padding: calc(14px + env(safe-area-inset-top)) 14px calc(32px + env(safe-area-inset-bottom)); }
  .dialog.narrow { max-width: none; }
  .dialog-close { width: 44px; height: 44px; font-size: 26px; top: calc(6px + env(safe-area-inset-top)); }
  .cd-title { font-size: 19px; width: calc(100% - 48px); }
  .cd-grid { grid-template-columns: 1fr; gap: 12px; }
  .cd-side { order: -1; display: flex; flex-wrap: wrap; gap: 6px; }
  .cd-side h4 { width: 100%; margin: 6px 0 0; }
  .cd-side .btn { width: auto; margin: 0; padding: 8px 12px; }
  .popover { left: 8px !important; right: 8px; width: auto; max-height: 70vh; }
  .side-panel { width: 100vw; padding-top: calc(16px + env(safe-area-inset-top)); }
  .btn { padding: 8px 12px; }
  .toast { bottom: calc(16px + env(safe-area-inset-bottom)); }
}
@media (max-width: 420px) {
  .brand { display: none; }
}
/* Handy quer: wenig Höhe */
@media (max-height: 500px) and (orientation: landscape) {
  .board-head { padding: 4px 10px; }
  .topbar { padding-top: 4px; padding-bottom: 4px; }
}
