/* ── Design tokens ───────────────────────────────────────────────── */
:root {
  --bg-0:#040a14; --bg-1:#060d1a; --bg-2:#0a1422; --bg-3:#0f1e30; --bg-4:#1a2d44;
  --text-0:#e2e8f0; --text-1:#b0bec5; --text-2:#78909c; --text-3:#546e7a;
  --border:#1e3a5f; --border-hi:#2d5a8e;
  --teal:#0d9488; --blue:#2563eb; --ok:#16a34a; --warn:#d97706; --err:#dc2626;
  --red:#ef4444;
  --sans:'Space Grotesk', system-ui, sans-serif;
  --mono:'JetBrains Mono', 'Courier New', monospace;
  --radius:8px; --radius-lg:12px; --card:var(--bg-2);
  --media-btn-size: 42px;
}

/* ── Reset / base ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body,
body.briefcast-shell,
#page, #primary, #content,
.site, .site-content {
  background: var(--bg-0) !important;
  color: var(--text-0);
}
body {
  font-family: var(--sans) !important;
  margin: 0;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
body.briefcast-shell, body.briefcast-shell * {
  font-family: var(--sans) !important;
}

/* ── Shell wrapper ───────────────────────────────────────────────── */
.ff-shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 12px 14px;
  min-height: 100vh;
}

/* ── Breadcrumb ──────────────────────────────────────────────────── */
.saap-crumbs {
  display: flex;
  align-items: center;
  font-family: var(--mono) !important;
  font-size: .82rem;
  color: var(--text-2);
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 2px;
}
.saap-crumbs .c + .c::before { content: ' | '; padding: 0 5px; color: var(--border-hi); }
.saap-crumbs a { color: var(--teal); text-decoration: none; }

/* ── Hero ────────────────────────────────────────────────────────── */
.ff-hero {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}
.ff-kicker {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: .15em;
  color: var(--teal);
  font-size: .68rem;
}
.ff-hero h1 { margin: 0 0 4px; font-size: 1.75rem; line-height: 1.1; }
.ff-sub { margin: 0; font-size: .92rem; line-height: 1.45; color: var(--text-1); max-width: 52ch; }
.ff-token-pill {
  background: rgba(37,99,235,.12);
  border: 1px solid rgba(37,99,235,.25);
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 1rem;
  white-space: nowrap;
}
.ff-token-stack { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* ── Tabs ────────────────────────────────────────────────────────── */

/* ── Content grid ────────────────────────────────────────────────── */
.ff-grid {
  display: grid;
  grid-template-columns: 1fr;   /* mobile: single column */
  gap: 14px;
}
.ff-main, .ff-side { min-width: 0; }
.ff-side { display: none; }     /* sidebar hidden on mobile */

/* ── Panels ──────────────────────────────────────────────────────── */
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

/* ── Cards ───────────────────────────────────────────────────────── */
.ff-card, .ff-briefing-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
}
.ff-briefing-card { margin-bottom: 12px; line-height: 1.6; font-size: .95rem; }
.ff-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.ff-panel-head h2, .ff-card h3 { margin: 0; }

/* ── Buttons ─────────────────────────────────────────────────────── */
.ff-btn {
  background: var(--blue);
  color: #fff;
  border: 1px solid rgba(37,99,235,.45);
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  font-family: var(--sans) !important;
  font-size: .9rem;
  transition: filter .15s;
}
.ff-btn:hover { filter: brightness(1.1); }
.ff-btn-ghost {
  background: transparent;
  color: var(--text-0);
  border-color: var(--border-hi);
}
.ff-btn-sm { padding: 7px 11px; font-size: .82rem; }

/* Icon button — square, centred icon */
.ff-icon-btn {
  width: var(--media-btn-size);
  height: var(--media-btn-size);
  min-width: var(--media-btn-size);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  flex-shrink: 0;
}
.ff-icon-btn svg { pointer-events: none; }

/* ── Chat form ───────────────────────────────────────────────────── */
.ff-chat-form {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  align-items: center;
}
.ff-chat-form .ff-input { flex: 1; }
/* Send button is smaller inside chat form */
.ff-chat-form .ff-icon-btn {
  width: 42px;
  height: 42px;
  min-width: 42px;
  background: var(--blue);
  border-color: rgba(37,99,235,.45);
  color: #fff;
}

/* ── Chat log ────────────────────────────────────────────────────── */
.ff-chatlog {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px;
  min-height: 140px;
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ff-bubble {
  max-width: 80%;
  padding: 9px 13px;
  border-radius: 12px;
  font-size: .875rem;
  line-height: 1.5;
  word-wrap: break-word;
}
.ff-bubble-user     { align-self: flex-end;   background: rgba(37,99,235,.15);  border: 1px solid rgba(37,99,235,.3); }
.ff-bubble-assistant{ align-self: flex-start; background: rgba(13,148,136,.12); border: 1px solid rgba(13,148,136,.25); }
.ff-bubble-system   { align-self: center; color: var(--text-3); font-style: italic; font-size: .78rem; border: none; background: none; padding: 2px 0; }

/* ── Media toolbar ───────────────────────────────────────────────── */
.ff-media-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.ff-media-btn {
  width: var(--media-btn-size);
  height: var(--media-btn-size);
  border-radius: 10px;
  color: var(--text-1);
  border-color: var(--border);
  transition: color .15s, border-color .15s, background .15s;
}
.ff-media-btn:hover { color: var(--text-0); border-color: var(--border-hi); }

/* Active states */
.ff-media-btn.is-active-voice {
  color: var(--teal);
  border-color: rgba(13,148,136,.5);
  background: rgba(13,148,136,.08);
}
.ff-media-btn.is-active-voice:hover { background: rgba(13,148,136,.14); }

.ff-media-btn.is-active-stop {
  color: var(--err);
  border-color: rgba(220,38,38,.4);
  background: rgba(220,38,38,.08);
}

.ff-media-btn.is-muted {
  color: var(--warn);
  border-color: rgba(217,119,6,.4);
  background: rgba(217,119,6,.08);
}

.ff-media-btn.is-active-camera {
  color: var(--blue);
  border-color: rgba(37,99,235,.4);
  background: rgba(37,99,235,.08);
}

/* Capture/record button */
.ff-capture-btn { position: relative; }
.ff-capture-indicator {
  display: block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--err);
  flex-shrink: 0;
}
.ff-capture-indicator.is-recording {
  animation: ff-pulse 1.2s ease-in-out infinite;
}
.ff-capture-indicator.ff-capture-photo {
  border-radius: 3px;   /* square = photo mode */
  background: var(--text-0);
}
@keyframes ff-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .4; transform: scale(.8); }
}

/* Divider between voice and camera groups */
.ff-media-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 2px;
  flex-shrink: 0;
}

/* ── Camera viewport ─────────────────────────────────────────────── */
.ff-camera-wrap {
  margin-top: 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}
.ff-camera-viewport { position: relative; }
#cameraFeed {
  width: 100%;
  max-height: 260px;
  display: block;
  background: #000;
  border-radius: 0;
  object-fit: cover;
}
.ff-recording-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0,0,0,.65);
  color: #fff;
  font-size: .75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: .08em;
}
.ff-rec-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--err);
  animation: ff-pulse 1.2s ease-in-out infinite;
}

/* ── Inputs ──────────────────────────────────────────────────────── */
.ff-input, select.ff-input {
  width: 100%;
  background: var(--bg-1);
  color: var(--text-0);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: var(--sans) !important;
  font-size: .9rem;
}
.ff-input::placeholder { color: var(--text-2); opacity: 1; }
.ff-input:focus { outline: none; border-color: var(--border-hi); }

/* Reveal wrapper for password input */
.ff-input-reveal {
  position: relative;
  display: flex;
  align-items: center;
}
.ff-input-reveal .ff-input { padding-right: 48px; }
.ff-reveal-btn {
  position: absolute;
  right: 4px;
  width: 36px;
  height: 36px;
  min-width: 36px;
  border: none;
  background: transparent;
  color: var(--text-2);
}
.ff-reveal-btn:hover { color: var(--text-0); }

/* ── Forms ───────────────────────────────────────────────────────── */
.ff-form-grid {
  display: grid;
  grid-template-columns: 1fr;  /* single col on mobile */
  gap: 12px;
}
.ff-form-grid label span { display: block; font-size: .8rem; color: var(--text-1); margin-bottom: 5px; }
.full-span { grid-column: 1 / -1; }
.ff-fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; grid-column: 1 / -1; }
.ff-fieldset legend { padding: 0 6px; color: var(--text-1); font-size: .85rem; }
.ff-checks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ff-checkline { display: flex; align-items: center; gap: 8px; color: var(--text-1); font-size: .9rem; }
.ff-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ── Settings ────────────────────────────────────────────────────── */
.ff-settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
.ff-settings-card h3 { margin: 0 0 6px; }

/* Toggle switch */
.ff-toggle-list { display: flex; flex-direction: column; gap: 0; }
.ff-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  gap: 12px;
}
.ff-toggle-row:last-child { border-bottom: none; }
.ff-toggle-row span { font-size: .9rem; color: var(--text-1); flex: 1; }
.ff-toggle-switch { position: relative; flex-shrink: 0; }
.ff-toggle-check { position: absolute; opacity: 0; width: 0; height: 0; }
.ff-toggle-pill {
  display: block;
  width: 42px; height: 24px;
  background: var(--bg-4);
  border: 1px solid var(--border-hi);
  border-radius: 999px;
  position: relative;
  transition: background .2s, border-color .2s;
  cursor: pointer;
}
.ff-toggle-pill::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--text-2);
  transition: transform .2s, background .2s;
}
.ff-toggle-check:checked + .ff-toggle-pill { background: rgba(13,148,136,.25); border-color: var(--teal); }
.ff-toggle-check:checked + .ff-toggle-pill::after { transform: translateX(18px); background: var(--teal); }

/* ── Misc helpers ────────────────────────────────────────────────── */
.ff-hidden { display: none !important; }
.ff-help { color: var(--text-1); line-height: 1.5; font-size: .88rem; margin: 0; }
.ff-mini-stats { display: grid; grid-template-columns: 1fr; gap: 8px; }
.ff-mini-stats div { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.ff-mini-stats span { color: var(--text-2); }
.ff-status-row { display: flex; justify-content: space-between; gap: 10px; margin: 0 0 10px; color: var(--text-2); font-size: .8rem; flex-wrap: wrap; }
.ff-columns { display: grid; grid-template-columns: 1fr; gap: 12px; }
.ff-news-item { padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,.05); }
.ff-news-item:last-child { border-bottom: none; }
.ff-news-item a { color: var(--teal); text-decoration: none; }
.ff-news-item small { color: var(--text-2); display: block; margin-top: 4px; }
.ff-weather-stat { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
.ff-weather-stat div { background: var(--bg-1); border: 1px solid rgba(255,255,255,.05); border-radius: 10px; padding: 10px; font-size: .88rem; }
.ff-history-list { display: grid; gap: 10px; }
.ff-history-item { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.ff-build-footer { margin-top: 16px; text-align: right; font-family: var(--mono) !important; font-size: .82rem; color: var(--text-2); }

audio#remoteAudio { width: 0; height: 0; opacity: 0; position: absolute; pointer-events: none; }

/* ── Tablet: 640px+ ──────────────────────────────────────────────── */
@media (min-width: 640px) {
  .ff-shell { padding: 16px 20px; }
  .ff-hero h1 { font-size: 2rem; }
  .ff-form-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .ff-columns { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .ff-checks { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .ff-settings-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .ff-settings-grid .full-span { grid-column: 1 / -1; }
  #cameraFeed { max-height: 320px; }
}

/* ── Desktop: 960px+ ─────────────────────────────────────────────── */
@media (min-width: 960px) {
  .ff-shell { padding: 20px 24px; }
  .ff-grid { grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); }
  .ff-side { display: block; }
  .ff-chatlog { max-height: 360px; }
  #cameraFeed { max-height: 360px; }
}

/* ── VAD — voice activity indicator ─────────────────────────────── */
.ff-vad-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding: 8px 12px;
  background: rgba(13,148,136,.08);
  border: 1px solid rgba(13,148,136,.2);
  border-radius: 10px;
  width: fit-content;
}
.ff-vad-dot {
  width: 4px;
  height: 16px;
  border-radius: 2px;
  background: var(--teal);
  opacity: .25;
  transform-origin: center bottom;
  transition: height .1s, opacity .1s;
}
/* Animated when speaking */
.ff-vad-bar.is-speaking .ff-vad-dot:nth-child(1) { animation: ff-vad 0.8s ease-in-out infinite 0.0s; }
.ff-vad-bar.is-speaking .ff-vad-dot:nth-child(2) { animation: ff-vad 0.8s ease-in-out infinite 0.1s; }
.ff-vad-bar.is-speaking .ff-vad-dot:nth-child(3) { animation: ff-vad 0.8s ease-in-out infinite 0.2s; }
.ff-vad-bar.is-speaking .ff-vad-dot:nth-child(4) { animation: ff-vad 0.8s ease-in-out infinite 0.1s; }
.ff-vad-bar.is-speaking .ff-vad-dot:nth-child(5) { animation: ff-vad 0.8s ease-in-out infinite 0.0s; }
@keyframes ff-vad {
  0%, 100% { height: 4px;  opacity: .2; }
  50%       { height: 20px; opacity: 1;  }
}
.ff-vad-label {
  font-size: .75rem;
  color: var(--teal);
  margin-left: 6px;
  font-family: var(--mono) !important;
}
/* ── Tab nav — underline style (factory standard) ───────────────────────── */
.ff-tabs {
  display: flex; gap: 0; flex-wrap: nowrap;
  padding: 10px 0 0; border-bottom: 2px solid var(--border);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none; overscroll-behavior-x: contain;
  align-items: flex-end;
}
.ff-tabs::-webkit-scrollbar { display: none; }
.ff-tab {
  background: none; border: none;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  color: var(--text-2, var(--muted)); padding: 8px 16px;
  font-size: .88rem; font-weight: 500; cursor: pointer;
  font-family: inherit; white-space: nowrap; transition: color .15s;
}
.ff-tab:hover:not(.is-active) { color: var(--text-1, var(--text)); }
.ff-tab.is-active { color: var(--teal); border-bottom-color: var(--teal); font-weight: 600; }
/* ── Space between nav and content ──────────────────────────────────────── */
.tab-panel.is-active { padding-top: 14px; }
