:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #f0f0ec;
  --border: #e3e3dd;
  --text: #1b1c1f;
  --muted: #6b6d74;
  --accent: #3b5bdb;
  --accent-soft: #e7ecfd;
  --warn: #b5470b;
  --warn-soft: #fdeee2;
  --danger: #c92a2a;
  --ok: #2b8a3e;
  --wait: #7048b6;
  --wait-soft: #f0eafb;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 4px 16px rgb(0 0 0 / 0.04);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15161a;
    --surface: #1e2025;
    --surface-2: #26282e;
    --border: #2f3238;
    --text: #ececef;
    --muted: #9a9ca5;
    --accent: #7c95ff;
    --accent-soft: #252d4d;
    --warn: #ff9b5c;
    --warn-soft: #3a2619;
    --danger: #ff6b6b;
    --ok: #69db7c;
    --wait: #b197fc;
    --wait-soft: #2c2540;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

/* Layout ------------------------------------------------------------------ */

.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 16px 96px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px max(16px, calc((100% - 760px) / 2 + 16px));
  padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: -0.01em; }
.brand-lg { font-size: 1.35rem; justify-content: center; margin-bottom: 8px; }
.logo {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 15px;
}

.tabs { display: flex; gap: 4px; margin-left: auto; overflow-x: auto; }
.tabs a {
  padding: 7px 12px; border-radius: 999px;
  color: var(--muted); font-weight: 550; font-size: 0.95rem; white-space: nowrap;
}
.tabs a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

h1 { font-size: 1.6rem; letter-spacing: -0.02em; margin: 4px 0 16px; }
h2 { font-size: 1.05rem; margin: 0; }

.section { margin-top: 28px; }
.section-head {
  display: flex; align-items: baseline; gap: 8px;
  margin-bottom: 8px; color: var(--muted);
  font-size: 0.85rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em;
}
.section-head .count { font-weight: 500; }

.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head h1 { margin-right: auto; }
.back { color: var(--muted); font-size: 0.95rem; display: inline-block; margin-bottom: 6px; }

.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 14px 4px; font-size: 0.95rem; }
.hint { color: var(--muted); font-size: 0.88rem; margin: 6px 2px 0; }

/* Cards & lists ------------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.list { list-style: none; margin: 0; padding: 0; }
.list > li + li { border-top: 1px solid var(--border); }

.task {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 14px;
}
.task-body { flex: 1; min-width: 0; cursor: pointer; }
.task-title { overflow-wrap: anywhere; }
.task.done .task-title { color: var(--muted); text-decoration: line-through; }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }

.check {
  appearance: none; flex: none;
  width: 22px; height: 22px; margin: 1px 0 0;
  border: 2px solid var(--border); border-radius: 50%;
  background: var(--surface); cursor: pointer;
  display: grid; place-items: center; transition: 0.15s;
}
.check:hover { border-color: var(--accent); }
.check:checked { background: var(--ok); border-color: var(--ok); }
.check:checked::after { content: "✓"; color: #fff; font-size: 13px; font-weight: 700; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
  font-size: 0.8rem; font-weight: 550; white-space: nowrap;
}
a.chip:hover { color: var(--text); }
.chip.wait { background: var(--wait-soft); color: var(--wait); }
.chip.overdue { background: var(--warn-soft); color: var(--warn); }
.chip.today { background: var(--accent-soft); color: var(--accent); }

.filters { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 4px; margin-top: 14px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filter {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  padding: 6px 12px; border-radius: 999px; font: inherit; font-size: 0.9rem; font-weight: 550;
  white-space: nowrap; cursor: pointer;
}
.filter.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* Kunden-Kacheln */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.tile {
  aspect-ratio: 1;
  display: flex; flex-direction: column; justify-content: space-between; gap: 8px;
  padding: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform 0.12s, border-color 0.12s;
  min-width: 0;
}
.tile:hover { border-color: var(--accent); transform: translateY(-2px); }
.tile-name { font-weight: 650; font-size: 1.05rem; line-height: 1.25; overflow-wrap: anywhere; }
.tile-meta { display: flex; flex-wrap: wrap; gap: 4px; font-size: 0.85rem; }
.tile-add {
  font: inherit; color: var(--muted); cursor: pointer;
  background: transparent; border-style: dashed; box-shadow: none;
  align-items: center; justify-content: center; font-weight: 600;
}
.tile-add .plus { font-size: 2rem; line-height: 1; font-weight: 400; }
.tile-add:hover { color: var(--accent); }

.client-row { display: flex; align-items: center; gap: 12px; padding: 14px; }
.client-row .name { font-weight: 600; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.client-row .arrow { color: var(--muted); }

details.done-list > summary {
  cursor: pointer; list-style: none; color: var(--muted);
  font-size: 0.85rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em;
}
details.done-list > summary::before { content: "▸ "; }
details.done-list[open] > summary::before { content: "▾ "; }

/* Forms -------------------------------------------------------------------- */

.field { display: grid; gap: 4px; flex: 1; min-width: 0; }
.field > span { font-size: 0.82rem; color: var(--muted); font-weight: 600; }

input, select, textarea {
  width: 100%;
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 11px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }

.row { display: flex; gap: 10px; flex-wrap: wrap; }

.quick-add { padding: 12px; display: grid; gap: 10px; }
.quick-add .main { display: flex; gap: 8px; }
.quick-add .main input { flex: 1; }
.quick-add .extra { display: flex; gap: 8px; flex-wrap: wrap; }
.quick-add .extra > * { flex: 1 1 140px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: 0.95rem;
  padding: 9px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { border-color: var(--accent); filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--danger); }
.btn-block { width: 100%; }
.spacer { flex: 1; }

/* Notizen beim Kunden */
.notes { padding: 4px; }
.notes textarea { border: none; background: transparent; min-height: 64px; }
.notes textarea:focus { outline: none; }

/* Import ------------------------------------------------------------------- */

.import-card { padding: 14px; display: grid; gap: 12px; }
.import-card textarea { min-height: 200px; }
.file-label { cursor: pointer; }
.file-label input { display: none; }

.suggestion { display: grid; grid-template-columns: auto 1fr; gap: 10px 12px; padding: 12px 14px; align-items: start; }
.suggestion .fields { display: grid; gap: 8px; }
.suggestion .fields .row > * { flex: 1 1 130px; }
.suggestion.off .fields { opacity: 0.45; }

.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(1turn); } }

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

.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); display: grid; gap: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 24px; box-shadow: var(--shadow);
}
.error { color: var(--danger); margin: 0; font-size: 0.92rem; }

/* Dialog & Toast ----------------------------------------------------------- */

.dialog {
  width: min(480px, calc(100% - 24px));
  border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); color: var(--text);
  padding: 20px; box-shadow: 0 20px 60px rgb(0 0 0 / 0.25);
}
.dialog::backdrop { background: rgb(0 0 0 / 0.35); }
.dialog form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 4px; }
.dialog-actions { gap: 6px; }
.dialog-actions .btn { padding: 9px 11px; font-size: 0.9rem; }
.dialog-actions .btn-danger-ghost { padding-inline: 0 4px; }
.dialog .row > .field { flex: 1 1 0; }
input[type="date"] { min-width: 0; -webkit-appearance: none; appearance: none; min-height: 42px; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 999px; font-size: 0.92rem; font-weight: 550;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.2); z-index: 50; max-width: calc(100% - 32px);
}

@media (max-width: 560px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  h1 { font-size: 1.4rem; }
}
