/* Electric Emporium — warm-white paper, charcoal ink, brand red signal.
   Tokens mirror FanLensColors in the Android app so both surfaces match. */

:root {
  --paper: #FFFBFA;
  --paper-raised: #F5F1F0;
  --paper-sunk: #EDE8E7;
  --ink: #101923;
  --ink-muted: #59616A;
  --ink-faint: #8B9298;
  --rule: #D9D5D4;
  --rule-soft: #E7E2E1;
  --red: #FF0017;          /* fills, indicators */
  --red-ink: #D10014;      /* red text on paper — 5.5:1 contrast */
  --danger: #B3261E;
  --shadow: 0 1px 2px rgba(16,25,35,.06), 0 10px 28px -18px rgba(16,25,35,.30);
  --radius: 10px;
  --sans: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

/* The browser's own [hidden] rule is easily beaten by any author rule that sets
   `display` — which is how the loading overlay ended up permanently on screen.
   This keeps `hidden` meaning hidden, whatever a component sets. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- masthead ---------- */

.mast {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 14px 24px;
  border-bottom: 2px solid var(--ink);
  background: var(--paper);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: baseline; gap: 6px; }
.brand-mark { color: var(--red); font-weight: 800; font-size: 22px; letter-spacing: -.01em; }
.brand-rest { color: var(--ink); font-weight: 800; font-size: 22px; letter-spacing: -.01em; }
.brand-sub {
  margin-left: 12px; padding-left: 12px; border-left: 1px solid var(--rule);
  color: var(--ink-muted); font-size: 13px; letter-spacing: .04em; text-transform: uppercase;
}
.mast-actions { display: flex; align-items: center; gap: 10px; }
.stats { font-family: var(--mono); font-size: 12px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }

/* ---------- buttons ---------- */

.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 8px; padding: 8px 14px; border: 1px solid transparent;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.btn:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.btn.solid { background: var(--red); color: #fff; }
.btn.solid:hover { background: #E00014; }
.btn.ghost { background: var(--paper); color: var(--ink); border-color: var(--rule); }
.btn.ghost:hover { background: var(--paper-raised); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--rule); }
.btn.danger:hover { background: #FCEDEC; border-color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  align-items: start;
  min-height: calc(100vh - 61px);
}

.sidebar {
  border-right: 1px solid var(--rule);
  padding: 16px;
  position: sticky; top: 61px;
  max-height: calc(100vh - 61px);
  display: flex; flex-direction: column; gap: 12px;
}
.sidebar-top { display: flex; flex-direction: column; gap: 10px; }
.search {
  font: inherit; width: 100%; padding: 9px 12px;
  border: 1px solid var(--rule); border-radius: 8px; background: var(--paper);
}
.search:focus { outline: 2px solid var(--red); outline-offset: -1px; }

.product-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.product-list li {
  display: flex; gap: 10px; align-items: center;
  padding: 8px; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent;
}
.product-list li:hover { background: var(--paper-raised); }
.product-list li[aria-selected="true"] { background: var(--paper-raised); border-color: var(--red); }
.product-list img, .product-list .noimg {
  width: 44px; height: 44px; border-radius: 6px; object-fit: cover;
  background: var(--paper-sunk); flex: none;
}
.pl-text { min-width: 0; }
.pl-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-sub { font-size: 12.5px; color: var(--ink-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-badge {
  margin-left: auto; font-family: var(--mono); font-size: 10.5px; color: var(--ink-faint);
  white-space: nowrap;
}
.list-empty { color: var(--ink-muted); font-size: 13.5px; padding: 4px 8px; }

/* ---------- editor ---------- */

.editor, .placeholder { padding: 24px 28px 64px; max-width: 1000px; }
.placeholder h2 { margin: 8px 0 6px; }
.placeholder p { color: var(--ink-muted); max-width: 52ch; }
.placeholder-note { font-size: 13px; }

.editor-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding-bottom: 12px; border-bottom: 1px solid var(--rule); margin-bottom: 20px;
}
.editor-head h2 { margin: 0; font-size: 21px; }
.editor-head-actions { display: flex; gap: 8px; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12.5px; color: var(--ink-muted); font-weight: 600; }
.field .req { color: var(--red-ink); }
.field .opt { font-style: normal; font-weight: 400; color: var(--ink-faint); }
select.search { appearance: auto; }
.field input, .field textarea {
  font: inherit; padding: 9px 11px; border: 1px solid var(--rule);
  border-radius: 8px; background: var(--paper); color: var(--ink); width: 100%;
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--red); outline-offset: -1px; }
.field.wide { margin-top: 14px; }
.field.invalid input { border-color: var(--danger); }

.specs { margin-top: 22px; }
.specs-head { display: flex; align-items: center; justify-content: space-between; }
.specs h3, .photos h3 { margin: 0; font-size: 15px; }
.spec-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-top: 8px; }
.spec-row input {
  font: inherit; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper);
}

/* ---------- photos ---------- */

.photos { margin-top: 30px; }
.photos-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.photos h3 em { font-style: normal; color: var(--ink-muted); font-weight: 500; }
.hint { font-family: var(--mono); font-size: 11.5px; color: var(--ink-muted); }
.photos-note { color: var(--ink-muted); font-size: 13px; margin: 4px 0 10px; max-width: 68ch; }

.dropzone {
  border: 2px dashed var(--rule); border-radius: var(--radius);
  background: var(--paper-raised); padding: 16px; transition: border-color .12s, background .12s;
}
.dropzone.over { border-color: var(--red); background: #FFF3F3; }
.dz-inner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--ink-muted); font-size: 13.5px; }
.dz-inner strong { color: var(--ink); font-size: 14px; }
.url-row { display: flex; gap: 6px; margin-left: auto; }
.url-input {
  font: inherit; font-size: 13px; padding: 6px 10px; min-width: 260px;
  border: 1px solid var(--rule); border-radius: 8px; background: var(--paper);
}

.tiles { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.tile {
  width: 132px; border: 1px solid var(--rule); border-radius: var(--radius);
  overflow: hidden; background: var(--paper); box-shadow: var(--shadow); cursor: grab;
}
.tile.dragging { opacity: .45; }
.tile.drop-target { border-color: var(--red); }
.tile img { display: block; width: 100%; height: 104px; object-fit: cover; background: var(--paper-sunk); }
.tile-bar { display: flex; align-items: center; gap: 4px; padding: 5px 6px; border-top: 1px solid var(--rule-soft); }
.tile-bar button {
  font: inherit; font-size: 11px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--rule); background: var(--paper); color: var(--ink-muted);
  border-radius: 5px; padding: 2px 6px;
}
.tile-bar button:hover { background: var(--paper-raised); color: var(--ink); }
.tile-bar .is-cover { background: var(--red); color: #fff; border-color: var(--red); }
.tile-bar .rm { margin-left: auto; color: var(--danger); }
.tile-meta { font-family: var(--mono); font-size: 10px; color: var(--ink-faint); padding: 0 6px 5px; }
.tile-help { color: var(--ink-muted); font-size: 13px; margin-top: 18px; max-width: 72ch; }

/* ---------- feedback ---------- */

/* ---------- URL import dialog ---------- */

.modal { position: fixed; inset: 0; background: rgba(16,25,35,.45); z-index: 55; display: grid; place-items: center; padding: 24px; }
.modal-box {
  background: var(--paper); border-radius: 14px; box-shadow: var(--shadow);
  width: min(860px, 100%); max-height: 90vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--rule);
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; border-top: 1px solid var(--rule); background: var(--paper-raised);
}
.modal-foot-actions { display: flex; gap: 8px; }
.url-fetch { display: flex; gap: 8px; }
.url-fetch input {
  font: inherit; flex: 1; padding: 9px 12px;
  border: 1px solid var(--rule); border-radius: 8px; background: var(--paper);
}
.url-fetch input:focus { outline: 2px solid var(--red); outline-offset: -1px; }
.modal-note { color: var(--ink-muted); font-size: 13px; margin: 10px 0 0; max-width: 74ch; }
.modal-error {
  margin: 12px 0 0; padding: 10px 12px; border-radius: 8px;
  background: #FCEDEC; border: 1px solid var(--danger); color: var(--danger); font-size: 13.5px;
}
.preview-flag {
  margin: 16px 0 14px; padding: 9px 12px; border-radius: 8px;
  background: var(--paper-raised); border-left: 3px solid var(--red);
  font-size: 13px; color: var(--ink-muted); word-break: break-all;
}
.preview-h { margin: 22px 0 6px; font-size: 15px; }
.cand { width: 150px; }
.cand img { height: 116px; }
.cand-bar { display: flex; align-items: center; gap: 6px; padding: 6px; border-top: 1px solid var(--rule-soft); }
.cand-bar label { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink-muted); }
.cand-bar select { font: inherit; font-size: 11.5px; padding: 2px 4px; border: 1px solid var(--rule); border-radius: 5px; background: var(--paper); }
.cand.off { opacity: .45; }
.cand.bad { display: none; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 11px 18px;
  border-radius: 10px; box-shadow: var(--shadow); z-index: 50; max-width: 70ch;
}
.toast.bad { background: var(--danger); }

.busy { position: fixed; inset: 0; background: rgba(16,25,35,.35); display: grid; place-items: center; z-index: 60; }
.busy-box {
  background: var(--paper); border-radius: 12px; padding: 18px 24px;
  display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow); font-weight: 600;
}
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--rule); border-top-color: var(--red);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; border-right: none; border-bottom: 1px solid var(--rule); }
  .url-row { margin-left: 0; width: 100%; }
  .url-input { min-width: 0; flex: 1; }
}

.variant-row { margin: 0 0 18px; }
.variant-row select {
  font: inherit; width: 100%; padding: 9px 11px;
  border: 1px solid var(--red); border-radius: 8px; background: var(--paper);
}
.field input[readonly] { background: var(--paper-raised); color: var(--ink-muted); }
.pl-price { font-family: var(--mono); font-size: 11px; color: var(--ink-muted); white-space: nowrap; }
.pl-off { color: var(--red-ink); font-weight: 700; }

.url-fetch textarea {
  font: inherit; flex: 1; padding: 9px 12px; resize: vertical; min-height: 62px;
  border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); color: var(--ink);
}
.url-fetch textarea:focus { outline: 2px solid var(--red); outline-offset: -1px; }
.queue-bar {
  margin: 0 0 14px; padding: 9px 12px; border-radius: 8px;
  background: var(--red); color: #fff; font-size: 13px; font-weight: 600;
}
.specs-actions { display: flex; gap: 8px; }

.product-list li.just-saved {
  border-color: var(--red);
  background: #FFF3F3;
  animation: saved-pulse 2.4s ease-out;
}
@keyframes saved-pulse { 0% { background: #FFD9DC; } 100% { background: #FFF3F3; } }
@media (prefers-reduced-motion: reduce) { .product-list li.just-saved { animation: none; } }

.field select {
  font: inherit; padding: 9px 11px; border: 1px solid var(--rule);
  border-radius: 8px; background: var(--paper); color: var(--ink); width: 100%;
}
.field select:focus { outline: 2px solid var(--red); outline-offset: -1px; }
.pairing {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px,1fr)); gap: 14px;
  margin: 16px 0 4px; padding: 16px; border-radius: 10px;
  background: var(--paper-raised); border: 1px solid var(--rule);
}
.pairing span { display: block; font-size: 12.5px; color: var(--ink-muted); font-weight: 600; }
.pairing strong { font-size: 20px; font-family: var(--mono); }
.pairing .code { color: var(--red-ink); letter-spacing: .12em; }
