:root {
  --bg: #0d0a12;
  --bg-elevated: #16111d;
  --panel: #1d1627;
  --panel-2: #241c31;
  --border: #332846;
  --border-soft: #2a2238;
  --text: #ebe7f2;
  --text-muted: #a79bb8;
  --purple: #6f3ccf;
  --purple-bright: #8b5cf6;
  --red: #c81d25;
  --red-bright: #ef3340;
  --success-bg: #173024;
  --success-text: #9fe3b4;
  --warn-bg: #35290c;
  --warn-text: #f5d27a;
  --danger-bg: #3b1218;
  --danger-text: #ffb5bc;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  --radius: 18px;
  --radius-small: 12px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
  background:
    radial-gradient(circle at top, rgba(111, 60, 207, 0.22), transparent 30%),
    radial-gradient(circle at 80% 0%, rgba(200, 29, 37, 0.14), transparent 18%),
    linear-gradient(180deg, #130e1c 0%, var(--bg) 32%, #0a0810 100%);
  color: var(--text);
}

body,
input,
select,
textarea,
button {
  -webkit-tap-highlight-color: transparent;
}

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

button {
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.15s ease, border-color 0.15s ease, filter 0.15s ease;
}

.app-shell {
  width: min(1200px, calc(100vw - 32px));
  margin: 28px auto 36px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  padding: 18px 8px 16px;
  border-bottom: 1px solid var(--border-soft);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand-mark {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  object-fit: cover;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.brand-block h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.5rem);
  line-height: 1;
  letter-spacing: -0.04em;
}

.brand-block p {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 1.1rem;
}

.control-cluster {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  align-items: center;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  min-width: 220px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(29, 22, 39, 0.82);
  box-shadow: var(--shadow);
  flex: 0 1 auto;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--red-bright);
  box-shadow: 0 0 0 4px rgba(239, 51, 64, 0.14);
  flex: 0 0 auto;
}

.status-pill.checking .status-dot {
  background: #f2c86f;
  box-shadow: 0 0 0 4px rgba(242, 200, 111, 0.14);
}

.status-pill.connected .status-dot {
  background: #73db78;
  box-shadow: 0 0 0 4px rgba(115, 219, 120, 0.14);
}

.status-copy {
  display: grid;
  gap: 3px;
}

.status-copy strong {
  font-size: 1.05rem;
}

.status-copy small {
  color: var(--text-muted);
}

.auth-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  position: relative;
}

.auth-controls-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  width: min(720px, calc(100vw - 32px));
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(29, 22, 39, 0.92);
  box-shadow: var(--shadow);
}

.auth-controls-panel.collapsed {
  display: none;
}

.menu-button {
  display: inline-grid;
  place-content: center;
  gap: 5px;
  width: 46px;
  min-width: 46px;
  height: 46px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(36, 28, 49, 0.94);
  color: var(--text);
  box-shadow: var(--shadow);
}

.menu-button span {
  display: block;
  width: 20px;
  height: 2px;
  border-radius: 999px;
  background: var(--text);
  box-shadow: 0 0 8px rgba(139, 92, 246, 0.42);
}

.menu-button:hover,
.menu-button:focus-visible {
  border-color: var(--purple-bright);
  background: rgba(52, 39, 73, 0.96);
  box-shadow:
    0 0 0 2px rgba(139, 92, 246, 0.12),
    0 0 18px rgba(111, 60, 207, 0.18);
}

.main-panel {
  margin-top: 22px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(25, 18, 35, 0.94), rgba(17, 13, 24, 0.98));
  box-shadow: var(--shadow);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(5, 3, 10, 0.58);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.app-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 90;
  display: grid;
  align-content: start;
  gap: 18px;
  width: min(380px, calc(100vw - 24px));
  height: 100vh;
  padding: 18px;
  border-left: 1px solid rgba(139, 92, 246, 0.34);
  background:
    radial-gradient(circle at top right, rgba(111, 60, 207, 0.2), transparent 28%),
    linear-gradient(180deg, rgba(29, 22, 39, 0.98), rgba(13, 10, 18, 0.99));
  box-shadow:
    -24px 0 48px rgba(0, 0, 0, 0.34),
    0 0 28px rgba(111, 60, 207, 0.16);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateX(104%);
  transition: transform 0.2s ease;
}

.app-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-soft);
}

.drawer-header div {
  display: grid;
  gap: 4px;
}

.drawer-header strong {
  font-size: 1.12rem;
}

.drawer-header span {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.drawer-close-button {
  display: inline-grid;
  place-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(36, 28, 49, 0.94);
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1;
}

.drawer-close-button:hover,
.drawer-close-button:focus-visible {
  border-color: var(--purple-bright);
  box-shadow: 0 0 12px rgba(111, 60, 207, 0.18);
}

.drawer-section {
  display: grid;
  gap: 10px;
}

.drawer-field {
  max-width: none;
  width: 100%;
}

.drawer-section h3 {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.drawer-nav,
.drawer-actions {
  display: grid;
  gap: 8px;
}

.drawer-auth-controls {
  display: grid;
  gap: 10px;
  width: 100%;
  position: static;
}

.app-drawer .auth-controls-panel {
  position: static;
  display: grid;
  gap: 10px;
  align-items: stretch;
  width: 100%;
  padding: 12px;
  border-radius: 14px;
  background: rgba(16, 12, 24, 0.72);
  box-shadow: none;
}

.app-drawer .auth-controls-panel.collapsed {
  display: none;
}

.app-drawer .field,
.app-drawer .field-small,
.app-drawer .token-field {
  max-width: none;
  min-width: 0;
  width: 100%;
  flex-basis: auto;
}

.app-drawer .token-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
}

.drawer-nav-button,
.drawer-action-button {
  justify-content: flex-start;
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 10px 12px;
  border-radius: 12px;
  text-align: left;
}

.app-drawer .drawer-nav-button,
.app-drawer .drawer-action-button {
  width: 100%;
  min-width: 0;
  flex: none;
  scroll-snap-align: unset;
}

.drawer-nav-button.tab-button {
  border: 1px solid var(--border);
  background: rgba(36, 28, 49, 0.82);
  color: var(--text-muted);
}

.drawer-nav-button.tab-button:hover {
  border-color: var(--purple-bright);
  color: var(--text);
}

.drawer-nav-button.tab-button.active {
  background: linear-gradient(135deg, rgba(111, 60, 207, 0.34), rgba(61, 34, 110, 0.82));
  border-color: rgba(139, 92, 246, 0.62);
  color: var(--text);
  box-shadow:
    inset 3px 0 0 var(--purple-bright),
    0 0 16px rgba(111, 60, 207, 0.16);
}

.tab-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
  scrollbar-width: thin;
}

.tab-button {
  min-width: 124px;
  padding: 12px 18px;
  border: 1px solid var(--border-soft);
  border-radius: 14px 14px 0 0;
  background: rgba(29, 22, 39, 0.72);
  color: var(--text-muted);
  flex: 0 0 auto;
}

.tab-button:hover {
  border-color: var(--purple);
  color: var(--text);
}

.tab-button.active {
  background: linear-gradient(180deg, rgba(111, 60, 207, 0.3), rgba(61, 34, 110, 0.88));
  border-color: rgba(139, 92, 246, 0.6);
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--purple-bright);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.panel-section {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(26, 20, 36, 0.96);
}

.section-heading {
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-soft);
}

.section-heading h2 {
  margin: 0 0 8px;
  color: var(--purple-bright);
  font-size: 1.8rem;
}

.section-heading p {
  margin: 0;
  color: var(--text-muted);
}

.form-stack {
  display: grid;
  gap: 16px;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.form-row > .ghost-button,
.form-row > .action-button {
  flex: 0 0 auto;
  min-width: 0;
  max-width: 100%;
}

.field {
  display: grid;
  gap: 8px;
  min-width: 180px;
  flex: 1 1 220px;
}

.field span {
  font-size: 0.92rem;
  font-weight: 600;
}

.field-small {
  max-width: 160px;
  flex: 0 1 140px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  background: #140f1c;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

input::placeholder,
textarea::placeholder {
  color: #867a97;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--purple-bright);
  box-shadow:
    0 0 0 2px rgba(139, 92, 246, 0.14),
    0 0 10px rgba(111, 60, 207, 0.18);
  background: #171120;
}

textarea {
  resize: vertical;
  min-height: 120px;
}

.token-field {
  min-width: 280px;
}

.token-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.ghost-button,
.action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  color: var(--text);
  min-height: 46px;
  width: auto;
  max-width: 100%;
}

.auth-toggle-button {
  min-height: 42px;
  padding: 10px 14px;
  white-space: nowrap;
}

.ghost-button {
  background: rgba(36, 28, 49, 0.94);
}

.ghost-button:hover {
  border-color: var(--purple-bright);
  background: rgba(52, 39, 73, 0.96);
  box-shadow: 0 0 10px rgba(111, 60, 207, 0.16);
}

.action-button {
  background: linear-gradient(135deg, rgba(200, 29, 37, 0.82), rgba(111, 60, 207, 0.72));
  border-color: rgba(239, 51, 64, 0.48);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.action-button:hover {
  filter: brightness(1.04);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 0 12px rgba(200, 29, 37, 0.18),
    0 0 18px rgba(111, 60, 207, 0.12);
}

.ghost-button:focus-visible,
.action-button:focus-visible {
  border-color: var(--purple-bright);
  box-shadow:
    0 0 0 2px rgba(139, 92, 246, 0.16),
    0 0 10px rgba(111, 60, 207, 0.14);
}

.ghost-button:active,
.action-button:active {
  transform: scale(0.98);
}

.ghost-button:active {
  box-shadow: 0 0 6px rgba(111, 60, 207, 0.14);
}

.action-button:active {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 0 6px rgba(200, 29, 37, 0.16),
    0 0 10px rgba(111, 60, 207, 0.1);
}

.output-panel {
  margin-top: 20px;
  min-height: 240px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(19, 15, 28, 0.92);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.chat-shell {
  display: grid;
  gap: 14px;
}

.chat-window {
  display: grid;
  grid-template-rows: auto minmax(420px, 1fr);
  min-height: 560px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(24, 19, 34, 0.98), rgba(17, 14, 24, 0.98));
  overflow: hidden;
}

.chat-window-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(29, 22, 39, 0.68);
}

.chat-window-title {
  display: grid;
  gap: 4px;
}

.chat-window-title strong {
  font-size: 0.98rem;
}

.chat-window-title span {
  color: var(--text-muted);
  font-size: 0.86rem;
}

.chat-window-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.ask-chat-thread {
  display: grid;
  align-content: start;
  gap: 14px;
  min-height: 0;
  padding: 18px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  cursor: default;
  background:
    linear-gradient(180deg, rgba(22, 18, 30, 0.92), rgba(18, 14, 26, 0.98));
}

.ask-chat-hint {
  align-self: center;
  justify-self: center;
  width: min(100%, 680px);
  padding: 18px 20px;
  border: 1px dashed rgba(139, 92, 246, 0.22);
  border-radius: 18px;
  background: rgba(24, 18, 35, 0.64);
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.6;
  letter-spacing: 0.01em;
  text-align: center;
}

.ask-composer {
  position: sticky;
  bottom: 0;
  z-index: 2;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(27, 21, 39, 0.98), rgba(20, 16, 29, 0.98));
  box-shadow: 0 -10px 24px rgba(0, 0, 0, 0.14);
}

.ask-composer-main {
  display: grid;
  gap: 12px;
}

.ask-message-field {
  min-width: 0;
}

.ask-message-field textarea {
  min-height: 88px;
  resize: none;
}

.ask-composer-actions {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 12px;
}

.ask-limit-field {
  margin: 0;
}

.ask-memory-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 0;
}

.memory-action-button {
  min-height: 40px;
  padding: 10px 14px;
}

.ask-memory-output {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(20, 15, 28, 0.92);
}

.ask-recent-memories-list {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.chat-message {
  display: grid;
  gap: 8px;
  width: 100%;
}

.chat-message-label {
  color: var(--text-muted);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.chat-message-body {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(24, 18, 34, 0.98);
  white-space: pre-wrap;
  word-break: break-word;
}

.user-message {
  justify-items: end;
}

.user-message .chat-message-body {
  width: min(100%, 760px);
  background: linear-gradient(180deg, rgba(62, 43, 97, 0.98), rgba(38, 28, 58, 0.98));
  border-color: rgba(139, 92, 246, 0.3);
}

.user-message .chat-message-label {
  width: min(100%, 760px);
  text-align: right;
}

.assistant-message .chat-message-body,
.assistant-message .assistant-body {
  width: min(100%, 880px);
}

.assistant-body {
  width: 100%;
}

.pending-message {
  color: var(--text-muted);
  font-style: italic;
}

.pending-message::after {
  content: " ...";
  display: inline-block;
  animation: pendingPulse 1s ease-in-out infinite;
}

@keyframes pendingPulse {
  0% {
    opacity: 0.3;
  }
  100% {
    opacity: 1;
  }
}

.chat-sources {
  margin-top: 12px;
}

.intent-correction-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border-soft);
}

.intent-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 6px 10px;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  background: rgba(36, 28, 49, 0.78);
  color: var(--text-muted);
  font-size: 0.82rem;
}

.intent-correction-field {
  display: inline-flex;
  align-items: center;
}

.intent-correction-field select {
  width: auto;
  min-width: 160px;
  padding: 8px 10px;
  border-radius: 10px;
}

.intent-correction-button {
  min-height: 36px;
  padding: 8px 12px;
}

.intent-correction-status {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.intent-correction-status.success {
  color: var(--success-text);
}

.feedback-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.feedback-field {
  display: inline-flex;
  align-items: center;
}

.feedback-field select {
  width: auto;
  min-width: 190px;
  padding: 8px 10px;
  border-radius: 10px;
}

.feedback-button {
  min-height: 36px;
  padding: 8px 12px;
}

.feedback-status {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.feedback-status.success {
  color: var(--success-text);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.chat-sources summary {
  cursor: pointer;
  color: var(--text-muted);
}

.chat-sources-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.chat-source-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(20, 15, 28, 0.92);
}

.assistant-message .result-section:first-child {
  margin-top: 0;
}

.assistant-message .answer-card,
.assistant-message .result-card,
.assistant-message .status-line {
  cursor: default;
}

.chat-message .status-line {
  margin-bottom: 0;
}

.action-button:disabled,
.ghost-button:disabled {
  cursor: not-allowed;
  opacity: 0.72;
  filter: none;
  transform: none;
  box-shadow: none;
}

.result-section + .result-section {
  margin-top: 18px;
}

.result-section h3,
.result-card h4 {
  margin: 0 0 12px;
}

.result-section h3 {
  color: var(--purple-bright);
}

.two-column {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.result-card,
.answer-card,
.diagnostic-summary {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  background: linear-gradient(180deg, rgba(28, 21, 39, 0.98), rgba(21, 17, 30, 0.98));
}

.result-card + .result-card {
  margin-top: 12px;
}

.result-card.success {
  border-color: rgba(115, 219, 120, 0.35);
  background: linear-gradient(180deg, rgba(23, 48, 36, 0.88), rgba(17, 31, 24, 0.98));
}

.summary-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.summary-pill,
.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(36, 28, 49, 0.92);
  color: var(--text-muted);
  font-size: 0.92rem;
}

.summary-pill:first-child {
  color: var(--purple-bright);
}

.tag {
  margin-right: 6px;
  margin-bottom: 6px;
}

.meta-grid {
  display: grid;
  gap: 10px;
}

.kv-row {
  display: grid;
  gap: 4px;
}

.kv-key {
  color: var(--text-muted);
  font-size: 0.84rem;
}

.kv-value,
.answer-text,
.excerpt {
  word-break: break-word;
  white-space: pre-wrap;
}

.status-line {
  margin: 0 0 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(36, 28, 49, 0.92);
}

.status-line.warn {
  border-color: rgba(245, 210, 122, 0.24);
  background: var(--warn-bg);
  color: var(--warn-text);
}

.status-line.error {
  border-color: rgba(255, 181, 188, 0.24);
  background: var(--danger-bg);
  color: var(--danger-text);
}

.status-line.success {
  border-color: rgba(159, 227, 180, 0.24);
  background: var(--success-bg);
  color: var(--success-text);
}

.diagnostic-summary {
  margin: 18px 0;
}

.hidden {
  display: none !important;
}

.empty-state,
.muted {
  color: var(--text-muted);
}

.issue-list {
  margin: 0;
  padding-left: 20px;
}

.raw-json {
  margin-top: 18px;
}

.raw-json summary {
  cursor: pointer;
  color: var(--text-muted);
}

.raw-json pre {
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  background: #09070d;
  color: #ddd4ef;
}

@media (max-width: 980px) {
  .app-shell {
    width: min(100vw - 24px, 1200px);
    margin-top: 16px;
  }

  .app-header {
    flex-direction: column;
    align-items: stretch;
    padding-right: 64px;
  }

  .control-cluster {
    justify-content: stretch;
  }

  .menu-button {
    position: fixed;
    top: 14px;
    right: 12px;
    z-index: 70;
  }

  .chat-window {
    min-height: 520px;
  }

  .chat-window-header {
    padding: 12px 14px;
  }

  .chat-window-meta {
    justify-content: flex-start;
  }

  .ask-chat-thread {
    padding: 16px;
  }

  .ask-composer {
    padding: 12px;
  }

  .ask-composer-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
  }
}

@media (max-width: 720px) {
  .chat-window {
    min-height: 500px;
    grid-template-rows: auto minmax(360px, 1fr);
  }

  .chat-window-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .ask-chat-thread {
    padding: 14px;
  }

  .ask-memory-actions {
    gap: 8px;
  }

  .memory-action-button {
    min-height: 38px;
    padding: 9px 12px;
  }
}

@media (max-width: 560px) {
  .chat-window {
    min-height: 460px;
  }

  .ask-chat-hint {
    text-align: left;
    padding: 16px;
  }

  .ask-composer-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
  }

  .ask-limit-field {
    max-width: none;
  }

  .ask-submit-button {
    min-width: 110px;
  }
}

@media (max-width: 420px) {
  .ask-composer-actions {
    grid-template-columns: 1fr;
  }

  .ask-submit-button {
    width: 100%;
  }

  .ask-limit-field {
    width: 100%;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: calc(100vw - 16px);
    margin: 6px auto 18px;
  }

  .app-header {
    gap: 12px;
    padding: 10px 2px 12px;
  }

  .main-panel {
    margin-top: 10px;
    padding: 12px;
    border-radius: 18px;
  }

  .panel-section {
    padding: 14px;
    border-radius: 16px;
  }

  .output-panel {
    min-height: 180px;
    margin-top: 16px;
    padding: 14px;
    border-radius: 16px;
  }

  .ask-chat-thread {
    min-height: 240px;
    gap: 12px;
  }

  .ask-composer {
    margin-top: 14px;
  }

  .ask-memory-actions {
    gap: 8px;
    margin-top: 14px;
  }

  .ask-memory-output {
    margin-top: 12px;
    padding: 14px;
    border-radius: 14px;
  }

  .brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 12px;
  }

  .brand-block {
    gap: 10px;
    align-items: flex-start;
  }

  .brand-block h1 {
    font-size: 1.9rem;
  }

  .brand-block p {
    margin-top: 4px;
    font-size: 0.92rem;
  }

  .control-cluster {
    gap: 8px;
    align-items: stretch;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
    min-width: 0;
  }

  .status-pill {
    min-width: 0;
    min-height: 58px;
    padding: 11px 12px;
    border-radius: 14px;
    width: auto;
    flex: 1 1 auto;
    grid-column: 1 / -1;
  }

  .menu-button {
    display: inline-grid;
    align-self: stretch;
    width: 46px;
    min-width: 46px;
  }

  .status-copy strong {
    font-size: 0.98rem;
  }

  .status-copy small {
    font-size: 0.82rem;
  }

  .auth-controls {
    gap: 8px;
    width: auto;
    min-width: 0;
    flex: 0 0 auto;
    align-items: stretch;
    grid-column: 1 / -1;
    justify-content: flex-end;
    justify-self: end;
  }

  .auth-controls-panel {
    gap: 8px;
    padding: 10px;
    border-radius: 14px;
    width: min(420px, calc(100vw - 20px));
  }

  .app-drawer .drawer-auth-controls {
    display: grid;
    grid-column: auto;
    justify-self: stretch;
    justify-content: stretch;
    width: 100%;
  }

  .app-drawer .auth-controls-panel {
    width: 100%;
  }

  .tab-strip {
    flex-wrap: nowrap;
    gap: 10px;
    margin: 0 -2px 14px;
    padding: 0 2px 8px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .tab-strip::-webkit-scrollbar {
    height: 6px;
  }

  .tab-strip::-webkit-scrollbar-thumb {
    background: rgba(111, 60, 207, 0.5);
    border-radius: 999px;
  }

  .tab-button {
    min-width: max-content;
    padding: 12px 16px;
    border-radius: 12px;
    scroll-snap-align: start;
  }

  .app-drawer {
    width: min(360px, calc(100vw - 18px));
  }

  .app-drawer .tab-button,
  .app-drawer .drawer-nav-button,
  .app-drawer .drawer-action-button {
    width: 100%;
    min-width: 0;
    padding: 10px 12px;
    border-radius: 12px;
    scroll-snap-align: unset;
  }

  .section-heading {
    margin-bottom: 14px;
    padding-bottom: 12px;
  }

  .section-heading h2 {
    font-size: 1.45rem;
  }

  .section-heading p {
    font-size: 0.95rem;
    line-height: 1.45;
  }

  .form-stack {
    gap: 14px;
  }

  .form-row,
  .token-input-row {
    flex-direction: column;
    align-items: stretch;
  }

  .ask-form-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .ask-form-row .field-small {
    order: 1;
    max-width: none;
    width: 100%;
  }

  .ask-submit-button {
    order: 2;
    width: 100%;
    max-width: 100%;
    display: flex;
  }

  .memory-action-button {
    flex: 1 1 180px;
  }

  .field,
  .field-small {
    min-width: 0;
    max-width: none;
    flex-basis: 100%;
  }

  .field {
    gap: 6px;
  }

  input,
  select,
  textarea {
    padding: 11px 12px;
    border-radius: 10px;
    font-size: 16px;
  }

  textarea {
    min-height: 132px;
  }

  .token-field {
    min-width: 0;
  }

  .token-input-row > input {
    min-width: 0;
  }

  .two-column {
    grid-template-columns: 1fr;
  }

  .summary-strip {
    gap: 6px;
  }

  .summary-pill,
  .tag {
    padding: 5px 9px;
    font-size: 0.86rem;
  }

  .result-card,
  .answer-card,
  .diagnostic-summary {
    padding: 14px;
    border-radius: 14px;
  }

  .chat-message-body {
    padding: 12px 14px;
    border-radius: 14px;
  }

  .result-section + .result-section {
    margin-top: 16px;
  }

  .raw-json pre {
    padding: 12px;
    font-size: 0.85rem;
  }
}


@media (max-width: 480px) {
  .app-shell {
    width: calc(100vw - 12px);
  }

  .app-header {
    padding-top: 8px;
  }

  .status-pill {
    width: auto;
    grid-column: 1 / -1;
  }

  .auth-toggle-button {
    width: auto;
    align-self: stretch;
  }

  .auth-controls {
    justify-content: flex-end;
    grid-column: 1 / -1;
  }

  .menu-button {
    top: 12px;
    right: 10px;
  }

  .auth-controls-panel {
    right: 0;
    width: min(360px, calc(100vw - 20px));
  }

  .app-drawer .auth-controls-panel {
    width: 100%;
  }

  .brand-block h1 {
    font-size: 1.65rem;
  }

  .brand-block p {
    font-size: 0.86rem;
  }

  .main-panel {
    padding: 10px;
    border-radius: 16px;
  }

  .panel-section,
  .output-panel {
    padding: 12px;
    border-radius: 14px;
  }

  .ask-chat-hint {
    font-size: 0.95rem;
  }

  .tab-button {
    padding: 11px 14px;
    font-size: 0.94rem;
  }

  .app-drawer .tab-button,
  .app-drawer .drawer-nav-button,
  .app-drawer .drawer-action-button {
    width: 100%;
    min-width: 0;
    padding: 10px 12px;
  }

  .section-heading h2 {
    font-size: 1.28rem;
  }

  .section-heading p,
  .kv-value,
  .answer-text,
  .excerpt {
    font-size: 0.95rem;
  }

  .summary-pill,
  .tag {
    font-size: 0.82rem;
  }
}
