/* ==========================================================================
   MAC BESPOKE WATCH CO. — internal ledger
   Layout language borrowed from Darkone (fixed sidebar, slim topbar, cards);
   palette and type are MAC's own: near-black ground, white as the accent,
   thin rules, geometric sans, tabular figures everywhere numbers matter.
   ========================================================================== */

:root {
  --ink:        #0a0b0d;
  --panel:      #121417;
  --panel-2:    #171a1e;
  --panel-3:    #1e2227;
  --line:       #262b31;
  --line-soft:  #1c2025;
  --text:       #e9ebee;
  --text-dim:   #9aa2ab;
  --text-faint: #656d76;
  --accent:     #ffffff;
  --accent-ink: #0a0b0d;

  --ok:    #4ea87a;
  --good:  #6aa84f;
  --warn:  #c9974a;
  --bad:   #c4635b;
  --info:  #6b8cae;

  --sidebar-w: 244px;
  --topbar-h:  64px;
  --radius:    10px;
  --radius-sm: 7px;

  --font: 'Archivo', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body { overflow-x: hidden; }

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

a { color: inherit; text-decoration: none; }
a:hover { color: #fff; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  z-index: 60;
  transition: transform .22s ease;
}

.brand {
  display: block;
  padding: 22px 20px 20px;
  border-bottom: 1px solid var(--line);
}
/* The lockup is centre-composed, so it has to be optically centred in the
   sidebar rather than flushed left, or it reads left-heavy. */
.brand__logo {
  display: block; width: 122px; height: auto; margin: 0 auto;
}

.nav { padding: 16px 12px; flex: 1; overflow-y: auto; }
.nav__label {
  margin: 0 0 9px 8px;
  font-size: 9.5px; font-weight: 600;
  letter-spacing: .22em; text-transform: uppercase;
  color: var(--text-faint);
}
.nav__item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13.5px; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav__item svg { width: 17px; height: 17px; flex: none; opacity: .75; }
.nav__item:hover { background: var(--panel-2); color: var(--text); }
.nav__item.is-active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.nav__item.is-active svg { opacity: 1; }

.sidebar__foot { padding: 16px; border-top: 1px solid var(--line); }
.sidebar__next {
  margin: 0 0 11px;
  font-family: var(--mono); font-size: 15px; font-weight: 500;
  letter-spacing: .04em;
}

/* ---------- Shell / topbar ---------- */
.shell { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px;
  background: rgba(10,11,13,.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar__burger {
  display: none;
  width: 38px; height: 38px; padding: 8px;
  background: none; border: 1px solid var(--line); border-radius: var(--radius-sm);
  color: var(--text); cursor: pointer;
}
.topbar__burger svg { width: 100%; height: 100%; }

.topbar__search { position: relative; flex: 1; max-width: 440px; }
.topbar__search svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--text-faint); pointer-events: none;
}
.topbar__search input {
  width: 100%; height: 38px;
  padding: 0 12px 0 34px;
  background: var(--panel-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  color: var(--text); font: inherit; font-size: 13px;
}
.topbar__search input::placeholder { color: var(--text-faint); }
.topbar__search input:focus { outline: none; border-color: #3a424b; background: var(--panel-3); }

.topbar__user { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.topbar__name { font-size: 13px; color: var(--text-dim); }

/* ---------- Page ---------- */
.page { flex: 1; padding: 22px 20px 40px; }
.page__head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.page__title {
  margin: 0; font-size: 21px; font-weight: 600; letter-spacing: -.015em;
}
.page__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { margin-top: 5px; font-size: 12px; color: var(--text-faint); }
.crumbs a { color: var(--text-dim); }
.crumbs a:hover { color: #fff; }
.crumbs i { margin: 0 7px; font-style: normal; opacity: .5; }

.foot {
  padding: 18px 20px; border-top: 1px solid var(--line-soft);
  font-size: 11.5px; letter-spacing: .04em; color: var(--text-faint);
}

/* ---------- Cards ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.card__head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.card__title { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; }
.card__body { padding: 16px; }
.card__body--flush { padding: 0; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 15px 16px;
}
.stat__label {
  margin: 0 0 8px; font-size: 9.5px; font-weight: 600;
  letter-spacing: .2em; text-transform: uppercase; color: var(--text-faint);
}
.stat__value {
  margin: 0; font-family: var(--mono); font-size: 25px; font-weight: 500;
  letter-spacing: -.01em; font-variant-numeric: tabular-nums;
}
.stat__note { margin: 5px 0 0; font-size: 11.5px; color: var(--text-faint); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 15px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { background: #d8dade; color: var(--accent-ink); }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--text-dim); }
.btn--ghost:hover { border-color: #3c444d; color: #fff; background: var(--panel-2); }
.btn--danger { background: transparent; border-color: #462c2a; color: var(--bad); }
.btn--danger:hover { background: #2a1a19; color: #e08b83; }
.btn--sm { height: 30px; padding: 0 11px; font-size: 12px; }
.btn--block { width: 100%; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field--wide { grid-column: 1 / -1; }
.field > label {
  font-size: 10px; font-weight: 600; letter-spacing: .16em;
  text-transform: uppercase; color: var(--text-faint);
}
.field input[type=text], .field input[type=number], .field input[type=date],
.field input[type=email], .field input[type=password], .field input[type=url],
.field select, .field textarea {
  width: 100%; min-height: 38px; padding: 8px 11px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); color: var(--text);
  font: inherit; font-size: 13.5px;
}
.field textarea { min-height: 82px; resize: vertical; line-height: 1.55; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: #454e58; background: var(--panel-3);
}
.field__hint { font-size: 11.5px; color: var(--text-faint); }
.field input[type=file] { font-size: 12.5px; color: var(--text-dim); }

.form-actions {
  display: flex; gap: 9px; flex-wrap: wrap;
  padding-top: 16px; margin-top: 16px; border-top: 1px solid var(--line);
}

/* ---------- Filter bar ---------- */
.filters {
  display: flex; flex-wrap: wrap; gap: 9px; padding: 13px 16px;
  border-bottom: 1px solid var(--line);
}
.filters > * { flex: 1 1 138px; min-width: 0; }
.filters > input[type=search] { flex: 3 1 240px; }
.filters > .btn { flex: 0 0 auto; }
.filters input, .filters select {
  min-height: 36px; padding: 0 10px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); color: var(--text); font: inherit; font-size: 13px;
}
.filters input:focus, .filters select:focus { outline: none; border-color: #454e58; }

.multi { position: relative; }
.multi__trigger {
  width: 100%; min-height: 36px; padding: 0 10px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); color: var(--text);
  font: inherit; font-size: 13px; text-align: left; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.multi__menu {
  display: none; position: absolute; top: 42px; left: 0; z-index: 70;
  min-width: 218px; max-height: 320px; overflow: auto;
  background: var(--panel-3); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 7px;
  box-shadow: 0 16px 36px rgba(0,0,0,.55);
}
.multi__menu.is-open { display: block; }
.multi__menu label {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 5px; font-size: 13px; cursor: pointer;
}
.multi__menu label:hover { background: var(--panel-2); }
.multi__clear {
  width: 100%; margin-top: 5px; min-height: 30px;
  background: transparent; border: 1px solid var(--line); border-radius: 5px;
  color: var(--text-dim); font: inherit; font-size: 12px; cursor: pointer;
}

.result-count {
  padding: 9px 16px; border-bottom: 1px solid var(--line);
  font-size: 11.5px; color: var(--text-faint);
}

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; }
table.data--wide { min-width: 1180px; }
table.data th {
  position: sticky; top: 0; z-index: 2;
  background: var(--panel-3); color: var(--text-dim);
  text-align: left; white-space: nowrap;
  font-size: 10px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase;
  padding: 11px 12px; border-bottom: 1px solid var(--line);
}
table.data th[data-col] { cursor: pointer; user-select: none; }
table.data th[data-col]::after { content: ' ↕'; opacity: .3; }
table.data th.asc::after  { content: ' ↑'; opacity: 1; color: #fff; }
table.data th.desc::after { content: ' ↓'; opacity: 1; color: #fff; }
table.data td {
  padding: 11px 12px; border-bottom: 1px solid var(--line-soft);
  font-size: 13px; vertical-align: top;
}
table.data tbody tr:hover { background: var(--panel-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
.num, .cost { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cost { font-weight: 500; }
.t-strong { font-weight: 600; }
.t-dim { color: var(--text-dim); }
.t-faint { color: var(--text-faint); }

.empty { padding: 44px 20px; text-align: center; color: var(--text-faint); }
.empty p { margin: 0 0 14px; }

/* ---------- Codename ---------- */
.codename {
  display: inline-block;
  font-family: var(--mono); font-size: 11.5px; font-weight: 500;
  letter-spacing: .06em; text-transform: uppercase;
  padding: 3px 8px; border: 1px solid var(--line);
  border-radius: 4px; background: var(--panel-2); color: var(--text);
  white-space: nowrap;
}

/* ---------- Badges / ratings ---------- */
.badge {
  display: inline-block; padding: 3px 9px;
  border: 1px solid var(--line); border-radius: 100px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase;
  color: var(--text-dim); white-space: nowrap;
}
.st--completed, .st--delivered, .st--approved, .st--used { color: var(--ok);   border-color: #244434; }
.st--building, .st--testing, .st--ready-to-build         { color: var(--info); border-color: #263846; }
.st--parts-ordered, .st--waiting-on-parts, .st--candidate,
.st--parts-research, .st--returned-for-repair            { color: var(--warn); border-color: #46381f; }
.st--avoid, .st--discontinued, .st--unavailable, .st--retired { color: var(--bad); border-color: #452b28; }

.rate { white-space: nowrap; letter-spacing: .07em; }
.rate__off { opacity: .2; }
.rate--none { color: var(--text-faint); letter-spacing: 0; }
.diff-label { display: inline-block; min-width: 66px; font-size: 12px; color: var(--text-dim); }

/* ---------- Flash ---------- */
.flash {
  padding: 11px 15px; margin-bottom: 16px;
  border: 1px solid var(--line); border-left-width: 3px;
  border-radius: var(--radius-sm); font-size: 13px; background: var(--panel);
}
.flash--ok    { border-left-color: var(--ok); }
.flash--error { border-left-color: var(--bad); }

/* ---------- Detail lists ---------- */
.dl { display: grid; grid-template-columns: minmax(104px, 40%) 1fr; gap: 1px; }
.dl > dt {
  padding: 9px 0; font-size: 10px; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase; color: var(--text-faint);
}
.dl > dd { padding: 9px 0; margin: 0; font-size: 13.5px; border-bottom: 1px solid var(--line-soft); }
.dl > dt { border-bottom: 1px solid var(--line-soft); }

/* ---------- Photo grid ---------- */
.photos { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 132px), 1fr)); gap: 10px; }
.photo {
  position: relative; aspect-ratio: 1; overflow: hidden;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel-2);
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo__tag {
  position: absolute; left: 6px; bottom: 6px;
  padding: 2px 7px; border-radius: 3px;
  background: rgba(10,11,13,.82); font-size: 10px; letter-spacing: .06em; text-transform: uppercase;
}
.photo--empty { display: grid; place-items: center; color: var(--text-faint); font-size: 12px; aspect-ratio: 1; }

/* ---------- Two-column split ---------- */
.split { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }

/* ---------- Scrim (mobile nav) ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(0,0,0,.6); opacity: 0; pointer-events: none;
  transition: opacity .22s;
}
body.nav-open .scrim { opacity: 1; pointer-events: auto; }

/* ==========================================================================
   Responsive — the phone is on the bench while a watch is being assembled,
   so mobile is a first-class layout, not a fallback.
   ========================================================================== */
@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  body.nav-open .sidebar { transform: none; }
  .shell { margin-left: 0; }
  .topbar__burger { display: block; }
  .topbar__name { display: none; }
  .page { padding: 16px 12px 32px; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters > :first-child, .filters > .btn { grid-column: 1 / -1; }
  .filters input, .filters select, .multi__trigger { min-height: 42px; font-size: 16px; }
  .multi__menu { position: fixed; left: 12px; right: 12px; width: auto; max-height: 54vh; }
  .dl { grid-template-columns: 1fr; gap: 0; }
  .dl > dt { padding-bottom: 0; border-bottom: 0; }
  .dl > dd { padding-top: 3px; }

  /* Tables collapse to tap-to-expand rows */
  .table-wrap { overflow: visible; }
  table.data, table.data--wide { width: 100%; min-width: 0; }
  table.data thead { display: none; }
  table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data tbody tr {
    position: relative;
    display: flex; flex-direction: column;
    border-bottom: 1px solid var(--line);
    padding: 4px 0 18px;
    cursor: pointer;
  }
  /* Summary fields always lead, regardless of column order in the table. */
  table.data td[data-key]    { order: 0; }
  table.data td[data-detail] { order: 1; }
  table.data tbody tr:last-child { border-bottom: 0; }
  table.data td { padding: 4px 14px; border: 0; font-size: 13px; }
  table.data td[data-key] { display: block; }
  table.data td[data-detail] { display: none; }
  table.data tr.is-open td[data-detail] {
    display: grid; grid-template-columns: 42% 58%; gap: 10px;
    padding: 7px 14px; border-top: 1px solid var(--line-soft);
  }
  table.data tr.is-open td[data-detail]::before {
    content: attr(data-label);
    font-size: 9.5px; font-weight: 600; letter-spacing: .14em;
    text-transform: uppercase; color: var(--text-faint);
  }
  table.data tbody tr::after {
    content: 'Tap for details';
    position: absolute; right: 14px; bottom: 4px;
    font-size: 9.5px; color: var(--text-faint); pointer-events: none;
  }
  table.data tbody tr.is-open::after { content: 'Tap to close'; }
  table.data tbody tr.is-open { background: var(--panel-2); }
}

@media (max-width: 520px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stat__value { font-size: 21px; }
  .page__title { font-size: 18px; }
}

/* ==========================================================================
   Public landing page — the only page the outside world sees.
   Deliberately spare: brand, one line, one door.
   ========================================================================== */
.landing {
  min-height: 100vh; margin: 0;
  display: grid; grid-template-rows: auto 1fr auto;
  background: var(--ink); color: var(--text);
}
.landing__bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 28px; border-bottom: 1px solid var(--line-soft);
}
.landing__hero {
  display: grid; place-items: center; text-align: center; padding: 60px 24px;
}
.landing__mark { margin: 0; line-height: 0; }
.landing__mark img {
  width: clamp(210px, 42vw, 380px); height: auto;
}
.landing__baremark {
  display: block; width: 128px; height: auto;
}
.landing__rule {
  width: min(360px, 72vw); height: 1px; margin: 32px auto 0;
  background: linear-gradient(90deg, transparent, var(--line) 18%, var(--line) 82%, transparent);
}
.landing__sub {
  margin: 0; font-size: 10.5px; font-weight: 600;
  letter-spacing: .42em; text-transform: uppercase; color: var(--text-dim);
}
.landing__line {
  margin: 30px auto 0; max-width: 480px;
  font-size: 16px; line-height: 1.65; color: var(--text-dim);
}
.landing__line strong { color: var(--text); font-weight: 600; }
.landing__foot {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  flex-wrap: wrap; padding: 20px 28px;
  border-top: 1px solid var(--line-soft);
  font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--text-faint);
}

/* ---------- Sign-in ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth__box { width: 100%; max-width: 372px; }
.auth__brand { display: block; text-align: center; margin-bottom: 30px; }
.auth__logo { display: block; width: 168px; height: auto; margin: 0 auto; }
.auth__sub {
  display: block; margin-top: 8px; font-size: 9.5px; font-weight: 600;
  letter-spacing: .3em; text-transform: uppercase; color: var(--text-faint);
}

/* ==========================================================================
   Parts intake — the add form
   ========================================================================== */
.shotdrop {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 11px 13px;
  border: 1px dashed var(--line); border-radius: var(--radius-sm);
  background: var(--panel-2);
  transition: border-color .15s, background .15s;
}
.shotdrop.is-over { border-color: var(--accent); border-style: solid; background: var(--panel-3); }
.shotdrop input[type=file] { font-size: 12.5px; color: var(--text-dim); }
.shotdrop__hint { font-size: 12px; color: var(--text-faint); }
.shotdrop__state { font-size: 12px; color: var(--ok); margin-left: auto; }

.intake__url {
  display: inline-block; margin-top: 4px;
  font-size: 11.5px; color: var(--text-faint); word-break: break-all;
}
.intake__url:hover { color: var(--text-dim); }
.intake .field__hint code {
  font-family: var(--mono); font-size: 11px;
  padding: 1px 4px; border-radius: 3px; background: var(--panel-3);
}
.js-suggest-note { display: inline-block; margin-left: 8px; font-size: 11.5px; }

/* ---------- Intake: AI suggestions with per-field confirm ---------- */
.ai-strip {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 9px 12px; margin-bottom: 14px;
  border: 1px solid var(--line); border-left: 3px solid var(--info);
  border-radius: var(--radius-sm); background: var(--panel-2);
  font-size: 12.5px; color: var(--text-dim);
}
.ai-strip.is-done { border-left-color: var(--ok); }
.ai-strip__state { flex: 1 1 220px; }
.ai-strip__actions { display: flex; gap: 6px; }
.ai-strip__note {
  margin: -6px 0 14px; padding: 0 2px;
  font-size: 12px; line-height: 1.5; color: var(--text-faint);
}

/* The checkbox sits under its field and shows exactly what would be written. */
.suggest {
  display: flex; align-items: flex-start; gap: 7px;
  margin-top: 6px; padding: 5px 8px;
  border: 1px solid var(--line); border-radius: 5px;
  background: var(--panel-2);
  font-size: 12px; line-height: 1.4; color: var(--text-dim);
  cursor: pointer;
}
.suggest:hover { border-color: #3c444d; }
.suggest__box { margin: 1px 0 0; flex: none; accent-color: #fff; }
.suggest__text { overflow-wrap: anywhere; }
.suggest__box:checked + .suggest__text { color: var(--text); }

/* A field currently showing a suggested value is marked, so you can see at a
   glance which values are yours and which came from the model. */
.field.is-suggested > input,
.field.is-suggested > select {
  border-color: #3a4a5c;
  box-shadow: inset 2px 0 0 var(--info);
}

@media (max-width: 900px) {
  .ai-strip { padding: 10px; }
  .ai-strip__actions { width: 100%; }
  .ai-strip__actions .btn { flex: 1; }
  .suggest { padding: 8px; font-size: 12.5px; }
  .suggest__box { width: 18px; height: 18px; }
}

/* Topbar name doubles as the settings link */
a.topbar__name:hover { color: #fff; }

/* A disabled control must look disabled. */
.btn:disabled, .btn[disabled] {
  opacity: .45; cursor: not-allowed;
}
.btn:disabled:hover, .btn[disabled]:hover {
  background: transparent; border-color: var(--line); color: var(--text-dim);
}
.btn--primary:disabled:hover { background: var(--accent); color: var(--accent-ink); }

/* ==========================================================================
   Extraction workbench
   ========================================================================== */
.dbg-split { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 16px; align-items: start; }
@media (max-width: 1400px) { .dbg-split { grid-template-columns: 1fr; } }

.dbg-log {
  margin-top: 14px; max-height: 220px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #0d0f12; font-family: var(--mono); font-size: 12px;
}
.dbg-log:empty { display: none; }
.dbg-log__line {
  display: flex; gap: 12px; padding: 6px 11px;
  border-bottom: 1px solid var(--line-soft); color: var(--text-dim);
}
.dbg-log__line:last-child { border-bottom: 0; }
.dbg-log__ms { flex: none; min-width: 62px; text-align: right; color: var(--text-faint); }
.dbg-log__line.is-ok    { color: var(--ok); }
.dbg-log__line.is-error { color: var(--bad); }

.dbg-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.dbg-table th {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line);
  font-size: 9.5px; font-weight: 600; letter-spacing: .16em;
  text-transform: uppercase; color: var(--text-faint);
}
.dbg-table td { padding: 7px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; font-size: 13px; }
.dbg-table tr:last-child td { border-bottom: 0; }
.dbg-table tr.is-missing .dbg-key { color: var(--warn); }
.dbg-key { font-family: var(--mono); font-size: 11.5px; color: var(--text-dim); white-space: nowrap; }
.dbg-got { color: var(--text); overflow-wrap: anywhere; }
.dbg-fix {
  width: 100%; min-height: 32px; padding: 5px 9px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 5px; color: var(--text); font: inherit; font-size: 12.5px;
}
.dbg-fix:focus { outline: none; border-color: #454e58; }
.dbg-fix.is-target { border-color: var(--info); box-shadow: inset 2px 0 0 var(--info); }

.dbg-label {
  margin: 14px 0 6px; font-size: 9.5px; font-weight: 600;
  letter-spacing: .16em; text-transform: uppercase; color: var(--text-faint);
}
.dbg-label:first-child { margin-top: 0; }
.dbg-pre {
  margin: 0; padding: 11px 13px; max-height: 320px; overflow: auto;
  background: #0d0f12; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 11.5px; line-height: 1.55; color: var(--text-dim);
  white-space: pre; tab-size: 2;
}

.dbg-frame-card { position: sticky; top: calc(var(--topbar-h) + 16px); }
.dbg-frame {
  display: block; width: 100%; height: 60vh; min-height: 420px;
  border: 0; border-top: 1px solid var(--line); background: #fff;
}
.dbg-pick {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel-2); font-size: 12.5px; color: var(--text-dim);
}
.dbg-pick__text { color: var(--text); overflow-wrap: anywhere; }
.dbg-pick__meta { margin-top: 6px; }
.dbg-pick__meta code {
  font-family: var(--mono); font-size: 11px; color: var(--text-faint);
  overflow-wrap: anywhere;
}
.dbg-pick__hint { margin-top: 8px; color: var(--warn); font-size: 11.5px; }

details.card > summary { list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after {
  content: '▾'; margin-left: auto; color: var(--text-faint); font-size: 12px;
}
details.card[open] > summary::after { content: '▴'; }

/* Colour options read as a set of choices, not one value. */
.swatch {
  display: inline-block; margin: 1px 3px 1px 0; padding: 1px 7px;
  border: 1px solid var(--line); border-radius: 100px;
  font-size: 10.5px; letter-spacing: .04em; color: var(--text-dim);
  white-space: nowrap;
}

/* The re-read control belongs with the content it reads. */
.reread {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-top: 8px;
}
.reread .js-suggest-note { margin-left: 0; }

/* Assign-to-build sits inline with the save actions. */
.assign {
  display: flex; align-items: center; gap: 8px;
  padding: 0 11px 0 12px; min-height: 36px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel-2);
}
.assign__label {
  font-size: 9.5px; font-weight: 600; letter-spacing: .14em;
  text-transform: uppercase; color: var(--text-faint); white-space: nowrap;
}
.assign select {
  border: 0; background: none; color: var(--text);
  font: inherit; font-size: 13px; padding: 0; max-width: 260px;
}
.assign select:focus { outline: none; }
@media (max-width: 900px) {
  .assign { width: 100%; }
  .assign select { flex: 1; max-width: none; }
}

/* `.field { display: flex }` outranks the browser's [hidden] rule, so hidden
   fields kept showing. Restore the intent explicitly. */
[hidden] { display: none !important; }

/* ---------- Parts list: thumbnail, clickable rows, stocked colours ---------- */
/* Photo gets its own narrow leading column, so the part name has room. */
.th-thumb { width: 60px; padding-left: 12px !important; padding-right: 0 !important; }
.td-thumb { width: 60px; padding-right: 0 !important; }
.partcell__thumb {
  display: block; width: 48px; height: 48px;   /* 1:1 — parts photograph square */
  object-fit: cover; border-radius: 6px;
  border: 1px solid var(--line); background: var(--panel-2);
}

/* Subcategory sits under its category rather than taking a column. */
.subcat {
  margin-top: 3px; font-size: 11px; letter-spacing: .02em; color: var(--text-faint);
}
.partcell__thumb--none {
  display: block;
  background:
    linear-gradient(135deg, transparent 46%, var(--line) 46%, var(--line) 54%, transparent 54%),
    var(--panel-2);
}

table.data tr[data-href] { cursor: pointer; }
table.data tr[data-href]:focus-visible {
  outline: 2px solid var(--info); outline-offset: -2px;
}

/* A filled swatch is a colour actually on the shelf; an outlined one is only
   offered by the listing. */
.swatch--have {
  background: var(--panel-3); border-color: #46525f; color: var(--text);
  font-weight: 600;
}
.swatch--have::before {
  content: '●'; margin-right: 5px; font-size: 8px; color: var(--ok);
  vertical-align: 1px;
}

.listing-link { word-break: break-all; font-size: 12.5px; }

@media (max-width: 900px) {
  /* Stacked rows: the photo leads, full width of its own line. */
  .th-thumb, .td-thumb { width: auto; padding-left: 14px !important; }
  .partcell__thumb { width: 56px; height: 56px; }
}

/* Form-level actions belong to the form, not to whichever card happens to be
   last. Sticky, because these forms are long. */
.formbar {
  position: sticky; bottom: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; margin-top: 16px;
  background: rgba(10,11,13,.92); backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.formbar__note { font-size: 11.5px; color: var(--text-faint); margin-left: auto; }
@media (max-width: 900px) {
  .formbar__note { margin-left: 0; width: 100%; order: 3; }
}

/* ---------- Parts library: view controls ---------- */
.viewbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 9px 16px; border-bottom: 1px solid var(--line);
  font-size: 11.5px; color: var(--text-faint);
}
.viewbar__group { display: flex; align-items: center; gap: 4px; }
.viewbar__label {
  margin-right: 4px; font-size: 9.5px; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase;
}
.viewbar__cols { margin-left: auto; }
.viewbar .multi__trigger { min-height: 28px; font-size: 12px; width: auto; }
.viewbar .multi__menu { left: auto; right: 0; }

.segbtn {
  min-height: 28px; padding: 0 11px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); color: var(--text-dim);
  font: inherit; font-size: 12px; cursor: pointer;
}
.segbtn:hover { color: #fff; border-color: #3c444d; }
.segbtn.is-on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* Thumbnail size is a body-level switch so table and grid stay in step. */
body.thumbs-sm .partcell__thumb { width: 48px;  height: 48px; }
body.thumbs-md .partcell__thumb { width: 76px;  height: 76px; }
body.thumbs-lg .partcell__thumb { width: 116px; height: 116px; }
body.thumbs-sm .th-thumb, body.thumbs-sm .td-thumb { width: 60px; }
body.thumbs-md .th-thumb, body.thumbs-md .td-thumb { width: 90px; }
body.thumbs-lg .th-thumb, body.thumbs-lg .td-thumb { width: 130px; }

/* ---------- Grid view ---------- */
.pgrid {
  display: grid; gap: 12px; padding: 16px;
  grid-template-columns: repeat(auto-fill, minmax(212px, 1fr));
}
body.thumbs-md .pgrid { grid-template-columns: repeat(auto-fill, minmax(252px, 1fr)); }
body.thumbs-lg .pgrid { grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); }

.pcard {
  display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel-2); overflow: hidden;
  transition: border-color .15s, transform .15s;
}
.pcard:hover { border-color: #3c444d; transform: translateY(-1px); }
.pcard__img { aspect-ratio: 1; background: var(--panel-3); }   /* 1:1 */
.pcard__img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pcard__none {
  display: block; width: 100%; height: 100%;
  background:
    linear-gradient(135deg, transparent 46%, var(--line) 46%, var(--line) 54%, transparent 54%),
    var(--panel-3);
}
.pcard__body { padding: 11px 12px 12px; display: flex; flex-direction: column; gap: 6px; }
.pcard__name { margin: 0; font-size: 13.5px; font-weight: 600; line-height: 1.35; }
.pcard__meta { margin: 0; font-size: 11.5px; color: var(--text-faint); }
.pcard__colours { display: flex; flex-wrap: wrap; gap: 2px; }
.pcard__foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-top: 2px;
}

@media (max-width: 900px) {
  .viewbar { gap: 10px; }
  .viewbar__cols { margin-left: 0; width: 100%; }
  .viewbar .multi__menu { left: 12px; right: 12px; }
  .pgrid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); padding: 12px; }
}

/* ---------- Build page: parts picker ---------- */
.pickfilter {
  width: 100%; min-height: 36px; margin-bottom: 6px; padding: 0 11px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); color: var(--text); font: inherit; font-size: 13px;
}
.pickfilter:focus { outline: none; border-color: #454e58; }
.pickbox {
  width: 100%; padding: 4px; overflow-y: auto;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); color: var(--text); font: inherit; font-size: 13px;
}
.pickbox:focus { outline: none; border-color: #454e58; }
.pickbox option { padding: 6px 8px; border-radius: 4px; }
.pickbox option:checked { background: var(--accent); color: var(--accent-ink); }

/* A photo record whose file has gone: say so, offer to clear it. */
.lostphotos {
  padding: 10px 12px; margin-bottom: 12px;
  border: 1px solid var(--line); border-left: 3px solid var(--warn);
  border-radius: var(--radius-sm); background: var(--panel-2);
}
.lostphotos p { margin: 0; font-size: 12.5px; line-height: 1.5; color: var(--text-dim); }

/* Visually hidden, still read aloud. */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Unsaved-changes prompt ---------- */
.askbox {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(0,0,0,.6); backdrop-filter: blur(3px);
}
.askbox__panel {
  width: 100%; max-width: 420px; padding: 20px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.askbox__title { margin: 0 0 8px; font-size: 15px; letter-spacing: .02em; }
.askbox__body  { margin: 0 0 16px; font-size: 13px; color: var(--text-dim); }
.askbox__actions { display: flex; flex-direction: column; gap: 8px; }
.askbox__actions .btn { width: 100%; justify-content: center; }

/* A form with edits pending says so before you try to walk away. */
form.is-dirty .card__head::after,
.card.is-dirty .card__head::after {
  content: 'Unsaved'; margin-left: auto;
  font-size: 9.5px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase;
  color: var(--warn, #d9a441);
}

/* ---------- Three cards side by side ---------- */
.cols3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: start; }
.cols3 > .card { margin-bottom: 0; }
/* Narrow columns: one field per row reads better than two cramped ones. */
.cols3 .form-grid { grid-template-columns: 1fr; }
@media (max-width: 1200px) { .cols3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 800px)  { .cols3 { grid-template-columns: 1fr; } }

/* ---------- Picking photos to move ---------- */
.pickphotos { display: flex; flex-wrap: wrap; gap: 8px; }
.pickphoto { position: relative; cursor: pointer; line-height: 0; }
.pickphoto img {
  width: 72px; height: 72px; object-fit: cover;
  border: 2px solid var(--line); border-radius: 8px; opacity: .5;
}
.pickphoto input { position: absolute; top: 6px; left: 6px; z-index: 1; margin: 0; }
.pickphoto:has(input:checked) img { border-color: var(--accent, #d9d9d9); opacity: 1; }

/* ---------- Photo thumbnails with a remove button ---------- */
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; }
.thumb { position: relative; line-height: 0; }
.thumb img {
  width: 84px; height: 84px; object-fit: cover;
  border: 1px solid var(--line); border-radius: 8px; display: block;
}
.thumb__x {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; padding: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; line-height: 1; cursor: pointer;
  background: #2a1a19; color: var(--bad); border: 1px solid #462c2a;
}
.thumb__x:hover { background: var(--bad); color: #12100f; }

/* Actions sit right; the note takes the slack on the left. */
.formbar__note { margin-right: auto; margin-left: 0; }
.formbar--top {
  position: static; margin: 0 0 16px;
  background: rgba(10,11,13,.6);
}
@media (max-width: 900px) {
  .formbar--top { flex-wrap: wrap; }
  .formbar__note { width: 100%; order: 3; }
}

/* A field with a button welded to its right. */
.withbtn { display: flex; gap: 6px; }
.withbtn input { flex: 1; min-width: 0; }
.withbtn .btn { flex: 0 0 auto; font-size: 15px; line-height: 1; padding: 0 12px; }

/* Thumbnail column in the fitted-components table. */
.cell-thumb { width: 52px; padding-right: 0 !important; }
.cell-thumb img {
  width: 40px; height: 40px; object-fit: cover; border-radius: 6px;
  border: 1px solid var(--line); display: block;
}
.thumb--none {
  display: block; width: 40px; height: 40px; border-radius: 6px;
  border: 1px dashed var(--line);
}

/* The millimetre filter is a number box among selects. */
.filter-mm { max-width: 130px; }

/* ---------- Compatibility ---------- */
.cdot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  flex: 0 0 9px; margin-top: 5px;
}
.cdot--green { background: var(--good, #6aa84f); }
.cdot--amber { background: var(--warn, #c9974a); }
.cdot--red   { background: var(--bad,  #c4635b); }
.cell-dot { width: 22px; padding-right: 0 !important; }
.cell-dot a { display: inline-block; line-height: 0; }

.badge--compat { text-decoration: none; }
.badge--green { border-color: #2f4034; color: #86c08a; }
.badge--amber { border-color: #4a3a22; color: var(--warn, #c9974a); }
.badge--red   { border-color: #462c2a; color: var(--bad,  #c4635b); }

.compat-sum { display: flex; gap: 12px; font-size: 11.5px; color: var(--text-faint); }
.compat-sum__bit { display: flex; align-items: center; gap: 5px; }
.compat-sum__bit .cdot { margin-top: 0; }

.compat { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.compat__row {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 9px 0; border-bottom: 1px solid var(--line);
}
.compat__row:last-child { border-bottom: 0; }
.compat__body { flex: 1; min-width: 0; }
.compat__text { margin: 0; font-size: 13px; }
.compat__row--green .compat__text { color: var(--text-dim); }
.compat__note { margin: 3px 0 0; font-size: 11.5px; color: var(--text-faint); }
.compat__act { flex: 0 0 auto; }
.compat__act summary { list-style: none; cursor: pointer; }
.compat__act summary::-webkit-details-marker { display: none; }
.linkish {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--text-dim); text-decoration: underline; font: inherit; font-size: 11.5px;
}
@media (max-width: 620px) {
  .compat__row { flex-wrap: wrap; }
  .compat__act { width: 100%; }
}

/* ---------- Tabs ---------- */
/* A build page answers one question at a time. Photos stay outside the tabs —
   you want to see the watch whichever question you are asking. */
.tabs {
  display: flex; gap: 4px; margin-bottom: 16px;
  border-bottom: 1px solid var(--line); padding-bottom: 0;
}
/* Tabs sit above both columns, so Specification and Photos line up. */
.tabs + .split--photos { margin-top: 0; }
.tab {
  display: flex; align-items: center; gap: 7px;
  padding: 9px 14px; margin-bottom: -1px;
  background: none; border: 1px solid transparent; border-bottom: 0;
  border-radius: 8px 8px 0 0; cursor: pointer;
  font: inherit; font-size: 12.5px; color: var(--text-faint);
}
.tab:hover { color: var(--text-dim); }
.tab.is-on {
  color: var(--text); background: var(--panel);
  border-color: var(--line); border-bottom: 1px solid var(--panel);
}
.tab__n {
  font-size: 10.5px; padding: 1px 6px; border-radius: 999px;
  background: var(--line-soft, rgba(255,255,255,.07)); color: var(--text-faint);
}
.tab.is-on .tab__n { color: var(--text-dim); }
.tabpane { display: none; }
.tabpane.is-on { display: block; }

/* Photos column, a fifth narrower than the old sidebar. */
.split--photos { grid-template-columns: 2fr 0.8fr; }
@media (max-width: 900px) {
  .split--photos { grid-template-columns: 1fr; }
  .tabs { overflow-x: auto; }
  .tab { white-space: nowrap; }
}

/* The editor's tab bar sits under the sticky action bar, not against the title. */
.formbar--top + .tabs { margin-top: 4px; }

/* Two cards abreast inside a tab, stacking when there is no room. */
.cols2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.cols2 > .card { margin-bottom: 0; }
@media (max-width: 1100px) { .cols2 { grid-template-columns: 1fr; } }
