:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-soft: #f8f9fc;
  --text: #16181d;
  --muted: #6d7280;
  --line: #e5e8ef;
  --accent: #5b43f1;
  --accent-2: #785ff7;
  --accent-soft: #eeebff;
  --success: #1c9a63;
  --warning: #bd7a11;
  --danger: #c83f4d;
  --shadow: 0 16px 40px rgba(26, 28, 40, 0.08);
  --radius: 20px;
  --radius-sm: 13px;
  --sidebar-width: 300px;
  --inspector-width: 315px;
  font-family: Inter, "Segoe UI", Tahoma, Arial, sans-serif;
}

:root[data-theme="dark"] {
  --bg: #0e1015;
  --panel: #171a21;
  --panel-soft: #1d2028;
  --text: #f3f4f8;
  --muted: #9da3b1;
  --line: #292e39;
  --accent: #8b78ff;
  --accent-2: #a08fff;
  --accent-soft: #282341;
  --success: #4cc58c;
  --warning: #e4a64b;
  --danger: #ee6c78;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

/* Author display:flex/grid rules must not override HTML's hidden state. */
[hidden] {
  display: none !important;
}

.content-grid:has(> .inspector-column[hidden]) {
  grid-template-columns: minmax(0, 1fr);
}

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

body {
  min-height: 100vh;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: .5;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 20px;
  background: var(--panel);
  border-inline-end: 1px solid var(--line);
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.brand-logo {
  width: 44px;
  height: 44px;
}

.brand > div {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.brand strong {
  font-size: 17px;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
}

.status-card {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 22px;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-row > div {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.status-row strong {
  font-size: 13px;
}

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

.status-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--warning) 13%, transparent);
}

.status-dot.ok {
  background: var(--success);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 13%, transparent);
}

.status-dot.error {
  background: var(--danger);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 13%, transparent);
}

.side-section {
  padding: 17px 0;
  border-top: 1px solid var(--line);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 14px;
}

.badge {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .06em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 7px;
  border-radius: 999px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
}

.field > span {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.field small,
.muted {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

input,
select,
textarea {
  width: 100%;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

input,
select {
  padding: 10px 11px;
}

textarea {
  resize: none;
  border: 0;
  background: transparent;
  padding: 13px 6px;
  min-height: 48px;
  max-height: 180px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 13%, transparent);
}

textarea:focus {
  box-shadow: none;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 11px 0;
  font-size: 13px;
}

.toggle-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.conversation-box {
  display: grid;
  gap: 5px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel-soft);
  margin-bottom: 10px;
}

.conversation-box small {
  color: var(--muted);
}

.conversation-box code {
  direction: ltr;
  text-align: left;
  overflow-wrap: anywhere;
  font-size: 10px;
}

.sidebar-footer {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 10px;
}

.main-panel {
  min-width: 0;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 70px;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(15px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar-title {
  display: grid;
  gap: 2px;
}

.topbar-title strong {
  font-size: 16px;
}

.topbar-title span {
  font-size: 11px;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.secondary-button,
.text-button,
.send-button,
.mic-button,
.prompt-chip {
  border: 0;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--text);
  background: var(--panel);
}

.secondary-button {
  padding: 9px 13px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel);
  border-radius: 11px;
  font-weight: 600;
  font-size: 12px;
}

.secondary-button:hover,
.icon-button:hover {
  background: var(--panel-soft);
}

.full {
  width: 100%;
}

.text-button {
  padding: 5px 0;
  background: transparent;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--inspector-width);
  gap: 18px;
  width: min(1420px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.chat-column {
  min-width: 0;
  min-height: calc(100vh - 106px);
  display: flex;
  flex-direction: column;
}

.welcome-panel {
  background:
    radial-gradient(circle at 85% 15%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 28%),
    var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 34px;
  margin-bottom: 18px;
}

.welcome-icon {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: var(--accent-soft);
  margin-bottom: 18px;
}

.welcome-icon img {
  width: 39px;
  height: 39px;
}

.welcome-panel h1 {
  margin: 0 0 8px;
  font-size: clamp(22px, 3vw, 34px);
  letter-spacing: -.03em;
}

.welcome-panel p {
  margin: 0;
  max-width: 700px;
  color: var(--muted);
  line-height: 1.8;
}

.quick-groups {
  display: grid;
  gap: 17px;
  margin-top: 25px;
}

.quick-title {
  margin-bottom: 9px;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.prompt-chip {
  padding: 9px 12px;
  border-radius: 999px;
  color: var(--text);
  background: var(--panel-soft);
  border: 1px solid var(--line);
  font-size: 12px;
  transition: .15s ease;
}

.prompt-chip:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--accent) 38%, var(--line));
  background: var(--accent-soft);
}

.messages {
  display: grid;
  gap: 14px;
}

.message {
  display: grid;
  gap: 6px;
  max-width: min(820px, 90%);
}

.message.user {
  justify-self: start;
}

.message.assistant {
  justify-self: stretch;
  max-width: min(930px, 96%);
}

.message-bubble {
  padding: 13px 15px;
  border-radius: 17px;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user .message-bubble {
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-bottom-right-radius: 5px;
}

.message.assistant .message-bubble {
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
  box-shadow: 0 7px 22px rgba(25, 30, 45, .035);
}

.message-meta {
  color: var(--muted);
  font-size: 10px;
  padding-inline: 5px;
}

.message.user .message-meta {
  text-align: right;
}

.answer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.inline-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.product-card {
  min-width: 0;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--panel-soft);
}

.product-card h3 {
  margin: 0 0 5px;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.product-card .product-store {
  color: var(--muted);
  font-size: 10px;
  margin-bottom: 10px;
}

.product-price {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 8px;
}

.product-price strong {
  font-size: 16px;
}

.old-price {
  color: var(--muted);
  text-decoration: line-through;
  font-size: 11px;
}

.stock {
  display: inline-flex;
  padding: 4px 7px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 800;
  background: color-mix(in srgb, var(--success) 12%, transparent);
  color: var(--success);
}

.stock.out {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}

.product-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 11px;
}

.commerce-card {
  margin-top: 10px;
  padding: 13px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: 15px;
}

.commerce-card dl {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 7px 10px;
  margin: 0;
  font-size: 11px;
}

.commerce-card dt {
  color: var(--muted);
}

.commerce-card dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.typing-indicator {
  align-self: flex-start;
  margin: 10px 0;
  padding: 10px 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 15px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: .13s; }
.typing-indicator span:nth-child(3) { animation-delay: .26s; }

.typing-indicator small {
  color: var(--muted);
  margin-inline-start: 6px;
}

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .45; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.composer-wrap {
  position: sticky;
  bottom: 0;
  z-index: 15;
  margin-top: auto;
  padding-top: 18px;
  padding-bottom: 4px;
  background: linear-gradient(to top, var(--bg) 76%, transparent);
}

.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: end;
  gap: 6px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.send-button {
  min-height: 44px;
  padding: 0 15px;
  border-radius: 13px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 800;
  font-size: 12px;
}

.mic-button {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  color: var(--text);
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.mic-button.listening {
  color: white;
  background: var(--danger);
  animation: pulse 1.1s infinite;
}

.voice-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 4px 0;
  padding: 9px 11px;
  color: var(--text);
  background: color-mix(in srgb, var(--danger) 8%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--danger) 30%, var(--line));
  border-radius: 12px;
  font-size: 11px;
}

.voice-status[hidden] {
  display: none;
}

.voice-status.processing {
  background: color-mix(in srgb, var(--accent) 8%, var(--panel));
  border-color: color-mix(in srgb, var(--accent) 30%, var(--line));
}

.voice-live-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: var(--danger);
  animation: voice-live 1.1s infinite;
}

.voice-status.processing .voice-live-dot {
  background: var(--accent);
}

.voice-status #voiceStatusText {
  flex: 1;
  min-width: 0;
}

.voice-status strong {
  font-variant-numeric: tabular-nums;
}

.message.voice-pending .message-bubble {
  opacity: .72;
}

.voice-cancel {
  padding: 4px 8px;
  color: var(--danger);
  background: transparent;
  border: 0;
  font-size: 11px;
  font-weight: 800;
}

@keyframes voice-live {
  0%, 100% { opacity: .4; transform: scale(.85); }
  50% { opacity: 1; transform: scale(1.15); }
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 35%, transparent); }
  50% { box-shadow: 0 0 0 8px transparent; }
}

.composer-meta,
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 10px;
  padding: 6px 5px 0;
}

.pagination-bar {
  justify-content: center;
  padding: 6px 10px;
  margin: 0 auto 7px;
  width: fit-content;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.inspector-column {
  min-width: 0;
}

.inspector-card {
  position: sticky;
  top: 88px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.inspector-card + .inspector-card {
  position: static;
  margin-top: 14px;
}

.inspector-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.inspector-empty {
  color: var(--muted);
  line-height: 1.6;
  font-size: 11px;
}

.kv-grid {
  margin: 0;
  display: grid;
  gap: 7px;
}

.kv-grid > div {
  min-width: 0;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--line);
}

.kv-grid dt {
  color: var(--muted);
  font-size: 10px;
}

.kv-grid dd {
  margin: 0;
  font-weight: 800;
  font-size: 10px;
  overflow-wrap: anywhere;
  text-align: left;
}

.json-details {
  margin-top: 13px;
}

.json-details summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
}

.json-details pre {
  margin: 10px 0 0;
  max-height: 350px;
  overflow: auto;
  direction: ltr;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 9px;
  line-height: 1.55;
  background: var(--panel-soft);
  border-radius: 10px;
  padding: 10px;
}

.small-card {
  font-size: 11px;
  line-height: 1.65;
}

.small-card ul {
  padding-inline-start: 18px;
  color: var(--muted);
}

.toast-container {
  position: fixed;
  inset-inline-end: 20px;
  bottom: 20px;
  z-index: 100;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 40px));
}

.toast {
  padding: 12px 14px;
  border-radius: 13px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 12px;
  animation: toast-in .18s ease-out;
}

.toast.error {
  border-color: color-mix(in srgb, var(--danger) 42%, var(--line));
}

.toast.success {
  border-color: color-mix(in srgb, var(--success) 42%, var(--line));
}

@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.mobile-only {
  display: none;
}

@media (max-width: 1120px) {
  .content-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .inspector-column {
    display: none;
  }

  .inspector-column.visible {
    display: block;
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(330px, 88vw);
    transform: translateX(-105%);
    box-shadow: var(--shadow);
    transition: transform .2s ease;
  }

  [dir="rtl"] .sidebar {
    inset: 0 0 0 auto;
    transform: translateX(105%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-only {
    display: inline-grid;
    place-items: center;
  }

  .topbar {
    padding: 10px 12px;
  }

  .topbar-title strong {
    font-size: 13px;
  }

  .topbar-actions .secondary-button {
    display: none;
  }

  .content-grid {
    padding: 10px;
  }

  .welcome-panel {
    padding: 22px 17px;
  }

  .welcome-panel h1 {
    font-size: 24px;
  }

  .message {
    max-width: 96%;
  }

  .message.assistant {
    max-width: 100%;
  }

  .product-grid {
    grid-template-columns: 1fr;
  }

  .send-button span:first-child {
    display: none;
  }

  .send-button {
    width: 44px;
    padding: 0;
    justify-content: center;
  }
}
