:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #e9eef5;
  background: #0a0f16;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 20% 0%, rgba(39, 113, 255, .16), transparent 35rem),
    radial-gradient(circle at 100% 100%, rgba(18, 184, 134, .10), transparent 32rem),
    #0a0f16;
}

button, textarea, input, select { font: inherit; }
button { cursor: pointer; }

.shell {
  width: min(920px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  padding: 28px clamp(16px, 4vw, 40px) 18px;
}

.topbar, .footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.topbar-actions { display: flex; align-items: center; gap: 10px; }
.utility-button {
  border: 1px solid #314158;
  border-radius: 10px;
  padding: 7px 10px;
  color: #bac7d8;
  background: #121b27;
}
.utility-button:hover { border-color: #6597ed; color: #fff; }

.history-panel {
  position: absolute;
  z-index: 10;
  top: 82px;
  left: 50%;
  width: min(860px, calc(100% - 32px));
  max-height: min(70vh, 680px);
  overflow-y: auto;
  transform: translateX(-50%);
  padding: 20px;
  border: 1px solid #314158;
  border-radius: 18px;
  background: rgba(12, 19, 28, .98);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .55);
}
.history-heading { display: flex; justify-content: space-between; gap: 16px; }
.history-heading h2 { margin: 0; font-size: 1.15rem; }
.history-help { margin: 12px 0 18px; color: #91a0b3; font-size: .85rem; }
.conversation-list { display: grid; gap: 8px; }
.history-search {
  width: 100%;
  margin-bottom: 14px;
  border: 1px solid #314158;
  border-radius: 10px;
  padding: 10px 12px;
  color: #e9eef5;
  background: #0e1722;
}
.memory-filters { display: grid; grid-template-columns: minmax(160px, .4fr) 1fr; gap: 10px; }
.memory-card {
  border: 1px solid #26364a;
  border-radius: 12px;
  padding: 13px 15px;
  background: #111c29;
}
.memory-card p { margin: 6px 0 0; white-space: pre-wrap; }
.memory-card a { color: #8db6ff; }
.memory-card-meta { color: #8494a8; font-size: .75rem; }
.conversation-item {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 14px;
  border: 1px solid #26364a;
  border-radius: 12px;
  padding: 12px 14px;
  color: #e9eef5;
  background: #111c29;
}
.conversation-item:hover, .conversation-item.active { border-color: #6597ed; background: #172842; }
.conversation-open {
  min-width: 0;
  display: grid;
  gap: 5px;
  text-align: left;
  border: 0;
  padding: 0;
  color: inherit;
  background: transparent;
}
.conversation-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.conversation-action {
  border: 1px solid #314158;
  border-radius: 8px;
  padding: 5px 7px;
  color: #9fb0c4;
  background: #101a27;
  font-size: .72rem;
}
.conversation-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-date, .conversation-count { color: #8494a8; font-size: .75rem; }
.history-empty { color: #91a0b3; }

.eyebrow {
  margin: 0 0 4px;
  color: #79a7ff;
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .18em;
}

h1 { margin: 0; font-size: clamp(1.5rem, 3vw, 2.15rem); letter-spacing: -.04em; }

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #aab6c5;
  font-size: .85rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #42d392;
  box-shadow: 0 0 0 5px rgba(66, 211, 146, .1);
}

.status.busy .status-dot { background: #f6c453; animation: pulse 1s infinite alternate; }
.status.error .status-dot { background: #ff6b6b; }
@keyframes pulse { to { opacity: .35; } }

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 42px 2px 28px;
  scroll-behavior: smooth;
}

.message {
  width: fit-content;
  max-width: min(720px, 92%);
  margin-bottom: 22px;
  padding: 15px 18px;
  border: 1px solid #243142;
  border-radius: 6px 20px 20px 20px;
  background: rgba(18, 27, 39, .88);
  line-height: 1.55;
  white-space: pre-wrap;
}

.message.user {
  margin-left: auto;
  border-color: #315ca8;
  border-radius: 20px 6px 20px 20px;
  background: #17335d;
}

.message p { margin: 0; }
.message-label { margin-bottom: 8px !important; color: #8fb4f8; font-size: .72rem; font-weight: 750; text-transform: uppercase; letter-spacing: .08em; }
.message-meta { margin-top: 12px !important; color: #8190a3; font-size: .75rem; }

.sources { margin: 14px 0 0; padding: 12px 0 0 20px; border-top: 1px solid #273447; }
.sources a { color: #8db6ff; text-decoration-thickness: 1px; text-underline-offset: 3px; }

.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.suggestions button, .clear {
  border: 1px solid #314158;
  border-radius: 999px;
  padding: 7px 11px;
  color: #bac7d8;
  background: #121b27;
}
.suggestions button:hover, .clear:hover { border-color: #6597ed; color: #fff; }

.composer {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  padding: 10px;
  border: 1px solid #2a394d;
  border-radius: 18px;
  background: rgba(16, 24, 35, .96);
  box-shadow: 0 18px 60px rgba(0, 0, 0, .32);
}

textarea {
  max-height: 180px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 11px 10px;
  color: #eff4fa;
  background: transparent;
}

.send {
  align-self: end;
  display: flex;
  gap: 10px;
  border: 0;
  border-radius: 12px;
  padding: 11px 15px;
  color: #07101d;
  background: #8db6ff;
  font-weight: 750;
}
.send:disabled { cursor: wait; opacity: .5; }
.mic {
  align-self: end;
  width: 42px;
  height: 42px;
  border: 1px solid #314158;
  border-radius: 12px;
  color: #ff8a8a;
  background: #172131;
}
.mic.recording { color: #fff; background: #c74444; animation: pulse .75s infinite alternate; }
.mic:disabled { cursor: not-allowed; opacity: .4; }

.footer { padding: 12px 3px 0; color: #68788c; font-size: .76rem; }
#session-label { overflow-wrap: anywhere; }
.footer-actions, .voice-toggle { display: flex; align-items: center; gap: 10px; }
.voice-toggle { color: #91a0b3; cursor: pointer; }
.voice-toggle input { accent-color: #8db6ff; }
.clear { padding: 5px 9px; font-size: .72rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }

@media (max-width: 560px) {
  .shell { padding-top: 18px; }
  .messages { padding-top: 28px; }
  .send span:first-child { display: none; }
  .message { max-width: 96%; }
  .topbar { align-items: flex-start; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
  .status { width: 100%; justify-content: flex-end; }
  .history-panel { top: 104px; }
  .memory-filters { grid-template-columns: 1fr; }
}
