/* The photo admin. Header and cell colors follow the inventory spreadsheet
   it replaced, so the two read the same. */

:root {
  --ink: #111827;
  --muted: #6b7280;
  --line: #d1d5db;
  --line-strong: #9ca3af;
  --paper: #ffffff;
  --wash: #f3f4f6;
  --accent: #1d4ed8;
  --accent-wash: #dbeafe;
  --yours: #fff9c4;
  --yours-head: #ffff00;
  --danger: #b91c1c;
  --ok: #15803d;
  --row: 72px;
  --bar: 52px;
  --toolbar: 46px;
  font: 13px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }

button, .button {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--paper); cursor: pointer; text-decoration: none; color: var(--ink);
  white-space: nowrap;
}
button:hover, .button:hover { background: var(--wash); }
button.primary, .button.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
button.primary:hover, .button.primary:hover { background: #374151; }
button.danger { color: var(--danger); }
button.ghost, .button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover, .button.ghost:hover { background: var(--wash); }
button:disabled { opacity: 0.5; cursor: default; }
button[aria-pressed="true"] { background: var(--accent-wash); border-color: #93c5fd; }
input[type="search"], input[type="text"], input[type="password"], select, textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; background: var(--paper);
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Sign in ---------- */

.login-page { min-height: 100vh; display: grid; place-items: center; background: var(--wash); }
.login {
  width: min(360px, calc(100vw - 32px)); padding: 28px; display: grid; gap: 10px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px;
}
.login h1 { margin: 0; font-size: 20px; }
.login p { margin: 0 0 8px; color: var(--muted); }
.login label { font-weight: 600; }
.login input { height: 38px; font-size: 15px; }
.login button { height: 38px; justify-content: center; background: var(--ink); color: #fff; border-color: var(--ink); }
.login-error { color: var(--danger); min-height: 1.35em; margin: 0; }

/* ---------- Frame ---------- */

.top {
  height: var(--bar); display: flex; align-items: center; gap: 12px; padding: 0 12px;
  border-bottom: 1px solid var(--line); background: var(--paper);
}
.brand { font-weight: 700; font-size: 15px; white-space: nowrap; }
.brand small { font-weight: 400; color: var(--muted); }
.tabs { display: flex; gap: 2px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; height: 34px; border-radius: 6px; color: var(--muted); }
.tabs button[aria-selected="true"] { color: var(--ink); background: var(--wash); font-weight: 600; }
.tabs .count { color: var(--muted); font-weight: 400; }
.spacer { flex: 1; }

.panel { height: calc(100vh - var(--bar)); overflow: auto; }
.panel.images { display: flex; flex-direction: column; overflow: hidden; }

.toolbar {
  min-height: var(--toolbar); display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
.toolbar input[type="search"] { width: min(320px, 50vw); height: 30px; }
.toolbar label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); white-space: nowrap; }
.status { color: var(--muted); white-space: nowrap; }
.save-state { margin-left: auto; color: var(--muted); white-space: nowrap; }
.save-state.error { color: var(--danger); }

/* The Images views (views.js), as a segmented control. */
.views { display: inline-flex; gap: 2px; padding: 3px; background: var(--wash); border-radius: 9px; }
.views button {
  height: 26px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-weight: 500;
}
.views button:hover { background: rgb(255 255 255 / 0.65); color: var(--ink); }
.views button[aria-selected="true"] {
  background: var(--paper); color: var(--ink); font-weight: 600;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.1), 0 0 0 1px rgb(0 0 0 / 0.04);
}
.views .count { color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }

.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-body {
  position: absolute; z-index: 40; top: 34px; left: 0; width: 300px; max-height: 70vh; overflow: auto;
  padding: 10px; background: var(--paper); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.12);
}
.menu-body h4 { margin: 10px 0 4px; font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.menu-body label { display: flex; gap: 6px; padding: 2px 0; color: var(--ink); }
.menu-body .presets { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- The grid ---------- */

.grid-wrap { flex: 1; overflow: auto; position: relative; outline: none; }
.grid { border-collapse: separate; border-spacing: 0; table-layout: fixed; width: max-content; }
.grid th, .grid td {
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  padding: 0; text-align: left; vertical-align: top; background: var(--paper);
}
.grid thead th { position: sticky; z-index: 10; }
.grid tr.groups th {
  top: 0; height: 22px; padding: 2px 8px; color: #fff; font-weight: 700; font-size: 12px; white-space: nowrap;
}
/* A group's name stays in view beside the frozen columns while it scrolls. */
.grid tr.groups th span { position: sticky; left: calc(var(--frozen-width, 0px) + 8px); }
.grid tr.groups th.frozen span { position: static; }
.grid tr.labels th {
  top: 22px; height: 52px; background: #4b5563; color: #fff; font-weight: 700; font-size: 12px; line-height: 1.2;
  cursor: pointer; user-select: none;
}
.grid tr.labels th.yours { background: var(--yours-head); color: #000; }
.grid tr.labels th .label { display: block; padding: 4px 16px 4px 7px; overflow: hidden; max-height: 52px; line-height: 1.15; }
.grid tr.labels th .sort { position: absolute; right: 8px; bottom: 4px; font-size: 10px; }
.grid tr.labels th .resize { position: absolute; top: 0; right: -4px; width: 8px; height: 100%; cursor: col-resize; z-index: 2; }
.grid tr.filters th { top: 74px; height: 32px; background: var(--wash); padding: 3px; }
.grid tr.filters input { width: 100%; height: 25px; padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.grid tr.filters input.active { border-color: var(--accent); background: var(--accent-wash); }

.grid td { height: var(--row); max-height: var(--row); overflow: hidden; position: relative; }
/* Four 16px lines and a 4px margin fill a row exactly. Margin rather than
   padding, so nothing of a fifth line shows below the clamp. */
.grid td > .v {
  margin: 4px 7px; height: calc(var(--row) - 8px); overflow: hidden; line-height: 16px;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; line-clamp: 4;
  white-space: pre-line; overflow-wrap: anywhere;
}
.grid .frozen { position: sticky; z-index: 5; }
.grid thead .frozen { z-index: 15; }
.grid .frozen.last { border-right: 2px solid var(--line-strong); }
.grid td.k-ref .v { font-weight: 700; }
.grid td.k-ref button {
  border: 0; padding: 0; height: auto; background: none; font-weight: 700; color: var(--accent); text-decoration: underline;
  text-underline-offset: 2px;
}
.grid td.c-name .v { font-weight: 600; }
.grid td.k-preview { text-align: center; }
.grid td.k-preview img { display: block; margin: 4px auto; max-width: calc(100% - 8px); max-height: calc(var(--row) - 8px); object-fit: contain; cursor: zoom-in; }
.grid td.k-preview .none { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: 11px; }
.grid td.k-choice .v, .grid td.k-year .v, .grid td.c-uploadYear .v, .grid td.c-year .v { text-align: center; }
.grid td.k-path a { color: var(--ink); text-decoration: none; border-bottom: 1px dotted var(--line-strong); }
.grid td.k-path a:hover { color: var(--accent); }
.grid td.k-path a.missing { color: var(--danger); border-bottom-color: var(--danger); }
.grid td.yours { background: var(--yours); }
.grid td .formula { color: var(--muted); font-style: italic; }
.grid td .typed { font-size: 10px; color: var(--muted); display: block; }
.grid td.wt-art { background: #e8f0fe; }
.grid td.wt-painting { background: #edf7ed; }
.grid td.wt-artist { background: #fdf2e9; }
.grid td.wt-branding { background: #f3e8fd; }
.grid td.wt-other { background: #f3f4f6; }
.grid tr.removed td { color: var(--muted); text-decoration: line-through; background: #f9fafb; }
.grid tr.removed td.k-preview img { opacity: 0.4; }
.grid td.selected { box-shadow: inset 0 0 0 2px var(--accent); z-index: 6; }
.grid td.saving { box-shadow: inset 0 0 0 2px #93c5fd; }
.grid td.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: #bbf7d0; } }
.grid tbody tr:hover td:not(.selected) { filter: brightness(0.98); }

/* A view's section headings stick under the header rows; the label stays
   at the left while the grid scrolls sideways. */
.grid tbody tr.section th {
  position: sticky; top: var(--head-height, 74px); z-index: 8; padding: 0;
  background: #f8fafc; border-right: 0; border-bottom: 1px solid var(--line-strong);
  font-size: 12px; font-weight: 400; color: var(--muted);
}
.grid tbody tr.section th > div { position: sticky; left: 0; width: max-content; display: flex; align-items: center; gap: 8px; padding: 6px 10px; }
.grid tbody tr.section strong { color: var(--ink); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.grid tbody tr.section .n {
  padding: 1px 8px; border-radius: 999px; background: #e5e7eb; color: #374151; font-variant-numeric: tabular-nums;
}
.grid tbody tr.section.warn .n { background: #fef3c7; color: #92400e; }

/* Check columns. */
.grid td.k-check > .v { display: flex; flex-direction: column; align-items: center; gap: 3px; margin-top: 2px; }
.grid td.k-check .check-note { font-size: 11px; line-height: 1.2; color: var(--muted); text-align: center; }

.check {
  display: inline-grid; place-items: center; flex: none; width: 20px; height: 20px; padding: 0; gap: 0;
  border: 1.5px solid #9ca3af; border-radius: 6px; background: var(--paper); color: #fff;
  transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.check:hover { background: var(--paper); border-color: var(--accent); box-shadow: 0 0 0 3px rgb(29 78 216 / 0.14); }
.check[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.check[aria-checked="true"]:hover { background: #1e40af; border-color: #1e40af; }
.check[aria-checked="mixed"] { background: #d97706; border-color: #d97706; }
.check[aria-checked="mixed"]:hover { background: #b45309; border-color: #b45309; }
.check svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.check .tick, .check .dash { display: none; }
.check[aria-checked="true"] .tick, .check[aria-checked="mixed"] .dash { display: inline; }
.check:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.check:disabled { opacity: 0.45; cursor: default; }
.check:disabled:hover { box-shadow: none; border-color: #9ca3af; }
.check[aria-checked="true"]:disabled:hover { border-color: var(--accent); background: var(--accent); }
/* Drawn when clicked, not on every render. */
.check.pop { animation: check-press 0.2s ease-out; }
.check.pop .tick { stroke-dasharray: 14; animation: check-draw 0.22s ease-out; }
@keyframes check-press { 45% { transform: scale(0.85); } }
@keyframes check-draw { from { stroke-dashoffset: 14; } }
@media (prefers-reduced-motion: reduce) {
  .check.pop, .check.pop .tick { animation: none; }
}
/* A bigger target for fingers. */
@media (pointer: coarse) {
  .check { width: 26px; height: 26px; border-radius: 7px; }
  .check svg { width: 18px; height: 18px; }
}
.empty { padding: 40px; text-align: center; color: var(--muted); }

.editor {
  position: fixed; z-index: 60; border: 2px solid var(--accent); border-radius: 2px; padding: 4px 7px;
  background: var(--paper); box-shadow: 0 8px 24px rgb(0 0 0 / 0.18); resize: none; line-height: 1.35;
}
textarea.editor { min-height: 72px; }
select.editor { padding: 2px 4px; }
.editor-hint {
  position: fixed; z-index: 61; font-size: 11px; color: var(--muted); background: var(--paper);
  padding: 2px 6px; border: 1px solid var(--line); border-radius: 4px; pointer-events: none;
}

/* ---------- Row drawer ---------- */

.drawer {
  position: fixed; z-index: 50; top: 0; right: 0; bottom: 0; width: min(560px, 100vw);
  display: flex; flex-direction: column; background: var(--paper); border-left: 1px solid var(--line);
  box-shadow: -12px 0 40px rgb(0 0 0 / 0.12);
}
.drawer header { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.drawer header h2 { flex: 1; margin: 0; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer .body { flex: 1; overflow: auto; padding: 12px 16px 40px; }
.drawer h3 { margin: 20px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.hero { margin: 0; background: var(--wash); border-radius: 8px; display: grid; place-items: center; min-height: 160px; }
.hero img { display: block; max-width: 100%; max-height: 52vh; object-fit: contain; }
.hero figcaption { padding: 6px 10px; color: var(--muted); font-size: 12px; }
.files { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 8px; }
.files li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-top: 1px solid var(--line); }
.files li:first-child { border-top: 0; }
.files .name { flex: 1; overflow-wrap: anywhere; }
.files .size { color: var(--muted); white-space: nowrap; }
.files .actions { display: flex; gap: 2px; }
.files .actions button { height: 26px; padding: 0 7px; font-size: 12px; }
.tag { display: inline-block; padding: 1px 6px; border-radius: 10px; font-size: 11px; background: var(--wash); color: var(--ink); white-space: nowrap; }
.tag.original { background: #e0e7ff; }
.tag.crop { background: #fef3c7; }
.tag.master { background: #dcfce7; }
.add-file { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 8px; padding: 10px; border: 1px dashed var(--line-strong); border-radius: 8px; }
.add-file .row { display: flex; gap: 8px; grid-column: 1 / -1; align-items: center; }
.add-file input[type="text"] { flex: 1; min-width: 0; }
.fields { display: grid; gap: 10px; }
.field { display: grid; gap: 3px; }
.field > span { font-size: 12px; font-weight: 600; color: #374151; display: flex; gap: 6px; align-items: baseline; }
.field > span small { font-weight: 400; color: var(--muted); }
.field textarea, .field input, .field select { width: 100%; }
.field textarea { resize: vertical; min-height: 32px; line-height: 1.35; }
.field.yours textarea, .field.yours select, .field.yours input { background: var(--yours); }
.field.check-field { display: flex; align-items: center; gap: 10px; min-height: 34px; }
.field.check-field.yours { padding: 6px 10px; border-radius: 6px; background: var(--yours); }
.field.check-field label { font-size: 12px; font-weight: 600; color: #374151; cursor: pointer; }
.field.check-field .check-note { color: var(--muted); }
.chip { height: 26px; margin-left: auto; padding: 0 10px; border-radius: 999px; font-size: 12px; }
.chip[aria-pressed="true"] { background: #fef3c7; border-color: #d97706; color: #92400e; }
.field .readonly { padding: 5px 8px; background: var(--wash); border-radius: 6px; min-height: 30px; }
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.history li { display: grid; gap: 2px; padding-bottom: 8px; border-bottom: 1px solid var(--wash); }
.history .meta { color: var(--muted); font-size: 12px; }
.history del { color: var(--danger); text-decoration-color: rgb(185 28 28 / 0.5); }
.history ins { color: var(--ok); text-decoration: none; }
.history .change { overflow-wrap: anywhere; white-space: pre-line; }

/* ---------- Upload ---------- */

.upload { max-width: 900px; margin: 0 auto; padding: 24px 16px 60px; }
.upload h2, .sheet h2 { margin: 0 0 6px; font-size: 18px; }
.upload > p, .sheet > p { margin: 0 0 16px; color: var(--muted); max-width: 70ch; }
.dropzone {
  display: grid; place-items: center; gap: 10px; min-height: 200px; padding: 24px; text-align: center;
  border: 2px dashed var(--line-strong); border-radius: 12px; background: #fafafa;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-wash); }
.dropzone strong { font-size: 16px; }
.upload-options { display: flex; flex-wrap: wrap; gap: 16px; margin: 16px 0; }
.upload-options label { display: grid; gap: 4px; font-weight: 600; }
.queue { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.queue li {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: center;
  padding: 8px; border: 1px solid var(--line); border-radius: 8px;
}
.queue .thumb { width: 64px; height: 64px; border-radius: 4px; background: var(--wash); object-fit: cover; display: grid; place-items: center; color: var(--muted); font-size: 11px; }
.queue .what { display: grid; gap: 3px; min-width: 0; }
.queue .what strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue .note { color: var(--muted); font-size: 12px; }
.queue .note.error { color: var(--danger); }
.queue .note.ok { color: var(--ok); }
.queue progress { width: 100%; height: 6px; }

/* ---------- Legend, Open questions, History ---------- */

.sheet { max-width: 1200px; margin: 0 auto; padding: 24px 16px 60px; }
.sheet h3 { margin: 28px 0 8px; font-size: 14px; }
.sheet table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.sheet th { text-align: left; font-size: 12px; padding: 6px 8px; background: #4b5563; color: #fff; }
.sheet td { border-bottom: 1px solid var(--line); padding: 0; vertical-align: top; }
.sheet td .cell { padding: 6px 8px; white-space: pre-line; overflow-wrap: anywhere; min-height: 30px; cursor: text; }
.sheet td .cell:hover { background: #fafafa; }
.sheet td textarea { width: 100%; min-height: 60px; border-radius: 0; border: 2px solid var(--accent); }
.sheet td.tools { width: 40px; text-align: right; }
.sheet td.tools button { height: 26px; padding: 0 6px; visibility: hidden; }
.sheet tr:hover td.tools button { visibility: visible; }
.sheet .add { margin-top: 10px; }
.activity { list-style: none; padding: 0; margin: 0; display: grid; gap: 0; }
.activity li { display: grid; grid-template-columns: 170px 70px 1fr; gap: 12px; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.activity .meta { color: var(--muted); }
.activity .change { overflow-wrap: anywhere; white-space: pre-line; max-height: 7.5em; overflow: hidden; }
.activity del { color: var(--danger); }
.activity ins { color: var(--ok); text-decoration: none; }

/* ---------- Toasts ---------- */

.toasts { position: fixed; z-index: 80; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--ink); color: #fff; box-shadow: 0 8px 24px rgb(0 0 0 / 0.2); max-width: min(560px, 90vw); }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

.lightbox { position: fixed; inset: 0; z-index: 90; background: rgb(0 0 0 / 0.85); display: grid; place-items: center; cursor: zoom-out; }
.lightbox img { max-width: 96vw; max-height: 94vh; object-fit: contain; }

@media (max-width: 720px) {
  .top { height: auto; flex-wrap: wrap; padding: 8px; }
  .panel { height: auto; min-height: calc(100vh - 100px); }
  .panel.images { height: calc(100vh - 100px); }
  .activity li { grid-template-columns: 1fr; gap: 2px; }
}
