/* ==========================================================================
   App layout + pieces the mockup didn't need (tables, dialogs, toasts).
   Colours only through theme.css variables.
   ========================================================================== */

/* ---- tone classes: lists.js items carry a `tone`, CSS maps it once ------ */
.tone-neutral { --tone-bg: var(--status-at-factory-bg); --tone-fg: var(--status-at-factory-text); --tone-dot: var(--status-at-factory-dot); }
.tone-teal    { --tone-bg: var(--status-at-factory-bg); --tone-fg: var(--status-at-factory-text); --tone-dot: var(--accent); }
.tone-accent  { --tone-bg: var(--accent-soft); --tone-fg: var(--accent-text); --tone-dot: var(--accent); }
.tone-ok      { --tone-bg: var(--status-in-service-bg); --tone-fg: var(--status-in-service-text); --tone-dot: var(--status-in-service-dot); }
.tone-info    { --tone-bg: var(--status-handed-over-bg); --tone-fg: var(--status-handed-over-text); --tone-dot: var(--status-handed-over-dot); }
.tone-warn    { --tone-bg: var(--status-docs-missing-bg); --tone-fg: var(--status-docs-missing-text); --tone-dot: var(--status-docs-missing-dot); }
.tone-violet  { --tone-bg: var(--status-shipped-bg); --tone-fg: var(--status-shipped-text); --tone-dot: var(--status-shipped-dot); }
.tone-orange  { --tone-bg: var(--sev-not-working-bg); --tone-fg: var(--sev-not-working-text); --tone-dot: var(--sev-not-working-solid); }
.tone-danger  { --tone-bg: var(--sev-safety-bg); --tone-fg: var(--sev-safety-text); --tone-dot: var(--sev-safety-solid); }
.tone-outline { --tone-bg: var(--status-at-factory-bg); --tone-fg: var(--status-at-factory-text); --tone-dot: transparent; }
.status-badge[class*="tone-"] { background: var(--tone-bg); color: var(--tone-fg); }
.status-badge[class*="tone-"] .status-badge__dot { background: var(--tone-dot); }
.tone-outline .status-badge__dot { border: 1.5px solid var(--status-at-factory-dot); }

/* ---- shell ----------------------------------------------------------------- */
body { display: flex; flex-direction: column; min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px; min-height: 56px;
  background: var(--bg-surface); border-bottom: 1px solid var(--border);
}
.topbar__brand { display: flex; align-items: center; gap: 8px; font-weight: 800; color: var(--text-primary); white-space: nowrap; }
.topbar__brand:hover { text-decoration: none; }
.topbar__mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 13px; font-weight: 800; }
.topnav { display: flex; gap: 4px; flex: 1; }
.topnav a {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 12px; border-radius: var(--radius-md);
  color: var(--text-secondary); font-weight: 600; font-size: var(--text-sm);
}
.topnav a:hover { background: var(--bg-surface-2); text-decoration: none; }
.topnav a[aria-current="page"] { color: var(--accent-text); background: var(--accent-soft); }
.topbar__end { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.who { font-size: var(--text-sm); color: var(--text-secondary); text-align: right; line-height: 1.2; }
.who small { display: block; color: var(--text-muted); font-size: var(--text-xs); }

.page { width: 100%; max-width: 1200px; margin: 0 auto; padding: 24px 20px 96px; display: flex; flex-direction: column; gap: 20px; flex: 1; }
.page--narrow { max-width: 760px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head__titles { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.page-head__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; font-size: var(--text-sm); color: var(--text-muted); }
.crumbs a { color: var(--text-secondary); }
.crumbs span[aria-hidden] { color: var(--border-strong); }

.bottom-nav.app-bottom-nav { display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
@media (max-width: 720px) {
  .topnav { display: none; }
  .who { display: none; }
  .bottom-nav.app-bottom-nav { display: grid; }
  .page { padding: 16px 14px 104px; }
}

/* ---- sections, grids, lists ---------------------------------------------- */
.section { display: flex; flex-direction: column; gap: 12px; }
.section__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.link-card { display: flex; flex-direction: column; gap: 6px; color: inherit; }
.link-card:hover { text-decoration: none; border-color: var(--accent); }
.list { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.list > .result-row:last-child { border-bottom: 0; }
.result-row:hover { background: var(--bg-surface-2); text-decoration: none; }
.result-row__main { display: flex; flex-direction: column; min-width: 0; }
.result-row__title { font-weight: 700; color: var(--text-primary); }
.result-row__sub { font-size: var(--text-sm); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 28px 16px; text-align: center; color: var(--text-muted); display: flex; flex-direction: column; gap: 10px; align-items: center; }
.empty strong { color: var(--text-primary); }
.count { font-size: var(--text-sm); color: var(--text-muted); font-weight: 600; }

/* ---- tables ---------------------------------------------------------------- */
.table-wrap { overflow-x: auto; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
table.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); font-weight: 700; background: var(--bg-surface-2); white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--bg-surface-2); }
.table td.num, .table th.num { text-align: right; }
.table .row-link { color: var(--text-primary); font-weight: 700; }
.table input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }
.table tr.is-error td { background: var(--sev-safety-bg); }
.table tr.is-warn td { background: var(--sev-missing-bg); }
.cell-msgs { display: flex; flex-direction: column; gap: 2px; font-size: var(--text-xs); }
.cell-msgs .err { color: var(--sev-safety-text); font-weight: 600; }
.cell-msgs .warn { color: var(--sev-missing-text); }

/* ---- forms ------------------------------------------------------------------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.field__fix { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-xs); }
.field__fix button { min-height: 28px; padding: 0 8px; font-size: var(--text-xs); }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.inline-form .field { flex: 1 1 180px; }
.select { appearance: auto; }

/* ---- bulk bar, toolbar ------------------------------------------------------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar .input, .toolbar .select { width: auto; min-width: 160px; flex: 1 1 160px; }
.bulkbar {
  position: sticky; bottom: 12px; z-index: 10;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 10px 12px; border-radius: var(--radius-lg);
  background: var(--bg-surface); border: 2px solid var(--accent); box-shadow: var(--shadow-md);
}
.bulkbar[hidden] { display: none; }
@media (max-width: 720px) { .bulkbar { bottom: 84px; } }

/* ---- dialog, toast, banners ---------------------------------------------- */
dialog.sheet {
  border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 0;
  background: var(--bg-surface); color: var(--text-primary); width: min(520px, calc(100vw - 24px));
  box-shadow: var(--shadow-phone);
}
dialog.sheet::backdrop { background: rgba(10, 12, 14, 0.5); }
.sheet__body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; z-index: 50; display: flex; flex-direction: column; gap: 8px; width: min(480px, calc(100vw - 24px)); pointer-events: none; }
@media (max-width: 720px) { .toasts { bottom: 92px; } }
.toast { pointer-events: auto; padding: 12px 14px; border-radius: var(--radius-md); background: var(--text-primary); color: var(--bg-surface); font-weight: 600; font-size: var(--text-sm); box-shadow: var(--shadow-md); }
.toast--error { background: var(--sev-safety-solid); color: var(--sev-safety-solid-ink); }
.offline-banner[hidden] { display: none; }
.callout { padding: 12px 14px; border-radius: var(--radius-md); background: var(--bg-surface-2); border: 1px solid var(--border); font-size: var(--text-sm); }
.callout--error { background: var(--sev-safety-bg); color: var(--sev-safety-text); border-color: var(--sev-safety-border); }
.callout--warn { background: var(--sev-missing-bg); color: var(--sev-missing-text); border-color: var(--sev-missing-border); }
.callout--ok { background: var(--status-in-service-bg); color: var(--status-in-service-text); border-color: transparent; }
main[aria-busy="true"] { opacity: 0.6; transition: opacity 0.2s 0.15s; }

/* ---- sign-in ----------------------------------------------------------------- */
.signin { width: min(400px, 100%); margin: 6vh auto 0; }

/* ---- stage durations (gear history) ------------------------------------------ */
.stage-days { display: flex; flex-direction: column; gap: 6px; }
.stage-days__row { display: grid; grid-template-columns: 130px 1fr 72px; gap: 10px; align-items: center; font-size: var(--text-sm); }
.stage-days__track { background: var(--bg-surface-2); border-radius: 4px; height: 8px; }
.stage-days__bar { height: 8px; border-radius: 4px; background: var(--accent); min-width: 2px; }
.stage-days__n { text-align: right; font-family: var(--font-mono); }

/* main takes focus on navigation (for screen readers); no ring around the whole page */
main:focus, main:focus-visible { outline: none; box-shadow: none; }

/* Lifecycle on phones: the chip names the status, so only the current step keeps its label. */
@media (max-width: 520px) {
  .gear-lifecycle__label { visibility: hidden; }
  .gear-lifecycle__step--current .gear-lifecycle__label { visibility: visible; overflow: visible; }
}

/* ---- status + condition side by side --------------------------------------- */
.badge-row { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip--tone { background: var(--tone-bg); color: var(--tone-fg); border-color: transparent; }
a.chip:hover { text-decoration: none; border-color: var(--accent); }

/* ---- key dates (received, first look, handed over) ------------------------- */
.key-dates { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; padding-top: 12px; border-top: 1px solid var(--border); }
.key-dates dt { font-size: var(--text-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
.key-dates dd { margin: 2px 0 0; font-weight: 600; font-size: var(--text-sm); }

/* ---- first look ----------------------------------------------------------------- */
.first-look-cta { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; border: 2px dashed var(--accent); }
.first-look-cta .btn { flex: 0 0 auto; }
@media (max-width: 520px) { .first-look-cta .btn { flex: 1 1 100%; } }
.first-look__add { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 420px) { .first-look__add { grid-template-columns: 1fr; } }
.first-look__add .btn, .first-look-cta .btn { cursor: pointer; justify-content: center; }
.segmented--big { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); width: 100%; }
.segmented--big .segmented__btn { min-height: 48px; font-size: var(--text-sm); }
.segmented--big .segmented__btn[aria-pressed="true"] { background: var(--tone-bg); color: var(--tone-fg); box-shadow: inset 0 0 0 2px var(--tone-dot); }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.photo-tile { position: relative; margin: 0; aspect-ratio: 4 / 3; border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-surface-2); border: 1px solid var(--border); }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tile a { display: block; height: 100%; }
.photo-tile--missing::after { content: "Not uploaded yet"; position: absolute; inset: 0; display: grid; place-items: center; font-size: var(--text-xs); color: var(--text-muted); text-align: center; padding: 4px; }
.photo-tile--missing img { display: none; }
.photo-tile__x { position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; border-radius: 50%; border: 0; background: rgba(10, 12, 14, 0.7); color: #fff; font-size: 20px; line-height: 1; cursor: pointer; }

/* ---- QR label sheets: real size on screen, exact on paper ------------------------ */
.label-sheets { display: flex; flex-direction: column; gap: 24px; overflow-x: auto; padding-bottom: 8px; }
.label-sheet { position: relative; flex: 0 0 auto; width: 8.5in; height: 11in; background: #fff; color: #000; box-shadow: var(--shadow-md); border: 1px solid var(--border); }
.qr-label { position: absolute; display: flex; gap: 0.06in; padding: 0.06in; overflow: hidden; outline: 1px dashed #d0d4d8; font-family: var(--font-sans); }
.qr-label .qr { flex: 0 0 auto; }
.qr-label--wide { flex-direction: row; align-items: center; }
.qr-label--wide .qr { height: 100%; width: auto; aspect-ratio: 1; }
.qr-label--square { flex-direction: column; align-items: center; text-align: center; }
.qr-label--square .qr { width: 70%; height: auto; }
.qr-label__text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; font-size: 8pt; }
.qr-label__text strong { font-size: 10pt; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qr-label__text span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qr-label__code { font-size: 7pt; letter-spacing: 0.04em; }

@media print {
  @page { size: letter; margin: 0; }
  body { background: #fff; min-height: 0; }
  .topbar, .app-bottom-nav, .offline-banner, .toasts, .no-print, .sr-only { display: none !important; }
  .page { padding: 0; max-width: none; margin: 0; gap: 0; }
  .label-sheets { gap: 0; overflow: visible; padding: 0; }
  .label-sheet { box-shadow: none; border: 0; break-after: page; }
  .label-sheet:last-child { break-after: auto; }
  .qr-label { outline: 0; }
}
.upload-banner { justify-content: flex-start; background: var(--accent-soft); color: var(--accent-text); border-color: var(--border); }
.upload-banner[hidden] { display: none; }

/* First look: Save always in reach, above the phone's bottom nav. */
.first-look .form-actions {
  position: sticky; bottom: 12px; z-index: 5;
  margin: 0 -8px; padding: 10px 8px; border-radius: var(--radius-lg);
  background: var(--bg-surface); box-shadow: var(--shadow-md);
}
.first-look .form-actions .btn { flex: 1 1 0; justify-content: center; min-height: 52px; }
@media (max-width: 720px) { .first-look .form-actions { bottom: 84px; } }
