:root {
  --bg: #faf6f2;
  --surface: #ffffff;
  --surface-2: #f3ece6;
  --text: #2b2320;
  --muted: #7d6f68;
  --border: #e7ddd5;
  --accent: #c2410c;
  --accent-strong: #9a3412;
  --accent-soft: #fde7da;
  --on-accent: #ffffff;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #a16207;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --info: #1d4ed8;
  --info-soft: #dbeafe;
  --shadow: 0 1px 2px rgba(60, 40, 30, .06), 0 4px 16px rgba(60, 40, 30, .06);
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #181412;
    --surface: #221d1a;
    --surface-2: #2c2622;
    --text: #f3ebe5;
    --muted: #b0a29a;
    --border: #3a322d;
    --accent: #fb8a4c;
    --accent-strong: #fdba74;
    --accent-soft: #3d2416;
    --on-accent: #1c0f08;
    --ok: #4ade80;
    --ok-soft: #12301d;
    --warn: #facc15;
    --warn-soft: #352a0a;
    --danger: #f87171;
    --danger-soft: #3b1414;
    --info: #93c5fd;
    --info-soft: #172446;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #181412; --surface: #221d1a; --surface-2: #2c2622; --text: #f3ebe5; --muted: #b0a29a;
  --border: #3a322d; --accent: #fb8a4c; --accent-strong: #fdba74; --accent-soft: #3d2416; --on-accent: #1c0f08;
  --ok: #4ade80; --ok-soft: #12301d; --warn: #facc15; --warn-soft: #352a0a; --danger: #f87171;
  --danger-soft: #3b1414; --info: #93c5fd; --info-soft: #172446; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--muted); }
code { font-size: .875em; background: var(--surface-2); padding: .1em .35em; border-radius: 5px; word-break: break-all; }

#app.loading::after {
  content: ""; display: block; width: 32px; height: 32px; margin: 30vh auto 0;
  border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 880px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; text-decoration: none; color: var(--text); }
.brand img { width: 30px; height: 30px; }
.main { max-width: 880px; margin: 0 auto; padding: 20px 16px calc(var(--nav-h) + 40px); }

.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px; border-radius: 10px; color: var(--muted); text-decoration: none; font-size: .75rem; font-weight: 500;
}
.nav a svg { width: 24px; height: 24px; }
.nav a[aria-current="page"] { color: var(--accent); }
@media (min-width: 760px) {
  .nav { position: static; background: none; border: 0; padding: 0; margin-left: auto; gap: 4px; justify-content: flex-end; }
  .nav a { flex: none; flex-direction: row; gap: 8px; padding: 8px 12px; font-size: .9rem; }
  .nav a svg { width: 18px; height: 18px; }
  .nav a[aria-current="page"] { background: var(--accent-soft); }
  .main { padding-bottom: 60px; }
}

.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin-right: auto; }

/* ---------- Bausteine ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.card + .card, .section + .section { margin-top: 16px; }
.card h2 { margin-bottom: 10px; }
.stack > * + * { margin-top: 12px; }

.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: .95rem; padding: 10px 16px; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; min-height: 44px;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .nav a:focus-visible, .row:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { background: none; border-color: transparent; }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: .875rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row.end { justify-content: flex-end; }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); z-index: 9;
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--on-accent); box-shadow: 0 6px 20px rgba(194, 65, 12, .35);
  display: grid; place-items: center; cursor: pointer;
}
.fab svg { width: 28px; height: 28px; }
@media (min-width: 760px) { .fab { display: none; } }
.desktop-only { display: none; }
@media (min-width: 760px) { .desktop-only { display: inline-flex; } }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.field + .field { margin-top: 14px; }
.field-row { display: grid; gap: 10px; grid-template-columns: 1fr 1.6fr 1.2fr; }
input[type=text], input[type=email], input[type=number], input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 80px; resize: vertical; }
.hint { font-size: .85rem; color: var(--muted); margin-top: 4px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; margin: 0; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }

.choices { display: grid; gap: 8px; }
.choice {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px; margin: 0;
  border: 1px solid var(--border); border-radius: 12px; cursor: pointer; font-weight: 400;
}
.choice input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice strong { display: block; }
.choice span { font-size: .875rem; color: var(--muted); }
.share-list { display: grid; gap: 8px; margin: 10px 0 0 30px; }

.notice { border-radius: 12px; padding: 12px 14px; font-size: .925rem; }
.notice.warn { background: var(--warn-soft); color: var(--text); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); }
.notice.info { background: var(--info-soft); border: 1px solid color-mix(in srgb, var(--info) 30%, transparent); }
.notice.ok { background: var(--ok-soft); border: 1px solid color-mix(in srgb, var(--ok) 30%, transparent); }
.notice.danger { background: var(--danger-soft); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); }

.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; font-weight: 600;
  padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge svg { width: 12px; height: 12px; }
.badge.family { background: var(--info-soft); color: var(--info); }
.badge.private { background: var(--surface-2); color: var(--muted); }
.badge.selected { background: var(--warn-soft); color: var(--warn); }
.badge.new { background: var(--ok-soft); color: var(--ok); }
.badge.duplicate { background: var(--danger-soft); color: var(--danger); }
.badge.possible { background: var(--warn-soft); color: var(--warn); }
.badge.invalid { background: var(--surface-2); color: var(--muted); }

/* ---------- Liste ---------- */
.toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: .85rem;
  padding: 6px 12px; border-radius: 99px; cursor: pointer; white-space: nowrap; min-height: 34px;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

.group-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 4px 8px; font-weight: 700; }
.group-title:first-child { margin-top: 0; }
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 14px; padding: 12px 14px; width: 100%;
  border: 0; background: none; font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.row + .row { border-top: 1px solid var(--border); }
.row:hover { background: var(--surface-2); }
.datebox {
  flex: none; width: 50px; text-align: center; border-radius: 10px; padding: 5px 0 6px;
  background: var(--surface-2); line-height: 1.1;
}
.datebox b { display: block; font-size: 1.25rem; }
.datebox span { font-size: .7rem; text-transform: uppercase; color: var(--muted); font-weight: 600; letter-spacing: .04em; }
.row.today .datebox { background: var(--accent); color: var(--on-accent); }
.row.today .datebox span { color: inherit; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-sub { font-size: .875rem; color: var(--muted); }
.row-side { text-align: right; font-size: .85rem; flex: none; }
.row-side strong { display: block; font-size: .95rem; }
.row.today .row-side strong { color: var(--accent); }

.hero {
  background: linear-gradient(135deg, var(--accent-soft), var(--surface));
  border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 20px;
}
.hero h2 { font-size: 1.05rem; margin-bottom: 4px; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .big { font-size: 2.5rem; }

/* ---------- Dialog ---------- */
dialog {
  border: 0; padding: 0; border-radius: 18px; background: var(--surface); color: var(--text);
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(20, 12, 8, .45); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.dialog-body { padding: 18px; }
.dialog-foot { display: flex; gap: 10px; justify-content: space-between; flex-wrap: wrap; padding: 14px 18px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--surface); }
.dialog-foot .right { display: flex; gap: 10px; margin-left: auto; }
.icon-btn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 8px; border-radius: 8px; display: grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }
@media (max-width: 560px) {
  dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: 92dvh; }
}

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 24px); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-size: .925rem; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 1000; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (min-width: 760px) { #toast { bottom: 28px; } }

/* ---------- Login ---------- */
.auth { max-width: 400px; margin: 0 auto; padding: 12vh 16px 40px; }
.auth .logo { width: 64px; height: 64px; display: block; margin: 0 auto 16px; }
.auth h1 { text-align: center; margin-bottom: 6px; }
.auth .lead { text-align: center; color: var(--muted); margin-bottom: 24px; }

/* ---------- Import ---------- */
.dropzone {
  display: block; border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px 16px; text-align: center;
  cursor: pointer; background: var(--surface); font-weight: 500;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone svg { width: 32px; height: 32px; color: var(--accent); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tr.dim td { color: var(--muted); }
td input[type=checkbox], th input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
td .reason { display: block; font-size: .8rem; color: var(--muted); }
.summary { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }

details.howto { border: 1px solid var(--border); border-radius: 12px; padding: 0 14px; background: var(--surface); }
details.howto + details.howto { margin-top: 8px; }
details.howto summary { cursor: pointer; font-weight: 600; padding: 12px 0; }
details.howto ol, details.howto ul { margin: 0 0 14px; padding-left: 20px; }
details.howto li + li { margin-top: 4px; }

.copy-field { display: flex; gap: 8px; }
.copy-field input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; }

.member { display: flex; align-items: center; gap: 12px; padding: 12px 14px; flex-wrap: wrap; }
.member + .member { border-top: 1px solid var(--border); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong);
  display: grid; place-items: center; font-weight: 700; flex: none;
}
.member-main { flex: 1; min-width: 160px; }
.member-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.btn-row.center { justify-content: center; }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.plain[disabled] { opacity: .55; }
@media (max-width: 559px) {
  .member-actions { width: 100%; padding-left: 52px; }
  .member-actions .btn { flex: 1 1 auto; }
}
