:root {
  --bg: #f6f1ea;
  --card: #fffdf9;
  --text: #26211c;
  --muted: #7a6f63;
  --line: #e6ddd0;
  --accent: #1f3a6b;
  --accent-text: #fff;
  --due-bg: #e9eef7;
  --due-line: #9db0d3;
  --ok: #3f7d58;
  --hint-bg: #e8f1ea;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 14px rgba(60, 40, 20, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1917;
    --card: #262320;
    --text: #f1ebe3;
    --muted: #a89c8e;
    --line: #3a3530;
    --accent: #8fb0e8;
    --accent-text: #111a2e;
    --due-bg: #1e2638;
    --due-line: #3f5888;
    --ok: #7fc39a;
    --hint-bg: #23332a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
main { max-width: 640px; margin: 0 auto; padding: 20px 16px 64px; }
h1 { font-size: 1.7rem; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
p { margin: 0; }
.muted { color: var(--muted); font-size: .9rem; }
.fine { color: var(--muted); font-size: .8rem; margin-top: 16px; }
.error { color: var(--accent); }

header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
.header-actions { display: flex; gap: 8px; flex-shrink: 0; }

.btn {
  font: inherit; font-weight: 600; font-size: .92rem;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 9px 14px; border-radius: 10px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.98); }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); font-weight: 500; }
.btn.danger { color: var(--accent); }
.btn.icon { width: 40px; padding: 0; font-size: 1.1rem; }
.btn.big { width: 100%; min-height: 48px; margin-top: 12px; font-size: 1rem; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn[disabled] { opacity: .5; cursor: default; }

/* Login */
#login { min-height: 90vh; display: grid; place-items: center; }
#login[hidden], #app[hidden] { display: none; }
.login-card { text-align: center; max-width: 380px; }
.login-card h1 { margin: 16px 0 10px; }
.login-card > p:first-of-type { color: var(--muted); margin-bottom: 14px; }

/* Banner */
.banner {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; margin-bottom: 14px; display: flex; gap: 12px; align-items: center; justify-content: space-between;
  box-shadow: var(--shadow);
}
.banner.warn { border-color: var(--due-line); background: var(--due-bg); }
.banner p { font-size: .9rem; }

/* Listen */
section { margin-bottom: 26px; }
section > h2 {
  font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
  margin: 0 4px 10px; display: flex; gap: 8px; align-items: center;
}
.count { background: var(--line); color: var(--text); border-radius: 99px; padding: 1px 8px; font-size: .75rem; letter-spacing: 0; }
section.due > h2 { color: var(--accent); }
section.due .count { background: var(--accent); color: var(--accent-text); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.card.due { background: var(--due-bg); border-color: var(--due-line); }
.card.suggested { border-style: dashed; }
.card.done { opacity: .85; }
.card-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.company { font-weight: 700; font-size: 1.05rem; overflow-wrap: anywhere; }
input.company {
  font: inherit; font-weight: 700; font-size: 1.05rem; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; background: var(--bg); width: 100%; min-width: 0;
}
.when { color: var(--muted); font-size: .82rem; white-space: nowrap; }
.subject { color: var(--muted); font-size: .9rem; margin-top: 2px; overflow-wrap: anywhere; }
.meta { font-size: .85rem; margin-top: 8px; color: var(--muted); }
.meta strong { color: var(--text); }
.card.due .meta strong { color: var(--accent); }
.hint { background: var(--hint-bg); color: var(--ok); border-radius: 8px; padding: 6px 10px; font-size: .85rem; margin-top: 8px; font-weight: 600; }
.badge { display: inline-block; border-radius: 99px; padding: 2px 10px; font-size: .8rem; font-weight: 600; background: var(--line); }
.badge.einladung, .badge.zusage { background: var(--hint-bg); color: var(--ok); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions .spacer { flex: 1; }

.empty { text-align: center; color: var(--muted); padding: 36px 16px; border: 1px dashed var(--line); border-radius: 14px; }
.empty strong { display: block; color: var(--text); font-size: 1.05rem; margin-bottom: 4px; }

details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary h2::after { content: "▸"; margin-left: auto; }
details[open] > summary h2::after { content: "▾"; }
details > summary h2 {
  font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
  margin: 0 4px 10px; display: flex; gap: 8px; align-items: center;
}

/* Dialoge */
dialog {
  border: 1px solid var(--line); border-radius: 18px; background: var(--card); color: var(--text);
  padding: 20px; width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(20, 15, 10, .5); }
label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
label input, label select {
  display: block; width: 100%; margin-top: 5px; font: inherit; font-size: 1rem; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
.dialog-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 18px; }
.outcomes { display: grid; gap: 8px; margin-top: 12px; }
.outcomes .btn { justify-content: flex-start; min-height: 46px; }
.setting-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 6px 0 4px; }
#scan-status { margin-top: 8px; }

#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-size: .9rem; font-weight: 600;
  max-width: calc(100vw - 32px); z-index: 10;
}

[hidden] { display: none !important; }
