:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --ink: #151b23;
  --muted: #667085;
  --line: #d8dee8;
  --line-strong: #b9c2d0;
  --accent: #1663d8;
  --accent-strong: #0d4fb8;
  --accent-soft: #e8f1ff;
  --danger: #c93434;
  --danger-soft: #fff0f0;
  --success: #16784a;
  --shadow: 0 18px 48px rgba(25, 36, 55, 0.12);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

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

button {
  cursor: pointer;
}

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

.app-shell {
  display: grid;
  grid-template-columns: minmax(340px, 430px) minmax(0, 1fr);
  gap: 20px;
  min-height: 100vh;
  padding: 20px;
}

.settings-panel,
.workspace-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.settings-panel {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 24px;
  border-bottom: 1px solid var(--line);
}

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

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
  line-height: 1.3;
}

.status-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.header-tools {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.lang-select {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.settings-form {
  display: grid;
  gap: 18px;
  padding: 24px;
}

.field-group {
  display: grid;
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

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

label,
legend {
  color: #263245;
  font-size: 14px;
  font-weight: 750;
}

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

input[type="password"],
input[type="text"],
input[type="url"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

input,
select {
  min-height: 42px;
  padding: 9px 11px;
}

textarea {
  min-height: 168px;
  resize: vertical;
  padding: 12px;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

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

.control-grid label,
.advanced-grid label {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.reference-box {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--panel-soft);
}

.reference-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.reference-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}

.reference-preview img {
  width: 58px;
  height: 58px;
  border-radius: 6px;
  object-fit: cover;
}

.advanced-options {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--panel-soft);
}

.advanced-options summary {
  cursor: pointer;
  color: #263245;
  font-size: 14px;
  font-weight: 800;
}

.advanced-grid {
  margin-top: 14px;
}

.check-row {
  align-content: end;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 9px;
}

.check-row input {
  min-height: auto;
}

.primary-button,
.secondary-button,
.text-button,
.icon-button,
.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: var(--radius);
  padding: 8px 13px;
  text-decoration: none;
  white-space: nowrap;
}

.primary-button {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 850;
}

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

.secondary-button,
.icon-button,
.file-button {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: #22304a;
  font-weight: 750;
}

.secondary-button:hover,
.icon-button:hover,
.file-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.text-button {
  min-height: 30px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  padding: 4px 0;
}

.form-alert {
  border: 1px solid #ffd0d0;
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--danger);
  padding: 11px 12px;
  font-size: 14px;
  line-height: 1.45;
}

.workspace-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  overflow: hidden;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 16px 18px 0;
  border-bottom: 1px solid var(--line);
}

.tab {
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 12px 14px;
  font-weight: 850;
}

.tab.is-active {
  border-bottom-color: var(--accent);
  color: var(--accent);
}

.tab-panel {
  min-height: 0;
  padding: 20px;
  overflow: auto;
}

.result-stage {
  display: grid;
  place-items: center;
  min-height: min(68vh, 720px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(45deg, #f2f4f7 25%, transparent 25%),
    linear-gradient(-45deg, #f2f4f7 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f2f4f7 75%),
    linear-gradient(-45deg, transparent 75%, #f2f4f7 75%);
  background-color: #fff;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
  padding: 22px;
}

.empty-state,
.loading-state {
  max-width: 360px;
  text-align: center;
  color: var(--muted);
}

.empty-icon {
  width: 78px;
  height: 78px;
  margin: 0 auto 18px;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.loading-state {
  width: min(420px, 100%);
}

.spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto 16px;
  border: 4px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

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

.progress-track {
  height: 10px;
  border-radius: 999px;
  background: #dfe7f3;
  overflow: hidden;
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

#progress-value {
  display: inline-block;
  margin-top: 8px;
  font-size: 13px;
  font-weight: 800;
}

.result-view {
  display: grid;
  gap: 16px;
  width: 100%;
  margin: 0;
}

.result-view img {
  display: block;
  max-width: 100%;
  max-height: min(62vh, 680px);
  margin: 0 auto;
  border-radius: var(--radius);
  object-fit: contain;
  box-shadow: 0 10px 28px rgba(22, 36, 60, 0.2);
}

.result-view figcaption {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  padding: 14px;
}

#result-prompt {
  color: #263245;
  line-height: 1.5;
}

.result-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.result-meta div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px;
  background: var(--panel-soft);
}

.result-meta dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.result-meta dd {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 750;
}

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

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.history-head h2 {
  margin-bottom: 0;
}

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

.history-empty {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.history-item {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 12px;
}

.history-thumb {
  width: 92px;
  height: 92px;
  border-radius: 7px;
  object-fit: cover;
  background: var(--panel-soft);
}

.history-copy {
  min-width: 0;
}

.history-copy strong {
  display: block;
  overflow: hidden;
  color: #263245;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-copy span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .settings-panel {
    max-height: none;
  }

  .result-stage {
    min-height: 56vh;
  }
}

@media (max-width: 560px) {
  .brand,
  .settings-form,
  .tab-panel {
    padding: 16px;
  }

  .control-grid,
  .advanced-grid,
  .result-meta {
    grid-template-columns: 1fr;
  }

  .input-row {
    grid-template-columns: 1fr;
  }

  .history-item {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .history-thumb {
    width: 72px;
    height: 72px;
  }

  .history-item .secondary-button {
    grid-column: 1 / -1;
  }

  .result-actions {
    display: grid;
  }
}
