:root {
  color-scheme: light;
  --paper: #f2f0e9;
  --paper-raised: #fbfaf6;
  --paper-muted: #e9e7df;
  --ink: #191b19;
  --ink-soft: #3f443f;
  --muted: #747971;
  --line: #d2d1c9;
  --line-strong: #b9bbb3;
  --accent: #e45737;
  --accent-dark: #bd3b20;
  --green: #28735a;
  --blue: #315f82;
  --amber: #a86b16;
  --danger: #b43f36;
  --radius-sm: 5px;
  --radius-md: 9px;
  --radius-lg: 13px;
  --shadow: 0 18px 50px rgba(25, 27, 25, 0.13);
  --focus: 0 0 0 3px rgba(228, 87, 55, 0.18);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
  scrollbar-color: rgba(63, 68, 63, 0.42) rgba(233, 231, 223, 0.65);
  scrollbar-width: thin;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  border-radius: 999px;
  background: rgba(233, 231, 223, 0.65);
}

*::-webkit-scrollbar-thumb {
  min-height: 40px;
  border: 2px solid transparent;
  border-radius: 999px;
  background: rgba(63, 68, 63, 0.42);
  background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
  background: rgba(228, 87, 55, 0.68);
  background-clip: padding-box;
}

*::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

html {
  max-width: 100%;
  overflow-x: hidden;
  scrollbar-gutter: stable;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  max-width: 100%;
  margin: 0;
  overflow-x: hidden;
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(25, 27, 25, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(25, 27, 25, 0.025) 1px, transparent 1px);
  background-size: 40px 40px;
  color: var(--ink);
  font-family: "Aptos", "Inter", "PingFang SC", "Microsoft YaHei", ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a,
input,
textarea,
summary {
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1,
h2,
h3,
.metric-card strong {
  letter-spacing: -0.025em;
}

a {
  color: inherit;
}

::selection {
  background: rgba(228, 87, 55, 0.22);
}

.hidden,
[hidden] {
  display: none !important;
}

.eyebrow {
  display: block;
  margin-bottom: 7px;
  color: var(--accent);
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 10px !important;
  font-weight: 700;
  letter-spacing: 0.14em;
  line-height: 1.2;
  text-transform: uppercase;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

/* Controls */
button,
.nav-link,
.file-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0 15px;
  cursor: pointer;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition:
    transform 180ms var(--ease),
    border-color 180ms ease,
    background-color 180ms ease,
    color 180ms ease,
    box-shadow 180ms ease;
}

button:hover,
.nav-link:hover,
.file-button:hover {
  transform: translateY(-2px);
}

button:active,
.nav-link:active,
.file-button:active {
  transform: translateY(0) scale(0.985);
}

button:focus-visible,
.nav-link:focus-visible,
.file-button:focus-within {
  outline: 0;
  box-shadow: var(--focus);
}

button:disabled {
  cursor: wait;
  opacity: 0.48;
  transform: none;
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fffaf5;
  box-shadow: 0 8px 20px rgba(189, 59, 32, 0.18);
}

.primary:hover {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
  box-shadow: 0 11px 24px rgba(189, 59, 32, 0.24);
}

.secondary,
.nav-link,
.file-button {
  border-color: var(--line);
  background: var(--paper-raised);
  color: var(--ink);
}

.secondary:hover,
.nav-link:hover,
.file-button:hover {
  border-color: var(--ink-soft);
  background: #fff;
}

.ghost {
  border-color: var(--line);
  background: transparent;
  color: var(--ink-soft);
}

.ghost:hover {
  border-color: var(--line-strong);
  background: rgba(25, 27, 25, 0.04);
}

.danger {
  border-color: rgba(180, 63, 54, 0.28);
  background: rgba(180, 63, 54, 0.07);
  color: var(--danger);
}

.danger:hover {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.wide {
  width: 100%;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: 0;
  background: rgba(255, 255, 255, 0.62);
  color: var(--ink);
  font-weight: 550;
  padding: 11px 12px;
  transition:
    border-color 160ms ease,
    background-color 160ms ease,
    box-shadow 160ms ease;
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 38px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 17px) calc(50% - 2px),
    calc(100% - 12px) calc(50% - 2px);
  background-repeat: no-repeat;
  background-size: 5px 5px, 5px 5px;
}

input,
select {
  min-height: 44px;
}

textarea {
  resize: vertical;
  line-height: 1.6;
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.84);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: var(--focus);
}

::placeholder {
  color: #9a9d97;
}

textarea.locked {
  background: var(--paper-muted);
  color: #676b65;
  cursor: default;
}

.grid-two,
.grid-three,
.admin-grid,
.metric-grid {
  display: grid;
  gap: 14px;
}

.grid-two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.settings-wide {
  grid-column: 1 / -1;
}

.codebox {
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  white-space: pre;
  overflow: auto;
}

.import-area {
  min-height: 154px;
}

/* Custom select */
.native-select-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.custom-select {
  position: relative;
  width: 100%;
  min-width: 0;
}

.custom-select-button {
  width: 100%;
  min-height: 44px;
  justify-content: space-between;
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.62);
  color: var(--ink);
  padding: 0 10px 0 12px;
  text-align: left;
}

.custom-select-button:hover {
  transform: none;
  border-color: var(--line-strong);
  background: #fff;
}

.custom-select.open .custom-select-button,
.custom-select-button:focus-visible {
  border-color: var(--accent);
  outline: 0;
  box-shadow: var(--focus);
}

.custom-select-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.custom-select-chevron {
  width: 23px;
  height: 23px;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  color: var(--muted);
  transition: transform 240ms var(--ease);
}

.custom-select-chevron::before {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translate(-1px, -1px);
}

.custom-select.open .custom-select-chevron {
  transform: rotate(180deg);
}

.custom-select-menu {
  position: absolute;
  z-index: 90;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  max-height: 272px;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: 5px;
  background: rgba(251, 250, 246, 0.98);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  overscroll-behavior: contain;
  scrollbar-color: rgba(63, 68, 63, 0.38) transparent;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  transform-origin: top;
  animation: selectOpen 180ms var(--ease) both;
}

.custom-select-menu::-webkit-scrollbar {
  width: 8px;
}

.custom-select-menu::-webkit-scrollbar-track {
  background: transparent;
}

.custom-select-menu::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: rgba(63, 68, 63, 0.34);
  background-clip: padding-box;
}

.custom-select-menu::-webkit-scrollbar-thumb:hover {
  background: rgba(228, 87, 55, 0.58);
  background-clip: padding-box;
}

.custom-select-option {
  width: 100%;
  min-height: 38px;
  justify-content: flex-start;
  border: 0;
  border-radius: 4px;
  padding: 0 10px;
  background: transparent;
  color: var(--ink-soft);
  box-shadow: none;
  text-align: left;
}

.custom-select-option:hover {
  transform: none;
  background: var(--paper-muted);
  color: var(--ink);
}

.custom-select-option.selected {
  background: rgba(228, 87, 55, 0.12);
  color: var(--accent-dark);
}

.custom-select.is-disabled,
.custom-select-button:disabled {
  opacity: 0.55;
}

.custom-select.inline-select {
  width: 108px;
}

.custom-select.inline-select.usage-date-select {
  width: 176px;
}

.custom-select.inline-select .custom-select-button {
  min-height: 38px;
}

/* Shared surfaces */
.user-shell,
.admin-shell {
  width: min(1480px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 24px 0 52px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(251, 250, 246, 0.94);
  box-shadow: 0 8px 24px rgba(25, 27, 25, 0.045);
  padding: 20px;
}

.panel-title {
  min-height: 42px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-title h2 {
  margin-bottom: 5px;
  font-size: 18px;
  line-height: 1.2;
}

.panel-title span:not(.eyebrow):not(.status-dot) {
  color: var(--muted);
  font-size: 11px;
}

.panel-actions,
.button-row,
.migration-actions,
.usage-chart-controls {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}

/* User workspace */
.user-shell {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 18px;
}

.user-shell > .panel {
  animation: panelEnter 620ms var(--ease) both;
}

.user-shell > .panel:nth-child(2) {
  animation-delay: 70ms;
}

.user-shell > .panel:nth-child(3) {
  animation-delay: 130ms;
}

.token-panel {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 124px;
  align-items: end;
  gap: 16px 12px;
  border-color: var(--line);
  background: rgba(251, 250, 246, 0.96);
  color: var(--ink);
  box-shadow: 0 8px 24px rgba(25, 27, 25, 0.05);
}

.account-panel {
  grid-column: 1 / -1;
}

.account-panel .panel-title {
  margin-bottom: 8px;
}

.account-hint {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
}

.account-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.account-summary > div {
  min-width: 0;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.46);
}

.account-summary dt {
  color: var(--muted);
  font-size: 12px;
}

.account-summary dd {
  margin: 6px 0 0;
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.account-preferences {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.4);
}

.account-preferences h3 { margin: 0 0 4px; font-size: 14px; }
.account-preferences p { margin: 0; color: var(--muted); font-size: 12px; }
.account-api-keys { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; margin-top: 18px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, 0.4); }
.account-api-keys h3 { margin: 0 0 4px; font-size: 14px; }
.account-api-keys p { margin: 0; color: var(--muted); font-size: 12px; }
.api-key-form { display: grid; grid-template-columns: minmax(0, 1fr) 150px auto; align-items: end; gap: 10px; }
.api-key-form label { min-width: 0; display: grid; gap: 5px; margin: 0; color: var(--muted); font-size: 12px; }
.api-key-form button { min-height: 40px; }
.api-key-once { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--accent); border-radius: 10px; background: rgba(228, 87, 55, 0.07); }
.api-key-once[hidden] { display: none; }
.api-key-once strong { font-size: 12px; color: var(--accent-dark); }
.api-key-once > div { display: flex; flex-wrap: wrap; gap: 8px; }
.api-key-once input { flex: 1; min-width: 200px; font-family: "Cascadia Code", Consolas, monospace; }
.api-key-list { display: grid; gap: 8px; }
.api-key-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.api-key-row span { color: var(--muted); font-size: 12px; }
.api-key-row button { min-height: 32px; font-size: 12px; }
.api-key-steps { min-width: 0; max-width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; background: #fff; }
.api-key-steps summary { cursor: pointer; font-size: 12px; font-weight: 700; }
.api-key-steps p { margin-top: 8px; }
.api-key-steps ol { margin: 8px 0; padding-left: 20px; font-size: 12px; line-height: 1.7; }
.api-key-steps pre { min-width: 0; max-width: 100%; overflow-x: auto; margin: 8px 0; padding: 9px; border-radius: 7px; background: var(--paper); font-size: 11px; }
.api-key-steps pre code { white-space: pre-wrap; overflow-wrap: anywhere; }
.client-connection-guides { min-width: 0; display: grid; gap: 9px; padding-top: 12px; border-top: 1px solid var(--line); }
.client-connection-guides[hidden], .client-connection-guides .api-key-steps[hidden] { display: none; }
.client-connection-guides h4 { margin: 0; font-size: 13px; }
.client-connection-guides > p { margin: 0; }
.client-connection-guides code { overflow-wrap: anywhere; }
.preferences-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
  gap: 10px;
}
.preferences-form[hidden] { display: none; }
.preferences-form label { min-width: 0; display: grid; gap: 5px; font-size: 12px; color: var(--muted); }
.preferences-form button { min-height: 40px; }

html[data-density="compact"] .user-shell { gap: 10px; }
html[data-density="compact"] .user-shell > .panel { padding: 14px; }
html[data-density="compact"] .user-shell .panel-title { margin-bottom: 10px; }

@media (max-width: 760px) {
  .preferences-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 480px) {
  .preferences-form { grid-template-columns: minmax(0, 1fr); }
}

.account-ledger-section {
  margin-top: 18px;
}

.account-ledger-section h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

.account-ledger {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.ledger-filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  align-items: end;
  gap: 10px;
  margin-bottom: 12px;
}

.ledger-filters label {
  min-width: 0;
  display: grid;
  gap: 5px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.ledger-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.account-ledger-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
}

.account-ledger-row time {
  color: var(--muted);
  font-size: 12px;
}

.ledger-breakdown {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.account-ledger-row strong {
  white-space: nowrap;
  text-align: right;
}

.token-panel .panel-title,
.token-panel label {
  margin-bottom: 0;
}

.token-panel .token-summary {
  grid-column: 1 / -1;
  min-height: 32px;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
}

.token-summary h1 {
  margin: 0;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.2;
  white-space: nowrap;
}

.token-summary h2 {
  margin: 0;
  font-size: 18px;
}

/* Public site and signed-in workspace */
.site-header {
  width: min(1480px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 17px 0 0;
  display: flex;
  align-items: center;
  gap: 24px;
}

.site-brand {
  flex: none;
  font-size: 19px;
  font-weight: 850;
  letter-spacing: -0.05em;
  text-decoration: none;
}

.site-brand span { color: var(--accent); }
.site-nav { display: flex; align-items: center; gap: 18px; flex: 1; }
.site-nav a { color: var(--ink-soft); font-weight: 650; text-decoration: none; }
.site-nav a:hover { color: var(--accent-dark); }
.header-account { flex: none; }
.user-shell > section[id] { scroll-margin-top: 18px; }
.welcome-panel, .auth-panel, .recent-panel, .explore-panel, .products-panel { grid-column: 1 / -1; }
.welcome-panel { order: 1; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 30px; background: linear-gradient(130deg, #fff9f1, #f7f2e9 60%, #f1e8dc); }
.welcome-panel h1 { font-size: clamp(28px, 3vw, 42px); line-height: 1.13; }
.welcome-panel p { margin-top: 10px; color: var(--ink-soft); }
.welcome-panel .primary { flex: none; }
.auth-panel { order: 2; }
.composer-panel { order: 3; }
.result-panel { order: 4; }
.account-panel { order: 5; }
.recent-panel { order: 6; }
.explore-panel { order: 7; }
.products-panel { order: 8; }
.auth-panel .panel-title { align-items: center; }
.auth-panel .panel-title > span { color: var(--muted); }
.auth-form { display: grid; grid-template-columns: 180px minmax(0, 1fr) minmax(0, 1fr) auto; align-items: end; gap: 12px; }
.auth-form label { margin: 0; }
.auth-form .primary { min-height: 44px; }
.auth-mode-switch { display: flex; align-items: center; gap: 5px; align-self: end; }
.auth-mode-switch button { min-height: 44px; flex: 1; border-color: var(--line); background: var(--paper-raised); color: var(--ink-soft); }
.auth-mode-switch button.selected { border-color: var(--accent); background: rgba(228,87,55,.1); color: var(--accent-dark); }
.signed-in-panel { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.signed-in-panel > span { font-size: 15px; }
.legacy-link { flex-basis: 100%; margin-top: 7px; border-top: 1px solid var(--line); padding-top: 12px; color: var(--muted); }
.legacy-link summary, .legacy-key-details summary { cursor: pointer; font-weight: 700; color: var(--ink-soft); }
.legacy-link p, .legacy-key-details > p { margin: 9px 0; font-size: 12px; }
.legacy-link-row { display: flex; gap: 8px; max-width: 560px; }
.legacy-link-row input { flex: 1; min-width: 0; }
.legacy-key-details { margin-top: 15px; border-top: 1px solid var(--line); padding-top: 12px; }
.legacy-key-details .token-panel { margin-top: 12px; box-shadow: none; }
.account-shortcuts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.account-shortcuts span { border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px; color: var(--muted); font-size: 12px; }
.account-shortcuts a { border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px; color: var(--ink-soft); font-size: 12px; text-decoration: none; }
.work-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.work-card { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.work-preview, .work-placeholder { width: 100%; height: 210px; padding: 0; border: 0; border-radius: 0; background: var(--paper-muted); }
.work-preview { display: block; overflow: hidden; }
.work-preview img { width: 100%; height: 100%; object-fit: cover; }
.work-placeholder { display: grid; place-items: center; color: var(--muted); }
.work-details { display: grid; gap: 8px; padding: 12px; }
.work-details strong { min-height: 42px; line-height: 1.4; overflow-wrap: anywhere; }
.work-details small { color: var(--muted); overflow-wrap: anywhere; }
.work-actions, .result-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.work-actions a, .work-actions button { min-height: 34px; padding: 0 10px; font-size: 12px; }
.result-tools { margin-top: 12px; color: var(--muted); font-size: 12px; }
.product-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(205px, 1fr)); gap: 12px; }
.product-card { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; min-width: 0; padding: 17px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.product-card > span { color: var(--muted); font-size: 12px; }
.product-card h3 { font-size: 17px; }
.product-card strong { color: var(--accent-dark); font-size: 24px; }
.product-card p { min-height: 52px; color: var(--ink-soft); font-size: 12px; }
.product-card button { margin-top: auto; width: 100%; }
.products-panel > .account-hint { margin: 13px 0 0; }
.product-orders-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }
.product-orders-heading strong { font-size: 14px; }
.product-orders-heading button { min-height: 32px; }
.product-orders { display: grid; gap: 7px; margin-top: 9px; color: var(--ink-soft); font-size: 12px; }
.product-orders p { margin: 0; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: #fff; overflow-wrap: anywhere; }

@media (max-width: 900px) {
  .site-header { width: calc(100vw - 20px); flex-wrap: wrap; gap: 9px 16px; }
  .site-nav { order: 3; flex-basis: 100%; overflow-x: auto; padding-bottom: 4px; white-space: nowrap; }
  .header-account { margin-left: auto; }
  .auth-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auth-form .primary { grid-column: 2; }
  .api-key-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .api-key-form button { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
  .welcome-panel { padding: 22px; align-items: flex-start; flex-direction: column; }
  .auth-form { grid-template-columns: 1fr; }
  .auth-form .primary { grid-column: auto; }
  .work-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .work-preview, .work-placeholder { height: 160px; }
  .work-details { padding: 9px; }
  .work-details strong { font-size: 12px; }
  .work-actions { align-items: stretch; flex-direction: column; }
  .work-actions a, .work-actions button { width: 100%; }
  .product-grid { grid-template-columns: 1fr; }
  .legacy-link-row { flex-direction: column; }
  .api-key-form { grid-template-columns: 1fr; }
  .api-key-form button { grid-column: auto; }
}

.token-summary #balanceText {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.token-heading,
.token-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.token-actions {
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.token-purchase {
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(228, 87, 55, 0.07);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color 160ms ease;
}

.token-purchase:hover {
  background: rgba(228, 87, 55, 0.13);
}

.token-purchase:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.status-dot {
  width: 9px;
  height: 9px;
  display: block;
  border-radius: 50%;
  background: #737972;
  box-shadow: 0 0 0 5px rgba(115, 121, 114, 0.12);
  transition: background-color 240ms ease, box-shadow 240ms ease;
}

.status-dot.connected {
  background: #72bc91;
  box-shadow: 0 0 0 5px rgba(114, 188, 145, 0.13);
  animation: statusPulse 2.4s ease-in-out infinite;
}

.token-panel label {
  color: var(--ink-soft);
}

.token-panel input {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.64);
  color: var(--ink);
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

.token-panel input:hover,
.token-panel input:focus {
  border-color: var(--accent);
  background: #fff;
}

.token-panel input:focus {
  box-shadow: 0 0 0 3px rgba(228, 87, 55, 0.22);
}

.token-panel .secondary {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.64);
  color: var(--ink-soft);
}

.token-panel .secondary:hover {
  border-color: var(--ink-soft);
  background: #fff;
  color: var(--ink);
}

.token-submit,
.merge-fields > button {
  min-height: 44px;
}

.merge-panel {
  grid-column: 1 / -1;
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.merge-toggle {
  min-height: 32px;
  justify-content: space-between;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.merge-toggle:hover {
  transform: none;
  color: var(--ink);
}

.merge-toggle-hint {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  transition: transform 220ms var(--ease);
}

.merge-toggle-hint::before {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
}

.merge-panel.open .merge-toggle-hint {
  transform: rotate(180deg);
}

.merge-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 124px;
  align-items: end;
  gap: 12px;
  animation: reveal 240ms var(--ease) both;
}

.merge-fields label {
  margin-bottom: 0;
}

.composer-panel,
.result-panel {
  min-height: calc(100vh - 132px);
}

.composer-panel {
  padding: 24px;
}

.composer-panel:has(.custom-select.open) {
  z-index: 2;
}

.form-section {
  border-top: 1px solid var(--line);
  padding-top: 20px;
  margin-top: 20px;
}

.prompt-section {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}

.form-section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 15px;
}

.form-section-title > span {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  color: var(--muted);
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
}

.form-section-title strong {
  font-size: 13px;
}

.prompt-section textarea {
  min-height: 180px;
  font-size: 15px;
}

.prompt-field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
}

.prompt-field-head label {
  margin: 0;
}

.prompt-convert-btn {
  min-height: 32px;
  padding: 0 11px;
  font-size: 11px;
}

.prompt-convert-modal {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(25, 27, 25, 0.28);
  backdrop-filter: blur(8px);
  animation: modalIn 180ms ease both;
}

.prompt-convert-dialog {
  width: min(560px, 100%);
  padding: 22px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--paper-raised);
  box-shadow: 0 28px 80px rgba(25, 27, 25, 0.2);
  animation: reveal 240ms var(--ease) both;
}

.prompt-convert-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.prompt-convert-close {
  width: 36px;
  min-height: 36px;
  padding: 0;
  border-color: var(--line);
  background: var(--paper-muted);
  color: var(--ink);
  font-size: 22px;
  font-weight: 400;
}

.prompt-convert-note {
  margin: -2px 0 15px;
  color: var(--muted);
  font-size: 11px;
}

#artistInput,
#negativeInput {
  min-height: 174px;
}

#promptConvertInput,
#negativeInput {
  font-size: 15px;
  line-height: 1.7;
}

.advanced-prompts {
  margin-top: 12px;
  border-top: 1px solid var(--line);
}

.advanced-prompts summary {
  padding: 14px 0;
  color: var(--ink-soft);
  font-weight: 600;
  cursor: pointer;
}

.advanced-prompts > label:last-child {
  margin-bottom: 0;
}

.character-prompts-panel { padding-bottom: 12px; }
.character-position-mode { display: grid; gap: 6px; margin-top: 12px; font-size: 12px; color: var(--muted); }
.character-position-mode select { width: 100%; }
.character-prompt-list { display: grid; gap: 12px; margin: 12px 0; }
.character-prompt-card { display: grid; gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: rgba(255,255,255,.52); }
.character-prompt-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.character-prompt-head strong { font-size: 13px; }
.character-prompt-head button { min-height: 32px; }
.character-prompt-card label { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.character-prompt-card textarea { width: 100%; min-height: 72px; resize: vertical; }
.character-prompts-panel > button { min-height: 38px; }
.precise-reference-panel { display: grid; gap: 10px; }
.precise-reference-panel > label { display: block; font-size: 12px; color: var(--muted); }
.precise-reference-panel > input { display: block; max-width: 100%; }
.precise-reference-panel > img { max-width: 160px; max-height: 180px; border-radius: 9px; object-fit: contain; background: #111; }
.precise-reference-panel > button { min-height: 38px; }
.inpaint-canvas-wrap { display: grid; gap: 9px; max-width: 520px; }
.inpaint-canvas-wrap canvas { width: 100%; height: auto; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 9px; background: #fff; touch-action: none; cursor: crosshair; }
.inpaint-tools { display: flex; flex-wrap: wrap; gap: 10px; }
.inpaint-tools label { display: grid; gap: 4px; min-width: 150px; color: var(--muted); font-size: 12px; }
.inpaint-tools select, .inpaint-tools input { width: 100%; }
.inpaint-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.inpaint-actions button { min-height: 38px; }

.parameter-grid { align-items: start; }
.parameter-grid input, .parameter-grid .custom-select-button { height: 44px; }
.parameter-field { display: grid; align-content: start; gap: 7px; min-width: 0; margin-bottom: 14px; }
.parameter-limits, .parameter-hint, .parameter-status { color: var(--muted); font-size: 12px; line-height: 1.6; }
.parameter-limits { margin: 4px 0 8px; }
.parameter-hint { display: block; }
.parameter-status { min-height: 1.6em; margin: 7px 0 0; }
.parameter-status.is-error { color: var(--accent-dark); font-weight: 600; }
.parameter-grid > label { align-content: start; }
.parameter-grid > label > span, .parameter-label { display: flex; align-items: center; gap: 6px; min-height: 28px; }
.parameter-label label { margin: 0; }
.parameter-range { display: flex; align-items: center; gap: 12px; height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: rgba(255, 255, 255, 0.62); }
.parameter-range:focus-within { border-color: var(--accent); box-shadow: var(--focus); }
.parameter-range input { flex: 1; min-width: 0; margin: 0; padding: 0; border: 0; background: transparent; box-shadow: none; accent-color: var(--accent); cursor: pointer; }
.parameter-range output { flex: 0 0 4ch; color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.parameter-help-button { position: relative; flex-shrink: 0; width: 20px; min-height: 20px; padding: 0; border: 1px solid var(--line-strong); border-radius: 50%; background: transparent; color: var(--muted); font-size: 11px; }
.parameter-help-button::after { content: ''; position: absolute; inset: -4px; }
.parameter-help-button:hover { transform: none; color: var(--accent); border-color: var(--accent); }
.parameter-help-dialog { width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); margin: auto; padding: 22px; border: 1px solid var(--line-strong); border-radius: var(--radius-lg); background: var(--paper-raised); color: var(--ink); box-shadow: 0 24px 80px rgba(25, 27, 25, 0.2); }
.parameter-help-dialog::backdrop { background: rgba(25, 27, 25, 0.32); backdrop-filter: blur(4px); }
.parameter-help-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.parameter-help-heading form { margin: 0; }
.parameter-help-dialog p { white-space: pre-line; font-size: 14px; line-height: 1.8; }
.parameter-help-dialog a { display: inline-block; margin-top: 18px; color: var(--muted); font-size: 12px; }
html:has(#parameterHelpDialog[open]) { overflow: hidden; }

.result-panel {
  position: sticky;
  top: 94px;
  padding: 16px;
}

.result-heading {
  margin: 2px 4px 15px;
}

.result-title-main {
  width: 100%;
  min-width: 0;
}

.result-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.result-title-row h2 {
  margin-bottom: 4px;
}

#jobText {
  display: none;
}

.result-actions {
  flex: 0 0 auto;
}

.generation-count-control {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 3px;
  background: var(--paper-muted);
}

.generation-count-control > span {
  padding: 0 7px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.generation-count-control button {
  min-width: 34px;
  min-height: 34px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  font-size: 11px;
}

.generation-count-control button:hover {
  background: rgba(255, 255, 255, 0.65);
  color: var(--ink);
  transform: none;
}

.generation-count-control button.selected {
  background: var(--paper-raised);
  color: var(--accent-dark);
  box-shadow: 0 2px 8px rgba(25, 27, 25, 0.09);
}

.image-frame {
  position: relative;
  min-height: 720px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: var(--radius-md);
  background-color: #e9e7df;
  background-image:
    linear-gradient(rgba(25, 27, 25, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(25, 27, 25, 0.045) 1px, transparent 1px);
  background-size: 32px 32px;
  color: var(--muted);
}

.image-frame::after {
  content: "";
  position: absolute;
  inset: 15px;
  border: 1px solid rgba(25, 27, 25, 0.09);
  border-radius: 5px;
  pointer-events: none;
}

.image-frame.loading {
  background-color: var(--paper-muted);
}

.image-frame.result-ready {
  min-height: 0;
  display: grid;
  align-items: start;
  overflow: visible;
  background: transparent;
}

.image-frame.result-ready::after {
  display: none;
}

.image-frame.batch-mode {
  min-height: 0;
  display: block;
  overflow: visible;
  padding: 0;
  background: transparent;
}

.image-frame.batch-mode::after {
  display: none;
}

.batch-result-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 12px;
}

.image-frame.batch-landscape .batch-result-grid {
  grid-template-columns: minmax(0, 1fr);
}

.batch-result-card {
  position: relative;
  min-width: 0;
  min-height: 310px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background-color: var(--paper-muted);
  background-image:
    linear-gradient(rgba(25, 27, 25, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(25, 27, 25, 0.035) 1px, transparent 1px);
  background-size: 24px 24px;
}

.batch-result-card:is(.has-generation-preview, .is-done) {
  min-height: 0;
}

.batch-card-state {
  width: min(210px, calc(100% - 32px));
  display: grid;
  place-items: center;
  gap: 6px;
  text-align: center;
}

.batch-card-state strong,
.batch-card-error strong {
  color: var(--ink-soft);
  font-size: 12px;
}

.batch-card-state .batch-card-number,
.batch-card-error .batch-card-number {
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 16px;
  font-style: normal;
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1;
}

.batch-card-status {
  color: var(--muted);
  font-size: 10px;
}

.batch-card-status:empty {
  display: none;
}

.batch-card-orbit {
  position: relative;
  width: 60px;
  height: 60px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
}

.batch-card-orbit::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px dashed var(--line-strong);
  border-radius: 50%;
}

.batch-card-orbit::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 999px;
  background: conic-gradient(from 0deg, transparent 0 56%, rgba(228, 87, 55, 0.18) 70%, var(--accent) 92%, #efb75a 100%);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 0);
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 0);
  animation: orbit 700ms linear infinite;
  backface-visibility: hidden;
  transform: translateZ(0);
  will-change: transform;
}

.result-image-button.batch-image-button {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 0;
  box-shadow: none;
}

.image-frame .batch-image-button img {
  width: 100%;
  height: auto;
  min-height: 0;
  object-fit: contain;
}

.batch-image-index {
  position: absolute;
  top: 10px;
  left: 10px;
  min-width: 30px;
  padding: 4px 7px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 999px;
  background: rgba(25, 27, 25, 0.62);
  color: #fff;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
  line-height: 1;
  backdrop-filter: blur(8px);
}

.batch-card-error {
  width: min(220px, calc(100% - 36px));
  display: grid;
  gap: 7px;
  text-align: center;
}

.batch-card-error span {
  color: var(--danger);
  font-size: 10px;
  overflow-wrap: anywhere;
}

.batch-result-card.is-review .batch-card-error span {
  color: var(--amber);
}

.image-frame > span,
.frame-error {
  position: relative;
  z-index: 1;
  padding: 12px 16px;
  text-align: center;
}

.frame-error {
  color: var(--danger);
  font-weight: 700;
}

.loading-state {
  position: relative;
  z-index: 1;
  width: min(380px, calc(100% - 40px));
  display: grid;
  place-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 30px 24px;
  background: rgba(251, 250, 246, 0.92);
  color: var(--ink);
  text-align: center;
}

.loading-state strong {
  font-size: 15px;
}

.loading-state p {
  color: var(--muted);
  font-size: 11px;
}

.loading-orbit {
  position: relative;
  width: 76px;
  height: 76px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
}

.loading-orbit::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px dashed var(--line-strong);
  border-radius: 50%;
}

.loading-orbit::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0 56%, rgba(228, 87, 55, 0.18) 70%, var(--accent) 92%, #efb75a 100%);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 0);
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 0);
  animation: orbit 700ms linear infinite;
  backface-visibility: hidden;
  transform: translateZ(0);
  will-change: transform;
}

.generation-stream-panel {
  width: 100%;
}

.image-frame:not(.has-generation-preview) > .loading-state > .generation-stream-panel,
.batch-result-card:not(.has-generation-preview) > .batch-card-state > .batch-card-progress,
.generation-stream-panel[hidden] {
  display: none;
}

.generation-stream-track,
.batch-card-progress {
  width: 100%;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(10, 17, 20, 0.58);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.28), 0 2px 8px rgba(0, 0, 0, 0.3);
}

.generation-stream-track span,
.batch-card-progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #f16d45, #ffab63 75%, #ffe3ad);
  box-shadow: 0 0 8px rgba(255, 171, 99, 0.5);
  transition: width 180ms linear;
}

.loading-steps {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.loading-steps span {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.5);
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
  transition: border-color 180ms ease, background-color 180ms ease, color 180ms ease, box-shadow 180ms ease;
}

.loading-steps span::before {
  content: "";
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--line-strong);
  transition: background-color 180ms ease, box-shadow 180ms ease;
}

.loading-steps span.active {
  border-color: rgba(40, 115, 90, 0.28);
  background: rgba(40, 115, 90, 0.07);
  color: var(--green);
}

.loading-steps span.active::before {
  background: var(--green);
}

.loading-steps span.current {
  border-color: rgba(228, 87, 55, 0.55);
  background: rgba(228, 87, 55, 0.1);
  color: var(--accent-dark);
  box-shadow: 0 0 0 3px rgba(228, 87, 55, 0.08);
}

.loading-steps span.current::before {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(228, 87, 55, 0.12);
  animation: stepPulse 1.4s ease-in-out infinite;
}

.result-image-button {
  width: 100%;
  max-width: 100%;
  min-height: 0;
  display: block;
  border: 0;
  border-radius: var(--radius-md);
  padding: 0;
  overflow: hidden;
  background: transparent;
  box-shadow: 0 18px 45px rgba(25, 27, 25, 0.16);
  cursor: zoom-in;
  animation: imageReveal 600ms var(--ease) both;
}

.result-image-button:hover {
  transform: none;
}

.image-frame img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: none;
  object-fit: contain;
}

.image-frame > .result-image-button img {
  width: 100%;
  height: auto;
}

.live-generation-preview {
  position: relative;
  width: 100%;
  overflow: hidden;
}

.live-generation-preview[hidden] {
  display: none;
}

.image-frame .live-generation-preview img {
  width: 100%;
  height: auto;
}

.image-frame.has-generation-preview {
  min-height: 0;
}

.image-frame.has-generation-preview::after {
  display: none;
}

.has-generation-preview > .loading-state,
.has-generation-preview > .batch-card-state {
  position: absolute;
  z-index: 2;
  left: 14px;
  right: 14px;
  bottom: 14px;
  width: auto;
  display: block;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  pointer-events: none;
  transition: opacity 180ms ease-out;
}

.has-generation-preview > .loading-state > :not(.generation-stream-panel),
.has-generation-preview > .batch-card-state > :not(.batch-card-progress) {
  display: none;
}

.finishing-generation > .result-image-button {
  position: absolute;
  inset: 0;
  height: 100%;
  z-index: 1;
}

.finishing-generation > .result-image-button img {
  height: 100%;
  min-height: 0;
  object-fit: contain;
}

.finishing-generation > .loading-state,
.finishing-generation > .batch-card-state {
  opacity: 0;
}

.result-image-button.from-generation-preview {
  animation: none;
}

/* Admin layout */
.admin-shell {
  font-size: 14px;
}

#dashboard {
  display: grid;
  gap: 18px;
}

.login-panel {
  width: min(900px, 100%);
  min-height: 430px;
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  margin: 8vh auto 0;
  overflow: hidden;
  padding: 0;
  animation: panelEnter 620ms var(--ease) both;
}

.login-intro,
.login-form {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(32px, 5vw, 64px);
}

.login-intro {
  position: relative;
  overflow: hidden;
  background: var(--paper-muted);
  color: var(--ink);
}

.login-intro::after {
  content: "N2";
  position: absolute;
  right: -12px;
  bottom: -52px;
  color: rgba(25, 27, 25, 0.035);
  font-size: 190px;
  font-weight: 800;
  letter-spacing: -0.12em;
  line-height: 1;
}

.login-intro h1 {
  margin-bottom: 14px;
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1.05;
}

.login-intro p {
  max-width: 360px;
  color: var(--muted);
  font-size: 13px;
}

.login-form label {
  margin-bottom: 18px;
}

.dashboard-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 2px 5px;
  animation: panelEnter 560ms var(--ease) both;
}

.dashboard-heading h1 {
  font-size: clamp(26px, 3vw, 38px);
  line-height: 1.08;
}

.metric-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.metric-card {
  position: relative;
  min-height: 146px;
  display: grid;
  align-content: space-between;
  overflow: hidden;
  border: 1px solid var(--line);
  border-top: 3px solid var(--ink);
  border-radius: var(--radius-md);
  padding: 18px;
  background: rgba(251, 250, 246, 0.92);
  animation: panelEnter 560ms var(--ease) both;
}

.metric-card:nth-child(2) {
  animation-delay: 50ms;
}

.metric-card:nth-child(3) {
  animation-delay: 100ms;
}

.metric-card:nth-child(4) {
  animation-delay: 150ms;
}

.metric-card:nth-child(5) {
  animation-delay: 200ms;
}

#metricSpeed1h {
  font-size: clamp(22px, 3vw, 38px);
}

.metric-card::after {
  content: attr(data-index);
  position: absolute;
  top: 14px;
  right: 16px;
  color: var(--line-strong);
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
}

.metric-card > span {
  color: var(--muted);
  font-size: 11px;
}

.metric-card strong {
  margin-top: 16px;
  font-size: clamp(30px, 4vw, 48px);
  font-weight: 650;
  line-height: 0.95;
}

.metric-card small {
  margin-top: 10px;
  color: var(--accent);
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 8px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.section-heading {
  display: grid;
  grid-template-columns: minmax(160px, 0.35fr) 1fr;
  gap: 24px;
  border-top: 1px solid var(--line-strong);
  padding: 25px 2px 2px;
  margin-top: 18px;
}

.section-heading > span {
  color: var(--accent);
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.section-heading h2 {
  margin-bottom: 3px;
  font-size: 21px;
}

.section-heading p {
  color: var(--muted);
  font-size: 11px;
}

.admin-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.wide-grid #requestLogPanel {
  grid-column: 1 / -1;
}

.account-form-panel {
  min-height: 100%;
}

.admin-side-stack {
  display: grid;
  align-content: start;
  gap: 14px;
  min-width: 0;
}

.prompt-api-model-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  margin-bottom: 14px;
}

.prompt-api-model-row label {
  margin-bottom: 0;
}

.prompt-api-model-row button {
  min-height: 44px;
}

.migration-panel {
  display: flex;
  flex-direction: column;
}

.migration-actions {
  margin-bottom: 14px;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.usage-panel {
  animation: panelEnter 620ms 190ms var(--ease) both;
}

.usage-chart {
  min-width: 0;
}

.usage-chart-stack {
  display: grid;
  gap: 14px;
}

.chart-stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.chart-stat-row span {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  background: var(--paper);
  color: var(--muted);
  font-size: 10px;
}

.usage-chart-block {
  min-width: 0;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.usage-chart-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
}

.usage-chart-heading strong {
  font-size: 12px;
}

.usage-chart-heading span {
  color: var(--muted);
  font-size: 10px;
}

.usage-chart-scroll {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-width: thin;
  cursor: grab;
}

.usage-chart-scroll.dragging {
  cursor: grabbing;
  user-select: none;
}

.single-hourly-chart {
  width: 100%;
  min-width: 900px;
  height: auto;
  display: block;
}

.chart-bg {
  fill: #f6f4ee;
}

.chart-grid {
  stroke: #dddcd4;
  stroke-width: 1;
}

.chart-grid-hour {
  stroke: #e8e6df;
}

.chart-axis {
  stroke: #aeb1aa;
  stroke-width: 1.2;
}

.chart-label,
.chart-tick,
.chart-axis-label,
.chart-empty-note {
  fill: #787d76;
  font-size: 10px;
}

.chart-axis-label {
  fill: #424742;
  font-weight: 700;
}

.chart-line {
  fill: none;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 2400;
  stroke-dashoffset: 2400;
  animation: drawLine 1.2s 100ms var(--ease) forwards;
}

.chart-line-count {
  stroke: var(--green);
}

.chart-line-failure {
  stroke: var(--danger);
}

.chart-point {
  stroke: #fff;
  stroke-width: 2;
}

.chart-point-count {
  fill: var(--green);
}

.chart-point-failure {
  fill: var(--danger);
}

.chart-hit-point {
  fill: transparent;
  cursor: crosshair;
}

.chart-node-tooltip {
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.chart-hour-point:hover .chart-node-tooltip {
  opacity: 1;
}

.chart-node-tooltip rect {
  fill: #191b19;
}

.chart-node-tooltip text {
  fill: rgba(255, 255, 255, 0.68);
  font-size: 10px;
}

.chart-node-tooltip .chart-tooltip-title {
  fill: #fff;
  font-weight: 700;
}

/* Admin lists */
.collapsible-panel {
  padding-bottom: 18px;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.collapsible-panel:not(.is-collapsed) {
  border-color: var(--line-strong);
  box-shadow: 0 14px 34px rgba(25, 27, 25, 0.07);
}

.collapsible-panel .panel-title {
  align-items: center;
  margin-bottom: 0;
}

.collapsible-panel:not(.is-collapsed) .panel-title {
  margin-bottom: 16px;
}

.collapse-toggle {
  min-width: 76px;
}

.collapsible-panel:not(.is-collapsed) .collapse-toggle::after {
  content: "↑";
}

.collapsible-body {
  min-width: 0;
  animation: reveal 260ms var(--ease) both;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  padding: 8px;
  background: var(--paper);
}

.toolbar button,
.toolbar input,
.toolbar .checkline {
  min-height: 36px;
}

.toolbar button {
  padding-inline: 11px;
  font-size: 11px;
}

.search-input {
  min-width: 220px;
  flex: 1 1 260px;
}

.inline-input {
  width: 96px;
  flex: 0 0 96px;
}

.checkline {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: var(--ink-soft);
  white-space: nowrap;
}

.checkline input,
.row-check {
  width: 16px;
  height: 16px;
  min-height: 0;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}

.data-list {
  max-height: 600px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.38);
}

.data-row {
  min-width: 0;
  min-height: 68px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 12px;
  animation: rowEnter 320ms var(--ease) both;
}

.data-row:last-child {
  border-bottom: 0;
}

.data-row.selectable {
  grid-template-columns: 18px minmax(0, 1fr) auto;
}

.data-row:hover {
  background: rgba(255, 255, 255, 0.72);
}

.row-main {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.user-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.row-heading {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.data-row strong {
  display: block;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 12px;
}

.data-row span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  word-break: break-all;
}

.token-text {
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

.account-audit-status {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 12px;
}

.account-operational,
.account-credential-summary {
  color: var(--ink-soft) !important;
}

.account-operational.account-warning {
  color: var(--danger) !important;
  font-weight: 650;
}

.account-cycle-budget-detail {
  color: var(--ink-soft);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.account-cycle-budget-detail summary { cursor: pointer; }
.account-cycle-budget-detail span { display: block; margin-top: 4px; }

.reconciliation-workspace { display: grid; gap: 12px; padding: 16px; border-bottom: 1px solid var(--line); }
.reconciliation-workspace > p { margin: 0; }
.reconciliation-query { display: grid; grid-template-columns: 145px minmax(180px, 1fr) auto; align-items: end; gap: 10px; }
.reconciliation-query label { display: grid; gap: 6px; min-width: 0; color: var(--ink-soft); font-size: 12px; }
.reconciliation-query input, .reconciliation-query select { width: 100%; }
.reconciliation-result, .reconciliation-pending { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: rgba(255, 255, 255, .56); color: var(--ink-soft); font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; }
.reconciliation-result.is-warning, .reconciliation-pending.is-warning { border-color: rgba(180, 63, 54, .4); }
.reconciliation-result h3 { margin: 0 0 8px; font-size: 14px; }
.reconciliation-result p { margin: 4px 0; }
.reconciliation-ledger { display: grid; gap: 5px; margin: 10px 0 0; padding: 0; list-style: none; }
.reconciliation-ledger li { display: flex; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); padding-top: 5px; }
.reconciliation-review-panel { display: grid; gap: 9px; border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: rgba(255,255,255,.4); }
.reconciliation-review-panel > div:first-child { display: grid; gap: 3px; }
.reconciliation-review-panel strong { font-size: 12px; }
.reconciliation-review-panel span, .reconciliation-review-panel .account-hint { color: var(--muted); font-size: 11px; }
.reconciliation-review-form { display: grid; grid-template-columns: 220px minmax(220px,1fr) auto; align-items: end; gap: 10px; }
.reconciliation-review-form label { display: grid; gap: 6px; min-width: 0; }
.reconciliation-review-form input, .reconciliation-review-form select { width: 100%; }
.reconciliation-review-history { display: grid; gap: 4px; color: var(--ink-soft); font-size: 11px; }
.reconciliation-review-history p { margin: 0; border-top: 1px solid var(--line); padding-top: 5px; overflow-wrap: anywhere; }
.reconciliation-review-history button { min-height: 28px; margin-left: 8px; padding: 0 8px; font-size: 11px; }
.reconciliation-adjustment-panel { display: grid; gap: 9px; border: 1px solid rgba(180, 63, 54, .34); border-radius: 10px; padding: 12px; background: rgba(255, 247, 243, .6); }
.reconciliation-adjustment-panel[hidden] { display: none; }
.reconciliation-adjustment-panel > div:first-child { display: grid; gap: 3px; }
.reconciliation-adjustment-panel strong { font-size: 12px; }
.reconciliation-adjustment-panel span, .reconciliation-adjustment-panel .account-hint { color: var(--ink-soft); font-size: 11px; }
.reconciliation-adjustment-form { display: grid; grid-template-columns: 220px minmax(220px,1fr) auto; align-items: end; gap: 10px; }
.reconciliation-adjustment-form label { display: grid; gap: 6px; min-width: 0; }
.reconciliation-adjustment-form input { width: 100%; }
.reconciliation-pending-heading, .job-audit-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.reconciliation-pending-heading strong, .job-audit-heading strong { font-size: 13px; }
.reconciliation-pending > * + * { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; }
.reconciliation-pending button { min-height: 30px; margin-left: 8px; padding: 0 8px; font-size: 11px; }
.test-orders-workspace { display: grid; gap: 10px; padding: 16px; border-bottom: 1px solid var(--line); }
.manual-orders-workspace { display: grid; gap: 12px; padding: 15px; border: 1px solid var(--line-strong); border-radius: 11px; background: #fffaf3; }
.manual-orders-workspace.is-disabled { border-color: var(--line); background: var(--paper-muted); }
.manual-orders-heading { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.manual-orders-heading > div { display: grid; gap: 5px; }
.manual-orders-heading strong { font-size: 15px; }
.manual-orders-heading span, .manual-orders-workspace > .account-hint { font-size: 11px; color: var(--ink-soft); }
.manual-orders-badge { flex: 0 0 auto; padding: 5px 9px; border: 1px solid var(--line-strong); border-radius: 99px; }
.manual-orders-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; align-items: end; }
.manual-orders-form label, .manual-order-decision-panel label { display: grid; gap: 6px; min-width: 0; font-size: 12px; color: var(--ink-soft); }
.manual-orders-form input, .manual-orders-form select, .manual-order-decision-panel input { width: 100%; min-height: 38px; }
.manual-orders-user-search, .manual-orders-user-results, #manualOrderSelectedUser { grid-column: 1 / -1; }
.manual-orders-query { display: flex; gap: 8px; }
.manual-orders-query input { flex: 1 1 auto; min-width: 0; }
.manual-orders-query button { flex: 0 0 auto; }
.manual-orders-user-results { display: grid; gap: 6px; max-height: 190px; overflow-y: auto; font-size: 11px; color: var(--muted); }
.manual-order-user-option { display: grid; gap: 3px; min-width: 0; text-align: left; white-space: normal; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); padding: 9px 11px; overflow-wrap: anywhere; }
.manual-order-user-option:hover, .manual-order-user-option.is-selected { border-color: var(--accent); background: rgba(228, 87, 55, .07); }
.manual-order-user-option strong { font-size: 12px; }
.manual-order-user-option span { font-size: 11px; color: var(--ink-soft); }
.manual-orders-form > button { justify-self: start; }
.manual-order-decision-panel { display: grid; gap: 10px; padding: 14px; border: 1px solid var(--accent); border-radius: 10px; background: #fff; }
.manual-order-decision-panel[hidden], .manual-order-decision-form[hidden] { display: none; }
.manual-order-decision-panel > span { color: var(--ink-soft); font-size: 12px; overflow-wrap: anywhere; }
.manual-order-decision-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.manual-order-decision-panel .checkline { display: flex; align-items: center; }
.manual-order-decision-panel .checkline input { width: auto; min-height: 0; }
.manual-order-decision-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.test-orders-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.test-orders-heading > div:first-child { display: grid; gap: 5px; }
.test-orders-heading strong { font-size: 13px; }
.test-orders-heading span { color: var(--muted); font-size: 11px; }
.test-orders-controls { display: flex; align-items: center; gap: 8px; }
.test-orders-controls select { width: auto; }
.test-orders-list { display: grid; gap: 8px; }
.test-order-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 9px; padding: 10px; background: rgba(255,255,255,.56); }
.test-order-row > div { display: grid; gap: 4px; min-width: 0; font-size: 11px; color: var(--ink-soft); overflow-wrap: anywhere; }
.test-order-row strong { color: var(--ink); font-size: 12px; }
.test-order-row button { flex: 0 0 auto; min-height: 30px; padding: 0 9px; font-size: 11px; }
.test-order-actions { display: flex !important; flex-wrap: wrap; gap: 6px !important; justify-content: flex-end; }
.test-order-decision-panel, .membership-adjustment-panel { display: grid; gap: 9px; border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: rgba(255,255,255,.55); }
.test-order-decision-panel[hidden], .membership-adjustment-panel[hidden] { display: none; }
.test-order-decision-panel span, .membership-adjustment-panel span { color: var(--ink-soft); font-size: 11px; }
.test-order-decision-panel input, .membership-adjustment-form input { min-height: 34px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; background: var(--paper-raised); color: var(--ink); }
.membership-adjustment-form { display: flex; flex-wrap: wrap; gap: 7px; }
.membership-adjustment-form input[type="number"] { width: 150px; }
.membership-adjustment-form input[type="text"] { flex: 1 1 240px; }
#membershipAdjustmentHistory { display: grid; gap: 5px; }
.test-orders-workspace > button { justify-self: start; }
.job-audit-heading { padding: 16px; }
.job-audit-heading > div:first-child { display: grid; gap: 5px; }
.job-audit-heading span { color: var(--muted); font-size: 11px; }
.job-audit-filters { display: flex; align-items: center; gap: 8px; }
.job-audit-filters select, .job-audit-filters input { width: auto; max-width: 220px; }
.job-audit-side { display: grid; justify-items: end; gap: 8px; }
.job-audit-side button { min-height: 30px; padding: 0 9px; font-size: 11px; }
.job-billing-line { color: var(--ink-soft) !important; font-size: 11px !important; }
.audit-job-id { font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace; }

@media (max-width: 820px) {
  .reconciliation-query { grid-template-columns: 1fr 2fr; }
  .reconciliation-query > button { grid-column: 1 / -1; }
  .reconciliation-review-form { grid-template-columns: 1fr 2fr; }
  .reconciliation-review-form > button { grid-column: 1 / -1; }
  .reconciliation-adjustment-form { grid-template-columns: 1fr 2fr; }
  .reconciliation-adjustment-form > button { grid-column: 1 / -1; }
  .job-audit-heading { align-items: stretch; flex-direction: column; }
  .test-orders-heading { align-items: stretch; flex-direction: column; }
  .manual-orders-form, .manual-order-decision-form { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .reconciliation-query { grid-template-columns: 1fr; }
  .reconciliation-query > button { grid-column: auto; }
  .reconciliation-review-form { grid-template-columns: 1fr; }
  .reconciliation-review-form > button { grid-column: auto; }
  .reconciliation-adjustment-form { grid-template-columns: 1fr; }
  .reconciliation-adjustment-form > button { grid-column: auto; }
  .job-audit-filters { flex-direction: column; align-items: stretch; }
  .job-audit-filters select, .job-audit-filters input { max-width: none; width: 100%; }
  .job-audit-side { justify-items: start; }
  .test-orders-controls { align-items: stretch; flex-direction: column; }
  .test-order-row { align-items: stretch; flex-direction: column; }
  .manual-orders-heading { align-items: start; }
  .manual-orders-query { flex-direction: column; align-items: stretch; }
}

.merge-trace,
.step-route {
  width: fit-content;
  max-width: 100%;
  border-left: 2px solid var(--blue);
  padding: 3px 7px;
  background: rgba(49, 95, 130, 0.06);
  color: var(--blue) !important;
  font-weight: 650;
}

.row-stats {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.row-stats > span {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  border: 1px solid var(--line);
  padding: 0 8px;
  background: var(--paper);
}

.row-stats b {
  color: var(--ink);
  font-size: 11px;
}

.row-action {
  min-height: 30px;
  border-color: var(--line);
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
  font-size: 10px;
  box-shadow: none;
}

.route-badge,
.tier-badge,
.status-badge,
.pill {
  min-height: 24px;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  margin: 0 !important;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 9px !important;
  font-weight: 800;
  white-space: nowrap;
  word-break: normal !important;
}

.route-badge {
  border: 1px solid rgba(49, 95, 130, 0.18);
  background: rgba(49, 95, 130, 0.07);
  color: var(--blue) !important;
}

.tier-opus {
  background: rgba(168, 107, 22, 0.11);
  color: #85540f !important;
}

.tier-scroll {
  background: rgba(49, 95, 130, 0.1);
  color: var(--blue) !important;
}

.tier-tablet,
.status-badge.ok {
  background: rgba(40, 115, 90, 0.1);
  color: var(--green) !important;
}

.tier-free,
.tier-unknown,
.status-badge.muted {
  background: rgba(116, 121, 113, 0.11);
  color: var(--muted) !important;
}

.tier-error,
.status-badge.danger {
  background: rgba(180, 63, 54, 0.1);
  color: var(--danger) !important;
}

.status-badge.active {
  background: rgba(49, 95, 130, 0.1);
  color: var(--blue) !important;
}

.pill {
  background: rgba(228, 87, 55, 0.1);
  color: var(--accent-dark) !important;
}

.job-time {
  margin: 0 !important;
  white-space: nowrap;
}

.error-line {
  color: var(--danger) !important;
}

.error-detail {
  margin-top: 6px;
}

.error-detail summary {
  width: fit-content;
  cursor: pointer;
  color: var(--blue);
  font-size: 10px;
  font-weight: 700;
}

.error-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.error-detail pre {
  max-height: 260px;
  overflow: auto;
  margin: 6px 0 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  background: var(--paper);
  color: var(--ink-soft);
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.error-log-list {
  max-height: 620px;
}

.empty {
  min-height: 148px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  padding: 20px;
  color: var(--muted);
  text-align: center;
}

.data-list .empty {
  border: 0;
  border-radius: 0;
}

.empty.small {
  min-height: 90px;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 10px;
}

.pager button {
  min-height: 34px;
  padding-inline: 12px;
}

/* Cache and preview */
.image-cache-actions {
  justify-content: flex-end;
}

.image-cache-actions .search-input {
  width: 250px;
  min-width: 180px;
}

.image-cache-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.image-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--paper-raised);
  transition: transform 240ms var(--ease), border-color 180ms ease, box-shadow 240ms ease;
  animation: rowEnter 420ms var(--ease) both;
}

.image-card:hover {
  z-index: 1;
  border-color: var(--line-strong);
  box-shadow: 0 16px 34px rgba(25, 27, 25, 0.1);
  transform: translateY(-4px);
}

.image-preview-trigger {
  width: 100%;
  min-height: 300px;
  aspect-ratio: 4 / 3;
  display: block;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: var(--paper-muted);
  cursor: zoom-in;
}

.image-preview-trigger:hover {
  transform: none;
}

.image-card img,
.preview-stage img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.image-preview-trigger img {
  transition: transform 500ms var(--ease), filter 300ms ease;
}

.image-card:hover .image-preview-trigger img {
  transform: scale(1.025);
}

.image-card-body {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.image-card-body strong {
  min-height: 33px;
  overflow: hidden;
  color: var(--ink);
  font-size: 11px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.image-card-body span {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-meta-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.modal-open {
  overflow: hidden !important;
}

html.modal-open,
html:has(body.modal-open) {
  width: 100%;
  height: 100%;
  overflow: hidden !important;
  scrollbar-gutter: auto;
}

.image-preview {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 24px;
  background: rgba(12, 14, 12, 0.9);
  backdrop-filter: blur(12px);
  animation: modalIn 220ms ease both;
}

.preview-stage {
  width: min(1080px, 100%);
  max-height: calc(100vh - 48px);
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-md);
  background: #151715;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.45);
}

.preview-stage > img {
  width: 100%;
  max-height: calc(100vh - 128px);
  object-fit: contain;
  background: #101210;
}

.result-preview-stage {
  position: relative;
  width: fit-content;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 48px);
  display: block;
  overflow: visible;
  border: 0;
  background: transparent;
  box-shadow: none;
  line-height: 0;
}

.result-preview-stage img {
  width: auto;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 48px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-md);
  object-fit: contain;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.45);
  cursor: zoom-in;
  transform-origin: center;
  transition: opacity 760ms cubic-bezier(0.22, 1, 0.36, 1), filter 760ms cubic-bezier(0.22, 1, 0.36, 1), transform 160ms ease;
  user-select: none;
  -webkit-user-drag: none;
}

.result-preview-stage img.zoomed {
  cursor: grab;
}

.result-preview-stage img.zoomed:active {
  cursor: grabbing;
}

.preview-meta {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  color: #fff;
}

.preview-meta strong {
  font-size: 12px;
}

.preview-meta span {
  color: rgba(255, 255, 255, 0.5);
  font-size: 10px;
}

.preview-close,
.preview-nav {
  position: fixed;
  z-index: 102;
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  backdrop-filter: blur(12px);
}

.preview-close {
  top: 16px;
  right: 16px;
  width: 42px;
  height: 42px;
  min-height: 42px;
  padding: 0 0 3px;
  font-size: 25px;
}

.preview-nav {
  top: 50%;
  width: 48px;
  height: 66px;
  min-height: 66px;
  padding: 0 0 3px;
  font-size: 36px;
  transform: translateY(-50%);
}

.preview-nav:hover,
.preview-nav:active,
.preview-nav:focus,
.preview-nav:focus-visible,
.preview-nav:disabled {
  transform: translateY(-50%);
}

.preview-prev {
  left: 18px;
}

.preview-next {
  right: 18px;
}

.toast {
  --toast-accent: var(--green);
  position: fixed;
  top: 22px;
  right: 22px;
  z-index: 120;
  width: max-content;
  min-width: 280px;
  max-width: min(420px, calc(100vw - 32px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 14px 18px 14px 45px;
  background: rgba(251, 250, 246, 0.96);
  color: var(--ink);
  box-shadow: 0 18px 48px rgba(25, 27, 25, 0.16);
  opacity: 0;
  pointer-events: none;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  transform: translateX(18px) scale(0.97);
  transition: opacity 180ms ease, transform 320ms var(--ease);
  backdrop-filter: blur(16px) saturate(120%);
}

.toast::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 18px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--toast-accent);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--toast-accent) 12%, transparent);
  transform: translateY(-50%);
}

.toast::after {
  content: "";
  position: absolute;
  top: 9px;
  bottom: 9px;
  left: 0;
  width: 3px;
  border-radius: 0 999px 999px 0;
  background: var(--toast-accent);
}

.toast.show {
  opacity: 1;
  transform: translateX(0) scale(1);
}

.toast.error {
  --toast-accent: var(--danger);
  border-color: rgba(180, 63, 54, 0.22);
  background: rgba(255, 248, 247, 0.97);
  color: #96352e;
}

/* Motion */
@keyframes panelEnter {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes rowEnter {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes imageReveal {
  from {
    opacity: 0;
    transform: scale(0.985);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes statusPulse {
  0%,
  100% {
    box-shadow: 0 0 0 5px rgba(114, 188, 145, 0.12);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(114, 188, 145, 0.03);
  }
}

@keyframes orbit {
  from {
    transform: translateZ(0) rotate(0deg);
  }
  to {
    transform: translateZ(0) rotate(360deg);
  }
}

@keyframes stepPulse {
  0%,
  100% {
    box-shadow: 0 0 0 3px rgba(228, 87, 55, 0.1);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(228, 87, 55, 0.02);
  }
}

@keyframes selectOpen {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes modalIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}


@keyframes drawLine {
  to {
    stroke-dashoffset: 0;
  }
}

/* Responsive */
@media (max-width: 1120px) {
  .user-shell {
    grid-template-columns: 1fr;
  }

  .result-panel {
    position: relative;
    top: auto;
    min-height: auto;
  }

  .composer-panel {
    min-height: auto;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-grid,
  .wide-grid {
    grid-template-columns: 1fr;
  }

  .wide-grid #requestLogPanel {
    grid-column: auto;
  }
}

@media (max-width: 820px) {
  .account-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  * {
    scrollbar-width: none !important;
    scrollbar-gutter: auto !important;
  }

  *::-webkit-scrollbar {
    display: none;
    width: 0 !important;
    height: 0 !important;
  }

  .user-shell,
  .admin-shell {
    width: calc(100vw - 20px);
    padding-top: 10px;
    padding-bottom: 28px;
  }

  .token-panel,
  .merge-fields {
    grid-template-columns: minmax(0, 1fr) 96px;
  }

  .login-panel {
    grid-template-columns: 1fr;
    margin-top: 10px;
  }

  .login-intro,
  .login-form {
    padding: 30px;
  }

  .dashboard-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .section-heading {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .panel-title {
    align-items: stretch;
    flex-direction: column;
  }

  .collapsible-panel .panel-title {
    align-items: flex-start;
    flex-direction: row;
  }

  .usage-chart-controls,
  .image-cache-actions {
    width: 100%;
  }

  .image-cache-actions .search-input {
    width: 100%;
    flex-basis: 100%;
  }

  .toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar .search-input {
    width: 100%;
    grid-column: 1 / -1;
  }

  .toolbar button,
  .toolbar .inline-input,
  .toolbar .checkline {
    width: 100%;
    min-width: 0;
  }

  .data-row.selectable,
  .account-row.selectable,
  .user-row.selectable {
    grid-template-columns: 18px minmax(0, 1fr);
  }

  .row-stats,
  .user-row .pill {
    grid-column: 2;
    justify-self: start;
  }

  .error-detail-grid {
    grid-template-columns: 1fr;
  }

  .image-frame {
    min-height: 520px;
  }
}

@media (max-width: 560px) {
  .account-summary {
    grid-template-columns: 1fr;
  }

  .ledger-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .account-ledger-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .account-ledger-row time {
    grid-column: 1;
    grid-row: 2;
  }

  .account-ledger-row strong {
    grid-column: 2;
    grid-row: 1 / 3;
  }
  body {
    background-size: 28px 28px;
  }

  .toast {
    width: calc(100vw - 24px);
    min-width: 0;
    top: 12px;
    right: 12px;
  }

  .dashboard-heading > .top-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
  }

  .dashboard-heading > .top-actions > * {
    width: 100%;
  }

  .panel {
    border-radius: var(--radius-md);
    padding: 15px;
  }

  .composer-panel {
    padding: 17px;
  }

  .grid-two,
  .grid-three,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .metric-card {
    min-height: 126px;
  }

  .result-title-row {
    align-items: stretch;
    flex-direction: column;
  }

  .result-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .generation-count-control {
    width: 100%;
    display: grid;
    grid-template-columns: auto repeat(3, minmax(0, 1fr));
  }

  .batch-result-grid {
    gap: 8px;
  }

  .batch-result-card {
    min-height: 230px;
  }

  .button-row,
  .migration-actions,
  .usage-chart-controls,
  .image-cache-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .button-row button,
  .button-row .file-button,
  .migration-actions button,
  .migration-actions .file-button,
  .usage-chart-controls button,
  .usage-chart-controls .custom-select,
  .image-cache-actions button,
  .image-cache-actions .custom-select {
    width: 100%;
  }

  .custom-select.inline-select,
  .custom-select.inline-select.usage-date-select {
    width: 100%;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .toolbar .search-input {
    grid-column: auto;
  }

  .data-list {
    max-height: none;
  }

  .data-row,
  .job-row,
  .error-log-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .row-stats {
    flex-wrap: wrap;
    justify-content: flex-start;
    white-space: normal;
  }

  .row-stats > span,
  .row-stats .row-action {
    flex: 1 1 auto;
  }

  .image-cache-grid {
    grid-template-columns: 1fr;
  }

  .image-preview-trigger {
    min-height: 240px;
  }

  .image-preview {
    padding: 12px;
  }

  .result-preview-stage,
  .result-preview-stage img {
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
  }

  .preview-nav {
    top: auto;
    bottom: 16px;
    width: 42px;
    height: 54px;
    min-height: 54px;
    transform: none;
  }

  .preview-nav:hover,
  .preview-nav:active,
  .preview-nav:focus,
  .preview-nav:focus-visible,
  .preview-nav:disabled {
    transform: none;
  }

  .preview-prev {
    left: 16px;
  }

  .preview-next {
    right: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
