:root {
  --radius: 0.625rem;
  --background: #fafafa;
  --foreground: #252525;
  --card: #ffffff;
  --secondary: #f7f7f7;
  --muted: #f7f7f7;
  --muted-foreground: #737373;
  --border: #e8e8e8;
  --destructive: #e11d48;
  --user-bubble: #303030;
  --user-fg: #ffffff;
  --assistant-bubble: #f1f5f9;
  --assistant-fg: #0f172a;
  --composer: #f1f5f9;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.1);
  --glass: rgba(255, 255, 255, 0.72);
  font-family: "Geist", "Segoe UI", system-ui, sans-serif;
}

html.dark {
  --background: #353535;
  --foreground: #fafafa;
  --card: #353535;
  --secondary: #262626;
  --muted: #262626;
  --muted-foreground: #a3a3a3;
  --border: rgba(255, 255, 255, 0.1);
  --user-bubble: #fafafa;
  --user-fg: #171717;
  --assistant-bubble: #262626;
  --assistant-fg: #fafafa;
  --composer: #303030;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --glass: rgba(38, 38, 38, 0.78);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  background: var(--background);
  color: var(--foreground);
}

body {
  overflow: hidden;
}

.app-shell {
  position: relative;
  height: 100dvh;
  width: 100%;
  display: flex;
  justify-content: center;
  overflow: hidden;
}

.control-rail {
  position: fixed;
  top: 1.25rem;
  left: 1.25rem;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.45rem;
  border-radius: 26px;
  background: var(--glass);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.rail-btn {
  appearance: none;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--foreground);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1rem;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.rail-btn:hover:not(:disabled) {
  background: var(--secondary);
}

.rail-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.rail-btn.primary {
  background: var(--user-bubble);
  color: var(--user-fg);
}

.rail-btn.active {
  background: var(--secondary);
  border-color: var(--border);
}

.rail-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.models-panel {
  position: fixed;
  top: 1.25rem;
  left: 5.1rem;
  z-index: 45;
  width: min(320px, calc(100vw - 6rem));
  padding: 1rem 1rem 0.9rem;
  border-radius: 18px;
  background: var(--glass);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  max-height: calc(100vh - 2.5rem);
  overflow-y: auto;
}

.models-panel[hidden] {
  display: none;
}

.knowledge-panel {
  width: min(380px, calc(100vw - 6rem));
}

.models-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.models-panel-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.models-close {
  appearance: none;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
}

.models-close:hover {
  background: var(--secondary);
  color: var(--foreground);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.78rem;
  color: var(--muted-foreground);
}

.field select,
.field input[type=text],
.field textarea {
  appearance: none;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--secondary);
  color: var(--foreground);
  font: inherit;
  font-size: 0.88rem;
  padding: 0.55rem 0.7rem;
}

.field textarea {
  resize: vertical;
  min-height: 5.5rem;
  line-height: 1.35;
}

.rag-knowledge-panel {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.7rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--secondary) 55%, transparent);
}

.rag-file-input {
  width: 100%;
  color: var(--muted-foreground);
  font: inherit;
  font-size: 0.75rem;
}

.rag-drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  min-height: 130px;
  padding: 1rem;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  background: var(--secondary);
  color: var(--muted-foreground);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.rag-drop-zone:hover,
.rag-drop-zone:focus-visible,
.rag-drop-zone.is-dragover {
  border-color: var(--foreground);
  background: color-mix(in srgb, var(--secondary) 70%, var(--foreground) 5%);
  outline: none;
}

.rag-drop-zone svg {
  width: 25px;
  height: 25px;
  margin-bottom: 0.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rag-drop-zone strong {
  color: var(--foreground);
  font-size: 0.82rem;
}

.rag-drop-zone span,
.rag-drop-zone small {
  font-size: 0.72rem;
  line-height: 1.3;
}

.rag-separator {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--muted-foreground);
  font-size: 0.7rem;
}

.rag-separator::before,
.rag-separator::after {
  content: ";
  flex: 1;
  border-top: 1px solid var(--border);
}

.rag-list-head {
  padding-top: 0.2rem;
  color: var(--foreground);
  font-size: 0.78rem;
}

.rag-documents { display: flex; flex-direction: column; gap: 0.4rem; }
.rag-document {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 0.75rem;
}
.rag-document span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rag-document-details {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 0.15rem;
}
.rag-document-details strong {
  overflow: hidden;
  color: var(--foreground);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rag-document-details span {
  color: var(--muted-foreground);
  font-size: 0.68rem;
}
.rag-document button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  font: inherit;
}
.rag-document button:hover { color: var(--foreground); }

.model-fields {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.model-fields[hidden] {
  display: none;
}

.field-hint,
.field-note {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--muted-foreground);
}

.field-check {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.field-check input {
  width: auto;
  margin: 0;
}

.field-note {
  opacity: 0.85;
}

.stack-start-btn {
  margin-top: 0.35rem;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--background);
  color: var(--foreground);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
}

.stack-start-btn:hover:not(:disabled) {
  background: var(--accent);
}

.stack-start-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.stack-progress-panel {
  margin: 0 0 0.75rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  background: color-mix(in srgb, var(--accent) 12%, var(--background));
}

.stack-progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.45rem;
  font-size: 0.8125rem;
  font-weight: 600;
}

.stack-progress-eta {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted-foreground);
}

.stack-progress-track {
  height: 0.45rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--border) 70%, transparent);
  overflow: hidden;
}

.stack-progress-bar {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #6366f1, #8b5cf6);
  transition: width 0.6s ease;
}

.stack-progress-message {
  margin: 0.45rem 0 0;
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--muted-foreground);
}

.brand-badge {
  position: fixed;
  bottom: 1.25rem;
  left: 1.5rem;
  z-index: 40;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: #111;
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
}

html.dark .brand-badge {
  background: #fafafa;
  color: #111;
}

.brand-mark {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.04em;
}

.chat-column {
  width: min(720px, 100%);
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem 1.1rem;
}

.chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.35rem;
}

.eyebrow {
  margin: 0 0 0.2rem;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}

.chat-header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
}

.dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--muted-foreground);
}

.dot.on {
  background: #22c55e;
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.15);
}

.dot.err {
  background: var(--destructive);
  box-shadow: 0 0 0 4px rgba(225, 29, 72, 0.15);
}

.meta {
  margin: 0 0 0.75rem;
  min-height: 1.1em;
  color: var(--muted-foreground);
  font-size: 0.8rem;
}

.unmute-embed {
  display: none;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 0.5rem 0.15rem 1rem;
  /* Keep programmatic/touch scrolling without showing a permanent rail. */
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.messages::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.message {
  display: flex;
  width: 100%;
}

.message.user {
  justify-content: flex-end;
}

.message.agent,
.message.system {
  justify-content: flex-start;
}

.message .bubble {
  width: fit-content;
  max-width: min(80%, 42rem);
  padding: 1rem;
  line-height: 1.45;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user .bubble {
  background: var(--user-bubble);
  color: var(--user-fg);
  border-radius: 1.5rem 1.5rem 0.35rem 1.5rem;
}

.message.agent .bubble {
  background: var(--assistant-bubble);
  color: var(--assistant-fg);
  border-radius: 1.5rem 1.5rem 1.5rem 0.35rem;
}

.message.system .bubble {
  max-width: 92%;
  background: transparent;
  color: var(--muted-foreground);
  border: 1px dashed var(--border);
  border-radius: 1rem;
  padding: 0.7rem 0.9rem;
  font-size: 0.85rem;
}

.voice-activity-dock {
  flex-shrink: 0;
  margin: 0.35rem 0 0.65rem;
  padding: 0.65rem 0.85rem;
  border-radius: 1.25rem;
  border: 1px solid var(--border);
  background: var(--composer);
  box-shadow: var(--shadow);
}

.voice-activity-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 7.5rem;
}

.voice-canvas {
  display: block;
  width: min(7.5rem, 42vw);
  height: min(7.5rem, 42vw);
}

.voice-activity-label {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--muted-foreground);
  text-align: center;
}

.composer {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.55rem 0.55rem 1rem;
  border-radius: 24px;
  background: var(--composer);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.composer input {
  appearance: none;
  flex: 1;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--foreground);
  font: inherit;
  font-size: 0.95rem;
  min-width: 0;
}

.composer input::placeholder {
  color: var(--muted-foreground);
}

.composer input:disabled {
  opacity: 0.55;
}

.icon-btn,
.send-btn {
  appearance: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.icon-btn {
  background: transparent;
  color: var(--muted-foreground);
  border: 1px solid var(--border);
  font-size: 1rem;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover:not(:disabled) {
  background: var(--secondary);
  color: var(--foreground);
}

.icon-btn.active {
  background: var(--user-bubble);
  color: var(--user-fg);
  border-color: transparent;
}

.icon-btn.speaking {
  animation: mic-pulse 0.85s ease-in-out infinite;
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--user-bubble) 45%, transparent);
}

@keyframes mic-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--user-bubble) 40%, transparent);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--user-bubble) 0%, transparent);
    transform: scale(1.06);
  }
}

.icon-btn:disabled,
.send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.send-btn {
  background: var(--user-bubble);
  color: var(--user-fg);
  font-size: 1.1rem;
  font-weight: 700;
}

.mic-icon {
  line-height: 1;
}

.hint {
  margin: 0.65rem 0 0;
  color: var(--muted-foreground);
  font-size: 0.78rem;
  text-align: center;
}

.voice-only-hidden {
  display: none !important;
}

.mic-level-panel {
  display: grid;
  grid-template-columns: minmax(7rem, auto) minmax(7rem, 1fr);
  align-items: center;
  gap: 0.65rem;
  margin: 0.55rem 0 0;
  padding: 0 0.35rem;
}

.mic-level-panel-settings {
  margin: -0.15rem 0 0.15rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: color-mix(in srgb, var(--composer) 82%, transparent);
}

.mic-level-panel[hidden] {
  display: none;
}

.mic-level-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted-foreground);
  font-size: 0.72rem;
}

.mic-level-track {
  height: 0.38rem;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--border) 75%, transparent);
}

.mic-level-bar {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #22c55e 0%, #84cc16 65%, #f59e0b 88%, #ef4444 100%);
  transition: width 80ms linear;
}

.system-log {
  display: none;
}

@media (max-width: 720px) {
  .control-rail {
    top: 0.75rem;
    left: 0.75rem;
  }

  .models-panel {
    top: 4.6rem;
    left: 0.75rem;
    width: calc(100vw - 1.5rem);
  }

  .knowledge-panel {
    width: calc(100vw - 1.5rem);
  }

  .brand-badge {
    left: 0.9rem;
    bottom: 0.9rem;
  }

  .chat-column {
    padding-top: 4.5rem;
  }

  .message .bubble {
    max-width: 92%;
  }
}
