:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece4;
  --ink: #1d2422;
  --ink-2: #5b6461;
  --line: #ddd8cc;
  --accent: #1f3a3d;
  --accent-ink: #ffffff;
  --accent-soft: #dfe9e7;
  --rec: #c2412d;
  --ok: #2f7a4f;
  --warn: #a8631a;
  --err: #b3261e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 28, .06), 0 4px 16px rgba(20, 30, 28, .06);
  --font: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141917; --surface: #1c2220; --surface-2: #232b28; --ink: #e8ece9; --ink-2: #9aa6a1;
    --line: #2e3734; --accent: #8fc3bb; --accent-ink: #0f1513; --accent-soft: #233532;
    --rec: #ef6a55; --ok: #6cc08f; --warn: #e3a35a; --err: #f08a80;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--err); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.icon { width: 20px; height: 20px; flex: none; }

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login form { width: min(360px, 100%); background: var(--surface); padding: 28px; border-radius: 16px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.login h1 { font-size: 22px; }
.field { display: grid; gap: 4px; }
.field label { font-size: 13px; color: var(--ink-2); }
.input, textarea.input, select.input { width: 100%; min-height: 40px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
textarea.input { resize: vertical; }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.error-text { color: var(--err); font-size: 13px; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 1fr; height: 100%; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--bg); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.topbar .spacer { flex: 1; }
.search { flex: 1; max-width: 420px; }
.sidebar { display: none; }
.main { display: flex; flex-direction: column; min-height: 0; }
.list-pane { flex: 1; overflow: auto; padding: 8px 12px calc(170px + var(--safe-b)); }
.detail-pane { display: none; }

.tabs { display: flex; gap: 6px; padding: 10px 12px 0; overflow-x: auto; }
.tab { white-space: nowrap; border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 999px; font-size: 13px; }
.tab.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-size: 12px; text-align: center; }
.tab.active .badge { background: rgba(255,255,255,.2); color: inherit; }

/* ---------- Karten ---------- */
.note-card { display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin: 8px 0; box-shadow: var(--shadow); }
.note-card.active { outline: 2px solid var(--accent); outline-offset: -1px; }
.note-card .row { display: flex; align-items: center; gap: 8px; }
.note-card .title { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-card .summary { color: var(--ink-2); font-size: 14px; margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.note-card .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; font-size: 12px; color: var(--ink-2); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); font-size: 12px; color: var(--ink-2); }
.chip.project { background: var(--accent-soft); color: var(--accent); }
.chip.proc { background: transparent; border: 1px dashed var(--line); }
.chip.err { color: var(--err); border: 1px solid var(--err); background: transparent; }
.chip.offline { color: var(--warn); border: 1px solid var(--warn); background: transparent; }
.empty { text-align: center; padding: 48px 16px; color: var(--ink-2); }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Erfassen ---------- */
.capture { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--surface); border-top: 1px solid var(--line);
  padding: 10px 12px calc(12px + var(--safe-b)); box-shadow: 0 -4px 20px rgba(0,0,0,.06); }
.capture .row { display: flex; gap: 10px; align-items: flex-end; }
.capture textarea { flex: 1; min-height: 46px; max-height: 160px; resize: none; padding: 11px 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg); }
.capture textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.send-btn { width: 46px; height: 46px; border-radius: 14px; border: none; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.mic-wrap { display: flex; justify-content: center; margin-top: 10px; }
.mic { width: 76px; height: 76px; border-radius: 50%; border: none; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; box-shadow: var(--shadow);
  transition: transform .15s ease; }
.mic .icon { width: 32px; height: 32px; }
.mic:active { transform: scale(.96); }
.mic.recording { background: var(--rec); color: #fff; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(194,65,45,.45); } 50% { box-shadow: 0 0 0 14px rgba(194,65,45,0); } }
.rec-info { text-align: center; font-size: 13px; color: var(--ink-2); margin-top: 6px; min-height: 18px; }
.rec-info .time { font-variant-numeric: tabular-nums; color: var(--rec); font-weight: 600; }

/* ---------- Detail ---------- */
.sheet { position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow: auto; padding-bottom: calc(24px + var(--safe-b)); }
.detail { padding: 14px 16px 24px; max-width: 760px; }
.detail-head { display: flex; align-items: flex-start; gap: 8px; }
.detail-head .title-input { flex: 1; font-size: 20px; font-weight: 700; border: 1px solid transparent; background: transparent; padding: 4px 6px; border-radius: 8px; }
.detail-head .title-input:hover, .detail-head .title-input:focus { border-color: var(--line); background: var(--surface); outline: none; }
.detail .meta-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 6px 0 12px; font-size: 13px; color: var(--ink-2); }
.detail select.input { width: auto; min-height: 32px; padding: 4px 8px; font-size: 13px; }
.section { margin-top: 18px; }
.section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.text-block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; white-space: pre-wrap; }
.text-block[contenteditable="true"]:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
audio { width: 100%; margin-top: 4px; }
details.orig summary { cursor: pointer; color: var(--ink-2); font-size: 13px; margin-top: 8px; }
details.orig div { white-space: pre-wrap; font-size: 14px; color: var(--ink-2); padding: 8px 0; }
.status-btns { display: flex; gap: 6px; flex-wrap: wrap; }

.action { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.action.done { opacity: .7; }
.action.dismissed { display: none; }
.action-head { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.action-head .type { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 2px 8px; }
.action-head .t { flex: 1; }
.action-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.action-fields .full { grid-column: 1 / -1; }
.action-fields .input { min-height: 36px; font-size: 14px; }
.action-fields textarea.input { min-height: 90px; }
.action-btns { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.action .result { margin-top: 8px; font-size: 13px; color: var(--ok); }
.action .action-err { margin-top: 8px; font-size: 13px; color: var(--err); }
.contacts-pop { grid-column: 1 / -1; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); padding: 4px; }
.contacts-pop button { display: block; width: 100%; text-align: left; border: none; background: transparent; padding: 6px 8px; border-radius: 8px; }
.contacts-pop button:hover { background: var(--surface-2); }
.add-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.run { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.run-head { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--ink-2); }
.run-head b { color: var(--ink); }
.md { margin-top: 8px; }
.md h1, .md h2, .md h3, .md h4 { font-size: 15px; margin: 12px 0 4px; }
.md p { margin: 6px 0; }
.md ul, .md ol { margin: 6px 0; padding-left: 20px; }
.agent-form { display: grid; grid-template-columns: 1fr; gap: 8px; }

/* ---------- Einstellungen ---------- */
.page { padding: 16px; max-width: 760px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 16px; margin-bottom: 8px; }
.card p { margin: 6px 0; }
.status-ok { color: var(--ok); font-weight: 600; }
.status-off { color: var(--warn); font-weight: 600; }
.problems { margin: 0; padding-left: 18px; color: var(--warn); }

#toast { position: fixed; left: 50%; bottom: calc(190px + var(--safe-b)); transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; transition: all .2s ease; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.kbd { font-family: ui-monospace, monospace; font-size: 12px; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }

/* ---------- PC-Ansicht ---------- */
@media (min-width: 960px) {
  .shell { grid-template-columns: 220px 1fr; }
  .topbar { grid-column: 1 / -1; padding: 10px 18px; }
  .sidebar { display: block; border-right: 1px solid var(--line); padding: 12px 10px; overflow: auto; height: calc(100vh - 59px); }
  .nav-item { display: flex; align-items: center; gap: 8px; width: 100%; border: none; background: transparent; padding: 8px 10px; border-radius: 8px; text-align: left; }
  .nav-item:hover { background: var(--surface-2); }
  .nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
  .nav-item .badge { margin-left: auto; }
  .nav-label { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); margin: 16px 10px 6px; }
  .tabs { display: none; }
  .main { flex-direction: row; height: calc(100vh - 59px); }
  .list-col { width: 400px; flex: none; display: flex; flex-direction: column; border-right: 1px solid var(--line); min-height: 0; }
  .list-pane { padding: 4px 14px 24px; }
  .capture { position: static; box-shadow: none; border-top: none; border-bottom: 1px solid var(--line); background: var(--bg); padding: 12px 14px; }
  .capture .mic-wrap { display: none; }
  .capture .desk-mic { display: grid !important; }
  .rec-info { text-align: left; }
  .detail-pane { display: block; flex: 1; overflow: auto; }
  .sheet { position: static; background: transparent; padding: 0; }
  .sheet .back { display: none; }
  .detail { padding: 20px 28px 40px; }
  #toast { bottom: 24px; }
  .page { padding: 24px 28px; }
}
.desk-mic { display: none !important; width: 46px; height: 46px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); place-items: center; }
.desk-mic.recording { background: var(--rec); color: #fff; border-color: var(--rec); }

/* ---------- Schmale Bildschirme: nichts darf über den Rand ragen ---------- */
html, body { overflow-x: hidden; }
.shell { grid-template-columns: minmax(0, 1fr); }
.main, .list-col, .detail, .page { min-width: 0; }
.search, .title-input, .input { min-width: 0; }
.topbar .search { width: 100%; }
.meta-row select.input { max-width: 100%; }
@media (max-width: 959px) {
  .action-fields { grid-template-columns: minmax(0, 1fr); }
  .detail-head .title-input { font-size: 18px; }
  .status-btns .btn { flex: 1 1 auto; }
}
@media (min-width: 960px) {
  .shell { grid-template-columns: 220px minmax(0, 1fr); }
}

/* Mittlere Fensterbreite: rechte Spalte darf nicht über den Rand ragen */
.detail-pane, .list-col { min-width: 0; }
.action-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.action-fields .input, .action-fields textarea { width: 100%; min-width: 0; }
@media (max-width: 1199px) { .action-fields { grid-template-columns: minmax(0, 1fr); } }
@media (min-width: 960px) and (max-width: 1199px) { .list-col { width: 340px; } }
