/* OtterLite Web Client — iOS-first design */

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

:root {
  --bg: #1A2A28;
  --surface: #1E302D;
  --surface-light: #264A44;
  --primary: #4DB8A8;
  --primary-hover: #5ECEB8;
  --text: #F0EDE8;
  --text-muted: #8AAA9F;
  --user-bubble: #264A44;
  --assistant-bubble: #1C2E2B;
  --border: #2D4F48;
  --radius: 12px;
}

html {
  height: 100vh;   /* fallback for older iOS */
  height: 100dvh;  /* dynamic viewport height — fixes iOS Safari PWA bottom gap */
  overflow: hidden;
}

body {
  height: 100%;
  overflow: hidden; /* prevent body scroll; only #chat-container scrolls internally */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  /* safe-area insets applied once here only — applying to both html and body doubles them */
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* iOS: prevent double-tap zoom on all interactive elements.
   This replaces user-scalable=no which blocks input focus on iOS. */
input, button, textarea, select, a {
  touch-action: manipulation;
}

/* iOS: all inputs must be >= 16px to prevent auto-zoom in standalone mode. */
input, textarea {
  font-size: 16px;
  -webkit-appearance: none;
}

.hidden {
  display: none !important;
}

/* ---- Splash screen ---- */

#splash {
  position: fixed;
  inset: 0;
  background: #3B9E8F;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transition: opacity 0.4s ease;
}

#splash.fade-out {
  opacity: 0;
}

#splash-logo {
  width: 80%;
  max-width: 480px;
}

/* ---- Auth overlay ---- */

#auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#auth-box {
  text-align: center;
  padding: 32px;
  max-width: 320px;
  width: 100%;
}

#auth-logo {
  height: 100px;
  width: 100px;
  object-fit: contain;
  margin-bottom: 8px;
}

#auth-box p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 16px;
}

#token-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  margin-bottom: 12px;
  -webkit-text-security: disc;
}

#token-input:focus {
  border-color: var(--primary);
}

#token-submit {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
}

#token-submit:active {
  transform: scale(0.98);
}

#auth-error {
  color: #D4856A;
  margin-top: 12px;
  margin-bottom: 0;
}

/* ---- Main app layout ---- */

#app {
  display: flex;
  flex-direction: column;
  height: 100%;  /* fills body's content area (100dvh minus safe-area-inset-top padding) */
  overflow: hidden;
  max-width: 800px;
  margin: 0 auto;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

#header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

#header-logo {
  height: 54px;
  width: 54px;
  object-fit: contain;
}

#header-title {
  font-size: 1.6rem;
  font-weight: 500;
  letter-spacing: -0.5px;
  color: var(--text);
  position: relative;
  top: -2px;
  left: -5px;
}

#connection-status {
  font-size: 0.85rem;
  padding: 4px 9px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#connection-status.connected {
  background: #264A44;
  color: #5ECEB8;
}

#connection-status.disconnected {
  background: #3D2820;
  color: #D4856A;
  cursor: pointer;
}

#connection-status.error {
  background: #5A1E1E;
  color: #F5C1C1;
  cursor: pointer;
}

#header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  top: 1px;
}


/* ---- Chat container ---- */

#chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  position: relative;
}

/* ---- Scrollbar styling (chat + drawer) ---- */

#chat-container::-webkit-scrollbar,
.sessions-list::-webkit-scrollbar {
  width: 6px;
}
#chat-container::-webkit-scrollbar-track,
.sessions-list::-webkit-scrollbar-track {
  background: transparent;
}
#chat-container::-webkit-scrollbar-thumb,
.sessions-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
#chat-container::-webkit-scrollbar-thumb:hover,
.sessions-list::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ---- Scroll-to-bottom button ---- */

#scroll-bottom-btn {
  position: sticky;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
  transition: opacity 0.2s ease;
  z-index: 10;
}

#scroll-bottom-btn:hover {
  opacity: 1;
  color: var(--text);
  background: var(--surface-light);
}

#scroll-bottom-btn.hidden {
  opacity: 0;
  pointer-events: none;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 100%;
  justify-content: flex-end;
}

.message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
  font-size: 0.95rem;
}

.message.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message.historical {
  opacity: 0.65;
}

.message.status {
  align-self: center;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
  padding: 4px 8px;
}

.message.error {
  align-self: center;
  background: #3D2820;
  color: #D4856A;
  font-size: 0.85rem;
  padding: 6px 12px;
}

.message.transcription {
  align-self: flex-end;
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
  opacity: 0.7;
  font-style: italic;
}

.message.typing-indicator {
  align-self: flex-start;
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 14px;
}

.message.typing-indicator .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.message.typing-indicator .dot:nth-of-type(2) { animation-delay: 0.2s; }
.message.typing-indicator .dot:nth-of-type(3) { animation-delay: 0.4s; }

.message.typing-indicator .typing-cancel {
  background: none;
  border: none;
  color: currentColor;
  opacity: 0.5;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 2px;
  margin-left: 6px;
}
.message.typing-indicator .typing-cancel:hover { opacity: 1; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-6px); opacity: 1; }
}

.message.alert {
  align-self: flex-start;
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-bottom-left-radius: 4px;
}

/* ---- Recall summary card ---- */

.recall-summary-card {
  align-self: stretch;
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.recall-summary-card-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.recall-summary-card-body {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
}

.recall-summary-open-btn {
  margin-top: 2px;
  padding: 6px 14px;
  border: 1px solid var(--primary);
  border-radius: 8px;
  background: transparent;
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  align-self: flex-start;
}

.recall-summary-open-btn:hover { background: rgba(77, 184, 168, 0.1); }
.recall-summary-open-btn:active { transform: scale(0.97); }

/* ---- New session button ---- */

#new-session-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 10px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#new-session-btn:hover, #new-session-btn:active {
  color: var(--text);
  background: var(--surface-light);
}

body:not(.connected) #new-session-btn {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---- Markdown rendering in assistant/alert bubbles ---- */

.message.assistant,
.message.alert {
  white-space: normal;
}

.message.assistant p,
.message.alert p {
  margin: 0 0 0.5em;
}

.message.assistant p:last-child,
.message.alert p:last-child {
  margin-bottom: 0;
}

.message.assistant ul,
.message.alert ul,
.message.assistant ol,
.message.alert ol {
  margin: 0.25em 0 0.5em 1.25em;
  padding: 0;
}

.message.assistant li,
.message.alert li {
  margin-bottom: 0.2em;
}

.message.assistant code,
.message.alert code {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.88em;
  background: rgba(255,255,255,0.08);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.message.assistant pre,
.message.alert pre {
  background: rgba(0,0,0,0.25);
  border-radius: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 0.4em 0;
}

.message.assistant pre code,
.message.alert pre code {
  background: transparent;
  padding: 0;
  font-size: 0.85em;
}

.message.assistant strong,
.message.alert strong {
  font-weight: 600;
}

.message.assistant em,
.message.alert em {
  font-style: italic;
}

.message.assistant a,
.message.alert a {
  color: var(--primary);
  text-decoration: underline;
}

.message.assistant img,
.message.alert img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  display: block;
  margin: 0.4em 0;
}

/* Inline images — appear in user bubbles (history replay) and assistant bubbles */
.inline-image {
  display: block;
  max-width: 400px;
  width: 100%;
  height: auto;
  border-radius: 8px;
  margin-top: 6px;
  cursor: zoom-in;
}

/* Lightbox overlay */
#image-lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
#image-lightbox.open { display: flex; }
#image-lightbox img {
  max-width: 92vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}

.message.assistant blockquote,
.message.alert blockquote {
  border-left: 3px solid var(--border);
  margin: 0.4em 0;
  padding-left: 0.75em;
  color: var(--text-muted);
}

.message.assistant hr,
.message.alert hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.5em 0;
}

/* ---- Token count footer ---- */

.message-meta {
  margin-top: 6px;
  padding-top: 5px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
}

/* ---- Confirmation prompt ---- */

.confirmation {
  align-self: flex-start;
  background: var(--surface-light);
  border: 1px solid var(--primary);
  padding: 12px 14px;
  border-radius: var(--radius);
}

.confirmation p {
  margin-bottom: 10px;
}

.confirmation-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-confirm {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.btn-confirm:hover { color: var(--text); border-color: var(--text-muted); }
.btn-confirm:active { transform: scale(0.97); }

.btn-deny {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.btn-deny:hover { color: var(--text); border-color: var(--text-muted); }
.btn-deny:active { transform: scale(0.97); }

.confirmation-auth-row {
  margin-top: 10px;
  gap: 8px;
  align-items: center;
}

.confirmation-auth-input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.confirmation-auth-input:focus {
  border-color: var(--primary);
}

.confirmation-auth-input::placeholder {
  color: var(--text-muted);
}

.btn-authorize-submit {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-authorize-submit:active {
  transform: scale(0.97);
}

.btn-authorize-cancel {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-authorize-cancel:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

/* ---- Controls bar ---- */

#controls {
  position: relative;
  overflow: hidden;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

#controls-track {
  display: flex;
  flex-wrap: nowrap;
  flex-shrink: 0;
  width: 200%;
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

#controls-primary,
#controls-secondary {
  flex: 0 0 50%;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

/* Text input takes all available width */
#text-input {
  flex: 1;
  min-width: 0;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}

#app.connected #text-input {
  border-color: #5ECEB8;
}

#app.disconnected #text-input {
  border-color: #D4856A;
}

/* Arrow navigation buttons — small, muted */
.panel-arrow {
  width: 28px !important;
  height: 44px !important;
  border-radius: 8px !important;
  background: none !important;
  color: var(--text-muted) !important;
  flex-shrink: 0;
  font-size: 20px;
  line-height: 1;
}
.panel-arrow:hover { color: var(--text) !important; background: none !important; }

/* Standard buttons */
#controls button {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: var(--surface-light);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

#controls button:hover { background: #2D5C54; }
#controls button:active { transform: scale(0.95); }

/* Mic — slightly larger, primary action */
#mic-btn { width: 56px; height: 56px; }

/* Conv toggle — teal ring when active */
#conv-btn.active {
  background: var(--surface-light);
  color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary);
}

/* Stop — grows in from nothing when agent is busy, spreading the other buttons apart */
#stop-btn {
  max-width: 0;
  min-width: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.7);
  transition: max-width 0.25s ease, opacity 0.2s ease, transform 0.2s ease;
}
#stop-btn.active {
  max-width: 64px;
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
  background: #C0392B;
  color: #fff;
}

/* Voice panel — image pinned left, conv+mic+stop group pinned right */
#image-btn-voice { margin-right: auto; }

#mic-btn.recording {
  background: #D4856A;
  animation: pulse 1.2s infinite;
}

#mic-btn.recording:hover {
  background: #D4856A;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(212, 133, 106, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(212, 133, 106, 0); }
}

#mic-btn.waiting {
  background: #2D8C7E;
  animation: pulse-wait 1.8s infinite;
}

#mic-btn.waiting:hover {
  background: #2D8C7E;
}

@keyframes pulse-wait {
  0%, 100% { box-shadow: 0 0 0 0 rgba(45, 140, 126, 0.4); }
  50%       { box-shadow: 0 0 0 8px rgba(45, 140, 126, 0); }
}

/* Conversation mode:
   base (cannot speak — agent processing/playing) = red
   waiting/recording (mic opening or open, no speech yet) = light blue
   recording.speaking (speech onset detected) = dark blue */
#mic-btn.conversation {
  background: #DC2626;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.4);
}

#mic-btn.conversation:hover {
  background: #B91C1C;
}

#mic-btn.conversation.waiting,
#mic-btn.conversation.recording {
  background: #60A5FA;
  box-shadow: none;
  animation: pulse-conv-listen 1.8s infinite;
}

#mic-btn.conversation.recording.speaking {
  background: #1D4ED8;
  animation: pulse-conv-speaking 1.2s infinite;
}

@keyframes pulse-conv-listen {
  0%, 100% { box-shadow: 0 0 0 0 rgba(96, 165, 250, 0.4); }
  50%       { box-shadow: 0 0 0 8px rgba(96, 165, 250, 0); }
}

@keyframes pulse-conv-speaking {
  0%, 100% { box-shadow: 0 0 0 0 rgba(29, 78, 216, 0.5); }
  50%       { box-shadow: 0 0 0 10px rgba(29, 78, 216, 0); }
}

/* ---- Recall banner ---- */

#recall-banner {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  background: var(--surface-light);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  font-size: 0.78rem;
  color: var(--text-muted);
  max-width: 320px;
  overflow: hidden;
  flex-wrap: wrap;
  line-height: 1.4;
}
#recall-banner.hidden { display: none; }
#recall-banner-text {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
#recall-banner-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 2px;
  font-size: 0.9rem;
  line-height: 1;
}
#recall-banner-close:hover { color: var(--text); }

/* ---- Sessions history button ---- */

#sessions-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 3px 5px;
  line-height: 1;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  position: relative;
  top: 2px;
}
#sessions-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

/* ---- Session history drawer ---- */

.sessions-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.sessions-overlay.hidden {
  display: block !important; /* stay in DOM so opacity transition fires */
}
.sessions-overlay:not(.hidden) {
  opacity: 1;
  pointer-events: all;
}

.sessions-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  height: 100%;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 201;
  overflow: hidden;
  transform: translateX(-100%);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
@media (min-width: 768px) {
  .sessions-drawer { width: 630px; }
}
@media (min-width: 1200px) {
  .sessions-drawer { width: 720px; }
}
.sessions-drawer:not(.hidden) {
  transform: translateX(0);
}
.sessions-drawer.hidden {
  display: flex !important; /* stay in DOM so transform transition fires */
  pointer-events: none;
}

.sessions-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  flex-shrink: 0;
}
#sessions-drawer-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}
#sessions-drawer-close:hover { color: var(--text); }

.sessions-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.sessions-date-group {
  padding: 8px 16px 4px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.session-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 16px;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.12s;
}
.session-item:hover { background: rgba(255, 255, 255, 0.05); }
.session-item.active { background: rgba(77, 184, 168, 0.12); }

.session-item-time {
  font-size: 0.95rem;
  color: var(--primary);
  font-weight: 500;
}
.session-item-summary {
  font-size: 0.95rem;
  color: var(--text-muted);
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}
.session-item-current {
  font-style: italic;
  opacity: 0.6;
}
.session-item-preview {
  font-style: italic;
  opacity: 0.75;
}

.session-item-delete-btn {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  opacity: 0;
  padding: 4px 6px;
  line-height: 1;
  border-radius: 4px;
  transition: opacity 0.15s, background 0.15s;
}
.session-item:hover .session-item-delete-btn { opacity: 0.6; }
.session-item-delete-btn:hover {
  opacity: 1 !important;
  color: var(--error, #c0392b);
  background: rgba(192, 57, 43, 0.1);
}

/* Overlay confirm strip over the compact row without changing its height */
.session-item .delete-confirm-strip {
  position: absolute;
  inset: 0;
  background: var(--surface);
  border-radius: 0;
  padding: 0 16px;
  justify-content: flex-end;
  z-index: 1;
}

.sessions-empty {
  padding: 24px 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

/* Main transcript exchange wrappers */
.main-exchange {
  position: relative;
  display: flex;
  flex-direction: column;
  padding-right: 36px;
}
.main-exchange-delete-btn {
  position: absolute;
  top: 8px;
  right: 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.95rem;
  opacity: 0.4;
  padding: 4px 7px;
  line-height: 1;
  border-radius: 4px;
  transition: opacity 0.15s, background 0.15s;
}
.main-exchange:hover .main-exchange-delete-btn,
.main-exchange-delete-btn:focus { opacity: 1; }
.main-exchange-delete-btn:hover { color: var(--error, #c0392b); background: rgba(192,57,43,0.1); }

/* Inline delete-confirm strip (shown after first click on × button) */
.delete-confirm-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
  align-self: flex-end;
}
.delete-confirm-yes,
.delete-confirm-no {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 2px 10px;
  transition: background 0.1s, color 0.1s;
}
.delete-confirm-yes { color: var(--error, #c0392b); border-color: var(--error, #c0392b); }
.delete-confirm-yes:hover { background: var(--error, #c0392b); color: #fff; }
.delete-confirm-no { color: var(--text-muted); }
.delete-confirm-no:hover { color: var(--text); background: var(--surface-light); }

/* Attachment bubble in transcript */
.message.attachment {
  align-self: flex-start;
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
}
.message.attachment img {
  width: 56px; height: 56px;
  object-fit: cover; border-radius: 6px; flex-shrink: 0;
}
.message.attachment .attachment-info {
  flex: 1; font-size: 0.85rem; color: var(--text-muted);
}
.message.attachment .attachment-clear {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 16px; padding: 0; line-height: 1;
}

/* ---- Responsive ---- */

@media (max-width: 600px) {
  header {
    padding: 8px 12px;
  }
  #chat-container {
    padding: 10px;
  }
  #controls-primary,
  #controls-secondary {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    gap: 8px;
  }
  .message {
    max-width: 92%;
    font-size: 1.15rem;
  }
  #controls button { width: 52px; height: 52px; }
  #mic-btn         { width: 60px; height: 60px; }
  #text-input      { padding: 14px 18px; font-size: 18px; border-radius: 26px; }
  #controls button svg { width: 26px; height: 26px; }
  /* Arrows hidden on mobile — swipe handles panel switching */
  .panel-arrow { display: none !important; }
}

/* ── Todo card ───────────────────────────────────────────────────────────── */

.todo-card {
  background: var(--surface-light);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.todo-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text);
}

.todo-checkbox {
  width: 18px;
  height: 18px;
  border: 2px solid var(--primary);
  border-radius: 4px;
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.todo-checkbox.checked {
  background: var(--primary);
}

.todo-checkbox.checked::after {
  content: "✓";
  color: #fff;
  font-size: 12px;
  font-weight: bold;
  line-height: 1;
}

.todo-card .done {
  text-decoration: line-through;
  opacity: 0.5;
}

.todo-card .todo-due {
  margin-left: auto;
  font-size: 0.75em;
  opacity: 0.6;
  white-space: nowrap;
}

/* Vision image grid card */
.vision-card {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  padding: 8px 0;
}

.vision-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.vision-cell img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}

.vision-cell img:hover {
  border-color: var(--accent, #4a9eff);
}

.vision-caption {
  font-size: 0.7em;
  opacity: 0.6;
  text-align: center;
}

.vision-card--single {
  display: block;
}

.vision-card--single .vision-cell {
  width: 400px;
}

/* ---- Background-error modal ---- */

.error-surface-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}

.error-surface-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 18px;
  min-width: 280px;
  max-width: 420px;
  max-height: 60vh;
  overflow-y: auto;
  color: var(--text);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
}

.error-surface-title {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 10px;
}

.error-surface-list {
  list-style: none;
  padding: 0;
  margin: 0 0 12px 0;
}

.error-surface-list li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.error-surface-list li:last-child {
  border-bottom: none;
}

.error-surface-source {
  font-weight: 600;
  color: #F5C1C1;
  font-size: 0.85rem;
}

.error-surface-reason {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 2px;
  word-break: break-word;
}

.error-surface-when {
  color: var(--text-muted);
  font-size: 0.7rem;
  margin-top: 2px;
}

.error-surface-close {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}

.error-surface-close:hover {
  background: rgba(255, 255, 255, 0.06);
}
