/* SpeechPuppet web surface v1 — tokens and layout per docs/design/v1/README.md.
   Deploy: copy web/* to ~/public_html/ (Apache serves statics; API is proxied). */

:root {
  --ink: #1d1d2b;
  --muted: #6e6e87;
  --bg: #f7f7fb;
  --surface: #ffffff;
  --line: #e7e7f0;
  --accent: #7c6cf0;
  --accent-tint: #f3f1ff;
  --accent-deep: #5646c8;
  --accent-line: #ddd6ff;
  --clay: #b93fae;
  --clay-tint: #fdf0fb;
  --clay-deep: #8f2585;
  --clay-line: #f4d9f0;
  --danger: #e0344a;
  --danger-solid: #d92d43;
  --danger-tint: #fdeef0;
  --focus: #7c6cf0;
  --pulse: #14b8a0;
  --scrim: rgba(28, 26, 44, .4);
  --tsc: 1;
}

* { box-sizing: border-box; margin: 0; }

body {
  font-family: 'Geist', system-ui, sans-serif;
  font-weight: 400;
  background: var(--bg);
  color: var(--ink);
  font-size: calc(15px * var(--tsc));
  line-height: 1.45;
}

button { font: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}

.mono-label {
  font-family: 'Geist Mono', monospace;
  font-weight: 500;
  font-size: calc(11px * var(--tsc));
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}

.hidden { display: none !important; }

/* --- header ------------------------------------------------------------- */
.site-header {
  background: var(--surface);
  padding: 17px 28px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 2px solid;
  border-image: linear-gradient(90deg, #5ee8cf, #59c2f2, #6ca7f5, #937ff4, #c67be2, #e37fd4) 1;
}
.site-header .wordmark { font-weight: 600; font-size: calc(14px * var(--tsc)); }
.site-header .grow { flex: 1; }
.header-btn {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 9px 16px;
  font-weight: 500;
  font-size: calc(14px * var(--tsc));
}
.header-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* --- generic cards / buttons -------------------------------------------- */
.page { max-width: 940px; margin: 0 auto; padding: 24px; display: flex; flex-direction: column; gap: 22px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 24px;
}
.card h2 { font-size: calc(17px * var(--tsc)); font-weight: 600; margin-bottom: 14px; }
.btn {
  border-radius: 2px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 12px 20px;
  font-weight: 500;
  min-height: 44px;
}
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:disabled { background: #c9c9d8; border-color: #c9c9d8; cursor: default; }
.btn-danger { background: var(--danger-solid); border-color: var(--danger-solid); color: #fff; }
.btn-big { padding: 16px 26px; font-size: calc(16px * var(--tsc)); }

input[type=text], input[type=email], input[type=password], input[type=tel], textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 12px;
  font: inherit;
  background: var(--surface);
}
textarea { min-height: 84px; resize: vertical; }

/* --- login ---------------------------------------------------------------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
}
.login-card { width: min(400px, 92vw); display: flex; flex-direction: column; gap: 12px; }
.login-sub { color: var(--muted); font-size: calc(19px * var(--tsc)); }
.err { color: var(--danger); font-size: calc(13px * var(--tsc)); min-height: 1.2em; }

/* --- start screen ---------------------------------------------------------- */
.contact-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.contact-card {
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: 2px; padding: 14px;
}
.contact-card.selected { border: 2px solid var(--accent); background: var(--accent-tint); padding: 13px; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent-tint); color: var(--accent-deep);
  display: flex; align-items: center; justify-content: center; font-weight: 600;
}
.contact-card .name { font-weight: 600; font-size: calc(15px * var(--tsc)); }
.contact-card .num { color: var(--muted); font-size: calc(13px * var(--tsc)); }

.dialpad { display: grid; grid-template-columns: repeat(3, 74px); gap: 10px; margin-top: 12px; }
.dialpad button { font-size: calc(22px * var(--tsc)); padding: 14px 0; border: 1px solid var(--line); border-radius: 2px; background: var(--surface); }

.seg { display: inline-flex; border: 1px solid var(--accent-line); border-radius: 2px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 10px 18px; font-weight: 500; }
.seg button.active { background: var(--accent); color: #fff; }

.lead-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.lead-card { text-align: left; padding: 18px; border: 1px solid var(--line); border-radius: 2px; background: var(--surface); }
.lead-card.selected { border: 2px solid var(--accent); background: var(--accent-tint); padding: 17px; }
.lead-card .t { font-weight: 600; margin-bottom: 4px; }
.lead-card .d { color: var(--muted); font-size: calc(13px * var(--tsc)); }

.toggle-row { display: flex; align-items: center; gap: 12px; margin-top: 14px; }

.sticky-footer {
  position: sticky; bottom: 0; background: var(--surface);
  border-top: 1px solid var(--line); box-shadow: 0 -4px 20px rgba(0,0,0,.05);
  padding: 14px 24px; display: flex; align-items: center; gap: 16px;
}
.sticky-footer .status { flex: 1; font-size: calc(14px * var(--tsc)); color: var(--muted); }
.sticky-footer .status b { color: var(--ink); }

.history-row { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); font-size: calc(13px * var(--tsc)); align-items: baseline; }
.history-row:first-of-type { border-top: 0; }
.history-row .who { font-weight: 600; min-width: 140px; }
.history-row .sum { color: var(--muted); flex: 1; }
.history-row .cost { font-family: 'Geist Mono', monospace; color: var(--muted); }

/* --- live call -------------------------------------------------------------- */
.status-bar { display: flex; align-items: center; gap: 14px; }
.pulse-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--pulse); animation: pulse 1.6s ease-in-out infinite; flex-shrink: 0; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.status-bar .who { flex: 1; }
.status-bar .who .n { font-weight: 500; font-size: calc(16px * var(--tsc)); }
.status-bar .who .t { color: var(--muted); font-size: calc(11px * var(--tsc)); }

.captions { display: flex; flex-direction: column; gap: 10px; max-height: 44vh; overflow-y: auto; margin-top: 12px; }
.bubble { border-radius: 2px; padding: 12px 14px; max-width: 88%; }
.bubble .speaker { margin-bottom: 4px; }
.bubble .txt { font-size: calc(20px * var(--tsc)); line-height: 1.4; overflow-wrap: anywhere; }
.bubble.them { background: var(--clay-tint); border-left: 4px solid var(--clay); align-self: flex-start; }
.bubble.them .speaker { color: var(--clay-deep); }
.bubble.us { background: var(--accent-tint); border-left: 4px solid var(--accent); align-self: flex-end; }
.bubble.us .speaker { color: var(--accent-deep); }
.bubble .txt.live::after {
  content: ""; display: inline-block; width: 3px; height: 1em;
  background: currentColor; margin-left: 3px; vertical-align: text-bottom;
  animation: caret 1s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }
.tone-pill {
  align-self: center; background: var(--bg); border: 1px solid var(--line);
  border-radius: 2px; padding: 4px 12px; font-family: 'Geist Mono', monospace;
  font-size: calc(11px * var(--tsc)); letter-spacing: .12em; color: var(--muted);
}
.sys-note { align-self: center; color: var(--muted); font-size: calc(12px * var(--tsc)); }

.draft-card { box-shadow: 0 1px 3px rgba(0,0,0,.05); }
.draft-text { font-size: calc(20px * var(--tsc)); line-height: 1.4; min-height: 1.4em; margin: 10px 0 16px; }
.draft-text.waiting { color: var(--muted); font-size: calc(14px * var(--tsc)); }
.draft-actions { display: flex; gap: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.chips button { border: 1px solid var(--accent-line); background: var(--surface); border-radius: 2px; padding: 10px 16px; font-weight: 500; min-height: 44px; }

.type-row { display: flex; gap: 12px; margin-top: 12px; align-items: flex-end; }
.type-row textarea { flex: 1; min-height: 56px; }

/* --- modals ------------------------------------------------------------- */
.overlay {
  position: fixed; inset: 0; background: var(--scrim);
  display: flex; align-items: center; justify-content: center; z-index: 40;
}
.modal { background: var(--surface); border-radius: 2px; padding: 30px; width: min(430px, 92vw); }
.modal h3 { font-size: calc(17px * var(--tsc)); font-weight: 600; margin-bottom: 16px; }
.keypad-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keypad-grid button { font-size: calc(22px * var(--tsc)); padding: 16px 0; border: 1px solid var(--line); border-radius: 2px; background: var(--surface); }

/* --- ended -------------------------------------------------------------- */
.ended-wrap { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 60px 24px; text-align: center; }
.ended-card { max-width: 560px; }

/* --- debug panel (spec §21) ---------------------------------------------- */
.debug-panel {
  position: fixed; right: 12px; bottom: 12px; width: 380px; max-height: 40vh;
  background: #111120; color: #b9f5c8; font-family: 'Geist Mono', monospace;
  font-size: 11px; border-radius: 2px; z-index: 50;
  display: flex; flex-direction: column; transition: box-shadow .4s;
}
.debug-panel.glow { box-shadow: 0 0 0 3px var(--pulse); }
.debug-panel header {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  color: #8f8fb0; letter-spacing: .12em; text-transform: uppercase; font-size: 10px;
}
.debug-panel header button { background: #26263c; color: #cfcfe8; border: 0; border-radius: 2px; padding: 4px 10px; font: inherit; }
.debug-log { overflow-y: auto; padding: 4px 10px 10px; white-space: pre-wrap; }

/* --- incoming call banner (Stage 6) -------------------------------------- */
.incoming-banner {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 60; display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 2px solid var(--accent); border-radius: 2px;
  padding: 14px 18px; box-shadow: 0 4px 24px rgba(0,0,0,.12); min-width: 340px;
}
.incoming-banner .grow { flex: 1; font-weight: 600; }

/* --- texting + scheduler (owner request 2026-07-04) ---------------------- */
.contact-wrap { display: flex; flex-direction: column; gap: 6px; }
.contact-wrap .contact-card { width: 100%; height: 100%; }
.text-chip {
  border: 1px solid var(--accent-line); background: var(--surface);
  border-radius: 2px; padding: 8px 10px; font-weight: 500; min-height: 42px;
  font-size: calc(14px * var(--tsc));
}
.text-chip.unread { border: 2px solid var(--accent); background: var(--accent-tint); font-weight: 600; }
.text-thread {
  display: flex; flex-direction: column; gap: 10px; margin-top: 14px;
  max-height: 44vh; overflow-y: auto; padding: 4px;
}
.bubble.sms { max-width: 78%; border-radius: 12px; }
.bubble.sms .txt { font-size: calc(16px * var(--tsc)); }
#emojiRow button { font-size: 22px; min-width: 52px; }
#schedForm select, #schedForm input[type="datetime-local"] { width: 100%; }

/* --- contact picker + contacts screen (owner request 2026-07-05) ---------- */
.selected-row { margin-bottom: 12px; }
.selected-row .contact-wrap { max-width: 340px; }
.picker-row { display: flex; flex-wrap: wrap; gap: 10px; }
.picker-row .btn:disabled { color: var(--muted); cursor: default; }
#pickContactBtn.unread-hint { border: 2px solid var(--accent); background: var(--accent-tint); font-weight: 600; }
#contactForm select { width: 100%; border: 1px solid var(--line); border-radius: 2px; padding: 12px; font: inherit; background: var(--surface); }
#accountScreen select { width: min(440px, 100%); border: 1px solid var(--line); border-radius: 2px; padding: 12px; font: inherit; background: var(--surface); }
.history-row .btn.unread { border: 2px solid var(--accent); background: var(--accent-tint); font-weight: 600; }
