:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --text: #182027;
  --muted: #64717d;
  --line: #d9e0e6;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --danger: #b42318;
  --shadow: 0 12px 32px rgba(24, 32, 39, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a {
  color: inherit;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 20px;
  min-height: 64px;
  padding: 0 28px;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  font-weight: 800;
  text-decoration: none;
}

.nav {
  display: flex;
  gap: 14px;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}

.user-chip {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-chip span {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.user-chip button,
.download,
.section-title a {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 11px;
  text-decoration: none;
  cursor: pointer;
}

.shell {
  width: min(1440px, calc(100vw - 40px));
  margin: 28px auto 60px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 520px);
  gap: 22px;
  align-items: start;
}

.tool-panel,
.result-panel,
.login-panel,
.history-page {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.tool-panel,
.result-panel,
.history-page {
  padding: 22px;
}

.login-panel {
  width: min(560px, 100%);
  margin: 90px auto;
  padding: 32px;
}

.login-panel h1,
.panel-head h1,
.section-title h1,
.section-title h2,
.result-panel h2 {
  margin: 0;
  line-height: 1.15;
}

.login-panel p,
.eyebrow,
small {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.login-form {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}

.login-form input {
  flex: 1;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 10px 11px;
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

label span {
  color: #2d3843;
  font-size: 0.92rem;
}

.panel-head,
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.tabs {
  display: inline-flex;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 8px;
}

.tab {
  border: 0;
  background: transparent;
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 800;
  color: var(--muted);
}

.tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 10px rgba(24, 32, 39, 0.08);
}

.job-form,
.tab-panel {
  display: none;
}

.tab-panel.active {
  display: grid;
  gap: 16px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 14px;
}

.custom-size {
  display: none;
}

.custom-size.visible {
  display: grid;
}

.primary,
.login-form button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 12px 18px;
  font-weight: 850;
  cursor: pointer;
}

.primary:hover,
.login-form button:hover {
  background: var(--accent-dark);
}

.template-button {
  justify-self: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 12px;
  font-weight: 800;
  cursor: pointer;
}

.template-button:hover {
  background: #dde7ec;
}

.alert,
.error-box {
  border: 1px solid #f3b7b0;
  background: #fff3f1;
  color: var(--danger);
  border-radius: 8px;
  padding: 12px 14px;
}

.record-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.record-grid.wide {
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
}

.record-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
}

.result-panel .record-card {
  padding: 0;
  border: 0;
}

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

.pill {
  background: #dff7f3;
  color: #07534e;
  border-radius: 999px;
  padding: 1px 8px;
  font-weight: 800;
}

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
  margin: 14px 0;
}

figure {
  margin: 0;
  display: grid;
  gap: 8px;
}

.image-button {
  border: 0;
  padding: 0;
  background: transparent;
  cursor: zoom-in;
}

.image-button img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  display: block;
}

.download {
  text-align: center;
  font-size: 0.88rem;
}

.prompt-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

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

.param-list div {
  min-width: 0;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px;
}

.param-list dt {
  color: var(--muted);
  font-size: 0.75rem;
}

.param-list dd {
  margin: 0;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.request-id {
  color: var(--muted);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.history-strip {
  margin-top: 26px;
}

.history-search {
  max-width: 360px;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 24px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.55);
}

.lightbox,
.busy {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
  background: rgba(12, 18, 24, 0.82);
}

.lightbox.open,
.busy.open {
  display: flex;
}

.lightbox img {
  max-width: 92vw;
  max-height: 88vh;
  border-radius: 8px;
}

.lightbox-close {
  position: fixed;
  top: 18px;
  right: 18px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  padding: 9px 12px;
  cursor: pointer;
}

.busy-box {
  display: grid;
  gap: 16px;
  justify-items: center;
  width: min(420px, 90vw);
  padding: 30px;
  background: #fff;
  border-radius: 8px;
}

.spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 5px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

  .settings-grid {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }
}

@media (max-width: 640px) {
  .topbar {
    flex-wrap: wrap;
    padding: 12px 16px;
  }

  .user-chip {
    width: 100%;
    margin-left: 0;
    justify-content: space-between;
  }

  .shell {
    width: min(100% - 24px, 1440px);
    margin-top: 16px;
  }

  .panel-head,
  .section-title,
  .login-form {
    align-items: stretch;
    flex-direction: column;
  }

  .settings-grid,
  .param-list {
    grid-template-columns: 1fr;
  }
}
