:root {
  color-scheme: light;
  --bg: #EEF2F4;
  --surface: #FFFFFF;
  --ink: #132430;
  --muted: #566874;
  --line: #D3DCE1;
  --primary: #1F4E79;
  --primary-ink: #FFFFFF;
  --before: #9A5600;
  --before-soft: #FFF0D9;
  --after: #0A7363;
  --after-soft: #DCF2EC;
  --danger: #B3261E;
  --radius-lg: 14px;
  --radius-sm: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0E1920;
    --surface: #16242D;
    --ink: #E5EDF1;
    --muted: #9AAFBB;
    --line: #2A3C47;
    --primary: #8CBCEB;
    --primary-ink: #0E1920;
    --before: #F2AE55;
    --before-soft: #3A2A13;
    --after: #52C9B3;
    --after-soft: #113630;
    --danger: #FF8A80;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
svg { width: 1.15em; height: 1.15em; flex: none; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .9rem clamp(1rem, 3vw, 2rem);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.1rem; }
.brand svg { width: 1.6rem; height: 1.6rem; color: var(--primary); }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 1.25rem;
  padding: 1.25rem clamp(1rem, 3vw, 2rem) 3rem;
  max-width: 1400px;
  margin: 0 auto;
}
.overview { grid-column: 1 / -1; }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
}
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  min-width: 0;
}
.capture { align-self: start; position: sticky; top: 1rem; }
@media (max-width: 860px) { .capture { position: static; } }

/* ---------- Form fields ---------- */
.field { margin: 1.1rem 0 0; border: 0; padding: 0; }
.field-row { display: flex; justify-content: space-between; align-items: baseline; }
label, legend { display: block; font-weight: 700; margin-bottom: .35rem; padding: 0; }
select, input[type="month"], input[type="password"], .add-row input {
  width: 100%;
  font: inherit; color: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: .65rem .75rem;
  min-height: 46px;
}

/* Before / After switch: the one bold element */
.stage-switch { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.stage-switch legend { grid-column: 1 / -1; }
.stage-option {
  position: relative;
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  padding: .7rem .8rem;
  cursor: pointer;
  margin: 0;
  transition: background-color .15s, border-color .15s;
}
.stage-option input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.stage-name { display: block; font-size: 1.15rem; }
.stage-sub { display: block; font-weight: 400; color: var(--muted); font-size: .85rem; }
.stage-before:has(input:checked) { border-color: var(--before); background: var(--before-soft); color: var(--before); }
.stage-after:has(input:checked)  { border-color: var(--after);  background: var(--after-soft);  color: var(--after); }
.stage-option:has(input:focus-visible) { outline: 3px solid var(--primary); outline-offset: 2px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  font: inherit; font-weight: 700;
  min-height: 46px; padding: .55rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-upload { width: 100%; margin-top: .75rem; background: var(--ink); color: var(--surface); border-color: var(--ink); }
.btn-upload.is-before:not(:disabled) { background: var(--before); border-color: var(--before); color: #fff; }
.btn-upload.is-after:not(:disabled)  { background: var(--after);  border-color: var(--after);  color: #fff; }
@media (prefers-color-scheme: dark) {
  .btn-upload.is-before:not(:disabled), .btn-upload.is-after:not(:disabled) { color: var(--bg); }
}
.capture-actions .btn { white-space: nowrap; padding-inline: .6rem; }
.capture-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-top: 1.25rem; }
.link-quiet, .link-danger {
  background: none; border: 0; padding: 0; font: inherit; cursor: pointer;
  color: var(--primary); text-decoration: underline; text-underline-offset: 3px;
}
.link-danger { color: var(--danger); }

/* ---------- Upload queue ---------- */
.queue { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: .5rem; margin-top: 1rem; }
.queue:empty { display: none; }
.q-item { position: relative; aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden; background: var(--bg); }
.q-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.q-item.failed { outline: 3px solid var(--danger); }
.q-item.done { opacity: .35; }
.q-remove {
  position: absolute; top: 4px; right: 4px;
  width: 26px; height: 26px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.65); color: #fff; font-size: 16px; line-height: 1; cursor: pointer;
}
.hint { color: var(--muted); font-size: .9rem; margin: .6rem 0 0; }
.status { margin: .5rem 0 0; font-size: .95rem; min-height: 1.5em; }
.status.error, .error-text { color: var(--danger); }

/* ---------- Before / After comparison ---------- */
.compare-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.sub { margin: .2rem 0 0; color: var(--muted); }
.columns { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1.1rem; }
@media (max-width: 640px) { .columns { grid-template-columns: 1fr; } }
.column { border-radius: var(--radius-sm); padding: .9rem; border-top: 5px solid; }
.column-before { background: var(--before-soft); border-color: var(--before); }
.column-after  { background: var(--after-soft);  border-color: var(--after); }
.column h3 { display: flex; align-items: center; gap: .5rem; }
.column-before h3 { color: var(--before); }
.column-after h3  { color: var(--after); }
.count { font-size: .85rem; padding: .05rem .5rem; border-radius: 999px; background: var(--surface); color: var(--ink); }
.empty { color: var(--muted); margin: .6rem 0 0; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .6rem; margin-top: .8rem; }
.thumb { margin: 0; background: var(--surface); border-radius: var(--radius-sm); overflow: hidden; }
.thumb-open { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; }
.thumb img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.thumb figcaption { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0 .4rem; padding: .4rem .55rem; font-size: .85rem; }
.thumb figcaption span { overflow-wrap: anywhere; }
.del { background: none; border: 0; padding: .2rem; color: var(--danger); font: inherit; font-size: .8rem; cursor: pointer; text-decoration: underline; }

/* ---------- Overview table ---------- */
.table-wrap { overflow-x: auto; margin-top: 1rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .65rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-size: .9rem; }
td a { color: inherit; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.right { text-align: right; }
tr.current td { background: var(--bg); }
tr.current td:first-child { font-weight: 700; }
.pill { display: inline-block; padding: .1rem .6rem; border-radius: 999px; font-size: .85rem; }
.pill-ok   { background: var(--after-soft);  color: var(--after); }
.pill-part { background: var(--before-soft); color: var(--before); }
.pill-none { background: var(--bg); color: var(--muted); }

/* ---------- Dialogs ---------- */
dialog {
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--ink);
  padding: 1.25rem; max-width: min(520px, 94vw); width: 100%;
}
dialog::backdrop { background: rgba(8, 18, 24, .6); }
.viewer { max-width: min(1100px, 96vw); padding: .75rem; }
.viewer img { display: block; max-width: 100%; max-height: 80vh; margin: 0 auto; border-radius: var(--radius-sm); }
.viewer p { margin: .5rem 0 0; text-align: center; font-weight: 700; }
.viewer form { text-align: right; margin-bottom: .5rem; }
.viewer-close { font: inherit; background: none; border: 0; color: var(--primary); text-decoration: underline; cursor: pointer; }
.manage-list { list-style: none; padding: 0; margin: 1rem 0; max-height: 45vh; overflow: auto; }
.manage-list li { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.manage-list small { display: block; color: var(--muted); }
.add-row { display: flex; gap: .5rem; }
.add-form { margin-bottom: 1rem; }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1.5rem; width: min(360px, 100%); display: grid; gap: .6rem; }
.login-card h1 { margin-bottom: .6rem; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
