:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #0ea5e9;
  --accent-2: #38bdf8;
  --good: #22c55e;
  --bad: #ef4444;
  --warn: #f59e0b;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", "Heebo", Arial, sans-serif;
  direction: rtl; min-height: 100vh;
}
header {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg); padding: 12px 16px;
  border-bottom: 1px solid var(--surface-2);
  display: flex; align-items: center; justify-content: space-between;
}
header h1 { margin: 0; font-size: 18px; }
.install-btn {
  background: var(--accent); color: #000; border: 0;
  border-radius: 8px; padding: 6px 12px; font-weight: 700; font-size: 13px;
  cursor: pointer; white-space: nowrap; flex: 0 0 auto;
}
.install-btn:active { transform: scale(0.96); }
header { gap: 8px; }
nav.tabs {
  display: flex; gap: 4px; padding: 8px 16px; background: var(--bg);
  border-bottom: 1px solid var(--surface-2);
  position: sticky; top: 50px; z-index: 9;
}
nav.tabs button {
  flex: 1; background: var(--surface); border: 0; color: var(--text);
  padding: 10px; border-radius: var(--radius); font-size: 14px; cursor: pointer;
}
nav.tabs button.active { background: var(--accent); color: #000; font-weight: 600; }
main { padding: 12px 16px 100px; }

.filters {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px;
}
.filters .chip {
  background: var(--surface); border: 1px solid var(--surface-2);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; user-select: none;
}
.filters .chip.active { background: var(--accent); color: #000; border-color: var(--accent); }

.day-header {
  margin: 16px 0 8px; padding: 6px 10px;
  background: var(--surface); border-radius: var(--radius);
  font-weight: 600; font-size: 14px; color: var(--accent-2);
}

.card {
  background: var(--surface); border-radius: var(--radius);
  padding: 12px; margin-bottom: 10px;
}
.card .title { font-weight: 600; font-size: 15px; margin-bottom: 6px; line-height: 1.3; }
.card .meta { color: var(--muted); font-size: 13px; margin: 2px 0; }
.card .badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.badge {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--text);
}
.badge.free { background: var(--good); color: #000; }
.badge.sold { background: var(--bad); color: #fff; }
.badge.low { background: var(--warn); color: #000; }
.card .actions { display: flex; gap: 6px; margin-top: 10px; }
.card .actions a, .card .actions button {
  flex: 1; padding: 8px; border-radius: 8px; border: 0;
  background: var(--surface-2); color: var(--text); text-align: center;
  text-decoration: none; cursor: pointer; font-size: 13px;
}
.card .actions a.primary { background: var(--accent); color: #000; font-weight: 600; }
.card .actions button.good { background: var(--good); color: #000; }
.card .actions button.bad { background: var(--bad); color: #fff; }

/* chat */
.chat { display: flex; flex-direction: column; height: calc(100vh - 200px); }
.chat .chat-toolbar {
  display: flex; justify-content: flex-end; padding: 0 4px 6px;
}
.chat .icon-link {
  background: transparent; border: 0; color: var(--muted);
  font-size: 12px; cursor: pointer; padding: 4px 8px;
}
.chat .icon-link:hover { color: var(--bad); }
.chat .stream { flex: 1; overflow-y: auto; padding: 4px; }
.bubble {
  max-width: 85%; padding: 10px 14px; border-radius: var(--radius);
  margin: 6px 0; white-space: pre-wrap; line-height: 1.5;
  position: relative;
}
.bubble.user { background: var(--accent); color: #000; margin-inline-start: auto; }
.bubble.assistant { background: var(--surface); padding-inline-end: 38px; }
.bubble.system { background: var(--surface-2); color: var(--muted); font-size: 12px; }
.bubble-body { display: block; }
.bubble-play {
  position: absolute; top: 4px; inset-inline-end: 4px;
  background: var(--surface-2); color: var(--text);
  border: 0; border-radius: 999px; width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 14px; line-height: 1;
  opacity: 0.85; transition: opacity .15s, background .15s;
}
.bubble-play:hover { opacity: 1; background: var(--accent); color: #000; }
.bubble-play.loading {
  opacity: 1; background: var(--surface-2); color: transparent; pointer-events: none;
  background-image: conic-gradient(from 0deg, transparent, var(--accent));
  animation: spin 0.8s linear infinite;
}
.bubble-play.playing {
  background: var(--accent); color: #000;
  box-shadow: 0 0 0 0 rgba(14, 165, 233, 0.6);
  animation: micPulse 1.2s ease-out infinite;
}
.chat .input-row {
  display: flex; gap: 6px; padding: 8px 0;
  position: sticky; bottom: 0; background: var(--bg);
}
.chat .input-row textarea {
  flex: 1; background: var(--surface); border: 1px solid var(--surface-2);
  color: var(--text); border-radius: var(--radius); padding: 10px;
  font-family: inherit; font-size: 14px; resize: none; min-height: 44px; max-height: 120px;
}
.chat .input-row button {
  background: var(--accent); color: #000; border: 0;
  border-radius: var(--radius); padding: 0 14px; font-weight: 600; cursor: pointer;
}
.chat .input-row button.icon {
  background: var(--surface); color: var(--text); padding: 0 12px; font-size: 18px;
}
.chat .input-row button.icon.recording { background: var(--bad); color: #fff; }

/* profile */
.profile-section {
  background: var(--surface); border-radius: var(--radius); padding: 12px; margin-bottom: 12px;
}
.profile-section h3 { margin: 0 0 8px; font-size: 14px; color: var(--accent-2); }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.field label { font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--surface-2);
  border-radius: 8px; padding: 8px; font-family: inherit; font-size: 14px;
}
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 160px; min-width: 0; }
.row > .btn { flex: 0 0 auto; }
.row > input { flex: 1 1 200px; min-width: 0; }
.row > select { flex: 1 1 140px; min-width: 0; }

/* Tighter on phones — kids row stacks cleanly. */
@media (max-width: 480px) {
  .row > .field { flex: 1 1 100%; }
  .field input, .field select, .field textarea { width: 100%; }
  main { padding: 12px 12px 100px; }
}
.btn {
  background: var(--accent); color: #000; border: 0; border-radius: 8px;
  padding: 10px 14px; font-weight: 600; cursor: pointer; font-size: 14px;
}
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--bad); color: #fff; }

.empty { padding: 24px; text-align: center; color: var(--muted); }
.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid var(--surface-2); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Mic recording state — pulsing red ring so it's obvious */
.icon.recording, button.recording {
  background: var(--bad) !important;
  color: #fff !important;
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
  animation: micPulse 1.2s ease-out infinite;
}
@keyframes micPulse {
  0%   { box-shadow: 0 0 0 0   rgba(239, 68, 68, 0.6); }
  70%  { box-shadow: 0 0 0 14px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0   rgba(239, 68, 68, 0); }
}

/* ─── onboarding overlay ─── */
.onboarding {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(15, 23, 42, 0.92);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 16px; overflow: auto;
  backdrop-filter: blur(8px);
}
.onboarding[hidden] { display: none; }
.onboarding-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 22px 18px; width: 100%; max-width: 480px;
  border: 1px solid var(--surface-2);
  box-shadow: 0 16px 40px rgba(0,0,0,0.4);
}
.onboarding-card h2 { margin: 0 0 6px; font-size: 22px; }
.onboarding-card p.muted { color: var(--muted); margin: 0 0 16px; font-size: 14px; }
.onboarding-card small.muted { color: var(--muted); font-size: 12px; }
.onboarding-card .field { margin-bottom: 12px; }
.onboarding-card .row { margin-top: 14px; }
.onboarding-card #ob-kids { margin-bottom: 8px; }
.onboarding-card #ob-kids .row { margin-bottom: 8px; align-items: flex-end; }
.btn.primary { background: var(--accent); color: #000; }
