:root {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1d222b;
  --surface-3: #232a36;
  --line: #2d3645;
  --line-soft: #222936;
  --text: #e6ebf2;
  --muted: #a2afc2;
  --accent: #3db1a5;
  --accent-strong: #2f8e84;
  --danger: #e36a6a;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #0d1015 0%, #10141b 100%);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
}

body.modal-open {
  overflow: hidden;
}

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

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.66;
}

.app-shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
}

.auth-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, rgba(8, 11, 16, 0.92) 0%, rgba(12, 16, 22, 0.96) 100%);
  z-index: 30;
}

.auth-card {
  width: min(460px, 100%);
  display: grid;
  gap: 18px;
  padding: 24px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(23, 26, 33, 0.96);
  box-shadow: var(--shadow);
}

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

.auth-submit {
  width: 100%;
}

.auth-error {
  color: #f0b2b2;
  font-size: 13px;
  line-height: 1.5;
}

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

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
}

.badge-muted {
  color: var(--muted);
}

.badge-success {
  border-color: rgba(61, 177, 165, 0.35);
  color: #8ae0d8;
}

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

.settings-strip,
.mode-switch,
.workspace {
  margin-bottom: 18px;
}

.settings-strip {
  display: grid;
  grid-template-columns: minmax(240px, 1.2fr) minmax(220px, 0.8fr);
  gap: 14px;
}

.settings-strip-compact {
  align-items: stretch;
}

.service-config-card {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(23, 26, 33, 0.92);
}

.service-config-title {
  font-size: 13px;
  color: var(--muted);
}

.service-config-text {
  line-height: 1.6;
}

.mode-switch {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 8px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
}

.tab-button {
  min-width: 112px;
  height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab-button.is-active {
  background: var(--surface-3);
  border-color: var(--line);
  color: var(--text);
}

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

.editor-pane,
.results-pane {
  min-height: 640px;
  padding: 18px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(23, 26, 33, 0.92);
  box-shadow: var(--shadow);
}

.tool-form,
.field-group {
  display: grid;
  gap: 16px;
}

.tool-form.is-hidden {
  display: none;
}

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

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

.field span {
  color: var(--muted);
  font-size: 13px;
}

.prompt-field-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.prompt-field-header label {
  color: var(--muted);
  font-size: 13px;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  padding: 12px 14px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
}

textarea {
  resize: vertical;
  min-height: 140px;
}

.actions {
  display: flex;
  justify-content: flex-start;
}

.primary-button,
.download-button,
.secondary-button,
.icon-button,
.result-preview-button,
.upload-preview-button {
  min-width: 120px;
  height: 42px;
  border: 0;
  cursor: pointer;
}

.primary-button,
.download-button,
.secondary-button {
  padding: 0 18px;
  border-radius: 8px;
  font-weight: 600;
}

.primary-button,
.download-button {
  background: var(--accent);
  color: #081210;
}

.primary-button:hover,
.download-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--line);
}

.secondary-button:hover {
  background: #2a3341;
}

.prompt-optimize-button {
  min-width: 0;
  height: 36px;
  padding: 0 14px;
  font-size: 13px;
}

.logout-button {
  min-width: 72px;
  height: 36px;
  padding: 0 14px;
}

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

.results-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.request-status {
  color: var(--muted);
  font-size: 13px;
}

.progress-shell {
  width: 100%;
  height: 8px;
  margin-bottom: 14px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
}

.progress-bar {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #2f8e84 0%, #55d7c8 100%);
  transition: width 0.24s ease;
}

.error-box {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid rgba(227, 106, 106, 0.35);
  border-radius: 8px;
  background: rgba(227, 106, 106, 0.08);
  color: #f0b2b2;
}

.is-hidden {
  display: none !important;
}

.cache-button {
  min-width: 0;
  height: 36px;
  padding: 0 14px;
  font-size: 13px;
}

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

.result-tile,
.preview-item,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.empty-state {
  min-height: 260px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.result-tile {
  overflow: hidden;
}

.result-preview-button,
.upload-preview-button {
  display: block;
  width: 100%;
  height: auto;
  min-width: 0;
  background: transparent;
  padding: 0;
}

.result-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: #11141a;
}

.result-meta {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.meta-text,
.meta-text a {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.preview-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}

.preview-item {
  overflow: hidden;
}

.preview-item img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
}

.preview-item span {
  display: block;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 12px;
}

.preview-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 8, 12, 0.82);
  z-index: 20;
}

.preview-dialog {
  width: min(1100px, 100%);
  max-height: calc(100vh - 48px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11161d;
  box-shadow: var(--shadow);
}

.preview-dialog-header,
.preview-dialog-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.preview-title {
  font-size: 18px;
  font-weight: 600;
}

.icon-button {
  min-width: 40px;
  width: 40px;
  padding: 0;
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--text);
  font-size: 24px;
  line-height: 1;
}

.preview-stage {
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: auto;
  border-radius: 8px;
  background: #0b0f14;
}

.preview-stage-image {
  max-width: 100%;
  max-height: calc(100vh - 220px);
  object-fit: contain;
}

@media (max-width: 1100px) {
  .settings-strip,
  .workspace {
    grid-template-columns: 1fr;
  }

  .editor-pane,
  .results-pane {
    min-height: auto;
  }
}

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

  .topbar {
    flex-direction: column;
  }

  h1 {
    font-size: 24px;
  }

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

  .prompt-field-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .mode-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .tab-button,
  .primary-button,
  .secondary-button,
  .download-button {
    width: 100%;
  }

  .result-actions,
  .preview-dialog-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .results-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .results-header-actions {
    width: 100%;
    justify-content: space-between;
  }
}
