:root {
  --bg: #0b0f14;
  --panel: #121821;
  --panel-2: #18202b;
  --line: #243041;
  --text: #dbe4ee;
  --muted: #8193a8;
  --accent: #4fc3f7;
  --ok: #4caf7d;
  --warn: #e0a53a;
  --bad: #e2595b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }

button, input, textarea {
  font: inherit;
  color: inherit;
}
button {
  background: var(--accent);
  color: #04121b;
  border: 0;
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
}
button:disabled { opacity: .5; cursor: default; }
button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  font-weight: 500;
}
button.danger { background: var(--bad); color: #fff; }
input, textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
}
select {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 8px;
  margin-right: auto;
}
input:focus, textarea:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--bad); min-height: 1.5em; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
}
.login {
  max-width: 360px;
  margin: 12vh auto 0;
  display: grid;
  gap: 12px;
}
.login h1 { margin: 0; letter-spacing: .3em; color: var(--accent); }
.login p { margin: 0; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

#app-view { display: flex; flex-direction: column; height: 100dvh; }
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { letter-spacing: .3em; color: var(--accent); font-weight: 700; }
.topbar nav { display: flex; gap: 6px; flex: 1; }
.tab { background: transparent; color: var(--muted); border: 1px solid transparent; }
.tab.active { color: var(--text); border-color: var(--line); background: var(--panel-2); }
.badge {
  background: var(--warn);
  color: #1b1200;
  border-radius: 10px;
  padding: 0 7px;
  font-size: 12px;
  margin-left: 4px;
}

.tabpane {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 16px;
}
#tab-approvals { overflow-y: auto; display: block; }

.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 12px;
}
.msg {
  padding: 10px 12px;
  border-radius: 8px;
  max-width: 85%;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user { align-self: flex-end; background: #1d3347; }
.msg.assistant { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); }
.msg.system { align-self: center; color: var(--warn); font-size: 13px; }
.msg .hint { display: block; margin-top: 6px; font-size: 12px; color: var(--warn); }

.composer { display: grid; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.composer textarea { resize: vertical; min-height: 52px; }
.composer-actions { display: flex; justify-content: space-between; gap: 8px; }

.row { display: flex; justify-content: space-between; align-items: center; }
.row h2 { margin: 0; font-size: 18px; }

.approval { margin: 12px 0; display: grid; gap: 8px; }
.approval header { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.approval pre {
  margin: 0;
  white-space: pre-wrap;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  font-size: 13px;
}
.approval code { font-size: 11px; color: var(--muted); word-break: break-all; }
.approval .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.approval .result:empty { display: none; }
.approval .result { font-size: 13px; color: var(--text, inherit); }
/* Karte direkt in der Chat-Antwort */
.approval.inline { margin: 10px 0 0; padding: 10px; white-space: normal; }
.approval.inline pre { max-height: 260px; overflow-y: auto; }
/* Deep-Link aus Talk (#freigabe/<id>) */
.approval.highlight { outline: 2px solid var(--warn); outline-offset: 2px; }
.status {
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.status.pending { color: var(--warn); border-color: var(--warn); }
.status.executed { color: var(--ok); border-color: var(--ok); }
.status.rejected, .status.failed, .status.expired, .status.verification_required {
  color: var(--bad);
  border-color: var(--bad);
}
.flag { font-size: 12px; color: var(--bad); }

/* ---------------------------------------------------------------- Geräte */

#tab-devices { overflow-y: auto; display: block; }
.device-form { display: grid; gap: 10px; margin: 12px 0; max-width: 520px; }
.token-once { display: grid; gap: 8px; margin: 12px 0; border-color: var(--warn); }
.token-once code { word-break: break-all; font-size: 13px; color: var(--warn); user-select: all; }
.token-once .actions, .device .actions { display: flex; gap: 8px; }
.device { margin: 12px 0; display: grid; gap: 6px; }
.device header { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------------------------------------------------------------- Sprache */

.composer-actions { flex-wrap: wrap; align-items: center; }
.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.toggle input { width: auto; margin: 0; accent-color: var(--accent); }

.mic {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-2);
  color: var(--accent);
  border: 1px solid var(--accent);
  /* Tippfläche mindestens 44 px (iOS-Richtlinie), auch mit Handschuh oder unterwegs. */
  min-height: 44px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.mic svg { width: 18px; height: 18px; fill: currentColor; }
.mic.recording {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
  animation: mic-pulse 1.2s ease-in-out infinite;
}
.mic.busy { opacity: .7; cursor: progress; }
.mic.speaking { background: var(--accent); color: #04121b; }
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(226, 89, 91, .55); }
  50% { box-shadow: 0 0 0 6px rgba(226, 89, 91, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .mic.recording { animation: none; }
}
.voice-status { font-size: 13px; color: var(--accent); min-height: 1.2em; }
/* Freihändiges Gespräch: gedrückt = Mikrofon bleibt offen. */
.mic.converse.active { background: var(--accent); color: #04121b; border-color: var(--accent); }

@media (max-width: 600px) {
  .msg { max-width: 95%; }
  .topbar { padding: 8px 10px; gap: 6px; }
  .tabpane { padding: 10px; }
  /* Am Telefon ist das Mikrofon die Hauptaktion: breit und gut erreichbar. */
  .mic { order: -1; flex: 1 1 40%; justify-content: center; }
  .composer-actions select { flex: 1; }
  /* Drei Reiter plus Abmelden passen sonst nicht auf 390 px Breite. */
  .topbar .brand { display: none; }
  .topbar nav { min-width: 0; overflow-x: auto; }
  .topbar .tab, #logout { padding: 7px 9px; }
}
