:root {
  --espresso: #43382b;
  --caramel: #9c6b43;
  --caramel-dark: #855835;
  --bg: #f5f0e6;
  --card: #fffdf8;
  --text: #3b332a;
  --muted: #8b7d6a;
  --border: #e7ddcb;
  --danger: #a8432e;
  --warn: #a3722a;
  --success: #4a6b3a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(80, 60, 30, .10);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px; line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: #96683c; text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-family: Georgia, "Times New Roman", serif; font-weight: 600; font-size: 1.6rem; margin: 0 0 .25rem; letter-spacing: .01em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 1.25rem 0 .5rem; }
code { background: #f1ead9; padding: .1em .35em; border-radius: 4px; font-size: .9em; }

/* ---------- Kopfzeile ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.25rem;
  background: var(--espresso); color: #f7f1e5; padding: .6rem 1rem;
  position: sticky; top: 0; z-index: 50;
}
.brand { color: #f7f1e5; font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, #d9b071, #8a6a42);
  color: #fffdf6; font-weight: 800;
  font-family: Georgia, "Times New Roman", serif;
}
.brand-mark.big { width: 56px; height: 56px; border-radius: 16px; font-size: 1.8rem; }
.mainnav { display: flex; gap: .25rem; flex: 1; }
.mainnav a { color: #cfc3ac; padding: .35rem .75rem; border-radius: 8px; font-weight: 500; }
.mainnav a:hover { color: #fff; text-decoration: none; }
.mainnav a.active { background: rgba(255, 250, 238, .16); color: #fffdf6; }
.usermenu { position: relative; }
.usermenu summary { cursor: pointer; list-style: none; color: #f7f1e5; font-weight: 500; padding: .35rem .5rem; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu .menu {
  position: absolute; right: 0; top: 2.4rem; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  min-width: 220px; padding: .4rem; z-index: 60;
}
.usermenu .menu a, .usermenu .menu button {
  display: block; width: 100%; text-align: left; padding: .5rem .75rem;
  color: var(--text); border-radius: 8px; background: none; border: none;
  font: inherit; cursor: pointer;
}
.usermenu .menu a:hover, .usermenu .menu button:hover { background: var(--bg); text-decoration: none; }

/* ---------- Layout ---------- */
main { max-width: 1080px; margin: 0 auto; padding: 1.25rem 1rem 5rem; }
.page.narrow, .page-narrow { max-width: 720px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.head-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem; margin-bottom: 1rem;
}
.grid .card { margin-bottom: 0; }
.card.accent { border-left: 4px solid var(--caramel); }
.empty-state { text-align: center; padding: 2.5rem 1rem; }
.section-gap { margin-top: 1.5rem; }

/* ---------- Formulare ---------- */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .9rem; }
input, select, textarea {
  display: block; width: 100%; margin-top: .3rem;
  padding: .55rem .7rem; font: inherit; color: var(--text);
  border: 1px solid #d8cbb2; border-radius: 8px; background: #fffefb;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #b08954; outline-offset: 1px; border-color: #b08954; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.form-actions { display: flex; gap: .5rem; margin-top: .5rem; flex-wrap: wrap; }
.checkline { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.checkline input { width: auto; margin: 0; }
.hint {
  background: #f7efdd; border: 1px solid #e3d3ab; color: #6d5322;
  border-radius: 8px; padding: .6rem .8rem; font-size: .85rem; margin-bottom: .9rem;
}
.code-input { font-size: 1.4rem; letter-spacing: .35em; text-align: center; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block; padding: .5rem 1rem; border-radius: 8px;
  border: 1px solid #d8cbb2; background: #fffefb; color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--caramel); border-color: var(--caramel); color: #fffdf6; }
.btn-primary:hover { background: var(--caramel-dark); }
.btn-danger { color: var(--danger); border-color: #e6c0b5; }
.btn-danger:hover { background: #f9efe9; }
.btn-success { background: var(--success); border-color: var(--success); color: #fffdf6; }
.btn-success:hover { background: #3c5830; }
.btn-small { padding: .25rem .6rem; font-size: .82rem; }
.btn-block { width: 100%; }
.linklike { background: none; border: none; cursor: pointer; font: inherit; }

/* ---------- Anmelde-Seiten ---------- */
.auth-wrap { display: flex; justify-content: center; padding: 2.5rem 0; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card.wide { max-width: 560px; }
.auth-logo { text-align: center; margin-bottom: .75rem; }
.center { text-align: center; }
.setup-step { margin-bottom: 1.5rem; }
.recovery-key {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.05rem; font-weight: 700; letter-spacing: .05em;
  background: #fdf6e3; border: 2px dashed #c89b4a; color: #7c5a1a;
  padding: .9rem; border-radius: 8px; text-align: center;
  margin: .75rem 0; word-break: break-all; user-select: all;
}
.qr-wrap { text-align: center; margin: .75rem 0; }
.qr-wrap img { width: 200px; height: 200px; }

/* ---------- Meldungen ---------- */
.flashes { max-width: 1080px; margin: .75rem auto 0; padding: 0 1rem; }
.flash { padding: .6rem .9rem; border-radius: 8px; margin-bottom: .5rem; font-size: .92rem; }
.flash-success { background: #eef3e4; border: 1px solid #cfdfb9; color: #43602f; }
.flash-error { background: #f8e9e4; border: 1px solid #e6c0b5; color: #8c3c27; }
.banner {
  padding: .8rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 1rem;
}
.banner-birthday { background: #f9ecdc; border: 1px solid #ecd2b0; color: #8a5a24; }
.banner a { margin-left: .5rem; }

/* ---------- Listen & Tabellen ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .5rem 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: none; }
.list .meta { display: block; color: var(--muted); font-size: .84rem; }
.list.small li { padding: .3rem 0; font-size: .9rem; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: .85rem; }
.prewrap { white-space: pre-wrap; margin: .25rem 0; }
.overdue { color: var(--danger); font-weight: 600; }
.warn { color: var(--warn); font-weight: 600; }
.actions-inline { display: inline-flex; gap: .35rem; margin-left: .5rem; vertical-align: middle; }
.actions-inline form { display: inline; }

.table-card { padding: .25rem 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: .6rem 1rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:last-child td { border-bottom: none; }
tr.clickable:hover { background: #faf6ec; cursor: pointer; }

.datalist { display: grid; grid-template-columns: auto 1fr; gap: .3rem 1rem; margin: 0; }
.datalist dt { color: var(--muted); font-size: .88rem; }
.datalist dd { margin: 0; }

/* ---------- Badges, Status, Prioritaet ---------- */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.3em; padding: .05em .45em; border-radius: 999px;
  font-size: .78rem; font-weight: 700;
}
.badge-alert { background: #c05b3c; color: #fffdf6; }
.status {
  display: inline-block; padding: .15em .6em; border-radius: 999px;
  font-size: .8rem; font-weight: 600; background: #efe8d8; color: #5d5342;
  white-space: nowrap;
}
.status-aktiv, .status-erledigt { background: #e7efdc; color: #47632f; }
.status-vertrag { background: #e4e9ed; color: #44607a; }
.status-angebot { background: #f7ecd2; color: #86651c; }
.status-in-abstimmung { background: #f4e5df; color: #97563d; }
.status-pausiert { background: #eee9e0; color: #857c6d; }
.status-offen { background: #f7e8d8; color: #a3663a; }
.prio { font-weight: 700; font-size: .82rem; }
.prio-hoch { color: #b4452f; }
.prio-mittel { color: #a3722a; }
.prio-niedrig { color: #5f7d48; }

/* ---------- Filterleiste ---------- */
.filterbar {
  display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap;
}
.filterbar input, .filterbar select { width: auto; flex: 1 1 140px; margin: 0; }
.filterbar input[type="search"] { flex: 2 1 220px; }
.filterbar .btn { flex: 0 0 auto; }

/* ---------- Notizen ---------- */
.note { border-top: 1px solid var(--border); padding: .8rem 0; }
.note-form { margin-bottom: 1rem; }
.note-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.note-actions { margin-left: auto; display: flex; gap: .35rem; }
.note-actions form { display: inline; }
.note-type {
  padding: .1em .55em; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: #efe8d8; color: #5d5342;
}
.note-type-telefonat { background: #e4e9ed; color: #44607a; }
.note-type-email { background: #f7ecd2; color: #86651c; }
.note-type-meeting { background: #e7efdc; color: #47632f; }
.edited-hint { color: var(--muted); font-size: .78rem; font-style: italic; margin: 0; }

/* ---------- Wochenleiste ---------- */
.week-card { overflow-x: auto; }
.week-strip { display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem; min-width: 560px; }
.week-day { background: #f3ecdd; border-radius: 8px; padding: .5rem; min-height: 5.5rem; }
.week-day.today { outline: 2px solid #b08954; background: #f9f2e2; }
.week-day-head { font-weight: 700; font-size: .85rem; margin-bottom: .35rem; }
.week-day-head span { color: var(--muted); font-weight: 400; }
.week-item {
  display: block; font-size: .8rem; padding: .15rem .35rem; border-radius: 6px;
  margin-bottom: .25rem; color: var(--text); background: #fffdf8;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.week-item:hover { text-decoration: none; outline: 1px solid #b08954; }
.week-empty { color: #d5c9b2; text-align: center; }

/* ---------- Kontakt-Auswahl (@-Verknuepfung) ---------- */
.mention-box {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); margin: -.4rem 0 .9rem; max-height: 220px; overflow-y: auto;
}
.mention-box button {
  display: block; width: 100%; text-align: left; padding: .5rem .75rem;
  background: none; border: none; font: inherit; cursor: pointer;
}
.mention-box button:hover, .mention-box button.selected { background: #f6efe0; }
.mention-box .company { color: var(--muted); font-size: .85rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .9rem; }
.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  background: #f3ead8; border: 1px solid #ddc9a3; color: #6d5322;
  border-radius: 999px; padding: .2rem .3rem .2rem .7rem; font-size: .85rem;
}
.chip em { font-style: normal; color: #a98c53; }
.chip-x {
  background: none; border: none; cursor: pointer; font-size: 1rem;
  color: #6d5322; padding: 0 .3rem; border-radius: 999px;
}
.chip-x:hover { background: #eadfc4; }

/* ---------- Bereiche (Kategorien) ---------- */
.cat-picker { border: none; padding: 0; margin: 0 0 .9rem; }
.cat-picker legend { font-weight: 600; font-size: .9rem; padding: 0; margin-bottom: .4rem; }
.cat-options { display: flex; flex-wrap: wrap; gap: .4rem; }
.cat-option {
  display: inline-flex; align-items: center; gap: .4rem; cursor: pointer;
  background: #fffefb; border: 1px solid #d8cbb2; border-radius: 999px;
  padding: .3rem .8rem; font-weight: 500; font-size: .88rem; margin: 0;
}
.cat-option:has(input:checked) {
  background: #f3ead8; border-color: #b08954; color: #6d5322; font-weight: 600;
}
.cat-option input { width: auto; margin: 0; accent-color: #9c6b43; }
.cat-badges { display: inline-flex; flex-wrap: wrap; gap: .3rem; margin: .2rem 0 0; }
.cat {
  display: inline-block; padding: .1em .55em; border-radius: 999px;
  font-size: .74rem; font-weight: 600; background: #ece2cc; color: #6d5322;
  white-space: nowrap;
}

.upload-form { display: flex; gap: .5rem; align-items: center; margin-top: .5rem; flex-wrap: wrap; }
.upload-form input[type="file"] { width: auto; flex: 1; margin: 0; font-size: .85rem; }

/* ---------- Untere Navigation (nur Handy) ---------- */
.bottomnav { display: none; }

@media (max-width: 760px) {
  body { font-size: 15px; }
  main { padding-bottom: 6rem; }
  .mainnav { display: none; }
  .bottomnav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: var(--card); border-top: 1px solid var(--border);
    padding: .35rem 0 calc(.35rem + env(safe-area-inset-bottom));
  }
  .bottomnav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: .1rem;
    color: var(--muted); font-size: .7rem; font-weight: 600;
  }
  .bottomnav a.active { color: var(--caramel); }
  .bottomnav svg { width: 22px; height: 22px; }
  .bottomnav a:hover { text-decoration: none; }
  .form-row { grid-template-columns: 1fr; gap: 0; }
  .page-head { flex-direction: column; }
  .datalist { grid-template-columns: 1fr; gap: 0; }
  .datalist dt { margin-top: .5rem; }

  /* Tabellen werden auf dem Handy zu Karten */
  .table-card { padding: .5rem 1rem; }
  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tr { border-bottom: 1px solid var(--border); padding: .6rem 0; }
  tr:last-child { border-bottom: none; }
  td { border: none; padding: .15rem 0; }
  td[data-label]::before {
    content: attr(data-label) ": "; color: var(--muted); font-size: .78rem;
  }
  td[data-label="Name"]::before, td[data-label="Aufgabe"]::before { content: ""; }
  td[data-label="Name"] a, td[data-label="Aufgabe"] a { font-weight: 700; font-size: 1rem; }
  .note-actions { margin-left: 0; width: 100%; }
}
