/* Colours are light-dark(light, dark): without a data-theme on <html> they follow prefers-color-scheme
   (src/ui/theme.js sets data-theme once the user picked one). Needs Firefox 120, Chrome 123, Safari 17.5. */
:root {
  color-scheme: light dark;
  --bg: light-dark(#eceef1, #1c1e21);
  --surface: light-dark(#f7f8fa, #25282c);
  --surface-raised: light-dark(#ffffff, #2e3236);
  --border: light-dark(#c5cad1, #3a3f45);
  --text: light-dark(#1d2024, #e4e6e8);
  --text-muted: light-dark(#59616a, #9aa1a8);
  --accent: light-dark(#1d6fd6, #6fb3ff);
  --accent-text: light-dark(#ffffff, #0e1a26);
  --ok: light-dark(#18804a, #5fcf8a);
  --warn: light-dark(#9a6200, #e8c15a);
  --error: light-dark(#c42b2b, #ff7a7a);
  --overlay-bg: light-dark(rgba(255, 255, 255, 0.92), rgba(20, 22, 24, 0.9));
  --strip-width: 152px;
  --panel-width: 300px;
  --gap: 8px;
  --radius: 4px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
}

:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

body.dropping .stage {
  outline: 2px dashed var(--accent);
  outline-offset: -6px;
}

h1,
h2 {
  margin: 0;
  font-weight: 600;
}

h1 {
  font-size: 15px;
  white-space: nowrap;
}

h2 {
  font-size: 13px;
  margin-bottom: 6px;
}

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

button {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover:not(:disabled) {
  border-color: var(--text-muted);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

kbd {
  font: inherit;
  font-size: 11px;
  padding: 0 4px;
  border: 1px solid currentColor;
  border-radius: 3px;
  opacity: 0.7;
}

input[type="text"],
input[type="number"],
select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 6px;
  width: 100%;
}

input.invalid {
  border-color: var(--error);
}

.note,
.hint {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: normal;
  margin: 4px 0;
}

.warning {
  color: var(--warn);
  font-size: 12px;
  margin: 6px 0 0;
}

/* Toolbar */

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-width: 0;
}

.mode-switch {
  display: flex;
  gap: 4px;
}

.commit-step {
  border-color: var(--ok);
}

.commit-step:disabled {
  color: var(--ok);
}

.inline-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.inline-toggle:has(input:disabled) {
  opacity: 0.5;
}

.export-buttons {
  display: flex;
  align-items: center;
  gap: 4px;
}

button.small {
  font-size: 12px;
  padding: 2px 8px;
}

.icon-button {
  display: flex;
  align-items: center;
  padding: 4px 6px;
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

#theme-toggle[data-state="light"] .icon-moon,
#theme-toggle:not([data-state="light"]) .icon-sun {
  display: none;
}

.model-status {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 12px;
  text-align: right;
}

.model-status[data-state="loading"] {
  color: var(--warn);
}

.model-status[data-state="error"] {
  color: var(--error);
}

/* Workspace */

.workspace {
  display: grid;
  grid-template-columns: var(--strip-width) minmax(0, 1fr) var(--panel-width);
  min-height: 0;
}

.strip,
.panel {
  background: var(--surface);
}

.strip {
  overflow-y: auto;
  padding: var(--gap);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* The Name section stays pinned at the top; the rest of the panel scrolls below it. */
.panel {
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel > .panel-pinned {
  flex: none;
  padding: var(--gap);
}

.panel-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 var(--gap) var(--gap);
}

.photo-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.photo-item {
  position: relative;
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 4px;
  background: var(--bg);
}

.photo-item.active {
  border-color: var(--accent);
}

.photo-thumb {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
}

.photo-thumb canvas {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

.photo-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 0 6px;
  line-height: 18px;
  background: rgba(0, 0, 0, 0.65);
  border-color: transparent;
  color: #ffffff;
}

.photo-caption {
  font-size: 12px;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.photo-marks {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 3px;
}

.mark {
  font-size: 10px;
  padding: 0 4px;
  border-radius: 3px;
  border: 1px solid currentColor;
}

.mark[data-state="ok"] {
  color: var(--ok);
}

.mark[data-state="warn"] {
  color: var(--warn);
}

.mark[data-state="missing"] {
  color: var(--text-muted);
  border-style: dashed;
}

.mark[data-state="error"] {
  color: var(--error);
  font-weight: 600;
}

.mark[data-state="info"] {
  color: var(--text-muted);
}

/* Stage */

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.empty-hint {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  pointer-events: none;
  text-align: center;
  padding: 24px;
}

.stage[data-status="empty"] .empty-hint {
  display: flex;
}

.message {
  position: absolute;
  left: 12px;
  bottom: 12px;
  max-width: calc(100% - 24px);
  margin: 0;
  padding: 6px 10px;
  background: var(--overlay-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  pointer-events: none;
}

.message[data-error="true"] {
  border-color: var(--error);
  color: var(--error);
}

/* Panel */

.panel-section {
  padding: var(--gap) 0;
  border-bottom: 1px solid var(--border);
}

.panel-section:last-child {
  border-bottom: 0;
}

.panel-section > summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}

.files {
  font-size: 12px;
  margin: 6px 0 0;
  word-break: break-all;
}

.problems {
  font-size: 12px;
  margin: 4px 0 0;
  color: var(--warn);
}

.problems[data-ready="true"] {
  color: var(--ok);
}

.preview-canvas {
  display: block;
  width: 100%;
  height: auto;
  background: var(--bg);
}

#preview[data-state="pending"] .preview-canvas {
  opacity: 0.75;
}

.slider-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: var(--gap);
  margin-bottom: 4px;
}

.slider-row input {
  grid-column: 1 / -1;
  width: 100%;
  margin: 2px 0 0;
}

.slider-row output {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  font-size: 12px;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: var(--gap);
}

.field-row {
  margin-top: var(--gap);
}

.field-row label {
  display: block;
  font-size: 12px;
  margin-bottom: 2px;
}

.field-row.field-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
}

.field-row.field-checkbox label {
  margin: 0;
}

/* A click on these labels resets their setting (settings-panel.js). */
label.resettable {
  width: fit-content;
  cursor: pointer;
}

label.resettable:hover {
  text-decoration: underline dotted;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.settings-actions > .note {
  margin: 0;
}

.settings-actions > p.note {
  flex-basis: 100%;
}

.field-error {
  color: var(--error);
  font-size: 12px;
  margin: 2px 0 0;
}

.shortcuts {
  font-size: 12px;
  margin: 6px 0 0;
}

.shortcuts dt {
  color: var(--text);
  font-weight: 600;
  margin-top: 6px;
}

.shortcuts dd {
  margin: 0;
  color: var(--text-muted);
}

.shortcuts[data-ai="off"] .needs-ai {
  opacity: 0.45;
}

.ai-icon {
  display: inline-block;
  vertical-align: -1px;
  color: var(--accent);
}

.ai-icon svg {
  display: block;
  width: 12px;
  height: 12px;
  fill: currentColor;
}

.privacy {
  font-size: 12px;
  margin: 6px 0;
}

.credits {
  font-size: 12px;
  margin: 4px 0;
  padding-left: 18px;
}

.credits li {
  margin-bottom: 4px;
}

/* Dialogs */

dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px 20px;
  max-width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  overflow-y: auto;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

dialog h2 {
  font-size: 15px;
  margin-bottom: 8px;
}

dialog p {
  margin: 0 0 8px;
}

.dialog-details,
.export-summary {
  margin: 0 0 12px;
  padding-left: 18px;
  font-size: 13px;
}

.export-summary li {
  margin-bottom: 8px;
}

.export-summary .summary-warning {
  color: var(--warn);
  font-weight: 600;
}

.export-choice {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  font-size: 13px;
}

.export-choice li {
  margin-bottom: 6px;
}

.export-choice label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.export-choice .warning {
  margin: 2px 0 0 22px;
}

.export-summary li.failed {
  color: var(--error);
}

.dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: var(--gap);
}

#progress-dialog progress {
  width: 320px;
  max-width: 100%;
}
