/* Kompass UI (§12): tab bar, chat, Heute, Mehr, cards, sheets.
   Dark only, reuses the :root tokens from style.css; style.css itself stays untouched. */

:root {
  --bubble-me: #2b2d6b;
  --bubble-agent: var(--surface);
  --card-warn: #3a2a0a;
  --tabbar-h: 56px;
  --surface-2: #232323;
}

/* --- Layout with tabs --- */
body.has-tabs .container {
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}

body.has-tabs header {
  padding: 4px 0 10px;
}
body.has-tabs header h1 { font-size: 17px; }
body.has-tabs header p { font-size: 12px; margin-top: 2px; }

body.has-tabs .undo-toast {
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px);
}
body.k-kbd .undo-toast {
  bottom: max(20px, calc(env(safe-area-inset-bottom) + 8px));
}

.k-toast { z-index: 70; }

#tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  justify-content: center;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

/* While the keyboard is up the bar would sit on top of the composer */
body.k-kbd #tab-bar { display: none; }

.k-tab {
  flex: 1;
  max-width: 120px;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-dim);
  font: inherit;
  font-size: 11px;
  touch-action: manipulation;
}
.k-tab.active { color: var(--accent); }
.k-tab-icon svg { display: block; width: 24px; height: 24px; }

.tab-panel { min-height: 40vh; }

/* --- Common bits --- */
.k-dim { color: var(--text-dim); font-size: 13px; line-height: 1.45; }
.k-pad { padding: 12px 0; }
.k-wrap { white-space: pre-wrap; word-break: break-word; }
.k-head {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin: 22px 0 10px;
}
.k-subhead {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin: 16px 0 6px;
}
.k-chev { color: var(--text-dim); margin-left: 6px; }

.k-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  touch-action: manipulation;
  cursor: pointer;
}
.k-btn:disabled { opacity: 0.5; }
.k-btn:active:not(:disabled) { background: #2c2c2c; }
.k-btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.k-btn-primary:active:not(:disabled) { background: var(--accent-hover); }
.k-btn-ghost { background: transparent; }
.k-btn-danger { background: transparent; border-color: rgba(239, 68, 68, 0.5); color: var(--danger); }
.k-small { min-height: 36px; padding: 6px 10px; font-size: 13px; }
.k-wide { width: 100%; margin-top: 10px; }

.k-link {
  background: none;
  border: none;
  color: var(--accent-hover);
  font: inherit;
  font-size: 13px;
  padding: 8px 6px;
  min-height: 36px;
  touch-action: manipulation;
}

.k-icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 22px;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}
.k-icon-btn svg { width: 22px; height: 22px; }
.k-icon-btn:disabled { opacity: 0.4; }
.k-send:not(:disabled) { background: var(--accent); color: #fff; }
.k-send.k-stop { background: var(--surface-2); color: var(--text); }

.k-input {
  width: 100%;
  font: inherit;
  font-size: 16px; /* 16 px prevents the iOS zoom */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  -webkit-user-select: text;
  user-select: text;
  -webkit-appearance: none;
  appearance: none;
}
.k-input:focus { outline: none; border-color: var(--accent); }
textarea.k-input { resize: none; line-height: 21px; }
select.k-input { background-image: none; }
.k-time { width: auto; min-width: 110px; }

.k-field { display: block; margin: 8px 0; }
.k-field > span { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 4px; }

.k-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.k-chip {
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent-hover);
  font: inherit;
  font-size: 14px;
  touch-action: manipulation;
}

.k-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.k-badge {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #1a1a2e;
  color: var(--accent-hover);
}

.k-highlight {
  box-shadow: 0 0 0 2px var(--accent);
  transition: box-shadow 0.3s ease;
}

.k-collapsing {
  overflow: hidden;
  opacity: 0;
  transition: height 0.2s ease, opacity 0.2s ease, margin 0.2s ease, padding 0.2s ease;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}
.k-busy { opacity: 0.6; pointer-events: none; }

.k-confirm-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 10px;
  border-radius: 10px;
  background: var(--card-warn);
  font-size: 14px;
}
.k-confirm-row > span { flex: 1 1 100%; }

/* --- Kompass lock card --- */
.k-lockcard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 20px;
  margin-top: 8px;
  text-align: center;
}
.k-lockcard-icon { color: var(--text-dim); margin-bottom: 8px; }
.k-lockcard-icon svg { width: 28px; height: 28px; }
.k-lockcard-text { color: var(--text-dim); font-size: 14px; margin-bottom: 14px; line-height: 1.45; }
.k-lockcard .btn { margin-bottom: 0; }
.k-lockcard-msg { margin-top: 10px; min-height: 1.2em; font-size: 13px; color: var(--warning); }

/* --- Full-screen views (Verlauf, module views) --- */
body.k-view-open { overflow: hidden; }
.k-view {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
}
.k-view-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 -16px 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.k-view-back {
  background: none;
  border: none;
  color: var(--accent-hover);
  font: inherit;
  font-size: 16px;
  min-height: 44px;
  padding: 0 8px 0 0;
}
.k-view-title { font-weight: 600; font-size: 16px; flex: 1; text-align: center; margin-right: 52px; }
.k-view-body { max-width: 480px; margin: 0 auto; }

/* --- Rows (lists in Mehr and Verlauf) --- */
.k-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.k-row:last-child { border-bottom: none; }
.k-row-main {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  padding: 0;
}
.k-row-title { font-size: 15px; font-weight: 500; }
.k-row-sub { font-size: 13px; color: var(--text-dim); margin-top: 2px; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; }
.k-thread .k-row-sub { white-space: nowrap; }
.k-row-actions { display: flex; gap: 6px; }
.k-row .k-confirm-row, .k-row .k-mem-edit { flex: 1 1 100%; }
.k-thread-list { margin-top: 12px; }

/* --- Chat --- */
.k-chat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.k-chat-title { font-weight: 600; font-size: 17px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.k-chat-older { text-align: center; margin-bottom: 8px; }
.k-chat-empty { color: var(--text-dim); text-align: center; padding: 40px 12px; font-size: 14px; }
.k-chat-list { display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; }

.k-divider { display: flex; align-items: center; gap: 10px; color: var(--text-dim); font-size: 12px; margin: 6px 0; }
.k-divider::before, .k-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.k-event { align-self: center; color: var(--text-dim); font-size: 13px; text-align: center; max-width: 90%; line-height: 1.4; }

.k-msg { display: flex; flex-direction: column; max-width: 88%; }
.k-me { align-self: flex-end; align-items: flex-end; }
.k-agent { align-self: flex-start; align-items: stretch; max-width: 94%; }

.k-bubble {
  font-size: 15px;
  line-height: 1.45;
  padding: 10px 13px;
  border-radius: 16px;
  word-break: break-word;
  -webkit-user-select: text;
  user-select: text;
}
.k-me .k-bubble { background: var(--bubble-me); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.k-agent .k-bubble { background: var(--bubble-agent); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.k-agent .k-bubble + .k-bubble, .k-agent .k-card + .k-bubble { margin-top: 8px; }
.k-md p { margin: 0 0 8px; }
.k-md p:last-child { margin-bottom: 0; }
.k-md ul { margin: 4px 0 8px 20px; }
.k-md ul:last-child { margin-bottom: 0; }
.k-md li { margin: 2px 0; }
.k-md .body-link { color: var(--accent-hover); text-decoration: underline; word-break: break-all; }
.k-fallback .k-bubble { opacity: 0.85; }

.k-quote {
  font-size: 13px;
  color: var(--text-dim);
  border-left: 2px solid var(--border);
  padding: 2px 8px;
  margin-bottom: 4px;
  max-width: 100%;
  white-space: pre-wrap;
}
.k-meta { font-size: 12px; color: var(--text-dim); margin-top: 3px; padding: 0 4px; }
.k-meta-agent { display: flex; align-items: center; gap: 6px; }
.k-meta-agent .k-speak { padding: 4px 6px; min-height: 32px; font-size: 12px; }
.k-tools { font-size: 12px; color: var(--text-dim); margin: 0 4px 4px; }
.k-notice { font-size: 13px; color: var(--warning); margin: 4px; }
.k-turn-error { font-size: 13px; color: var(--warning); margin: 6px 4px 0; }

.k-typing { display: flex; gap: 4px; padding: 12px 14px; background: var(--bubble-agent); border: 1px solid var(--border); border-radius: 16px; align-self: flex-start; }
.k-typing span { width: 6px; height: 6px; border-radius: 3px; background: var(--text-dim); animation: k-blink 1.2s infinite ease-in-out; }
.k-typing span:nth-child(2) { animation-delay: 0.2s; }
.k-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes k-blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.k-composer-wrap {
  position: sticky;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  z-index: 5;
  margin: 0 -16px;
  padding: 8px 16px 10px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}
body.k-kbd .k-composer-wrap { bottom: 0; }
body:not(.has-tabs) .k-composer-wrap { bottom: 0; }
.k-composer { display: flex; align-items: flex-end; gap: 8px; }
.k-composer .k-input { flex: 1; min-height: 44px; max-height: calc(21px * 6 + 22px); border-radius: 22px; padding: 11px 14px; }
.k-status { font-size: 13px; color: var(--text-dim); margin-bottom: 6px; padding: 0 4px; }
.k-seed {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
  border-left: 2px solid var(--accent);
  padding: 2px 0 2px 8px;
  margin-bottom: 6px;
}
.k-seed-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.k-seed-x { background: none; border: none; color: var(--text-dim); font-size: 20px; min-width: 44px; min-height: 36px; }
.k-mic-hint { font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }

.k-rec { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.k-rec-dot { width: 12px; height: 12px; border-radius: 6px; background: var(--danger); animation: k-pulse 1.2s infinite ease-in-out; }
.k-rec.k-rec-paused .k-rec-dot { animation: none; background: var(--text-dim); }
.k-rec-time { font-variant-numeric: tabular-nums; font-size: 15px; }
.k-rec-label { flex: 1; font-size: 13px; color: var(--text-dim); }
@keyframes k-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* --- Cards (actions, Heute) --- */
.k-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-top: 8px;
}
.k-agent .k-card { border-color: #34345a; }
.k-card-dim { opacity: 0.55; }
.k-card-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; font-size: 14px; margin-bottom: 6px; }
.k-card-chan {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 5px;
  background: #1a1a2e;
  color: var(--accent-hover);
}
.k-card-to { word-break: break-word; }
.k-card-line { font-size: 13px; color: var(--text-dim); margin: 3px 0; line-height: 1.4; }
.k-card-warn {
  font-size: 13px;
  margin: 6px 0;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--card-warn);
  color: var(--warning);
  line-height: 1.4;
}
.k-card-subject { font-size: 14px; font-weight: 600; margin: 6px 0 4px; }
.k-card-text {
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 10px 12px;
  margin: 6px 0;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  -webkit-user-select: text;
  user-select: text;
}
.k-card-edit { margin: 6px 0; }
.k-card-oneline { font-size: 15px; line-height: 1.45; }
.k-card-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
/* The send button sits apart from "Abbrechen", so one stray touch does not send */
.k-card-foot .k-btn-send { margin-left: auto; min-width: 96px; }
.k-card-state { font-size: 13px; color: var(--text-dim); flex: 1; }
.k-card-failed { color: var(--warning); }

/* --- Heute --- */
.k-today-date { font-size: 20px; font-weight: 600; margin-top: 4px; }
.k-today-budget { margin: 2px 0 12px; }
.k-briefing { padding: 14px 16px; }
.k-brief-head { font-size: 17px; font-weight: 600; margin-bottom: 8px; }
.k-brief-sec { margin: 10px 0; }
.k-brief-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-dim); margin-bottom: 4px; }
.k-brief-sec ul { list-style: none; }
.k-brief-sec li { font-size: 15px; line-height: 1.45; padding: 4px 0; border-bottom: 1px solid var(--border); }
.k-brief-sec li:last-child { border-bottom: none; }
.k-brief-ask {
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  padding: 4px 0;
  min-height: 36px;
}
.k-brief-ask .k-chev { color: var(--accent-hover); font-size: 18px; }
.k-feedback .k-dim:first-child { flex: 1; }
.k-curate { display: flex; gap: 8px; margin-top: 10px; }
.k-curate .k-input { flex: 1; }

.k-modsec { margin-top: 8px; }
.k-modsec:has(> .k-modsec-body:empty) { display: none; }

.k-item-title { font-size: 15px; font-weight: 600; line-height: 1.35; }
.k-item-body { font-size: 14px; color: var(--text); margin-top: 4px; white-space: pre-wrap; word-break: break-word; line-height: 1.45; }
.k-item-why { margin-top: 4px; }
.k-item-age { margin-top: 4px; font-size: 12px; }
.k-item-high { border-left: 3px solid var(--accent); }
.k-item-urgent { border-left: 3px solid var(--warning); }
.k-item-actions .k-btn { min-height: 36px; padding: 6px 10px; font-size: 13px; }

.k-compact {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 14px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.k-compact:last-child { border-bottom: none; }
.k-compact-time { color: var(--text-dim); font-variant-numeric: tabular-nums; min-width: 44px; }
.k-compact-time + span { flex: 1; }
.k-today-health { margin-top: 16px; }
.k-health-bad { color: var(--warning); justify-content: flex-start; }

/* --- Mehr --- */
.k-more { margin-top: 4px; }
.k-acc { border-bottom: 1px solid var(--border); }
.k-acc-head {
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  min-height: 52px;
  background: none;
  border: none;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 500;
  text-align: left;
  padding: 0 2px;
}
.k-acc-head .k-chev { transition: transform 0.15s ease; }
.k-acc.open .k-acc-head .k-chev { transform: rotate(90deg); }
.k-acc-body { padding: 0 2px 16px; }

.k-setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.k-setting-text { flex: 1; font-size: 15px; line-height: 1.35; }
.k-setting-block { padding: 10px 0; border-bottom: 1px solid var(--border); }
.k-setting-label { font-size: 15px; margin-bottom: 8px; }

.k-switch {
  flex: none;
  position: relative;
  width: 52px;
  height: 32px;
  border-radius: 16px;
  border: none;
  background: #3a3a3a;
  transition: background 0.15s ease;
  touch-action: manipulation;
}
.k-switch span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 13px;
  background: #fff;
  transition: transform 0.15s ease;
}
.k-switch[aria-checked="true"] { background: var(--success); }
.k-switch[aria-checked="true"] span { transform: translateX(20px); }

.k-seg {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
  margin-bottom: 8px;
}
.k-seg-btn {
  flex: 1;
  min-height: 40px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text-dim);
  font: inherit;
  font-size: 13px;
  line-height: 1.2;
  padding: 4px 6px;
  touch-action: manipulation;
}
.k-seg-btn.active { background: var(--surface-2); color: var(--text); font-weight: 600; }

.k-stepper { display: flex; align-items: center; gap: 6px; }
.k-step { min-width: 44px; padding: 6px; font-size: 18px; }
.k-step-val { min-width: 54px; text-align: center; font-variant-numeric: tabular-nums; }

.k-form {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.k-mem .k-row-sub { white-space: pre-wrap; }

.k-audit { display: flex; gap: 10px; font-size: 13px; padding: 7px 0; border-bottom: 1px solid var(--border); line-height: 1.4; }
.k-audit-time { color: var(--text-dim); flex: none; min-width: 84px; font-variant-numeric: tabular-nums; }
.k-audit-week { margin: 6px 0 10px; }
.k-sec-actions .k-wide:first-child { margin-top: 12px; }
