* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font-family: inherit; cursor: pointer; }
a { color: var(--accent-ink); }

/* ---------- Sign-in screen ---------- */
#signin {
  height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 22px; padding: 24px; text-align: center;
}
#signin h1 { font-family: var(--font-display); font-size: 2rem; font-weight: 700; letter-spacing: -0.01em; }
#signin p { color: var(--text-dim); max-width: 380px; line-height: 1.5; }
.gbtn {
  display: inline-flex; align-items: center; gap: 10px;
  background: #fff; color: #1f1f1f; border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  padding: 12px 20px; border-radius: var(--radius-sm); font-size: 0.98rem; font-weight: 600;
}
.gbtn:hover { background: #fafafa; }
.signin-note { color: var(--text-faint); font-size: 0.82rem; }

/* ---------- App shell ---------- */
#app { display: none; height: 100dvh; grid-template-columns: 264px 1fr; }
@media (max-width: 760px) { #app { grid-template-columns: 1fr; } #sidebar { display: none; } }

#sidebar {
  background: var(--bg-raised); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.side-head { padding: 16px; display: flex; align-items: center; justify-content: space-between; }
.side-head .brand { font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; }
.newbtn {
  margin: 0 16px 10px; padding: 10px; border-radius: var(--radius-sm);
  background: var(--accent-soft); color: var(--accent-ink); border: 1px solid var(--border); font-weight: 600;
}
.navlink { display: block; margin: 0 16px 10px; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-dim); text-decoration: none; font-size: 0.88rem; border: 1px solid var(--border); }
.navlink:hover { color: var(--text); background: var(--bg-input); }
.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.conv {
  padding: 10px 12px; border-radius: var(--radius-sm); color: var(--text-dim);
  font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv:hover { background: var(--bg-input); color: var(--text); }
.conv.active { background: var(--bg-input); color: var(--text); }
.side-foot { padding: 12px 16px; border-top: 1px solid var(--border); font-size: 0.82rem; color: var(--text-faint);
  display: flex; align-items: center; justify-content: space-between; }
.side-foot button { background: none; border: none; color: var(--text-dim); font-size: 0.82rem; }

/* ---------- Chat ---------- */
#main { display: flex; flex-direction: column; min-height: 0; }
.topbar { display: none; padding: 12px 16px; border-bottom: 1px solid var(--border);
  align-items: center; justify-content: space-between; }
@media (max-width: 760px) { .topbar { display: flex; } }
.topbar .brand { font-family: var(--font-display); font-weight: 700; }

.budget-banner { display: flex; align-items: center; gap: 10px; background: var(--accent-soft);
  border-bottom: 1px solid var(--border); color: var(--accent-ink); padding: 10px 16px; font-size: 0.86rem; }
.budget-banner a { color: var(--accent-ink); font-weight: 700; white-space: nowrap; }
.budget-banner button { margin-left: auto; background: none; border: none; color: var(--accent-ink); font-size: 1.2rem; line-height: 1; }

.messages { flex: 1; overflow-y: auto; padding: 24px 16px 8px; }
.thread { max-width: var(--maxw); margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }

.msg { display: flex; flex-direction: column; gap: 6px; }
.msg .who { font-size: 0.74rem; color: var(--text-faint); }
.bubble { padding: 13px 15px; border-radius: var(--radius); line-height: 1.55; font-size: 0.96rem;
  white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-items: flex-end; }
.msg.user .bubble { background: var(--user-bubble); }
.msg.assistant .bubble { background: var(--bg-raised); border: 1px solid var(--border); }
.bubble.thinking { color: var(--text-faint); font-style: italic; }

.cites { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.cite { font-size: 0.78rem; color: var(--text-dim); background: var(--bg-input);
  border: 1px solid var(--border); padding: 3px 9px; border-radius: 20px; text-decoration: none; }
.cite:hover { color: var(--text); border-color: var(--accent-ink); }

.empty { max-width: var(--maxw); margin: 14vh auto 0; text-align: center; color: var(--text-dim); }
.empty h2 { font-family: var(--font-display); color: var(--text); font-weight: 700; font-size: 1.5rem; margin-bottom: 8px; }

/* ---------- Input bar ---------- */
.composer { padding: 12px 16px 18px; }
.composer-inner { max-width: var(--maxw); margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 8px 8px 14px; }
.composer textarea {
  flex: 1; background: none; border: none; color: var(--text); resize: none; outline: none;
  font-family: inherit; font-size: 0.98rem; line-height: 1.5; max-height: 160px; padding: 6px 0;
}
.iconbtn { width: 40px; height: 40px; border-radius: 10px; border: none; background: var(--bg-raised);
  color: var(--text-dim); display: grid; place-items: center; font-size: 1.1rem; }
.iconbtn:hover { color: var(--text); }
.iconbtn.send { background: var(--accent); color: var(--on-accent); }
.iconbtn.send:disabled { opacity: 0.45; cursor: default; }
.iconbtn.mic.recording { background: var(--danger); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(229,83,75,.5); } 50% { box-shadow: 0 0 0 6px rgba(229,83,75,0); } }
.composer-note { max-width: var(--maxw); margin: 6px auto 0; font-size: 0.74rem; color: var(--text-faint); text-align: center; }

/* Recording bar with live waveform */
.recbar { max-width: var(--maxw); margin: 0 auto 8px; display: flex; align-items: center; gap: 12px;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px 8px 14px; }
.recdot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); flex: 0 0 auto;
  animation: pulse 1.2s infinite; }
.wave { flex: 1; height: 40px; display: block; }
.rectext { font-size: 0.8rem; color: var(--text-dim); flex: 0 0 auto; }
.iconbtn.stop { background: var(--danger); color: #fff; }

/* Transcribing state: replace the waveform with a label */
.recbar.transcribing .recdot,
.recbar.transcribing .wave,
.recbar.transcribing .stop { display: none; }
.recbar.transcribing .rectext { color: var(--accent-ink); font-weight: 600; margin: 0 auto;
  animation: fade 1.2s ease-in-out infinite; }
@keyframes fade { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
