/*
 * theme.css — INKSHIRE StockLens.
 * Paper and ink, with the brand's poster-yellow as the one loud colour:
 * the same palette as the INKSHIRE catalogue, so the stock tool feels like
 * the shop's own. Opens light (a shop counter in daylight); dark is a
 * printing-room night version where the yellow becomes the action colour.
 */

:root {
  --canvas: #f6f2ea;
  --surface: #fffdf8;
  --surface-2: #efe9dd;
  --border: #ddd5c5;
  --border-strong: #a99f8b;
  --ink: #16140f;
  --muted: #625b4e;
  --accent: #16140f;
  --accent-hover: #2e2a22;
  --accent-ink: #ffd166;
  --accent-text: #7a4f00;
  --accent-strong: #5c3d00;
  --accent-soft: #ffe7a3;
  --accent-border: #e0bb55;
  --success: #15803d;
  --success-ink: #ffffff;
  --success-soft: #dcefe2;
  --success-strong: #136c34;
  --warning: #b45309;
  --warning-ink: #ffffff;
  --warning-soft: #f8e6d2;
  --warning-strong: #8f4207;
  --danger: #b91c1c;
  --danger-ink: #ffffff;
  --danger-soft: #f6dddb;
  --danger-strong: #9f1818;
  --chart-1: #16140f;
  --chart-2: #d99a00;
  --chart-3: #c2410c;
  --chart-4: #2f6f5e;
  --chart-5: #3b5bdb;
  --chart-6: #9d4edd;

  --font-display: "Anton", "Archivo Variable", ui-sans-serif, system-ui, sans-serif;
  --font-body: "Inter Variable", ui-sans-serif, system-ui, sans-serif;
  --font-sans: "Inter Variable", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "JetBrains Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --display-weight: 400;
  --display-tracking: 0.01em;
  --eyebrow-tracking: 0.08em;

  --radius-btn: 10px;
  --radius-card: 14px;
  --radius-input: 10px;
  --shadow-card: 0 1px 0 color-mix(in srgb, var(--ink) 6%, transparent);
  --shadow-raised: 0 12px 32px -12px color-mix(in srgb, var(--ink) 35%, transparent);
  --btn-weight: 600;
  --card-pad: 1.25rem;
}

html[data-theme="dark"] {
  --canvas: #12110e;
  --surface: #1c1a16;
  --surface-2: #26231d;
  --border: #34302a;
  --border-strong: #5f574a;
  --ink: #f4efe4;
  --muted: #b0a898;
  --accent: #ffd166;
  --accent-hover: #ffdc85;
  --accent-ink: #16140f;
  --accent-text: #ffd166;
  --accent-strong: #ffe39b;
  --accent-soft: #3a2f12;
  --accent-border: #6b5520;
  --success: #15803d;
  --success-ink: #ffffff;
  --success-soft: #14271b;
  --success-strong: #79d39d;
  --warning: #b45309;
  --warning-ink: #ffffff;
  --warning-soft: #33240f;
  --warning-strong: #f0b25a;
  --danger: #b91c1c;
  --danger-ink: #ffffff;
  --danger-soft: #3a1717;
  --danger-strong: #f29a9a;
  --chart-1: #ffd166;
  --chart-2: #f4efe4;
  --chart-3: #f08a4b;
  --chart-4: #5fbfa3;
  --chart-5: #8ea7ff;
  --chart-6: #c792ff;
}

/*
 * app.css — StockLens's own pieces: the wordmark, the camera-first scan
 * station (stage, frame, guide, the dock under the camera, focus mode), the
 * mode and format switches, poster thumbnails, the upload report and the
 * phone tab bar. Tokens only.
 */

/* ---- Brand + type ------------------------------------------------------ */
.wordmark {
  font-family: var(--font-display);
  font-size: 1.65rem;
  line-height: 1;
  letter-spacing: 0.02em;
  color: var(--ink);
}
.sublabel {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.page-title {
  font-family: var(--font-display);
  font-size: 2.4rem;
  line-height: 1;
  letter-spacing: 0.01em;
  text-transform: uppercase;
}
@media (min-width: 48rem) { .page-title { font-size: 3.1rem; } }
.section-title {
  font-family: var(--font-display);
  font-size: 1.75rem;
  line-height: 1;
  text-transform: uppercase;
}
.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: var(--eyebrow-tracking);
  text-transform: uppercase;
  color: var(--accent-text);
}
.figure {
  font-family: var(--font-display);
  font-size: 2.5rem;
  line-height: 1.05;
  margin-top: 0.5rem;
}
.stock-figure {
  font-family: var(--font-display);
  font-size: 1.35rem;
  line-height: 1.1;
  letter-spacing: 0.02em;
}

/* ---- Bars -------------------------------------------------------------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.navlink {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 2.25rem;
  padding: 0 0.85rem;
  border-radius: var(--radius-btn);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  transition: background-color 150ms, color 150ms;
}
.navlink:hover { background: var(--surface-2); color: var(--ink); }
.navlink[aria-current="page"] { background: var(--accent-soft); color: var(--accent-strong); }

.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 40;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tablink {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.6rem 0 0.55rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
}
.tablink .icon { width: 1.35rem; height: 1.35rem; }
.tablink[aria-current="page"] { color: var(--ink); }
.tablink[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 30%;
  right: 30%;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--accent-border);
}

/* ---- Scanner: mode + format bar ---------------------------------------- */
.scanner { overflow: hidden; }
@media (width < 48rem) {
  /* Edge to edge on a phone: every pixel of width goes to the camera. */
  .scanner {
    width: calc(100% + 2rem);
    max-width: none;
    margin-inline: -1rem;
    border-radius: 0;
    border-left-width: 0;
    border-right-width: 0;
  }
}
.modes { border-bottom: 1px solid var(--border); }
.mode {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.55rem 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border-right: 1px solid var(--border);
  cursor: pointer;
  transition: background-color 150ms, color 150ms;
}
@media (min-width: 48rem) { .mode { padding: 0.8rem 0.25rem; font-size: 0.8rem; gap: 0.3rem; } }
.mode:last-child { border-right: 0; }
.mode:hover { background: var(--surface-2); color: var(--ink); }
.mode[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* The format of a sale: shown only in Sale mode. */
.formats {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.formats[hidden] { display: none; }
.formats-label {
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}
.fmt {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  height: 2.5rem;
  min-width: 0;
  padding: 0 0.4rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-btn);
  cursor: pointer;
  transition: background-color 150ms, border-color 150ms, color 150ms;
}
.fmt .icon { width: 0.95rem; height: 0.95rem; flex-shrink: 0; }
.fmt span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fmt:hover { border-color: var(--ink); }
.fmt[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent-strong); }
@media (width < 30rem) {
  .formats-label { display: none; }
  .fmt .icon { display: none; }
}

/* ---- Scanner: the stage ------------------------------------------------- */
.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  min-height: 16rem;
  max-height: 56vh;
  background: rgba(0, 0, 0, 0.92);
  overflow: hidden;
}
@media (min-width: 48rem) { .stage { aspect-ratio: 4 / 3; max-height: 62vh; } }

/* The frame is sized by app.js to the video's own shape, fitted inside the
   stage, so the guide's percentages always line up with what the camera sees. */
.frame { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }
.frame video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; }
.guide {
  position: absolute;
  left: 28%;
  top: 7%;
  width: 44%;
  height: 86%;
  border: 2px dashed rgba(255, 255, 255, 0.55);
  border-radius: 8px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.38);
  transition: border-color 120ms, transform 120ms;
  pointer-events: none;
}
.guide i {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 0 solid var(--accent-border);
}
.guide i:nth-child(1) { left: -3px; top: -3px; border-left-width: 4px; border-top-width: 4px; border-top-left-radius: 8px; }
.guide i:nth-child(2) { right: -3px; top: -3px; border-right-width: 4px; border-top-width: 4px; border-top-right-radius: 8px; }
.guide i:nth-child(3) { left: -3px; bottom: -3px; border-left-width: 4px; border-bottom-width: 4px; border-bottom-left-radius: 8px; }
.guide i:nth-child(4) { right: -3px; bottom: -3px; border-right-width: 4px; border-bottom-width: 4px; border-bottom-right-radius: 8px; }
.stage[data-state="match"] .guide { border-color: var(--success); border-style: solid; transform: scale(1.01); }
.stage[data-state="match"] .guide i { border-color: var(--success); }
.stage[data-state="unsure"] .guide { border-color: var(--warning); border-style: solid; }
.stage[data-state="unsure"] .guide i { border-color: var(--warning); }

.stage-idle {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 1.5rem;
  text-align: center;
  background: var(--surface-2);
  color: var(--ink);
}
.stage[data-state="idle"] .guide,
.stage[data-state="idle"] .hud { display: none; }
.stage:not([data-state="idle"]) .stage-idle { display: none; }

/* Floating camera controls, top right of the picture. */
.hud {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.hud-btn {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
  color: rgba(255, 255, 255, 0.95);
  cursor: pointer;
  transition: background-color 150ms, transform 150ms;
}
.hud-btn[hidden] { display: none; }
.hud-btn:active { transform: scale(0.94); }
.hud-btn .icon { width: 1.25rem; height: 1.25rem; }
.hud-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-strong); }
.hud-btn .when-on { display: none; }
.hud-btn[aria-pressed="true"] .when-on { display: inline; }
.hud-btn[aria-pressed="true"] .when-off { display: none; }

/* ---- Scanner: the dock UNDER the camera ---------------------------------
   Fixed height (the camera never jumps). A one-line result on top, the live
   picker filling the rest — both at once, so the next poster can always be
   tapped right after the last. */
.dock {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex-shrink: 0;
  height: 8.5rem;
  padding: 0.4rem 0.5rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  overflow: hidden;
}

.result-line {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
  height: 2.3rem;
  padding: 0 0.3rem;
  background: var(--accent-soft);
  border-radius: 8px;
}
.result-line[hidden] { display: none; }
.result-line[data-flash] { animation: dock-in 200ms var(--ease-out, ease-out) both; }
.result-line[data-tone="undone"] { background: var(--surface-2); }
.result-line[data-tone="undone"] #result-kind { color: var(--muted); }
.result-line[data-tone="saving"] #result-stock { opacity: 0.45; }
.result-line .eyebrow { font-size: 0.62rem; margin-right: 0.15rem; }
.result-thumb {
  flex-shrink: 0;
  width: 1.45rem;
  height: 2rem;
  object-fit: cover;
  border-radius: 4px;
  background: var(--surface-2);
}
.result-stock { flex-shrink: 0; font-size: 0.72rem; white-space: nowrap; }
.result-btn { flex-shrink: 0; height: 1.9rem; min-height: 0; padding-inline: 0.45rem; }
.result-btn .icon { width: 0.9rem; height: 0.9rem; }
@keyframes dock-in {
  from { opacity: 0.3; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.dock-empty {
  flex: 1;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}
.dock:has(#picker:not([hidden])) .dock-empty { display: none; }

.picker {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.picker[hidden] { display: none; }
.picker-head { display: flex; align-items: center; gap: 0.5rem; height: 1.1rem; flex-shrink: 0; }
.picker-head .eyebrow { font-size: 0.62rem; }
.picker-none {
  flex-shrink: 0;
  padding: 0 0.25rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.picker-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
}
.pick {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  height: 100%;
  padding: 0.25rem;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 120ms, transform 120ms;
}
.pick:active { transform: scale(0.97); }
.pick:hover { border-color: var(--ink); }
.pick img {
  flex-shrink: 0;
  height: 100%;
  width: auto;
  aspect-ratio: 5 / 7;
  border-radius: 6px;
}
.pick span {
  min-width: 0;
  font-size: 0.68rem;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.pick b { display: block; font-family: var(--font-mono); font-size: 0.68rem; }
.pick.is-logged { border-color: var(--success); background: color-mix(in srgb, var(--success) 12%, var(--surface)); }
.pick.is-logged b::after { content: " ✓"; color: var(--success); }

/* ---- Scanner: bars under the dock --------------------------------------- */
.zoom-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}
.zoom-row[hidden] { display: none; }
.zoom-row input { flex: 1; min-width: 0; accent-color: var(--accent); }

.scan-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  font-size: 0.85rem;
  font-weight: 500;
  border-top: 1px solid var(--border);
}
.pulse {
  width: 0.6rem;
  height: 0.6rem;
  flex-shrink: 0;
  border-radius: 999px;
  background: var(--border-strong);
}
.pulse[data-live="true"] { background: var(--success); animation: pulse 1.4s ease-in-out infinite; }
.pulse[data-live="busy"] { background: var(--warning); animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 45%, transparent); }
  50% { box-shadow: 0 0 0 6px transparent; }
}

.scan-tools {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1rem;
  border-top: 1px solid var(--border);
}

.tuning { border-top: 1px solid var(--border); }
.tuning > summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}
.tuning > summary::-webkit-details-marker { display: none; }
.tuning > summary:hover { color: var(--ink); }

/* ---- Focus mode: the scanner alone, full screen ------------------------- */
body.scan-focus { overflow: hidden; }
body.scan-focus .scanner {
  position: fixed;
  inset: 0;
  z-index: 60;
  width: 100%;
  max-width: none;
  margin: 0;
  display: flex;
  flex-direction: column;
  border-radius: 0;
  border-width: 0;
  padding-bottom: env(safe-area-inset-bottom);
}
body.scan-focus .stage {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  aspect-ratio: auto !important;
}
/* Full screen keeps only what scanning needs: camera, dock, zoom, status. */
body.scan-focus .tuning,
body.scan-focus .scan-tools,
body.scan-focus .scan-meta { display: none; }

/* ---- Posters + thumbnails ----------------------------------------------- */
.thumb-sm, .thumb-md, .thumb-lg, .poster, .pick img {
  display: block;
  object-fit: cover;
  background: var(--surface-2);
}
.thumb-sm { width: 2.5rem; height: 3.5rem; flex-shrink: 0; border-radius: 6px; }
.thumb-md { width: 3rem; height: 4.2rem; flex-shrink: 0; border-radius: 6px; }
.thumb-lg { width: 5rem; height: 7rem; flex-shrink: 0; border-radius: 8px; box-shadow: var(--shadow-raised); }
.poster { width: 100%; aspect-ratio: 5 / 7; }

.design-card {
  min-width: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}

.recent-row { display: flex; align-items: center; gap: 0.75rem; padding: 0.7rem 1rem; }
.recent-row.is-undone { opacity: 0.55; }
.recent-row.is-undone .font-medium { text-decoration: line-through; }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 2rem 1rem;
  text-align: center;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-card);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 150ms, background-color 150ms;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--accent-border); background: var(--accent-soft); }
.dropzone .icon { width: 1.75rem; height: 1.75rem; }

/* ---- Upload report: duplicates skipped, look-alikes waiting ------------- */
.import-report {
  max-height: 11rem;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: var(--radius-input);
}
.import-report li + li { margin-top: 0.35rem; }
.held-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--warning-strong);
  border-radius: var(--radius-input);
  background: var(--warning-soft);
  color: var(--warning-strong);
}
.held-row .text-muted { color: var(--warning-strong); opacity: 0.85; }
@media (width < 35rem) {
  .held-row { flex-wrap: nowrap; }
  .held-row .btn { padding-inline: 0.6rem; }
}

.reprint { border-color: var(--accent-border); }

html.reduced-motion .pulse, html.reduced-motion .result-line[data-flash] { animation: none; }
