/* OpenClaw Voice v2 — dark, mobile-first */

:root {
  --bg: #0b0f14;
  --panel: #131a22;
  --panel2: #1a2330;
  --border: #233041;
  --text: #d7dee7;
  --muted: #6b7a8c;
  --accent: #4fc3f7;
  --green: #34d399;
  --green2: #86efac;
  --amber: #fbbf24;
  --red: #f87171;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  /* --app-height is set from window.innerHeight by app.js (setAppHeight) and
     tracks resize events. Plain 100dvh got stuck too tall after an in-place
     PWA reload (nav bar below the fold until relaunch — Simon 2026-07-10). */
  height: var(--app-height, 100dvh);
  display: flex;
  flex-direction: column;
  overflow: hidden;   /* pin the app shell; only .log / lists scroll internally
                         (stops a dvh/visual-viewport mismatch pushing the tab
                         bar below the fold — Simon 2026-07-08) */
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input[type="text"], input[type="password"], textarea {
  font: inherit; color: var(--text);
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; width: 100%; min-width: 0;
}
input[type="text"]:focus, input[type="password"]:focus, textarea:focus { outline: none; border-color: var(--accent); }
#textInput { resize: none; overflow-y: auto; max-height: 120px; line-height: 1.35; }

/* ── top bar ── */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--border); flex: none;
}
.app-title { font-weight: 600; flex: 1; }
.conn-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.conn-dot.conn-open { background: var(--green); }
.conn-dot.conn-connecting { background: var(--amber); }
.conn-dot.conn-closed { background: var(--red); }
.ghost-btn {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 12px; color: var(--muted); font-size: 0.85rem;
}
.ghost-btn:active { border-color: var(--accent); color: var(--accent); }

/* ── views ── */
main { flex: 1; min-height: 0; display: flex; }
.view {
  flex: 1; min-height: 0; width: 100%; max-width: 720px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 10px; padding: 10px 12px;
}
.view[hidden] { display: none; }

/* ── talk ── */
.talk-toolbar { display: flex; align-items: stretch; gap: 8px; flex: none; }
.mode-seg { display: flex; flex: 1; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.mode-seg button { flex: 1; padding: 8px 4px; font-size: 0.85rem; color: var(--muted); background: var(--panel); }
.mode-seg button.active { background: var(--accent); color: #062030; font-weight: 600; }

.big-status {
  --st: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 12px 0 6px; flex: none;
}
.big-status[data-state="idle"]       { --st: var(--muted); }
.big-status[data-state="armed"]      { --st: var(--green); }
.big-status[data-state="in_speech"]  { --st: var(--green2); }
.big-status[data-state="processing"] { --st: var(--amber); }
.big-status[data-state="speaking"]   { --st: var(--accent); }
.big-status.offline { opacity: 0.45; }
.big-status-ring {
  width: 118px; height: 118px; border-radius: 50%;
  border: 3px solid var(--st);
  transition: border-color 0.2s;
  background: radial-gradient(circle at 50% 42%,
              color-mix(in srgb, var(--st) 16%, transparent), transparent 72%);
}
@keyframes ocv-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(134, 239, 172, 0.35); }
  70%  { box-shadow: 0 0 0 22px rgba(134, 239, 172, 0); }
  100% { box-shadow: 0 0 0 0 rgba(134, 239, 172, 0); }
}
.big-status[data-state="in_speech"] .big-status-ring { animation: ocv-pulse 1.5s ease-out infinite; }
.big-status-label {
  color: var(--st); font-size: 1.05rem; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
}
.big-status-hint { color: var(--muted); font-size: 0.8rem; min-height: 1em; }

.log {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px; padding: 4px 2px;
}
.msg {
  max-width: 85%; padding: 8px 12px; border-radius: 12px;
  font-size: 0.95rem; line-height: 1.45;
  white-space: pre-wrap; word-break: break-word;
}
.msg-user { align-self: flex-end; background: #173042; border: 1px solid #1f4258; }
.msg-assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--border); }
.chip {
  align-self: flex-start; font-size: 0.75rem; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 2px 10px; background: var(--panel);
}
.latency {
  align-self: flex-start;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.7rem; color: var(--muted); padding-left: 4px;
}

.input-row { display: flex; gap: 8px; flex: none; align-items: flex-end; }
.cancel-btn { border: 1px solid var(--red); color: var(--red); border-radius: 8px; padding: 0 14px; flex: none; }
.send-btn { border: 1px solid var(--accent); color: var(--accent); border-radius: 8px; padding: 0 16px; flex: none; }

/* ── inbox ── */
.inbox-edit-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px 6px 6px 12px; font-size: 0.85rem; flex: none;
}
.inbox-edit-bar[hidden] { display: none; }
.inbox-edit-bar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-edit-bar button {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 14px; color: var(--muted); flex: none;
}
.inbox-field { display: flex; flex-direction: column; gap: 4px; flex: none; }
.inbox-field-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 0.8rem; color: var(--muted); padding: 0 2px;
}
.inbox-busy { color: var(--amber); }
.inbox-field-row { display: flex; gap: 8px; align-items: flex-end; }
.inbox-field-row textarea { resize: none; overflow-y: auto; line-height: 1.35; }
#inboxTitleInput { max-height: 120px; }
#inboxBodyInput { max-height: 40vh; }
.rec-btn {
  min-width: 48px; min-height: 44px; flex: none;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  border-radius: 10px; font-size: 1rem;
}
.rec-btn.recording { border-color: var(--red); color: var(--red); animation: ocv-pulse 1.5s ease-out infinite; }
.inbox-meta { display: flex; flex-direction: column; gap: 8px; flex: none; }
.inbox-prio {
  display: flex; align-items: center; gap: 12px;
  font-size: 0.85rem; color: var(--muted); padding: 0 2px;
}
.inbox-prio-label { flex: none; }
#inboxPrioVal { color: var(--text); display: inline-block; min-width: 1.4em; text-align: right; }
.inbox-prio input[type="range"] { flex: 1; min-height: 32px; }
.inbox-save {
  border: 1px solid var(--accent); color: var(--accent); background: var(--panel);
  border-radius: 10px; padding: 12px; min-height: 44px; font-size: 1rem; flex: none;
}
.inbox-list {
  list-style: none; flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
}
.inbox-list li {
  display: flex; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px;
}
.inbox-entry-main { flex: 1; min-width: 0; }
.inbox-entry-title { font-size: 0.95rem; word-break: break-word; }
.inbox-entry-body {
  font-size: 0.8rem; color: var(--muted); margin-top: 2px; word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  line-clamp: 2; overflow: hidden;
}
.inbox-entry-edit {
  flex: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 0 14px; min-height: 44px; color: var(--accent);
}

/* ── settings ── */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); flex: none; }
.token-row { display: flex; gap: 8px; }
.token-row button { border: 1px solid var(--accent); color: var(--accent); border-radius: 8px; padding: 0 16px; flex: none; }
.toggle-field { flex-direction: row; align-items: center; justify-content: space-between; }
.toggle-field input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
input[type="range"] { accent-color: var(--accent); }
input[type="range"]:disabled { opacity: 0.35; }
.settings-actions { display: flex; flex-wrap: wrap; gap: 8px; flex: none; }
.settings-actions button {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; color: var(--text); background: var(--panel);
}
#debugDump {
  font-size: 0.65rem; overflow: auto; max-height: 40vh; white-space: pre-wrap;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px;
}
#debugDump[hidden] { display: none; }

/* ── tab bar ── */
.tabbar {
  display: flex; border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom); background: var(--bg); flex: none;
}
.tab { flex: 1; padding: 12px 0; color: var(--muted); font-size: 0.9rem; }
.tab.active { color: var(--accent); font-weight: 600; }

/* ── pocket overlay ── */
#pocketOverlay {
  position: fixed; inset: 0; z-index: 2147483647;
  background: #000;
  touch-action: none; user-select: none; -webkit-user-select: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  cursor: none;
}
#pocketOverlay[hidden] { display: none; }
#pocketDot { width: 8px; height: 8px; border-radius: 50%; opacity: 0.25; background: var(--muted); }
#pocketDot[data-state="armed"]      { background: var(--green); }
#pocketDot[data-state="in_speech"]  { background: var(--green2); }
#pocketDot[data-state="processing"] { background: var(--amber); }
#pocketDot[data-state="speaking"]   { background: var(--accent); }
#pocketClock {
  color: #4a5661; opacity: 0.35; font-size: 1.3rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
#holdRing {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 84px; height: 84px; opacity: 0; pointer-events: none;
}
#pocketOverlay.holding #holdRing { opacity: 0.6; }
#holdRing .ring-bg { fill: none; stroke: #1c242e; stroke-width: 6; }
#holdRing .ring-fg {
  fill: none; stroke: #3b4956; stroke-width: 6; stroke-linecap: round;
  stroke-dasharray: 264; stroke-dashoffset: 264;
  transform: rotate(-90deg); transform-origin: 50% 50%;
}
#pocketOverlay.holding .ring-fg { stroke-dashoffset: 0; transition: stroke-dashoffset 1.5s linear; }

/* ── toast ── */
.toast {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 10000;
  background: #2a1519; border: 1px solid var(--red); color: #fecaca;
  border-radius: 10px; padding: 10px 14px;
  display: flex; gap: 12px; align-items: center;
  max-width: 90vw; font-size: 0.9rem;
}
.toast[hidden] { display: none; }
.toast button { color: #fecaca; flex: none; }

/* ── past chats overlay ── */
.chats-overlay {
  position: fixed; inset: 0; z-index: 900;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: flex-end; justify-content: center;
}
.chats-overlay[hidden] { display: none; }
.chats-panel {
  background: #101720; border: 1px solid #223042; border-radius: 14px 14px 0 0;
  width: min(560px, 100vw); max-height: 70vh; display: flex; flex-direction: column;
}
.chats-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; font-weight: 600; border-bottom: 1px solid #1c2836;
}
.chats-list { overflow-y: auto; padding: 6px; }
.chats-item {
  display: flex; flex-direction: column; gap: 2px; width: 100%;
  text-align: left; padding: 10px 12px; border-radius: 10px;
  background: none; border: none; color: inherit; cursor: pointer;
}
.chats-item:hover, .chats-item:active { background: #18222e; }
.ci-title { font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-meta { font-size: 0.75rem; color: #7d8fa5; }
