:root {
  color-scheme: light;
  --canvas: #f7f8fb;
  --surface: #ffffff;
  --surface-muted: #f1f4f8;
  --surface-soft: #f8fafc;
  --ink: #172033;
  --muted: #667085;
  --faint: #98a2b3;
  --line: #e4e7ec;
  --line-strong: #cfd6e1;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --accent-line: #bfdbfe;
  --sidebar-bg: #eef6ff;
  --sidebar-surface: #dcecff;
  --sidebar-active: #cfe5ff;
  --sidebar-line: #c7dcf6;
  --sidebar-nav: #38506f;
  --success: #039855;
  --danger: #d92d20;
  --shadow: 0 12px 28px rgba(16, 24, 40, 0.08);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #0f141b;
  --surface: #151b24;
  --surface-muted: #1b2430;
  --surface-soft: #111821;
  --ink: #eef2f7;
  --muted: #a6b0bf;
  --faint: #788496;
  --line: #283241;
  --line-strong: #3a4656;
  --accent: #60a5fa;
  --accent-soft: rgba(96, 165, 250, 0.12);
  --accent-line: rgba(96, 165, 250, 0.34);
  --sidebar-bg: #111c2b;
  --sidebar-surface: #17263a;
  --sidebar-active: #203a5c;
  --sidebar-line: #294465;
  --sidebar-nav: #b5c3d6;
  --success: #32d583;
  --danger: #f97066;
  --shadow: 0 16px 34px rgba(0, 0, 0, 0.24);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--canvas);
}

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

button {
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--accent-line);
  outline-offset: 2px;
}

noscript {
  position: fixed;
  inset: auto 16px 16px;
  z-index: 10;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

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

.sidebar {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 16px;
  border-right: 1px solid var(--sidebar-line);
  background: var(--sidebar-bg);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #ffffff;
  font-weight: 850;
}

.brand-row strong,
.brand-row span,
.sidebar-note span,
.sidebar-note small {
  display: block;
}

.brand-row span,
.sidebar-note small {
  color: var(--muted);
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-list a {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 10px;
  border-radius: var(--radius);
  color: var(--sidebar-nav);
  text-decoration: none;
  border: 1px solid transparent;
}

.nav-list a.active,
.nav-list a:hover {
  color: var(--ink);
  border-color: var(--sidebar-line);
  background: var(--sidebar-active);
}

svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex: 0 0 auto;
}

.sidebar-note {
  margin-top: auto;
  padding: 14px;
  border: 1px solid var(--sidebar-line);
  border-radius: var(--radius);
  background: var(--sidebar-surface);
}

.sidebar-note p {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.sidebar-note strong {
  display: block;
  margin-bottom: 4px;
  font-size: 24px;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 999px;
}

main {
  position: relative;
  z-index: 1;
  width: min(1500px, 100%);
  padding: 22px 24px 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1,
h2 {
  margin-bottom: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(26px, 3vw, 36px);
  line-height: 1.1;
}

h2 {
  font-size: 18px;
}

.top-actions,
.composer-actions,
menu,
.chat-toolbar,
.billing-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top-actions {
  position: relative;
  justify-content: flex-end;
  flex-wrap: wrap;
  align-items: flex-start;
}

.primary-button,
.ghost-button,
.icon-button,
.segment,
.payment,
.account-chip,
.prompt-chip {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}

.primary-button {
  padding: 0 16px;
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  font-weight: 750;
}

.ghost-button,
.account-chip {
  padding: 0 14px;
  color: var(--muted);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  padding: 0;
}

.full-button {
  width: 100%;
}

.ghost-button:hover,
.icon-button:hover,
.segment:hover,
.payment:hover,
.account-chip:hover,
.prompt-chip:hover {
  border-color: var(--line-strong);
  color: var(--ink);
  background: var(--surface-muted);
}

.primary-button:hover {
  filter: brightness(0.96);
}

.balance-card,
.market-strip,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.balance-card {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  gap: 4px 10px;
  min-width: 190px;
  padding: 12px 14px;
}

.balance-card .status-dot {
  grid-row: span 3;
  align-self: start;
  margin-top: 5px;
}

.balance-card p,
.balance-card strong,
.balance-card small {
  margin: 0;
}

.balance-card p,
.balance-card small {
  color: var(--muted);
  font-size: 12px;
}

.balance-card strong {
  font-size: 22px;
  line-height: 1.1;
}

.market-strip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  padding: 12px;
  margin-bottom: 14px;
}

.segmented,
.auth-switch {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.segment {
  min-width: 112px;
  padding: 0 12px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.segment.active {
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface);
  font-weight: 750;
}

.market-copy {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.chat-page-layout {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) 240px;
  gap: 14px;
  min-height: calc(100vh - 176px);
}

.panel {
  padding: 16px;
  box-shadow: var(--shadow);
}

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

.panel-heading.compact {
  margin-bottom: 12px;
}

.conversation-panel {
  display: grid;
  grid-template-columns: minmax(220px, 25%) minmax(0, 1fr);
  gap: 14px;
  min-height: calc(100vh - 232px);
  padding: 14px;
  box-shadow: var(--shadow);
}

.history-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding-right: 14px;
  border-right: 1px solid var(--line);
}

.history-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  overflow: auto;
}

.history-item {
  display: grid;
  gap: 6px;
  min-height: 62px;
  padding: 11px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.history-item span,
.history-item small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item span {
  color: var(--ink);
  font-weight: 720;
}

.history-item.active,
.history-item:hover {
  border-color: var(--line);
  background: var(--surface-muted);
}

.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-panel .panel-heading {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.chat-feed,
.chat-empty {
  flex: 1;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.chat-feed {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 14px;
  overflow: auto;
}

.chat-empty {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  padding: 28px;
  text-align: center;
}

.chat-empty strong {
  font-size: 24px;
}

.chat-empty p {
  max-width: 560px;
  color: var(--muted);
  line-height: 1.7;
}

.prompt-suggestions,
.composer-suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 720px;
}

.chat-empty .prompt-suggestions {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: min(430px, 100%);
}

.composer-suggestions {
  justify-content: flex-start;
}

.prompt-chip {
  min-height: 34px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.chat-empty .prompt-chip {
  width: 100%;
  min-height: 38px;
  padding: 0 14px;
  text-align: left;
}

.history-empty,
.usage-empty {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--surface-soft);
}

.message {
  max-width: min(760px, 86%);
  min-width: 0;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.34;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.message.assistant {
  align-self: flex-start;
}

.composer {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.composer-input {
  position: relative;
  display: grid;
}

textarea {
  width: 100%;
  min-height: 44px;
  max-height: 160px;
  resize: none;
  overflow-y: auto;
  padding: 11px 90px 11px 13px;
  line-height: 1.45;
  outline: none;
}

.composer-send {
  position: absolute;
  right: 6px;
  bottom: 6px;
  min-height: 32px;
  padding: 0 14px;
}

select,
textarea,
input {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}

select {
  min-height: 36px;
  padding: 0 10px;
}

textarea:focus,
select:focus,
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.right-rail {
  display: grid;
  gap: 12px;
  align-content: start;
  min-height: 0;
}

.compact-panel {
  min-height: 0;
}

.select-label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.model-list,
.catalog-grid,
.plan-list {
  display: grid;
  gap: 8px;
}

.catalog-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.model-card,
.plan-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 10px;
}

.model-card {
  display: grid;
  gap: 6px;
  text-align: left;
}

.model-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.model-top,
.model-meta,
.plan-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.model-name {
  display: grid;
  gap: 1px;
}

.model-name strong {
  font-size: 13px;
}

.model-name span,
.model-meta,
.model-use-case,
.plan-meta,
.api-scope-grid span {
  color: var(--muted);
  font-size: 11px;
}

.model-use-case {
  display: grid;
  gap: 2px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
  line-height: 1.28;
}

.model-use-case strong {
  color: var(--ink);
  font-size: 11px;
  font-weight: 650;
}

.badge,
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 7px;
  border: 1px solid var(--accent-line);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 720;
  white-space: nowrap;
}

.balance-row {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.balance-row span {
  color: var(--muted);
}

.balance-row strong {
  font-size: 26px;
}

.balance-row small,
.auth-helper {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.billing-layout,
.api-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.api-intro p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.plan-list {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.plan-card strong {
  display: block;
  margin-bottom: 8px;
  font-size: 20px;
}

.plan-card p {
  min-height: 20px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.plan-card small {
  display: block;
  min-height: 18px;
  color: var(--faint);
  font-size: 12px;
}

.plan-card button {
  width: 100%;
  margin-top: auto;
}

.plan-card {
  display: flex;
  flex-direction: column;
  min-height: 156px;
}

.custom-plan {
  gap: 0;
}

.inline-recharge {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 42px;
  margin-top: 6px;
  margin-bottom: 10px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.inline-recharge span {
  color: var(--muted);
  font-weight: 720;
}

.inline-recharge input {
  min-height: 36px;
  padding: 0;
  border: 0;
  background: transparent;
  outline: none;
}

.billing-actions {
  flex-wrap: wrap;
  margin-top: 14px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 780;
}

td {
  color: var(--ink);
}

.ok {
  color: var(--success);
  font-weight: 760;
}

.api-key-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

code {
  display: block;
  overflow: hidden;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--success);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.api-scope-grid {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 10px 12px;
}

.code-sample {
  margin: 0;
  overflow: auto;
}

.code-sample code {
  white-space: pre;
  line-height: 1.6;
}

dialog {
  width: min(460px, calc(100vw - 28px));
  border: 0;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.48);
}

.dialog-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.payment-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.payment.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 720;
}

.amount-field {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--muted);
}

.amount-field input {
  min-height: 44px;
  padding: 0 12px;
}

.purchase-summary {
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--ink);
  font-weight: 720;
}

.code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.code-row input {
  min-width: 0;
  min-height: 44px;
  padding: 0 12px;
}

.account-menu {
  position: absolute;
  top: 42px;
  right: 0;
  z-index: 20;
  display: grid;
  min-width: 112px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.account-menu button {
  min-height: 36px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 0 12px;
  font-size: 13px;
}

.account-menu button:hover {
  background: var(--surface-muted);
}

.account-menu button:last-child {
  border-bottom: 0;
  color: var(--danger);
}

.auth-switch {
  width: 100%;
  margin-bottom: 10px;
}

.auth-method-switch {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  padding: 3px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.auth-helper {
  margin: 2px 0 0;
}

menu {
  justify-content: flex-end;
  margin: 18px 0 0;
  padding: 0;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  max-width: min(360px, calc(100vw - 44px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--surface);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
  }

  .nav-list {
    display: flex;
  }

  .sidebar-note {
    min-width: 190px;
    margin-left: auto;
  }

  .chat-page-layout {
    grid-template-columns: minmax(0, 1fr);
    min-height: auto;
  }

  .conversation-panel {
    grid-template-columns: 250px minmax(0, 1fr);
    min-height: calc(100vh - 230px);
  }

  .right-rail {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  main {
    padding: 14px;
  }

  .topbar,
  .market-strip,
  .sidebar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .composer-actions,
  .chat-toolbar {
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .market-strip,
  .right-rail,
  .plan-list,
  .catalog-grid {
    grid-template-columns: 1fr;
  }

  .sidebar-note {
    margin-left: 0;
  }

  .segmented,
  .payment-grid {
    width: 100%;
  }

  .segment {
    min-width: 0;
  }

  .balance-card {
    width: 100%;
  }

  .conversation-panel {
    grid-template-columns: 1fr;
    min-height: 760px;
  }

  .history-panel {
    max-height: 220px;
    padding-right: 0;
    padding-bottom: 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat-feed {
    padding: 14px;
  }

  .message {
    max-width: 94%;
  }
}
