:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --text: #1c1f26;
  --muted: #6b7180;
  --border: #e2e4e9;
  --accent: #4f46e5;
  --accent-soft: #eceafd;
  --ok: #15803d;
  --ok-soft: #e3f5e9;
  --warn: #b45309;
  --warn-soft: #fdf1dc;
  --bad: #b91c1c;
  --bad-soft: #fde6e6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --nav-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #1a1d24;
    --surface-2: #232731;
    --text: #e7e9ee;
    --muted: #9aa1ae;
    --border: #2d323d;
    --accent: #8b85ff;
    --accent-soft: #2a2850;
    --ok: #4ade80;
    --ok-soft: #173325;
    --warn: #fbbf24;
    --warn-soft: #3a2d12;
    --bad: #f87171;
    --bad-soft: #3d1c1c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1rem; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
h2 .count { font-weight: 500; color: var(--muted); font-size: .85rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--bad); }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.nav {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 2px;
  padding: 16px 12px; background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; padding: 4px 10px 16px; }
.brand.big { font-size: 1.5rem; padding: 0 0 4px; }
.logo { color: var(--accent); }
.nav button {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 9px 10px; border: 0; border-radius: 8px; background: none;
  color: var(--muted); font: inherit; text-align: left; cursor: pointer;
}
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .logout { margin-top: auto; }
.ico { display: inline-flex; width: 20px; height: 20px; flex: none; }
.ico svg { width: 100%; height: 100%; }

main { padding: 28px 32px 48px; max-width: 1200px; width: 100%; }
section[data-view] { display: none; }
section[data-view].active { display: block; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .nav {
    position: fixed; inset: auto 0 0 0; top: auto; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    flex-direction: row; justify-content: space-around; gap: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--border); z-index: 10;
  }
  .nav .brand, .nav .logout { display: none; }
  .nav button { flex-direction: column; gap: 2px; padding: 6px 2px; font-size: .68rem; text-align: center; justify-content: center; }
  .nav button.active { background: none; }
  main { padding: 18px 16px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)); }
  h1 { font-size: 1.3rem; }
}

/* ---------- Karten ---------- */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.empty { color: var(--muted); font-size: .9rem; padding: 6px 0; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: flex-start; gap: 10px; padding: 9px 0; border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; padding-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 500; overflow-wrap: anywhere; }
.list .meta { color: var(--muted); font-size: .83rem; }
.day-label { font-size: .78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 12px 0 2px; }
.day-label:first-child { margin-top: 0; }
.time { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 600; min-width: 46px; font-size: .9rem; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.neutral { background: var(--surface-2); color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; margin-top: 7px; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); } .dot.warn { background: var(--warn); }

/* ---------- Formulare ---------- */
input, textarea, select {
  font: inherit; color: var(--text); background: var(--surface); width: 100%;
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type="checkbox"] { width: 18px; height: 18px; padding: 0; accent-color: var(--accent); flex: none; margin-top: 2px; }
label { display: block; font-size: .85rem; color: var(--muted); }
label > input, label > textarea { margin-top: 4px; }
label.inline { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: .9rem; }
.form { display: grid; gap: 10px; }
.row { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 14px; background: var(--surface); color: var(--text); cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 6px; font-size: 1.1rem; line-height: 1; }
.icon-btn:hover { background: var(--bad-soft); color: var(--bad); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.quick { display: flex; gap: 8px; margin-bottom: 18px; }
.quick input { padding: 12px 14px; font-size: 1rem; }
.answer { background: var(--accent-soft); border-radius: var(--radius); padding: 12px 14px; margin: -6px 0 18px; }

/* ---------- Kalender ---------- */
.cal-layout { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); align-items: start; }
@media (max-width: 1000px) { .cal-layout { grid-template-columns: 1fr; } }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-head h2 { margin: 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-dow { font-size: .75rem; font-weight: 600; color: var(--muted); text-align: center; padding: 4px 0; }
.cal-day {
  min-height: 84px; border-radius: 8px; padding: 6px; background: var(--surface-2);
  border: 2px solid transparent; cursor: pointer; text-align: left; font: inherit; color: inherit; overflow: hidden;
}
.cal-day.other { opacity: .45; }
.cal-day.today .num { background: var(--accent); color: #fff; }
.cal-day.selected { border-color: var(--accent); }
.cal-day .num { display: inline-block; min-width: 24px; height: 24px; line-height: 24px; text-align: center; border-radius: 50%; font-size: .85rem; font-weight: 600; }
.cal-ev { font-size: .72rem; background: var(--accent-soft); color: var(--accent); border-radius: 4px; padding: 1px 4px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-more { font-size: .7rem; color: var(--muted); margin-top: 2px; }
@media (max-width: 600px) {
  .cal-day { min-height: 52px; padding: 4px; }
  .cal-ev { font-size: 0; height: 6px; padding: 0; margin-top: 4px; }
  .cal-more { display: none; }
}

/* ---------- Dokumente ---------- */
.docs { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.docs.compact { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.doc { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; color: inherit; }
.doc:hover { text-decoration: none; border-color: var(--accent); }
.doc img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; object-position: top; background: var(--surface-2); display: block; }
.doc .body { padding: 10px 12px; display: grid; gap: 2px; }
.doc .title { font-weight: 600; font-size: .9rem; overflow-wrap: anywhere; }
.doc .meta { color: var(--muted); font-size: .8rem; }
.doc .excerpt { color: var(--muted); font-size: .8rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.drop {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 22px; text-align: center;
  color: var(--muted); cursor: pointer; background: var(--surface);
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* ---------- Tabellen ---------- */
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; color: var(--muted); font-weight: 600; font-size: .8rem; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
@media (max-width: 700px) {
  .table thead { display: none; }
  .table tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--border); }
  .table td { display: block; border: 0; padding: 2px 0; }
}

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; height: calc(100vh - 150px); min-height: 360px; }
@media (max-width: 860px) { .chat { height: calc(100vh - var(--nav-h) - 130px); } }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 2px 12px; }
.msg { max-width: 80%; padding: 10px 14px; border-radius: 14px; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg p { margin: 0 0 6px; } .msg p:last-child { margin: 0; }
.msg ul { margin: 4px 0; padding-left: 20px; }
.msg code { background: var(--surface-2); padding: 0 4px; border-radius: 4px; font-size: .88em; }
.msg.thinking { color: var(--muted); font-style: italic; }
.chat-input { display: flex; gap: 8px; align-items: flex-end; }
.chat-input textarea { resize: none; min-height: 46px; max-height: 160px; }
.suggestions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.suggestions button { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 99px; padding: 5px 12px; font: inherit; font-size: .85rem; cursor: pointer; }
.suggestions button:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Login & Toast ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.login-card p { margin: 0; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: .9rem; max-width: calc(100% - 32px);
}
@media (max-width: 860px) { .toast { bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); } }
