:root {
  color-scheme: light;
  --bg: #eef2f6;
  --panel: #ffffff;
  --panel-soft: #f7f9fb;
  --text: #1f2933;
  --muted: #66727f;
  --line: #d9e1e8;
  --accent: #12806d;
  --accent-dark: #0b5f52;
  --blue: #2c6ea3;
  --violet: #6f5cc2;
  --danger: #a33d35;
  --chip: #e9eef3;
  --shadow: 0 18px 48px rgba(20, 33, 47, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

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

a {
  color: var(--accent-dark);
  text-decoration: none;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  width: min(1400px, calc(100vw - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
}

.workspace,
.meter-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.workspace {
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
  min-height: calc(100vh - 32px);
}

.topbar,
.auth-strip,
.portal-panel,
.tabs,
.model-row,
.composer,
.section-head {
  border-bottom: 1px solid var(--line);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px 14px;
}

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

h1 {
  font-size: 23px;
  line-height: 1.1;
}

h2 {
  font-size: 16px;
}

.topbar p,
.subline,
.field span,
.route-card span,
.wallet-block span,
.payment-panel span,
.record-row span,
.todo-panel li {
  color: var(--muted);
  font-size: 13px;
}

.topbar p {
  margin: 6px 0 0;
}

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

.ghost-button,
.icon-button,
.auth-strip button,
.composer button,
#draw-button,
.primary-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: 8px;
  cursor: pointer;
}

.ghost-button,
.icon-button,
.auth-strip button,
.primary-link {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 0 12px;
}

.icon-button {
  width: 38px;
  padding: 0;
}

.primary-link.large,
.ghost-button.large {
  min-height: 42px;
  padding: 0 15px;
}

.auth-strip {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 86px 110px;
  gap: 10px;
  align-items: end;
  padding: 12px 22px;
  background: var(--panel-soft);
}

.portal-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
  gap: 18px;
  padding: 22px;
  background:
    linear-gradient(115deg, rgba(18, 128, 109, 0.09), rgba(44, 110, 163, 0.07) 50%, rgba(111, 92, 194, 0.06)),
    var(--panel);
}

.portal-copy {
  display: grid;
  align-content: center;
  gap: 10px;
}

.kicker {
  width: fit-content;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(18, 128, 109, 0.11);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
}

.portal-copy h2 {
  font-size: 24px;
  line-height: 1.15;
}

.portal-copy p,
.route-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.portal-copy p {
  max-width: 720px;
}

.portal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

.route-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  align-content: stretch;
}

.route-card {
  display: grid;
  gap: 7px;
  border: 1px solid rgba(217, 225, 232, 0.92);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  padding: 13px;
}

.route-card strong {
  font-size: 16px;
}

.field {
  display: grid;
  gap: 6px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.field input,
.field select {
  height: 38px;
  padding: 0 10px;
}

.field textarea,
.composer textarea {
  padding: 12px;
  line-height: 1.5;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 121, 100, 0.13);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 22px;
  background: var(--panel-soft);
}

.tab {
  height: 36px;
  min-width: 78px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab.active {
  background: var(--text);
  color: #fff;
}

.tab-panel {
  display: none;
  min-height: 0;
}

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

#chat-tab {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.model-row,
.image-form {
  display: grid;
  gap: 12px;
  padding: 14px 22px;
  background: var(--panel-soft);
}

.model-row {
  grid-template-columns: minmax(180px, 1fr) 110px 130px;
}

.chat-log {
  min-height: 360px;
  overflow: auto;
  padding: 20px 22px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 320px;
  color: var(--muted);
  border: 1px dashed var(--line);
  background: #f8fafc;
}

.message {
  display: grid;
  gap: 6px;
  max-width: 830px;
  margin-bottom: 16px;
}

.message.user {
  margin-left: auto;
}

.message-role {
  color: var(--muted);
  font-size: 12px;
}

.message-body {
  white-space: pre-wrap;
  line-height: 1.65;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.message.user .message-body {
  background: #edf8f5;
  border-color: #bedfd7;
}

.message.error .message-body,
.image-error {
  color: var(--danger);
  border-color: #e6b5ae;
  background: #fff4f2;
}

.message-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.pill {
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--chip);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 12px;
  padding: 16px 22px 20px;
  background: var(--panel-soft);
}

.composer textarea {
  min-height: 86px;
  max-height: 240px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.composer button,
#draw-button {
  border: 0;
  background: var(--accent);
  color: #fff;
  font-weight: 650;
}

.composer button:hover,
#draw-button:hover {
  background: var(--accent-dark);
}

.composer button:disabled,
#draw-button:disabled {
  cursor: wait;
  background: #8ab9aa;
}

#image-tab {
  grid-template-rows: auto minmax(0, 1fr);
}

.image-form {
  grid-template-columns: minmax(180px, 1fr) 130px 92px;
  align-items: end;
}

.prompt-field {
  grid-column: 1 / -1;
}

#draw-button {
  grid-column: 1 / -1;
  height: 44px;
}

.image-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  padding: 20px 22px;
}

.image-card,
.image-error {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.image-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: #edf2f7;
}

.image-card figcaption {
  padding: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.image-error {
  padding: 14px;
}

.image-meta {
  grid-column: 1 / -1;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 22px;
  background: var(--panel-soft);
}

.records-list {
  display: grid;
  gap: 10px;
  padding: 18px 22px;
  align-content: start;
}

.record-row {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #fff;
}

.record-row.image {
  border-left: 4px solid var(--blue);
}

.record-row.chat {
  border-left: 4px solid var(--accent);
}

.record-row p {
  margin: 4px 0 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}

#wallet-tab {
  align-content: start;
  padding: 18px 22px;
  gap: 14px;
}

.wallet-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.wallet-block,
.payment-panel,
.todo-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.wallet-block strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
  overflow-wrap: anywhere;
}

.payment-panel {
  display: grid;
  gap: 12px;
}

.primary-link {
  width: fit-content;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

code {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  padding: 9px;
  border-radius: 8px;
  background: #eef3f7;
  color: var(--text);
}

.todo-panel ul {
  margin: 10px 0 0;
  padding-left: 18px;
}

.todo-panel li + li {
  margin-top: 7px;
}

.meter-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  overflow: auto;
}

.meter-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.meter-block.current {
  background: #f0faf7;
  border-color: #bedfd7;
}

.entry-block {
  background: linear-gradient(145deg, #ffffff, #f2f7fb);
}

.entry-link {
  display: flex;
  align-items: center;
  min-height: 36px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
  font-weight: 650;
}

.endpoint-list {
  display: grid;
  gap: 5px;
  margin-top: 10px;
}

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

.endpoint-list code {
  margin-top: 0;
  font-size: 12px;
}

.block-title {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.metric-value {
  font-size: 28px;
  line-height: 1.1;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.metric-value.compact {
  font-size: 22px;
}

.usage-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.usage-grid div {
  border: 1px solid rgba(36, 121, 100, 0.22);
  border-radius: 8px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.7);
}

.usage-grid span,
.recent-list span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.usage-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 16px;
}

.recent-list {
  display: grid;
  gap: 8px;
}

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

  .workspace {
    min-height: 70vh;
  }

  .portal-panel {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 700px) {
  .app-shell {
    width: 100%;
    min-height: 100vh;
    margin: 0;
  }

  .workspace,
  .meter-panel {
    border-left: 0;
    border-right: 0;
    box-shadow: none;
  }

  .auth-strip,
  .model-row,
  .image-form,
  .wallet-grid,
  .composer {
    grid-template-columns: 1fr;
  }

  .tabs {
    overflow-x: auto;
  }

  .composer button {
    height: 46px;
  }
}
