:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --ink: #172033;
  --muted: #667085;
  --panel: #ffffff;
  --line: #d7dde8;
  --line-strong: #b7c0ce;
  --accent: #166534;
  --accent-dark: #0f4f2a;
  --blue: #2357d8;
  --warning: #b45309;
  --danger: #b42318;
  --shadow: 0 18px 46px rgba(28, 40, 62, 0.12);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #ffffff 0%, var(--bg) 38%, #eef3f8 100%);
  color: var(--ink);
}

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

.app-shell {
  min-height: 100vh;
  padding: 28px;
}

.workspace {
  width: min(1220px, 100%);
  margin: 0 auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 24px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #2a3447;
  font-size: 15px;
  font-weight: 700;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #172033;
  color: #f8fafc;
  font-size: 13px;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  margin-top: 18px;
  max-width: 780px;
  font-size: 78px;
  line-height: 0.94;
  letter-spacing: 0;
}

h2 {
  font-size: 22px;
  line-height: 1.2;
}

.account {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.credit-pill,
.account-pill {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid #b9d7c1;
  border-radius: 999px;
  background: #f1fbf3;
  color: var(--accent-dark);
  font-size: 14px;
  font-weight: 700;
}

.account-pill {
  border-color: #cfd7e5;
  background: #ffffff;
  color: #344054;
}

.login-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 430px);
  gap: 28px;
  align-items: stretch;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  padding: 16px 8px;
}

.login-copy h2 {
  font-size: 34px;
}

.login-copy p {
  max-width: 560px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
}

.login-form,
#generationForm {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.mode-switch {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  width: min(260px, 100%);
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.mode-button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #475467;
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
}

.mode-button.active {
  background: #ffffff;
  color: var(--accent-dark);
  box-shadow: 0 1px 4px rgba(16, 24, 40, 0.12);
}

label,
.field span {
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
  transition:
    border-color 140ms ease,
    box-shadow 140ms ease;
}

input,
select {
  height: 48px;
  padding: 0 14px;
}

textarea {
  resize: vertical;
  min-height: 190px;
  padding: 14px;
  line-height: 1.6;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(35, 87, 216, 0.12);
}

.primary-button,
.ghost-button,
.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 18px;
  cursor: pointer;
  text-decoration: none;
  font-size: 14px;
  font-weight: 800;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
}

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

.primary-button:disabled {
  cursor: wait;
  background: #8ab39a;
}

.ghost-button,
.download-link {
  background: #ffffff;
  color: #263245;
  border-color: var(--line);
}

.ghost-button:hover,
.download-link:hover {
  border-color: var(--line-strong);
}

.tool-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.9fr) minmax(380px, 1.1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 34px rgba(28, 40, 62, 0.08);
}

.composer,
.result,
.history {
  padding: 20px;
}

.history {
  grid-column: 1 / -1;
}

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

.section-heading span {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.form-row.two-cols {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.generate-button {
  height: 48px;
  width: 100%;
}

.reference-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
}

.reference-panel[hidden] {
  display: none !important;
}

.section-heading.compact {
  margin-bottom: 0;
}

.section-heading.compact h3 {
  margin: 0;
  font-size: 17px;
}

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

.upload-row input[type="file"] {
  height: auto;
  min-height: 44px;
  padding: 9px;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

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

.reference-item {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.reference-item img {
  width: 52px;
  height: 52px;
  border-radius: 6px;
  object-fit: cover;
  background: #eef2f7;
}

.reference-item span {
  min-width: 0;
  overflow: hidden;
  color: #344054;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  min-height: 36px;
  padding: 0 12px;
  font-size: 13px;
}

.image-stage {
  display: grid;
  place-items: center;
  min-height: 420px;
  border: 1px dashed #c9d2df;
  border-radius: 8px;
  background: #f9fbfd;
  overflow: hidden;
}

.image-stage img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 620px;
  object-fit: contain;
  background: #eef2f7;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 12px;
  color: var(--muted);
  text-align: center;
}

.empty-state svg {
  width: 68px;
  height: 68px;
  fill: none;
  stroke: #7b8799;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.history-item {
  display: flex;
  flex-direction: column;
  min-height: 230px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #ffffff;
}

.thumb {
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 0.72;
  background: #eef2f7;
  overflow: hidden;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.history-body {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.history-body p {
  min-height: 42px;
  color: #263245;
  font-size: 14px;
  line-height: 1.45;
}

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

.history-ref-count {
  color: var(--muted);
  font-size: 12px;
}

.status-failed {
  color: var(--danger);
}

.status-pending {
  color: var(--warning);
}

.toast {
  position: fixed;
  right: 20px;
  top: 86px;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #172033;
  color: #ffffff;
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

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

[hidden] {
  display: none !important;
}

@media (max-width: 860px) {
  .app-shell {
    padding: 18px;
  }

  .topbar,
  .login-panel,
  .tool-grid,
  .form-row,
  .form-row.two-cols,
  .upload-row {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  h1 {
    max-width: 100%;
    font-size: 44px;
    line-height: 1.04;
  }

  .account {
    justify-content: flex-start;
  }

  .login-panel {
    padding: 20px;
  }

  .login-copy h2 {
    font-size: 26px;
  }

  .image-stage {
    min-height: 300px;
  }

  .toast {
    top: auto;
    right: 18px;
    bottom: 18px;
  }
}

@media (max-width: 420px) {
  h1 {
    font-size: 40px;
  }
}
