/* Klaus 2.0 – dashboard styles. Mobile first; sidebar from 900px; dark mode via prefers-color-scheme. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #1a1d23;
  --muted: #5f6673;
  --border: #dde1e8;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --accent-soft: #e6ecfb;
  --ok: #1d7a46;
  --ok-soft: #e3f4ea;
  --warn: #8a5a00;
  --warn-soft: #fff3d6;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --nav-h: 64px;
  --focus: 0 0 0 3px rgba(47, 91, 211, 0.45);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1e24;
    --surface-2: #232830;
    --text: #eceef2;
    --muted: #a7afbc;
    --border: #363d47;
    --accent: #7b9cff;
    --accent-text: #0d1220;
    --accent-soft: #1f2a47;
    --ok: #5fd08f;
    --ok-soft: #173325;
    --warn: #f0c060;
    --warn-soft: #3a2f14;
    --danger: #ff8a80;
    --danger-soft: #3d1b1a;
    --shadow: none;
    --focus: 0 0 0 3px rgba(123, 156, 255, 0.55);
  }
}

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

html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
p { margin: 0.4rem 0; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }

.skip-link {
  position: absolute; left: -999px; top: 8px; z-index: 100;
  background: var(--surface); padding: 8px 12px; border-radius: 8px;
}
.skip-link:focus { left: 8px; }

.visually-hidden, .offscreen {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px;
}

.pre { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85em; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

/* ---- boot & login ---- */
.boot { padding: 3rem 1rem; text-align: center; color: var(--muted); }

.login {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 2rem 1.5rem; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 0.5rem; text-align: left;
}
.login-card h1 { font-size: 1.6rem; }

.brand {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text); font-weight: 700;
}
.brand-large { width: 52px; height: 52px; font-size: 1.5rem; border-radius: 14px; margin-bottom: 0.5rem; }

/* ---- form controls ---- */
label, .label { font-weight: 600; font-size: 0.9rem; display: block; margin-bottom: 0.25rem; }

input[type="text"], input[type="password"], input[type="email"], input[type="search"],
input[type="datetime-local"], input[type="time"], input[type="number"], input[type="tel"], input[type="url"], select, textarea {
  width: 100%; font: inherit; font-size: 16px; /* 16px avoids iOS zoom */
  color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 0.6rem 0.7rem; min-height: 44px;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: var(--focus); outline: none; }
input:disabled, textarea:disabled, select:disabled { opacity: 0.65; }
.select-small { width: auto; min-height: 36px; padding: 0.3rem 0.5rem; font-size: 0.9rem; }

.check { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 500; cursor: pointer; }
.check input { width: 20px; height: 20px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 44px; padding: 0.55rem 1rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-small { min-height: 36px; padding: 0.3rem 0.75rem; font-size: 0.9rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); }
.btn-danger-ghost { color: var(--danger); }

.icon-btn {
  min-width: 36px; min-height: 36px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; color: var(--muted); font-size: 1.3rem; line-height: 1; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--danger); }

.form { display: flex; flex-direction: column; gap: 0.75rem; }
.field { min-width: 0; }
.row > .field { flex: 1 1 180px; }
.hint { color: var(--muted); font-size: 0.8rem; margin: 0.2rem 0 0; }
.form-error { color: var(--danger); font-weight: 600; }
.row { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: flex-end; }
.row-end { justify-content: flex-end; }
.fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem; margin: 0; min-width: 0; }
.fieldset legend { font-weight: 600; padding: 0 0.3rem; }

.segmented {
  display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px;
  flex-wrap: wrap; margin-bottom: 0.75rem;
}
.seg {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: 0.9rem;
  padding: 0.35rem 0.8rem; border-radius: 8px; min-height: 34px; cursor: pointer;
}
.seg.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.view-actions .segmented { margin-bottom: 0; }

/* ---- layout ---- */
.app { min-height: 100vh; min-height: 100dvh; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-head { display: none; }
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(5, 1fr); }
.nav-list li.secondary { display: none; }
.nav-link {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--nav-h); width: 100%; color: var(--muted); text-decoration: none; font: inherit;
  font-size: 0.7rem; font-weight: 600; background: transparent; border: 0; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.nav-link[aria-current="page"], .nav-link.active { color: var(--accent); }
.icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.badge {
  position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: 0.7rem; line-height: 18px; text-align: center;
}

.more-sheet {
  position: absolute; left: 0.5rem; right: 0.5rem; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 0.5rem);
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2); padding: 0.5rem;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.25rem;
}
.more-sheet .nav-link { height: 72px; border-radius: 12px; font-size: 0.75rem; }
.more-sheet .nav-link[aria-current="page"] { background: var(--accent-soft); }

.main {
  padding: max(0.75rem, env(safe-area-inset-top)) max(0.9rem, env(safe-area-inset-right))
    calc(var(--nav-h) + env(safe-area-inset-bottom) + 1.5rem) max(0.9rem, env(safe-area-inset-left));
  max-width: 1100px; margin: 0 auto; outline: none;
}
.view-head {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.6rem;
  margin: 0.25rem 0 1rem;
}
.view-head h1 { font-size: 1.5rem; }
.view-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 240px 1fr; }
  .nav {
    position: sticky; top: 0; height: 100vh; border-top: 0; border-right: 1px solid var(--border);
    padding: 1rem 0.75rem; overflow-y: auto;
  }
  .nav-head { display: flex; align-items: center; gap: 0.6rem; padding: 0.25rem 0.5rem 1rem; }
  .nav-title { font-weight: 700; font-size: 1.15rem; }
  .nav-list { display: flex; flex-direction: column; gap: 2px; }
  .nav-list li.secondary { display: block; }
  .nav-list li.more, .more-sheet { display: none !important; }
  .nav-link {
    flex-direction: row; justify-content: flex-start; gap: 0.7rem; height: 42px; padding: 0 0.75rem;
    border-radius: 10px; font-size: 0.95rem; color: var(--text);
  }
  .nav-link:hover { background: var(--surface-2); }
  .nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
  .icon { width: 20px; height: 20px; }
  .badge { position: static; margin-left: auto; }
  .main { padding: 1.5rem 2rem 3rem; }
  .hide-wide { display: none !important; }
}

/* ---- cards & lists ---- */
.grid { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; min-width: 0;
}
.grid > .card { margin-bottom: 0; }
.card-title { font-size: 1.05rem; margin-bottom: 0.6rem; }
.section-title { font-size: 1.2rem; margin: 1.75rem 0 0.5rem; }
.small-title { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0.9rem 0 0.4rem; }
details > summary { cursor: pointer; font-weight: 600; min-height: 28px; list-style-position: outside; }
details[open] > summary { margin-bottom: 0.75rem; }
.add-card > summary { color: var(--accent); }

.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.item {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.8rem 0.9rem; box-shadow: var(--shadow); min-width: 0;
}
.item-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; }
.item-title { font-size: 1rem; overflow-wrap: anywhere; }
.item-body { margin: 0.4rem 0; }
.item-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; margin-top: 0.6rem; }
.item-done { opacity: 0.7; }
.item-done .item-title { text-decoration: line-through; }
.item-overdue { border-left: 4px solid var(--danger); }
.item-proposed { border: 2px solid var(--warn); background: var(--warn-soft); }
.proposed-label { color: var(--warn); font-weight: 700; font-size: 0.85rem; margin: 0 0 0.3rem; }
.item-click { padding: 0; }
.item-open {
  display: block; width: 100%; text-align: left; font: inherit; color: inherit; background: transparent;
  border: 0; padding: 0.8rem 0.9rem; border-radius: var(--radius); cursor: pointer;
}
.item-open:hover { background: var(--surface-2); }

.plain { list-style: none; margin: 0; padding: 0; }
.plain > li { padding: 0.45rem 0; border-bottom: 1px solid var(--border); }
.plain > li:last-child { border-bottom: 0; }

.meta { color: var(--muted); font-size: 0.85rem; margin: 0.25rem 0 0; }
.meta-inline { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.empty { color: var(--muted); padding: 1rem 0; text-align: center; }
.loading { color: var(--muted); }

.chip {
  display: inline-block; padding: 0.1rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 700;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.chip:empty { display: none; }
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-danger, .prio-P1 { background: var(--danger-soft); color: var(--danger); }
.prio-P2 { background: var(--accent-soft); color: var(--accent); }
.prio-P3 { background: var(--surface-2); color: var(--muted); }

.notice {
  padding: 0.65rem 0.8rem; border-radius: 10px; background: var(--surface-2); margin: 0.5rem 0;
  border: 1px solid var(--border);
}
.notice-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; font-weight: 600; }
.notice-error { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.notice-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.3rem 0.9rem; margin: 0.5rem 0; }
.kv dt { color: var(--muted); font-size: 0.9rem; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.totals dd { text-align: right; font-variant-numeric: tabular-nums; }
.totals dt:last-of-type, .totals dd:last-of-type { font-weight: 700; color: var(--text); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 0.5rem; margin-bottom: 0.6rem; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 0.6rem; display: flex; flex-direction: column; }
.stat-val { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 0.8rem; }
.stat-alert { background: var(--danger-soft); }
.stat-alert .stat-val { color: var(--danger); }

.usage { margin: 0.6rem 0; }
.usage-head { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.9rem; }
.usage-val { color: var(--muted); font-variant-numeric: tabular-nums; }
progress {
  -webkit-appearance: none; appearance: none; width: 100%; height: 10px; border: 0; border-radius: 5px;
  background: var(--surface-2); overflow: hidden; margin-top: 0.3rem;
}
progress::-webkit-progress-bar { background: var(--surface-2); border-radius: 5px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 5px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 5px; }
progress.warn::-webkit-progress-value { background: var(--warn); }
progress.warn::-moz-progress-bar { background: var(--warn); }
progress.danger::-webkit-progress-value { background: var(--danger); }
progress.danger::-moz-progress-bar { background: var(--danger); }

.search-form { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.search-form input { flex: 1 1 200px; }
.new-row { margin-bottom: 1rem; }

/* ---- chat ---- */
.chat-layout { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.chat-history { display: none; margin: 0; max-height: 50vh; overflow-y: auto; }
.chat-layout.history-open .chat-history { display: block; }
.chat-main {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); min-height: 260px; height: var(--chat-h, calc(100dvh - var(--nav-h) - 9rem));
  box-shadow: var(--shadow); min-width: 0;
}
.chat-log { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.6rem; -webkit-overflow-scrolling: touch; }
.chat-empty { color: var(--muted); text-align: center; margin: auto; max-width: 30rem; }
.msg { max-width: 85%; padding: 0.6rem 0.85rem; border-radius: 16px; }
.msg-user { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; }
.msg-klaus { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.msg-error { align-self: center; background: var(--danger-soft); color: var(--danger); }
.msg-meta { font-size: 0.75rem; opacity: 0.75; margin: 0.3rem 0 0; }
.chat-form {
  display: flex; gap: 0.5rem; align-items: flex-end; border-top: 1px solid var(--border); padding: 0.6rem;
}
.chat-form textarea { flex: 1; max-height: 40vh; }
.conv-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.conv-list li { display: flex; align-items: center; border-radius: 10px; }
.conv-list li.active { background: var(--accent-soft); }
.conv-open {
  flex: 1; min-width: 0; text-align: left; background: transparent; border: 0; padding: 0.5rem 0.6rem;
  font: inherit; color: inherit; cursor: pointer; border-radius: 10px; display: flex; flex-direction: column;
}
.conv-open:hover { background: var(--surface-2); }
.conv-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-meta { font-size: 0.75rem; color: var(--muted); }

@media (min-width: 900px) {
  .chat-layout { grid-template-columns: 260px 1fr; }
  .chat-history { display: block; max-height: calc(100vh - 8rem); }
  .chat-main { height: calc(100vh - 8rem); }
}

.typing { display: inline-flex; align-items: center; gap: 4px; padding: 0.7rem 0.9rem; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .dot { animation: none; opacity: 0.7; } }

/* ---- approvals ---- */
.approval-open { border-left: 4px solid var(--warn); }
.summary {
  background: var(--surface-2); border-radius: 10px; padding: 0.75rem; border: 1px solid var(--border);
  max-height: 60vh; overflow-y: auto;
}
.payload { margin-top: 0.6rem; }
.payload > summary { font-size: 0.85rem; color: var(--muted); }
.approval-actions { justify-content: flex-end; border-top: 1px solid var(--border); padding-top: 0.75rem; }

/* ---- drafts ---- */
.positions { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.5rem; }
.pos-row { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 0.4rem; align-items: center; }
.pos-row > input:first-child { grid-column: 1 / -1; }
.pos-head { display: none; }
@media (min-width: 700px) {
  .pos-row { grid-template-columns: 3fr 1fr 1fr 1.3fr 1fr auto; }
  .pos-row > input:first-child { grid-column: auto; }
  .pos-head { display: grid; font-size: 0.8rem; color: var(--muted); font-weight: 600; }
}
.preview { background: var(--surface-2); border-radius: 10px; padding: 0.75rem; border: 1px solid var(--border); }
.body-input { min-height: 14rem; }
.submit-box { border-top: 1px solid var(--border); margin-top: 1rem; padding-top: 0.5rem; }

/* ---- research & audit ---- */
.research { margin-bottom: 0; box-shadow: none; }
details .research { border: 0; padding: 0; }
.research-q { font-size: 1.05rem; }
.research-q:empty { display: none; }
.sources ol { margin: 0.3rem 0 0; padding-left: 1.3rem; }
.sources a { overflow-wrap: anywhere; }
.research-out { margin-bottom: 1rem; }
.log-list .pre { margin-top: 0.3rem; }

/* ---- toasts & dialogs ---- */
.toasts {
  position: fixed; z-index: 50; left: 0.75rem; right: 0.75rem;
  top: max(0.75rem, env(safe-area-inset-top)); display: flex; flex-direction: column; gap: 0.5rem;
  pointer-events: none; align-items: center;
}
.toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 0.6rem; max-width: 480px; width: 100%;
  background: var(--text); color: var(--bg); padding: 0.7rem 0.9rem; border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}
.toast-text { flex: 1; white-space: pre-wrap; }
.toast-error { background: var(--danger); color: #fff; }
.toast-ok { background: var(--ok); color: #fff; }
@media (prefers-color-scheme: dark) { .toast-ok, .toast-error { color: #111418; } }
.toast-close { background: transparent; border: 0; color: inherit; font-size: 1.2rem; line-height: 1; cursor: pointer; min-width: 28px; min-height: 28px; }

.dialog {
  border: 1px solid var(--border); border-radius: 16px; padding: 0; background: var(--surface); color: var(--text);
  width: min(92vw, 520px); max-height: 85vh; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog-body { padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }
.dialog-content { max-height: 60vh; overflow-y: auto; }
#confirm-text { font-size: 1.05rem; }
.dialog .row-end .btn { flex: 1 1 8rem; }

/* ---- touch comfort (iPhone & co.): 44px targets, no accidental zoom ---- */
.nav { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
.nav-link:active, .btn:active, .item-open:active { filter: brightness(0.94); }
.badge-dot { min-width: 10px; width: 10px; height: 10px; padding: 0; top: 10px; left: calc(50% + 8px); }
.view > .loading:only-child { min-height: 50vh; }
@media (pointer: coarse), (max-width: 899px) {
  .btn-small { min-height: 44px; padding: 0.4rem 0.85rem; }
  .select-small { min-height: 44px; }
  .seg { min-height: 44px; padding: 0.4rem 0.9rem; }
  .icon-btn { min-width: 44px; min-height: 44px; }
  .toast-close { min-width: 44px; min-height: 44px; }
  .check { min-height: 44px; }
  .check input { width: 24px; height: 24px; }
  details > summary { min-height: 44px; display: flex; align-items: center; }
  .conv-open { min-height: 48px; }
  .item-foot { gap: 0.5rem; }
}
@media (max-width: 899px) {
  .view-head h1 { font-size: 1.35rem; }
  .view-actions { gap: 0.4rem; }
}
@media (max-width: 420px) {
  .btn-refresh .btn-refresh-label { display: none; }
  .btn-refresh { min-width: 44px; padding: 0.3rem 0.6rem; }
}
.btn-refresh .icon { width: 18px; height: 18px; }
.btn-refresh.spinning .icon { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn-refresh.spinning .icon { animation: none; } }

/* ---- offline banner ---- */
.offline-banner {
  position: fixed; z-index: 45; left: 0; right: 0; top: 0;
  padding: max(0.5rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right)) 0.5rem max(0.75rem, env(safe-area-inset-left));
  display: flex; align-items: center; justify-content: center; gap: 0.75rem; flex-wrap: wrap;
  background: var(--warn-soft); color: var(--warn); font-weight: 600; font-size: 0.9rem;
  border-bottom: 1px solid var(--border); text-align: center;
}
.is-offline .main { padding-top: calc(max(0.75rem, env(safe-area-inset-top)) + 3.5rem); }

/* ---- overview: today ---- */
.today { border-top: 4px solid var(--accent); }
.today-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; }
.today-head .card-title { margin-bottom: 0.4rem; }
.stats-compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat-link { color: inherit; text-decoration: none; min-height: 44px; }
.stat-link:active { filter: brightness(0.94); }
.stat-warn { background: var(--warn-soft); }
.stat-warn .stat-val { color: var(--warn); }
.today-list { list-style: none; margin: 0; padding: 0; }
.today-row {
  display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; flex-wrap: wrap;
  padding: 0.55rem 0; border-bottom: 1px solid var(--border);
}
.today-row:last-child { border-bottom: 0; }
.today-main { flex: 1 1 12rem; min-width: 0; }
.today-actions { display: flex; gap: 0.4rem; flex: none; margin-left: auto; }
.today-approval .today-actions { width: 100%; justify-content: flex-end; }
.today-approval .today-actions .btn { flex: 1 1 0; max-width: 12rem; }
.time-tag {
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 0.85rem; color: var(--accent);
  background: var(--accent-soft); border-radius: 6px; padding: 0.05rem 0.4rem;
}
.summary-clamp {
  margin-top: 0.35rem; font-size: 0.9rem; max-height: 6.5em; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical;
}
.hint-slot:empty { display: none; }
.hint-card { border-left: 4px solid var(--accent); }

/* ---- chat on phones: composer always visible, also with keyboard ---- */
@media (max-width: 899px) {
  .view-chat .main { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
  .view-chat .view-head { margin-bottom: 0.6rem; }
  .chat-form { padding-bottom: 0.6rem; background: var(--surface); border-radius: 0 0 var(--radius) var(--radius); }
  .chat-form textarea { min-height: 44px; max-height: 160px; resize: none; }
  .chat-form .btn { min-height: 44px; }
  .kb-open .nav { display: none; }
  .kb-open.view-chat .chat-main {
    position: fixed; z-index: 30; left: 0; right: 0; top: var(--vv-top, 0); height: var(--vv-h, 50vh);
    border-radius: 0; border-left: 0; border-right: 0; min-height: 0;
    padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
  }
  .kb-open.view-chat .chat-form { border-radius: 0; }
}

/* ---- settings: push & Microsoft 365 ---- */
.steps { margin: 0.4rem 0 0; padding-left: 1.3rem; }
.steps li { margin: 0.2rem 0; }
.check-row { display: flex; font-weight: 500; margin: 0; }
.meta-error { color: var(--danger); }
.lazy-body > .form { margin-top: 0.25rem; }

/* ---- mailbox & calendar ---- */
.mail-unread .item-title { font-weight: 800; }
.unread-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); flex: none; }
.mail-preview {
  color: var(--muted); font-size: 0.9rem; margin: 0.3rem 0 0; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere;
}
.mail-subject { font-size: 1.15rem; overflow-wrap: anywhere; }
.data-label {
  margin: 0.75rem 0 0.4rem; padding: 0.4rem 0.6rem; border-radius: 8px; font-size: 0.8rem; font-weight: 700;
  background: var(--warn-soft); color: var(--warn);
}
.mail-text {
  background: var(--surface-2); border: 1px dashed var(--border); border-radius: 10px; padding: 0.75rem;
  font-size: 0.95rem; max-height: none;
}
.agenda-day { margin-bottom: 1.25rem; }
.agenda-date {
  font-size: 0.95rem; margin: 0 0 0.5rem; position: sticky; top: 0; z-index: 1;
  background: var(--bg); padding: 0.35rem 0;
}
.agenda-item { display: flex; gap: 0.75rem; align-items: flex-start; }
.agenda-time {
  flex: 0 0 6.5rem; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); font-size: 0.9rem;
  padding-top: 0.1rem;
}
.agenda-body { min-width: 0; flex: 1; }

/* ---- print: only the draft sheet ---- */
.print-sheet { display: none; }
@media print {
  body > * { display: none !important; }
  body > .print-sheet { display: block !important; color: #000; background: #fff; font-size: 12pt; }
  .print-sheet h1 { font-size: 16pt; margin-bottom: 0.5rem; }
  .print-meta { margin: 0.2rem 0; }
  .print-sheet .pre { margin-top: 1rem; }
}

/* ---- text never forces horizontal scrolling (long words, URLs, tokens) ---- */
.main, .dialog, .sheet, .toast-text { overflow-wrap: anywhere; }
.btn, .seg, .nav-link, .chip, .badge { overflow-wrap: normal; }
.card-title, .meta, .notice, .summary, .mail-text, .mail-preview, .kv dt, .today-main, .item-head { overflow-wrap: anywhere; min-width: 0; }
.kv { grid-template-columns: minmax(0, max-content) minmax(0, 1fr); }
.main img, .main video, .main table { max-width: 100%; }

/* ---- tab bar: labels stay whole on small phones ---- */
.nav-label { white-space: nowrap; max-width: 100%; }
@media (max-width: 380px) {
  .nav-list > li > .nav-link { font-size: 0.66rem; letter-spacing: -0.01em; padding: 0 1px; }
  .more-sheet .nav-link { font-size: 0.7rem; }
}

/* ---- tappable approval rows ---- */
.today-open {
  display: block; text-align: left; font: inherit; color: inherit; background: transparent; border: 0;
  padding: 0.25rem; margin: -0.25rem; border-radius: 10px; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.today-open:hover { background: var(--surface-2); }
.today-open:active { filter: brightness(0.94); }
.open-hint { display: block; margin-top: 0.3rem; color: var(--accent); font-size: 0.85rem; font-weight: 600; }
.title-btn {
  font: inherit; font-weight: 700; color: inherit; background: transparent; border: 0; padding: 0; margin: 0;
  text-align: left; cursor: pointer; min-height: 32px; min-width: 0; text-decoration: underline;
  text-decoration-color: var(--border); text-underline-offset: 3px;
}
.title-btn:hover { color: var(--accent); }

/* ---- approval sheet (full screen on phones) ---- */
.sheet {
  border: 0; padding: 0; margin: 0; background: var(--surface); color: var(--text);
  width: 100%; max-width: 100%; height: 100%; max-height: 100%;
  display: none; flex-direction: column; overscroll-behavior: contain;
}
.sheet[open] { display: flex; }
.sheet::backdrop { background: rgba(0, 0, 0, 0.45); }
.sheet-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem;
  padding: max(0.75rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 0.75rem max(1rem, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border); flex: none;
}
.sheet-titles { min-width: 0; }
.sheet-kicker { margin: 0; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.sheet-title { font-size: 1.2rem; overflow-wrap: anywhere; }
.sheet-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; min-height: 0;
  padding: 0.75rem max(1rem, env(safe-area-inset-right)) 1rem max(1rem, env(safe-area-inset-left));
}
.summary-full { max-height: none; overflow: visible; font-size: 1rem; }
.sheet-foot {
  flex: none; display: flex; gap: 0.75rem; border-top: 1px solid var(--border); background: var(--surface);
  padding: 0.75rem max(1rem, env(safe-area-inset-right)) max(0.75rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}
.btn-big { flex: 1 1 0; min-height: 54px; font-size: 1.05rem; border-radius: 12px; }
@media (min-width: 700px) {
  .sheet {
    margin: auto; width: min(92vw, 680px); height: auto; max-height: 90vh;
    border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
  }
  .sheet-head { padding: 1rem 1.25rem 0.75rem; }
  .sheet-body { padding: 0.75rem 1.25rem 1rem; }
  .sheet-foot { padding: 0.75rem 1.25rem 1rem; }
}
@media (prefers-reduced-motion: no-preference) {
  .sheet[open] { animation: sheet-in 0.22s ease-out; }
}
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- setup assistant ---- */
.setup-progress { margin: 0.5rem 0; }
.setup-progress-text { margin: 0 0 0.2rem; }
.setup-steps { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.setup-step {
  background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--border);
  border-radius: var(--radius); padding: 0.8rem 0.9rem; box-shadow: var(--shadow); min-width: 0;
}
.setup-step-head { display: flex; align-items: flex-start; gap: 0.65rem; }
.setup-step-titles { min-width: 0; flex: 1; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.6rem; }
.setup-step-title { font-size: 1rem; overflow-wrap: anywhere; }
.setup-icon {
  flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; font-size: 0.95rem; background: var(--surface-2); color: var(--muted);
}
.setup-status {
  font-size: 0.75rem; font-weight: 700; border-radius: 999px; padding: 0.1rem 0.55rem;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.setup-ok { border-left-color: var(--ok); }
.setup-ok .setup-icon, .setup-ok .setup-status { background: var(--ok-soft); color: var(--ok); }
.setup-warnung { border-left-color: var(--warn); }
.setup-warnung .setup-icon, .setup-warnung .setup-status { background: var(--warn-soft); color: var(--warn); }
.setup-fehler { border-left-color: var(--danger); }
.setup-fehler .setup-icon, .setup-fehler .setup-status { background: var(--danger-soft); color: var(--danger); }
.setup-offen { border-left-color: var(--accent); }
.setup-offen .setup-icon, .setup-offen .setup-status { background: var(--accent-soft); color: var(--accent); }
.setup-hint-text { margin: 0.5rem 0 0; }
.setup-step > .row, .setup-extra { margin-top: 0.6rem; }
.setup-extra { border-top: 1px dashed var(--border); padding-top: 0.6rem; }
.setup-foot { margin-bottom: 1rem; }
.cmd { margin-top: 0.6rem; }
.cmd-label { margin: 0 0 0.25rem; font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.cmd-row {
  display: flex; align-items: flex-start; gap: 0.5rem; flex-wrap: wrap;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 0.5rem 0.5rem 0.5rem 0.7rem;
}
.cmd-text {
  flex: 1 1 12rem; min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-all;
  font-size: 0.85rem; line-height: 1.45; padding-top: 0.35rem; user-select: all; -webkit-user-select: all;
}
.cmd-copy { flex: none; margin-left: auto; }

/* ---- reduced motion: no animations or smooth transitions anywhere ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important; scroll-behavior: auto !important;
  }
}
