:root {
  --bg0: #070a12;
  --bg1: #0c1220;
  --panel: rgba(17, 24, 39, 0.72);
  --panel-solid: #111827;
  --text: #eef2ff;
  --muted: #94a3b8;
  --line: rgba(148, 163, 184, 0.16);
  --line-strong: rgba(148, 163, 184, 0.28);
  --blue: #3b82f6;
  --cyan: #22d3ee;
  --violet: #8b5cf6;
  --good: #34d399;
  --bad: #f87171;
  --warn: #fbbf24;
  --radius: 18px;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --font: "DM Sans", system-ui, -apple-system, Segoe UI, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text);
  font-family: var(--font);
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(59, 130, 246, 0.28), transparent 55%),
    radial-gradient(700px 400px at 100% 0%, rgba(139, 92, 246, 0.18), transparent 50%),
    radial-gradient(600px 400px at 80% 100%, rgba(34, 211, 238, 0.1), transparent 45%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
  background-attachment: fixed;
}

code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: rgba(255, 255, 255, 0.06);
  padding: 0.1em 0.4em;
  border-radius: 6px;
}

.shell {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px 18px 18px;
  border-right: 1px solid var(--line);
  background: rgba(8, 12, 22, 0.78);
  backdrop-filter: blur(20px);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 4px 4px 8px;
}
.logo {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.25rem;
  color: white;
  background: linear-gradient(135deg, var(--blue), var(--violet) 55%, var(--cyan));
  box-shadow: 0 10px 30px rgba(59, 130, 246, 0.35);
}
.brand-text h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.brand-text p,
.muted,
.label,
.side-foot,
header small {
  color: var(--muted);
  margin: 0;
  font-size: 0.85rem;
}
.brand-text p { margin-top: 2px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 6px;
  font-size: 1rem;
  letter-spacing: -0.01em;
}
.card > .muted { margin-bottom: 8px; line-height: 1.45; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--muted);
}
.field em { font-style: normal; opacity: 0.7; }
.field span { font-weight: 600; }

input, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(2, 6, 23, 0.75);
  color: var(--text);
  padding: 12px 13px;
  outline: none;
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus {
  border-color: rgba(59, 130, 246, 0.65);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

.btn {
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
  font-weight: 650;
  padding: 10px 14px;
  cursor: pointer;
  transition: transform 0.12s, background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(148, 163, 184, 0.4);
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  border: none;
  background: linear-gradient(135deg, var(--blue), #6366f1 50%, var(--cyan));
  color: white;
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.28);
}
.btn.primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: rgba(248, 113, 113, 0.45); color: #fecaca; }
.btn.block { width: 100%; margin-top: 12px; }
.btn.icon {
  width: 48px;
  height: 48px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
}
.btn.tiny { padding: 4px 8px; font-size: 0.85rem; border-radius: 8px; }
.btn.listening {
  border-color: rgba(248, 113, 113, 0.55);
  background: rgba(248, 113, 113, 0.18);
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.15);
  animation: pulse-mic 1.2s ease-in-out infinite;
}
@keyframes pulse-mic {
  0%, 100% { box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.12); }
  50% { box-shadow: 0 0 0 8px rgba(248, 113, 113, 0.08); }
}
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn-row .btn { flex: 1; margin: 0; min-width: 0; }

.session-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.session-head h2 { margin: 2px 0 0; font-size: 1.15rem; }
.label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; }

.pill {
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  white-space: nowrap;
}
.pill.online {
  color: #a7f3d0;
  border-color: rgba(52, 211, 153, 0.35);
  background: rgba(16, 185, 129, 0.12);
}
.pill.offline {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
}

.voice-meta {
  margin-top: 10px;
  font-size: 0.75rem;
  line-height: 1.35;
  word-break: break-word;
}

.menu-nav-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.menu-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.menu-item:hover { background: rgba(59, 130, 246, 0.12); border-color: rgba(59, 130, 246, 0.35); }
.menu-item .emoji { font-size: 1.1rem; width: 1.5rem; text-align: center; }
.menu-desc { margin-top: 4px !important; }

.side-foot {
  margin-top: auto;
  padding: 8px 4px 0;
  font-size: 0.75rem;
}

/* Main */
.main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 18, 32, 0.65);
  backdrop-filter: blur(16px);
}
.topbar h2 {
  margin: 2px 0 0;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.top-actions .btn { white-space: nowrap; }

.messages {
  padding: 22px 24px 28px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.empty {
  margin: auto;
  text-align: center;
  max-width: 360px;
  color: var(--muted);
  padding: 32px 16px;
}
.empty-icon { font-size: 2rem; margin-bottom: 8px; opacity: 0.85; }
.empty h3 { margin: 0 0 8px; color: var(--text); font-size: 1.1rem; }
.empty p { margin: 0; line-height: 1.5; font-size: 0.95rem; }

.msg {
  max-width: min(760px, 92%);
  padding: 12px 15px;
  border: 1px solid var(--line);
  border-radius: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  animation: rise 0.22s ease;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.msg.user {
  align-self: flex-end;
  background: linear-gradient(145deg, rgba(37, 99, 235, 0.35), rgba(99, 102, 241, 0.22));
  border-color: rgba(96, 165, 250, 0.28);
}
.msg.assistant {
  align-self: flex-start;
  background: rgba(17, 24, 39, 0.88);
}
.msg.error {
  align-self: flex-start;
  border-color: rgba(248, 113, 113, 0.35);
  background: rgba(127, 29, 29, 0.25);
}
.msg.pending {
  opacity: 0.72;
  font-style: italic;
}
.msg .body { white-space: pre-wrap; }
.msg .body .code-block {
  display: block;
  margin: 8px 0 4px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.65);
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.82rem;
  overflow-x: auto;
  white-space: pre-wrap;
}
.msg .body code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: rgba(255, 255, 255, 0.06);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}
.meta {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.composer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: end;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
  background: rgba(11, 18, 32, 0.78);
  backdrop-filter: blur(16px);
}
.composer textarea {
  margin: 0;
  resize: none;
  min-height: 48px;
  max-height: 160px;
  line-height: 1.4;
  padding-top: 13px;
}
.composer .btn { margin: 0; }

.error {
  color: #fecaca;
  margin-top: 10px;
  font-size: 0.85rem;
  min-height: 1.2em;
}
.hint {
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--muted);
  white-space: pre-wrap;
  line-height: 1.45;
}
.hint.ok { color: #a7f3d0; }
.hint.bad { color: #fecaca; }

.hidden { display: none !important; }

/* Modal */
.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: min(560px, calc(100vw - 24px));
  width: 100%;
  color: var(--text);
}
.modal::backdrop {
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(6px);
}
.modal-card {
  background: linear-gradient(180deg, #121a2b, #0c1220);
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 18px 18px 16px;
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.modal-head h3 { margin: 2px 0 0; font-size: 1.15rem; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}
.menu-grid .menu-item {
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  min-height: 72px;
}
.menu-grid .menu-item .emoji { font-size: 1.35rem; }

.card-inset {
  background: rgba(2, 6, 23, 0.55);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  margin: 10px 0 12px;
  font-family: var(--mono);
  font-size: 0.8rem;
}
.link-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.link-actions .btn { margin: 0; }
.inline {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
.inline input { margin: 0; flex: 1; }
.inline .btn { margin: 0; flex-shrink: 0; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: none;
  }
  .main { min-height: 70vh; }
  .menu-grid { grid-template-columns: 1fr; }
  .composer { grid-template-columns: auto 1fr; }
  #send { grid-column: 1 / -1; }
}
