:root {
  color-scheme: light;
  --paper: #f7f6ef;
  --panel: #ffffff;
  --ink: #1e2528;
  --muted: #667074;
  --line: #d9ded7;
  --teal: #0f766e;
  --teal-strong: #0b5f59;
  --coral: #c2410c;
  --amber: #b7791f;
  --blue: #2563eb;
  --soft-teal: #e3f3ee;
  --soft-coral: #fff0e8;
  --soft-amber: #fff7df;
  --shadow: 0 18px 42px rgba(31, 41, 55, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(230px, 1fr);
  gap: 18px;
  align-items: center;
  min-height: 72px;
  padding: 12px clamp(16px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
  background: rgba(247, 246, 239, 0.92);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  width: fit-content;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--soft-teal);
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.topnav {
  display: inline-flex;
  justify-content: center;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.topnav a {
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
}

.topnav a:hover {
  background: var(--soft-teal);
  color: var(--ink);
}

.account-box {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

.button,
.icon-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  min-height: 40px;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  font-weight: 700;
}

.button:hover,
.icon-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(31, 41, 55, 0.12);
}

.button.primary {
  border-color: var(--teal);
  background: var(--teal);
  color: white;
}

.button.primary:hover {
  background: var(--teal-strong);
}

.button.secondary {
  border-color: #f1c27b;
  background: var(--soft-amber);
}

.button.ghost {
  background: transparent;
}

.button.wide {
  width: 100%;
}

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

.app-shell {
  display: grid;
  grid-template-columns: minmax(210px, 260px) minmax(0, 1fr) minmax(300px, 380px);
  gap: 18px;
  align-items: start;
  padding: 22px clamp(16px, 3vw, 34px);
}

.tool-rail,
.composer-panel,
.usage-panel,
.model-panel,
.result-panel,
.pricing-section,
.history-section,
.admin-section,
.checkout-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.tool-rail {
  position: sticky;
  top: 94px;
  padding: 14px;
}

.rail-heading,
.panel-heading,
.section-title,
.payment-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.rail-heading {
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 800;
}

.rail-heading small {
  color: var(--teal);
}

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

.tool-button {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 54px;
  padding: 9px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

.tool-button:hover,
.tool-button.active {
  border-color: #afd8ce;
  background: var(--soft-teal);
}

.tool-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #fffdf8;
  color: var(--teal-strong);
  font-weight: 900;
}

.tool-button strong,
.tool-button small {
  display: block;
}

.tool-button small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.cost-pill {
  padding: 4px 7px;
  border-radius: 999px;
  background: var(--soft-amber);
  color: #7c4a03;
  font-size: 12px;
  font-weight: 800;
}

.composer-panel {
  min-height: 680px;
  padding: clamp(18px, 3vw, 28px);
}

.panel-heading {
  margin-bottom: 18px;
}

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

.panel-heading h1,
.panel-heading h2,
.section-title h2 {
  margin: 0;
}

.panel-heading h1 {
  font-size: clamp(26px, 4vw, 42px);
  line-height: 1.08;
}

.panel-heading h2,
.section-title h2 {
  font-size: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--coral);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
}

.form-grid {
  display: grid;
  gap: 14px;
}

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

.field span,
.admin-form label,
.auth-form label,
.payment-row label {
  color: #364247;
  font-size: 14px;
  font-weight: 800;
}

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

input,
select {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 128px;
  resize: vertical;
  padding: 12px;
  line-height: 1.55;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 18px;
}

.side-stack {
  display: grid;
  gap: 18px;
  position: sticky;
  top: 94px;
}

.usage-panel,
.model-panel,
.result-panel {
  padding: 18px;
}

.text-link {
  color: var(--teal);
  font-weight: 900;
}

.meter {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7ebe4;
}

.meter-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--amber));
  transition: width 180ms ease;
}

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

.usage-grid div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.usage-grid strong,
.usage-grid span {
  display: block;
}

.usage-grid strong {
  overflow-wrap: anywhere;
  font-size: 18px;
}

.usage-grid span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

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

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(183, 121, 31, 0.14);
}

.status-dot.connected {
  background: var(--teal);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.14);
}

.model-value {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  font-weight: 900;
}

.model-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.mini-actions {
  display: inline-flex;
  gap: 6px;
}

.result-box {
  min-height: 420px;
  max-height: 620px;
  overflow: auto;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10191a;
  color: #ecfdf5;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.58;
}

.checkout-panel {
  margin: 0 clamp(16px, 3vw, 34px) 22px;
  padding: 16px;
}

.checkout-panel-inner {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
}

.pricing-section,
.history-section,
.admin-section,
.legal-section {
  margin: 0 clamp(16px, 3vw, 34px) 22px;
  padding: 22px;
}

.section-title {
  align-items: end;
  margin-bottom: 16px;
}

.payment-row {
  justify-content: flex-start;
  margin-bottom: 14px;
}

.payment-row select {
  max-width: 220px;
}

.payment-warning {
  min-height: 22px;
  margin: -4px 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.plan-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(170px, 1fr));
  gap: 12px;
}

.plan-card,
.history-item {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.plan-card.featured {
  border-color: var(--teal);
  background: var(--soft-teal);
}

.plan-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
}

.plan-card h3,
.plan-card p {
  margin: 0;
}

.plan-card p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.price {
  font-size: 28px;
  font-weight: 900;
}

.price small {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.badge {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--soft-coral);
  color: var(--coral);
  font-size: 12px;
  font-weight: 900;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item button {
  justify-self: start;
}

.history-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.history-output {
  display: -webkit-box;
  overflow: hidden;
  color: #364247;
  line-height: 1.5;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.admin-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(160px, 1fr));
  gap: 12px;
  align-items: end;
}

.admin-form label,
.auth-form label {
  display: grid;
  gap: 7px;
}

.admin-message {
  margin-top: 12px;
  color: var(--teal);
  font-weight: 800;
}

.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

.admin-dashboard {
  margin-top: 16px;
}

.empty-state {
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fffdf8;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
}

.stat-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.stat-card span,
.stat-card strong {
  display: block;
}

.stat-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stat-card strong {
  margin-top: 6px;
  overflow-wrap: anywhere;
  font-size: 24px;
}

.ops-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.ops-panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.ops-panel h3 {
  margin: 0 0 10px;
  font-size: 18px;
}

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

.check-item {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.check-item.ok {
  border-color: #9bd6c8;
  background: var(--soft-teal);
}

.check-item.warn {
  border-color: #f1c27b;
  background: var(--soft-amber);
}

.check-item span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

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

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

th,
td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-weight: 900;
}

.compact-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.legal-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

.legal-grid article {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.legal-grid h3 {
  margin: 0 0 10px;
}

.legal-grid p {
  margin: 0 0 10px;
  color: #364247;
  line-height: 1.6;
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  padding: 12px clamp(16px, 3vw, 34px) 28px;
  color: var(--muted);
  font-size: 13px;
}

.site-footer span {
  font-weight: 900;
  color: var(--ink);
}

.auth-dialog {
  width: min(420px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-dialog::backdrop {
  background: rgba(16, 25, 26, 0.34);
}

.auth-form {
  display: grid;
  gap: 12px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 40;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border: 1px solid #8bd5c5;
  border-radius: 8px;
  background: #ecfdf5;
  color: #134e4a;
  box-shadow: var(--shadow);
  font-weight: 800;
}

.hidden {
  display: none !important;
}

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

  .side-stack {
    grid-column: 1 / -1;
    position: static;
    grid-template-columns: minmax(260px, 360px) 1fr;
  }

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

  .admin-form {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }
}

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

  .topnav,
  .account-box {
    justify-content: start;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .tool-rail {
    position: static;
  }

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

  .side-stack {
    grid-template-columns: 1fr;
  }

  .plan-grid,
  .admin-form,
  .stat-grid,
  .ops-grid,
  .legal-grid {
    grid-template-columns: 1fr;
  }

  .checkout-panel-inner,
  .form-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .tool-list {
    grid-template-columns: 1fr;
  }

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

  .panel-heading {
    align-items: start;
  }
}
