/* Tablet Viewer — "buildings3" skin.
   Warm off-white page, white cards with hairline borders, near-black ink text,
   a deep brand-red accent used sparingly. Flat and editorial: no heavy shadows.
   This is a visual restyle only — class names and behaviour are unchanged. */

:root {
  --b3-font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --ink:   #1a1a1a;   /* primary text */
  --ink-2: #6b6a67;   /* secondary text */
  --ink-3: #9c9a96;   /* tertiary / hints */
  --ink-4: #c9c7c3;   /* faint */

  --line:   rgba(0, 0, 0, .07);   /* hairline borders */
  --line-2: rgba(0, 0, 0, .045);

  --accent:      #a3120c;   /* deep brand red — primary accent */
  --accent-soft: #fbe4e2;   /* soft red highlight/bg */

  --dark: #191915;

  --warn: #b06a10;  --warn-soft: #fbeeda;
  --good: #15884b;

  --bg:     #f3f4f1;   /* warm off-white page background */
  --panel:  #fff;      /* cards/panels */
  --panel-2: #f0efed;  /* insets */

  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--b3-font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* no long-press callout on a kiosk */
}

/* Demo-mode banner — in-theme (soft red), still clearly a banner */
.demo-banner {
  padding: 8px 14px;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border-bottom: 1px solid var(--line);
}

.hidden { display: none !important; }
.muted { color: var(--ink-2); }
.small { font-size: 0.85rem; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 60px;
}
.crumb {
  flex: 1;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 0.85rem; cursor: default; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-4); flex: none; }
.dot.online { background: var(--good); }
.dot.offline { background: var(--warn); }
.dot.syncing { background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

.icon-btn {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  min-width: 48px;
  min-height: 48px;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.icon-btn:active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.main { padding: 20px 16px; padding-bottom: 32px; }
.view { max-width: 1100px; margin: 0 auto; }

/* Grids */
.grid { display: grid; gap: 14px; }
.grid-trades { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.grid-files { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

.tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 16px;
  min-height: 124px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.12s, background 0.12s;
}
.tile:active { border-color: var(--accent); background: var(--accent-soft); }
.tile .tile-icon { font-size: 2.4rem; line-height: 1; }
.tile .tile-name { font-size: 1.05rem; font-weight: 600; color: var(--ink); letter-spacing: -0.01em; word-break: break-word; }
.tile .tile-sub { font-size: 0.78rem; color: var(--ink-3); }

/* File thumbnails */
.thumb {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 1 / 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.12s;
}
.thumb:active { border-color: var(--accent); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .ph { font-size: 2.4rem; color: var(--ink-4); }
.thumb .badge {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(255, 255, 255, 0.93);
  border-top: 1px solid var(--line);
  color: var(--ink);
  font-size: 0.72rem; font-weight: 500;
  padding: 5px 7px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thumb .pill {
  position: absolute; top: 7px; right: 7px;
  background: var(--accent); color: #fff;
  font-size: 0.6rem; font-weight: 700; letter-spacing: 0.04em;
  padding: 3px 7px; border-radius: 999px;
}
.thumb.pending { opacity: 0.55; }

/* Tap-to-retry overlay for a thumbnail that failed to load (never a broken img) */
.thumb .retry {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px;
  background: var(--panel);
  color: var(--ink-3);
  font-size: 0.72rem; text-align: center;
  cursor: pointer;
}
.thumb .retry .retry-icon { font-size: 1.6rem; line-height: 1; color: var(--accent); }
.thumb .retry:active { background: var(--panel-2); }

/* Loading skeletons (trade tiles + thumbnails) — a calm shimmer, no layout jump */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--panel-2);
}
.skeleton::after {
  content: "";
  position: absolute; inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(
    90deg,
    transparent,
    rgba(0, 0, 0, 0.045),
    transparent
  );
  animation: shimmer 1.25s ease-in-out infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) {
  .skeleton::after { animation: none; }
  .dot.syncing { animation: none; }
}

.empty { text-align: center; color: var(--ink-3); margin-top: 40px; font-size: 1.05rem; }

/* Pairing / waiting cards */
.pair-card {
  max-width: 520px; margin: 8vh auto 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 44px 32px;
  text-align: center;
}
.pair-card h1 { margin: 0 0 8px; font-size: 1.7rem; font-weight: 600; letter-spacing: -0.02em; color: var(--ink); }
.pair-code {
  font-size: clamp(3rem, 16vw, 6rem);
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin: 28px 0;
  font-variant-numeric: tabular-nums;
}
.spinner {
  width: 42px; height: 42px; margin: 28px auto 0;
  border: 4px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Full-screen viewer — an immersive warm-dark stage so photos/PDFs read well,
   with chrome that stays in the buildings3 family (warm dark, red accents). */
.viewer {
  position: fixed; inset: 0; z-index: 100;
  background: var(--dark);
  display: flex; flex-direction: column;
}
.viewer-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(25, 25, 21, 0.92);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: #f3f4f1;
  z-index: 2;
}
.viewer-bar .icon-btn {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.14);
  color: #f3f4f1;
}
.viewer-bar .icon-btn:active { background: var(--accent); border-color: var(--accent); color: #fff; }
.viewer-title { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-count { color: rgba(243, 244, 241, 0.6); font-variant-numeric: tabular-nums; }
.viewer-stage {
  flex: 1; position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  touch-action: none;
}
.viewer-stage img {
  max-width: 100%; max-height: 100%;
  transform-origin: 0 0;
  will-change: transform;
  -webkit-user-drag: none;
}
.viewer-stage .pdf-scroll {
  position: absolute; inset: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y pinch-zoom;
  padding: 12px 0;
  text-align: center;
}
.viewer-stage .pdf-scroll canvas {
  display: block; margin: 0 auto 12px; max-width: 100%; background: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}
.viewer-loading { color: rgba(243, 244, 241, 0.7); font-size: 1.05rem; }
.viewer-error { display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center; padding: 24px; }
.viewer-retry {
  background: var(--accent); color: #fff;
  border: none; border-radius: 12px;
  padding: 12px 28px; font-size: 1rem; font-weight: 600;
  min-height: 48px; cursor: pointer;
}
.viewer-retry:active { opacity: 0.85; }

.nav-btn {
  position: absolute; top: 50%; transform: translateY(-50%);
  z-index: 3;
  background: rgba(25, 25, 21, 0.55);
  color: #fff; border: none;
  width: 56px; height: 84px;
  font-size: 2.4rem; line-height: 1;
  cursor: pointer;
}
.nav-prev { left: 0; border-radius: 0 12px 12px 0; }
.nav-next { right: 0; border-radius: 12px 0 0 12px; }
.nav-btn:active { background: var(--accent); }
.nav-btn:disabled { opacity: 0.2; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--dark); color: #f3f4f1;
  padding: 12px 20px; border-radius: 999px;
  font-size: 0.92rem; z-index: 200;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}

/* Unsupported / download card in the full-screen viewer */
.viewer-unsupported {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  text-align: center; padding: 24px;
}
.viewer-unsupported .unsupported-icon { font-size: 3.2rem; line-height: 1; }
.viewer-unsupported .unsupported-name {
  font-size: 1.1rem; font-weight: 600; color: #f3f4f1; word-break: break-word;
}
.viewer-unsupported .unsupported-type { font-size: 0.9rem; }
.viewer-unsupported a.viewer-retry { text-decoration: none; display: inline-block; }

/* Hidden diagnostics panel (opened by a discreet 5-tap on the status area) */
.diag {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(25, 25, 21, 0.5);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.diag.hidden { display: none; }
.diag-card {
  background: var(--card, #fff); color: var(--ink);
  border: 1px solid var(--line); border-radius: 16px;
  width: 100%; max-width: 460px; max-height: 85vh; overflow: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  padding: 18px 20px;
}
.diag-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.diag-close {
  background: none; border: 1px solid var(--line); border-radius: 8px;
  width: 36px; height: 36px; font-size: 1rem; color: var(--ink-2); cursor: pointer;
}
.diag-row {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 8px 0; border-bottom: 1px solid var(--line-2); font-size: 0.9rem;
}
.diag-k { color: var(--ink-2); flex: none; }
.diag-v { color: var(--ink); text-align: right; word-break: break-word; }
.diag-v.diag-warn { color: var(--accent); font-weight: 600; }
.diag-actions { margin-top: 14px; display: flex; gap: 10px; }
.diag-btn {
  background: var(--accent); color: #fff; border: none; border-radius: 10px;
  padding: 10px 18px; font-size: 0.92rem; font-weight: 600; min-height: 44px; cursor: pointer;
}
.diag-btn:active { opacity: 0.85; }

/* ===========================================================================
   Field usability + onboarding polish
   - High-contrast / large toggle (persisted per tablet)
   - Pairing QR (offline, self-hosted generator)
   - Orientation resilience (portrait + landscape)
   =========================================================================== */

/* Topbar "large / high-contrast" toggle — a big, one-thumb target. */
.hc-toggle {
  flex: none;
  min-width: 48px; min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.hc-toggle .hc-glyph { font-size: 1.15rem; font-weight: 700; line-height: 1; }
.hc-toggle:active { border-color: var(--accent); color: var(--accent); }
.hc-toggle[aria-pressed="true"] {
  background: var(--ink); color: #fff; border-color: var(--ink);
}

/* Pairing QR — a scannable code so the operator never has to type six digits. */
.pair-qr { display: flex; justify-content: center; margin: 8px auto 2px; }
.pair-qr-svg {
  width: min(58vw, 250px); height: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
}
.pair-qr-hint { margin: 4px 0 0; }
.pair-retry {
  margin-top: 22px;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 22px;
  font-size: 0.95rem; font-weight: 600; font-family: inherit;
  min-height: 48px; cursor: pointer;
}
.pair-retry:active { border-color: var(--accent); color: var(--accent); }
.pair-retry:disabled { opacity: 0.5; }

/* A touch bigger + bolder count in the viewer for arm's-length reading. */
.viewer-count { font-size: 0.95rem; font-weight: 600; }

/* --- High-contrast / large mode (html.hc) --------------------------------- */
/* Deepen the buildings3 palette (no new brand colours) and scale the rem-based
   type ramp up via the root font-size, so type, padding and controls all grow
   together for bright sunlight / older eyes. */
:root.hc {
  --ink:   #000000;
  --ink-2: #2b2a27;
  --ink-3: #3d3b37;
  --ink-4: #6f6d68;
  --line:   rgba(0, 0, 0, 0.30);
  --line-2: rgba(0, 0, 0, 0.18);
  --accent:      #8a0f0a;
  --accent-soft: #f7d3d0;
  --bg:     #ffffff;
  --panel:  #ffffff;
  --panel-2: #ebe9e5;
}
html.hc { font-size: 116%; }

:root.hc .crumb { font-weight: 700; }
:root.hc .status { font-size: 0.95rem; color: var(--ink-2); }
:root.hc .icon-btn,
:root.hc .hc-toggle { min-width: 56px; min-height: 56px; border-width: 2px; }
:root.hc .tile { border-width: 2px; min-height: 150px; }
:root.hc .tile .tile-sub { color: var(--ink-2); }
:root.hc .grid-trades { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
:root.hc .grid-files { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
:root.hc .thumb { border-width: 2px; }
:root.hc .thumb .badge {
  font-size: 0.82rem; font-weight: 600;
  background: rgba(255, 255, 255, 0.98);
  color: var(--ink);
}
:root.hc .thumb .pill { font-size: 0.68rem; padding: 4px 9px; }
/* Empty / loading / offline states stay legible with real contrast. */
:root.hc .empty { color: var(--ink-2); font-weight: 600; }
:root.hc .demo-banner { color: #fff; background: var(--accent); }
/* Full-screen viewer chrome — brighter labels, larger, more opaque nav. */
:root.hc .viewer-count { color: #ffffff; font-weight: 700; }
:root.hc .viewer-title { color: #ffffff; }
:root.hc .nav-btn { background: rgba(0, 0, 0, 0.82); width: 64px; height: 96px; }
:root.hc .viewer-bar .icon-btn { border-width: 2px; }

/* --- Orientation resilience ----------------------------------------------- */
/* Short landscape (tablet on its side): keep the pairing card + QR fully on
   screen without scrolling, and lean the code/QR into the available height. */
@media (orientation: landscape) and (max-height: 600px) {
  .pair-card { margin-top: 3vh; padding: 24px 28px; }
  .pair-code { margin: 12px 0; }
  .pair-qr-svg { width: min(34vh, 200px); }
}
