/* ===== BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue: #0a6cff;
  --orange: #f4440c;
  --cream: #f9f6ec;
  --text: #0d0d0d;
  --sub: #6b6b6b;
  --line: #e5e5e5;
  --side-bg: #f9f9f9;
  --hover: #ececec;
  --bubble: #f2f2f2;
  --side-w: 260px;
  --col: 768px;
  --font: ui-sans-serif, -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html, body { height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: #fff;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
textarea { font: inherit; color: inherit; }

.app { display: flex; height: 100dvh; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--side-w);
  flex-shrink: 0;
  background: var(--side-bg);
  display: flex;
  flex-direction: column;
  padding: 8px;
  gap: 2px;
  transition: margin-left .2s ease, transform .2s ease;
}
.app.side-closed .sidebar { margin-left: calc(-1 * var(--side-w)); }

.sidebar-top { display: flex; justify-content: space-between; align-items: center; padding: 2px 2px 8px; }
.sidebar-icon { width: 30px; height: 30px; display: block; }

.icon-btn {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px;
  color: var(--sub);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

.side-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  text-align: left;
}
.side-item:hover { background: var(--hover); }

.side-heading { font-size: 12px; color: var(--sub); padding: 18px 10px 6px; }

.history { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.history-item {
  display: flex; align-items: center;
  border-radius: 8px;
  font-size: 14px;
}
.history-item:hover, .history-item.active { background: var(--hover); }
.history-item .open {
  flex: 1; min-width: 0;
  padding: 8px 10px;
  text-align: left;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-item .del {
  width: 30px; height: 30px; margin-right: 4px;
  border-radius: 6px; color: var(--sub);
  display: none; align-items: center; justify-content: center;
}
.history-item:hover .del, .history-item.active .del { display: inline-flex; }
.history-item .del:hover { color: var(--orange); }

.sidebar-bottom { border-top: 1px solid var(--line); padding: 10px 10px 4px; }
.side-note { font-size: 12px; color: var(--sub); line-height: 1.4; }

.scrim { display: none; }

/* ===== MAIN ===== */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

.topbar {
  height: 108px;
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 12px;
}
.topbar-left { display: flex; gap: 4px; }
.topbar-right { display: flex; justify-content: flex-end; }
#open-sidebar { visibility: hidden; }
.app.side-closed #open-sidebar { visibility: visible; }
.mobile-only { display: none; }

.brand img { height: 96px; width: auto; display: block; }

/* ===== CALL BUTTON ===== */
.call-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px;
  background: var(--orange);
  color: #fff;
  font-size: 14px; font-weight: 600;
  border-radius: 999px;
  transition: background .15s, transform .1s;
}
.call-btn:hover { background: #d93a08; }
.call-btn:active { transform: scale(.97); }
.call-btn.in-call { background: #1f9d55; }
.call-btn.in-call:hover { background: #188547; }

/* ===== THREAD ===== */
.thread { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.messages { max-width: var(--col); margin: 0 auto; padding: 16px 24px 40px; display: flex; flex-direction: column; gap: 28px; }

.empty { display: none; }
.app.is-empty .empty {
  display: flex; align-items: flex-end; justify-content: center;
  height: 42%;
  padding: 0 24px 28px;
}
.empty-title { font-size: 28px; font-weight: 500; letter-spacing: -.01em; text-align: center; }

.msg.user { align-self: flex-end; max-width: 75%; }
.msg.user .bubble {
  background: var(--bubble);
  padding: 10px 18px;
  border-radius: 22px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.assistant { align-self: stretch; }
.msg.assistant .body { word-wrap: break-word; }
.msg.assistant .body p + p { margin-top: 12px; }
.msg.assistant .body code { background: #f4f4f4; padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.msg.assistant .body a { color: var(--blue); }
.msg .tag { font-size: 12px; color: var(--sub); margin-bottom: 4px; display: flex; align-items: center; gap: 5px; }

.msg-tools { display: flex; gap: 2px; margin-top: 6px; opacity: 0; transition: opacity .15s; }
.msg.assistant:hover .msg-tools, .msg.assistant:last-child .msg-tools { opacity: 1; }
.tool-btn { width: 32px; height: 32px; border-radius: 8px; color: var(--sub); display: inline-flex; align-items: center; justify-content: center; }
.tool-btn:hover { background: var(--hover); color: var(--text); }

.thinking-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--text);
  animation: pulse 1s ease-in-out infinite;
  margin-top: 8px;
}
@keyframes pulse { 0%,100% { transform: scale(.7); opacity: .6; } 50% { transform: scale(1); opacity: 1; } }

/* ===== COMPOSER ===== */
.composer-wrap { padding: 0 24px 10px; flex-shrink: 0; }
.app.is-empty .composer-wrap { position: absolute; left: 0; right: 0; top: 50%; }
.composer {
  max-width: var(--col);
  margin: 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  background: #fff;
  border: 1px solid #d9d9d9;
  border-radius: 28px;
  padding: 10px 10px 10px 22px;
  box-shadow: 0 4px 16px rgba(0,0,0,.06), 0 0 1px rgba(0,0,0,.1);
}
.composer textarea {
  flex: 1;
  border: none; outline: none; resize: none;
  background: transparent;
  max-height: 200px;
  padding: 8px 0;
  line-height: 1.5;
}
.composer textarea::placeholder { color: #8f8f8f; }
.composer-actions { display: flex; gap: 6px; }

.round-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--text); color: #fff;
  transition: opacity .15s, background .15s;
}
.voice-btn { background: var(--blue); }
.voice-btn:hover { background: #0057d6; }
.send-btn, .stop-btn { display: none; }
.composer.has-text .send-btn { display: inline-flex; }
.composer.has-text .voice-btn { display: none; }
.composer.busy .send-btn, .composer.busy .voice-btn { display: none; }
.composer.busy .stop-btn { display: inline-flex; }

.disclaimer { text-align: center; font-size: 12px; color: var(--sub); padding-top: 8px; }
.app.is-empty .disclaimer { visibility: hidden; }

/* ===== VOICE MODE ===== */
.voice-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 12vh 24px calc(40px + env(safe-area-inset-bottom));
}
.voice-overlay[hidden] { display: none; }
.voice-center { display: flex; flex-direction: column; align-items: center; gap: 22px; }
.orb {
  width: 200px; height: 200px; border-radius: 28%;
  background: transparent;
  box-shadow: 0 0 0 0 rgba(10,108,255,.25);
  display: flex; align-items: center; justify-content: center;
  transition: transform .08s linear, box-shadow .2s;
  --level: 0;
  transform: scale(calc(1 + var(--level) * .18));
}
.orb img { width: 100%; height: 100%; border-radius: 28%; }
.orb.listening { box-shadow: 0 0 0 calc(6px + var(--level) * 30px) rgba(10,108,255,.18); }
.orb.speaking { box-shadow: 0 0 0 calc(6px + var(--level) * 30px) rgba(244,68,12,.2); }
.orb.connecting { animation: breathe 1.4s ease-in-out infinite; }
@keyframes breathe { 0%,100% { transform: scale(.94); } 50% { transform: scale(1.02); } }
.voice-status { font-size: 18px; font-weight: 500; }
.voice-caption { max-width: 560px; text-align: center; color: var(--sub); min-height: 3em; }
.voice-controls { display: flex; gap: 20px; }
.voice-ctl {
  width: 64px; height: 64px; border-radius: 50%;
  background: #f0f0f0;
  display: inline-flex; align-items: center; justify-content: center;
}
.voice-ctl:hover { background: #e4e4e4; }
.voice-ctl.muted { background: var(--text); color: #fff; }
.voice-ctl.end { background: var(--orange); color: #fff; }
.voice-ctl.end:hover { background: #d93a08; }

/* ===== MOBILE ===== */
@media (max-width: 800px) {
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 30;
    margin-left: 0 !important;
    transform: translateX(-100%);
  }
  .app.side-open .sidebar { transform: none; box-shadow: 0 0 24px rgba(0,0,0,.12); }
  .app.side-open .scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.25); }
  #open-sidebar { visibility: visible; }
  .mobile-only { display: inline-flex; }
  .topbar { padding: 0 6px; height: 88px; }
  .brand img { height: 66px; }
  .call-btn { padding: 8px 12px; }
  .messages { padding: 12px 16px 32px; }
  .composer-wrap { padding: 0 12px calc(8px + env(safe-area-inset-bottom)); }
  .msg.user { max-width: 85%; }
  .empty-title { font-size: 24px; }
}

/* Call button inside the text bar */
.composer .call-btn { height: 38px; padding: 0 16px; }
.composer-actions { align-items: center; }
@media (max-width: 800px) { .composer .call-btn { padding: 0 13px; } }

/* Voice mode hidden until the shampoooty.chat voice bot (not Andy) is set up */
body.no-voice .voice-btn, body.no-voice #side-voice { display: none !important; }

/* Phones: make room for the bigger logo (New chat stays in the side menu) */
@media (max-width: 800px) { #new-chat-top { display: none; } }
