/* 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));
  /* Text on a surface filled with --ok, --warn or --error. */
  --on-state: light-dark(#ffffff, #101418);
  --strip-width: 152px;
  --panel-width: 300px;
  --gap: 8px;
  --radius: 4px;
  /* Read by src/ui/theme.js: keep it in milliseconds. */
  --theme-fade: 1000ms;
  --slide-in: 350ms;
  --toolbar-gap: 12px;
  --toolbar-pad: 6px;
  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;
}

/* Set by theme.js only while the theme switches, so hover and state changes stay instant otherwise. */
:root.theme-switching,
:root.theme-switching *,
:root.theme-switching *::before,
:root.theme-switching *::after {
  transition: background-color var(--theme-fade), color var(--theme-fade), border-color var(--theme-fade),
    outline-color var(--theme-fade), fill var(--theme-fade), stroke var(--theme-fade) !important;
}

* {
  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 */

/* The bar has its full height from the start, with the title and the theme button. The tools between them wait
   above the bar, out of view, until the first photo is added, then slide down into it: nothing else moves. */
.toolbar {
  display: flex;
  align-items: center;
  gap: var(--toolbar-gap);
  padding: var(--toolbar-pad) 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-width: 0;
  overflow: hidden;
}

/* As tall as the bar's content (stretch), so its own height plus the bar's padding moves it out completely,
   whichever element of the bar is the tallest with the fonts at hand. Hidden as well until the start: a slide
   position that falls between two pixel rows would otherwise leave a hairline of the buttons at the top edge. */
.toolbar-tools {
  display: flex;
  align-items: center;
  align-self: stretch;
  gap: var(--toolbar-gap);
  flex: 1 1 auto;
  min-width: 0;
  visibility: hidden;
  transform: translateY(calc(-100% - var(--toolbar-pad)));
  transition: transform var(--slide-in) ease-out;
}

body.started .toolbar-tools {
  visibility: visible;
  transform: none;
}

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

/* Holds the label of every step in one grid cell, only the current one visible: the width never changes. */
.commit-step {
  display: inline-grid;
  border-color: var(--ok);
}

.commit-step > span {
  grid-area: 1 / 1;
}

.commit-step > span[aria-hidden="true"] {
  visibility: hidden;
}

.commit-step[data-state="done"] {
  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 */

/* The panel's column is there from the start, as an empty surface (::after). The panel waits to the right of it,
   out of view, until the first photo is added, then slides in over it: strip and stage never change their size. */
.workspace {
  display: grid;
  grid-template-columns: var(--strip-width) minmax(0, 1fr) var(--panel-width);
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.workspace::after {
  content: "";
  grid-area: 1 / 3;
  background: var(--surface);
  border-left: 1px solid var(--border);
}

.workspace > .panel {
  grid-area: 1 / 3;
  z-index: 1;
  visibility: hidden;
  transform: translateX(100%);
  transition: transform var(--slide-in) ease-out;
}

body.started .workspace > .panel {
  visibility: visible;
  transform: none;
}

.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 {
  width: var(--panel-width);
  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;
}

/* A mark with a state colour is filled with it, so the state reads at a glance in both themes. */
.mark[data-state="ok"],
.mark[data-state="warn"],
.mark[data-state="error"] {
  color: var(--on-state);
  font-weight: 600;
}

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

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

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

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

/* Information, not a state: filled with the text colour, so it does not read as a step that was not started. */
.mark[data-state="info"] {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
  font-weight: 600;
}

/* 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-level="error"] {
  border-color: var(--error);
  color: var(--error);
}

/* For what the user must not miss, such as working without seeing the result. */
.message[data-level="warning"] {
  padding: 10px 14px;
  background: var(--warn);
  border-color: var(--warn);
  color: var(--on-state);
  font-size: 16px;
  font-weight: 600;
}

/* 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);
}

.problems ul {
  margin: 0;
  padding-left: 16px;
}

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

#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;
}

#about a {
  color: var(--accent);
}

/* 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;
}

.zip-name {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 13px;
  white-space: nowrap;
}

/* Wide enough to show the whole default name. */
.zip-name input {
  flex: 1 1 auto;
  width: 34ch;
}

.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%;
}
