:root {
  --bg: #0e131b;
  --panel: #141a24;
  --panel-2: #1c2432;
  --text: #e8edf4;
  --muted: #93a1b5;
  --accent: #4f9cf9;
  --accent-2: #2ecc8f;
  --danger: #e2574c;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: var(--panel);
  border-bottom: 1px solid #232d3d;
  padding-top: calc(12px + env(safe-area-inset-top));
}
.topbar h1 { font-size: 1.05rem; margin: 0; font-weight: 600; }
.controls { display: flex; align-items: center; gap: 10px; }
.toggle { font-size: .8rem; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.toggle select {
  background: var(--panel-2); color: var(--text); border: 1px solid #2c3950;
  border-radius: 6px; padding: 2px 4px; font-size: .78rem;
}
.dot { width: 10px; height: 10px; border-radius: 50%; background: #666; display: inline-block; }
.dot.ok { background: var(--accent-2); }
.dot.err { background: var(--danger); }

.chat {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.msg {
  max-width: 85%; padding: 10px 14px; border-radius: var(--radius);
  line-height: 1.45; white-space: pre-wrap; word-wrap: break-word;
  font-size: .95rem;
}
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.agent { align-self: flex-start; background: var(--panel-2); border-bottom-left-radius: 4px; }
.msg.system { align-self: center; color: var(--muted); font-size: .8rem; background: none; }
.msg.thinking { align-self: flex-start; color: var(--muted); font-style: italic; background: none; }

.confirm-area {
  padding: 12px 16px; background: var(--panel);
  border-top: 1px solid #232d3d;
  display: flex; flex-direction: column; gap: 10px;
}

.mandate-area {
  width: min(760px, calc(100% - 2rem));
  margin: 0 auto 0.75rem;
}

.mandate-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.mandate-card pre.detail {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.mandate-review {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}
.mandate-review-item {
  border: 1px solid #2c3950;
  background: var(--bg);
  border-radius: 10px;
  padding: 10px;
}
.mandate-review-label {
  color: var(--muted);
  font-size: .76rem;
  font-weight: 600;
}
.mandate-review-value {
  color: var(--text);
  line-height: 1.35;
}

.mandate-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.mandate-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 600;
}
.mandate-form input, .mandate-form textarea, .mandate-form select {
  width: 100%;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid #2c3950;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.mandate-form h3 {
  grid-column: 1 / -1;
  margin: 6px 0 0;
  font-size: .9rem;
  color: var(--text);
}
.mandate-form button {
  grid-column: 1 / -1;
  justify-self: start;
  min-width: 180px;
  padding: 9px 14px;
}
@media (max-width: 640px) {
  .mandate-form { grid-template-columns: 1fr; }
  .mandate-form h3 {
  grid-column: 1 / -1;
  margin: 6px 0 0;
  font-size: .9rem;
  color: var(--text);
}
.mandate-form button { width: 100%; }
  .mandate-review { grid-template-columns: 1fr; }
}
.confirm-area.hidden { display: none; }
.confirm-card {
  background: var(--panel-2); border: 1px solid #2c3950;
  border-radius: var(--radius); padding: 12px 14px;
}
.confirm-card .summary { font-weight: 600; margin-bottom: 6px; }
.confirm-card .detail { color: var(--muted); font-size: .8rem; white-space: pre-wrap; margin-bottom: 10px; }
.confirm-card .actions { display: flex; gap: 8px; }
.confirm-card button {
  flex: 1; padding: 9px 0; border: none; border-radius: 10px;
  font-size: .9rem; font-weight: 600; cursor: pointer; color: #fff;
}
.confirm-card .approve { background: var(--accent-2); }
.confirm-card .deny { background: var(--danger); }

.composer {
  display: flex; gap: 8px; padding: 12px 16px; background: var(--panel);
  border-top: 1px solid #232d3d;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
.composer input {
  flex: 1; padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid #2c3950; background: var(--panel-2); color: var(--text);
  font-size: 1rem; outline: none;
}
.composer input:focus { border-color: var(--accent); }
.mic, .send {
  width: 48px; height: 48px; border-radius: 50%; border: none;
  font-size: 1.2rem; cursor: pointer; color: #fff; flex-shrink: 0;
}
.mic { background: var(--panel-2); border: 1px solid #2c3950; }
.mic.listening { background: var(--danger); animation: pulse 1.2s infinite; }
.send { background: var(--accent); }
.voice-mode {
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid #2c3950;
  font-size: 1.2rem; cursor: pointer; color: #fff; flex-shrink: 0;
  background: linear-gradient(135deg, #2a3b5c, #1c2432);
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(226, 87, 76, .5); }
  50% { box-shadow: 0 0 0 12px rgba(226, 87, 76, 0); }
}

/* ---------- Hands-free voice mode overlay ---------- */
.voice-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: radial-gradient(ellipse at 50% 35%, #162032 0%, var(--bg) 70%);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.voice-overlay.hidden { display: none; }
.vm-close {
  position: absolute; top: calc(14px + env(safe-area-inset-top)); right: 18px;
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid #2c3950;
  background: var(--panel-2); color: var(--muted); font-size: 1rem; cursor: pointer;
}
.vm-center {
  display: flex; flex-direction: column; align-items: center; gap: 22px;
  padding: 0 24px; max-width: 560px; width: 100%;
}
.orb {
  width: 150px; height: 150px; border-radius: 50%; border: none; cursor: pointer;
  background: radial-gradient(circle at 35% 30%, #6fb2ff 0%, var(--accent) 45%, #1d4e8f 100%);
  transition: transform .25s ease;
}
.orb.idle { opacity: .6; }
.orb.listening { animation: orb-listen 1.6s ease-in-out infinite; }
.orb.thinking {
  background: radial-gradient(circle at 35% 30%, #c9a2ff 0%, #8b5cf6 45%, #4c2a8f 100%);
  animation: orb-think 1.1s ease-in-out infinite;
}
.orb.speaking {
  background: radial-gradient(circle at 35% 30%, #7ce8bd 0%, var(--accent-2) 45%, #14775a 100%);
  animation: orb-speak .9s ease-in-out infinite;
}
@keyframes orb-listen {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(79, 156, 249, .45); }
  50% { transform: scale(1.06); box-shadow: 0 0 0 28px rgba(79, 156, 249, 0); }
}
@keyframes orb-think {
  0%, 100% { transform: scale(.96); filter: brightness(.9); }
  50% { transform: scale(1.02); filter: brightness(1.15); }
}
@keyframes orb-speak {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(46, 204, 143, .4); }
  50% { transform: scale(1.05); box-shadow: 0 0 0 20px rgba(46, 204, 143, 0); }
}
.vm-state { color: var(--muted); font-size: .95rem; min-height: 1.3em; }
.vm-caption {
  width: 100%; text-align: center; line-height: 1.45; min-height: 1.4em;
  white-space: pre-wrap; word-wrap: break-word;
}
.vm-caption.user { color: var(--accent); font-size: 1.02rem; }
.vm-caption.agent {
  color: var(--text); font-size: 1.02rem;
  max-height: 34vh; overflow-y: auto;
}
.vm-hint {
  position: absolute; bottom: calc(18px + env(safe-area-inset-bottom));
  color: var(--muted); font-size: .78rem;
}
