/* ============================================================
   TradeReel — field markup tool
   Palette + typography per spec. Self-hosted fonts, no CDN.
   ============================================================ */

/* ---- Self-hosted fonts ---- */
@font-face {
  font-family: 'Plex Cond';
  src: url('../fonts/plex-cond-600.woff2') format('woff2');
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Plex Cond';
  src: url('../fonts/plex-cond-500.woff2') format('woff2');
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Inter';
  src: url('../fonts/inter-400.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Inter';
  src: url('../fonts/inter-500.woff2') format('woff2');
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Inter';
  src: url('../fonts/inter-600.woff2') format('woff2');
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Plex Mono';
  src: url('../fonts/plex-mono-400.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Plex Mono';
  src: url('../fonts/plex-mono-500.woff2') format('woff2');
  font-weight: 500; font-style: normal; font-display: swap;
}

/* ---- Design tokens ---- */
:root {
  --paper:   #F4F6F5;   /* cool paper white background */
  --panel:   #FFFFFF;   /* card / surface */
  --ink:     #1F2428;   /* deep graphite text */
  --ink-2:   #55606A;   /* secondary ink (still high enough contrast) */
  --navy:    #1D3557;   /* blueprint navy — primary accent */
  --navy-2:  #16283F;   /* navy pressed/darker */
  --navy-3:  #274A73;   /* navy hover lighter */
  --amber:   #B8862E;   /* muted construction amber — secondary accent */
  --amber-2: #9A6F22;
  --line:    #D8DEE3;   /* soft blue-gray divider */
  --line-2:  #C2CBD2;
  --danger:  #9B2C2C;
  --danger-2:#7E2020;
  --graphite-bg: #2A3138; /* editor canvas backdrop (dark for photo contrast) */

  --font-head: 'Plex Cond', 'Archivo', ui-sans-serif, system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'Plex Mono', ui-monospace, 'SF Mono', 'SFMono-Regular', Menlo, Consolas, monospace;

  --radius: 3px;      /* stamped / technical, not pill */
  --radius-lg: 5px;
  --shadow-1: 0 1px 2px rgba(31,36,40,.06), 0 1px 3px rgba(31,36,40,.08);
  --shadow-2: 0 6px 22px rgba(22,40,63,.16);
  --tap: 44px;        /* min touch target */
}

/* ---- Reset / base ---- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}
button { font-family: inherit; }
img { display: block; max-width: 100%; }
:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 2px;
  border-radius: var(--radius);
}
[hidden] { display: none !important; }
.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;
}

/* ---- App scaffold ---- */
.app { min-height: 100%; display: flex; flex-direction: column; }
.view { flex: 1 1 auto; }

/* ---- Top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 14px;
  background: var(--navy);
  color: var(--paper);
  padding: 10px clamp(14px, 3vw, 28px);
  padding-top: calc(10px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--navy-2);
  min-height: 58px;
}
.topbar .brand {
  display: flex; align-items: center; gap: 12px; min-width: 0;
}
.topbar .brand-mark {
  width: 30px; height: 30px; border-radius: 6px; flex: none;
  background: var(--paper);
  -webkit-mask: center/contain no-repeat; mask: center/contain no-repeat;
}
.topbar .brand-mark { padding: 0; }
.topbar .brand img { width: 32px; height: 32px; border-radius: 7px; }
.topbar h1 {
  font-family: var(--font-head);
  font-weight: 600;
  font-size: clamp(19px, 2.4vw, 24px);
  letter-spacing: .06em;
  text-transform: uppercase;
  margin: 0; line-height: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .sub {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .04em;
  color: #AEBFD3;
  text-transform: uppercase;
  margin-top: 3px;
}
.topbar .spacer { flex: 1 1 auto; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* Back button (chevron) */
.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: var(--tap); min-height: var(--tap);
  background: transparent; border: 1px solid transparent; color: inherit;
  border-radius: var(--radius); cursor: pointer;
  transition: background .12s ease, transform .06s ease;
}
.iconbtn svg { width: 22px; height: 22px; }
.iconbtn:hover { background: rgba(255,255,255,.12); }
.iconbtn:active { transform: scale(.94); }
.topbar .iconbtn { color: var(--paper); }

/* ---- Buttons ---- */
.btn {
  --bg: var(--navy); --fg: var(--paper); --bd: var(--navy);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap);
  padding: 0 16px;
  font-family: var(--font-mono);
  font-size: 13px; font-weight: 500;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--fg); background: var(--bg);
  border: 1.5px solid var(--bd); border-radius: var(--radius);
  cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: background .12s ease, transform .06s ease, box-shadow .12s ease;
}
.btn svg { width: 18px; height: 18px; }
.btn:hover { background: var(--navy-3); border-color: var(--navy-3); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn.primary { --bg: var(--navy); --fg: var(--paper); --bd: var(--navy); }
.btn.accent  { --bg: var(--amber); --fg: #241a05; --bd: var(--amber); }
.btn.accent:hover { background: var(--amber-2); border-color: var(--amber-2); }
.btn.ghost   { --bg: transparent; --fg: var(--navy); --bd: var(--line-2); }
.btn.ghost:hover { background: rgba(29,53,87,.06); border-color: var(--navy); }
.btn.danger  { --bg: transparent; --fg: var(--danger); --bd: var(--line-2); }
.btn.danger:hover { background: rgba(155,44,44,.08); border-color: var(--danger); }
.btn.solid-danger { --bg: var(--danger); --fg: #fff; --bd: var(--danger); }
.btn.solid-danger:hover { background: var(--danger-2); border-color: var(--danger-2); }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 12px; }
.btn:disabled { opacity: .45; pointer-events: none; }

/* ---- Home / content wrapper ---- */
.wrap { max-width: 1180px; margin: 0 auto; padding: clamp(16px, 3vw, 30px); }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.page-head .titles h2 {
  font-family: var(--font-head); font-weight: 600;
  font-size: clamp(22px, 3vw, 30px); letter-spacing: .02em;
  margin: 0; text-transform: uppercase; color: var(--ink);
}
.eyebrow {
  font-family: var(--font-mono); font-size: 11px; font-weight: 500;
  letter-spacing: .12em; text-transform: uppercase; color: var(--amber);
  margin: 0 0 6px;
}
.page-head .meta { font-family: var(--font-mono); font-size: 12px; color: var(--ink-2); }

/* Storage indicator */
.storage {
  display: flex; align-items: center; gap: 12px;
  font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-2);
  border: 1px solid var(--line); background: var(--panel);
  border-radius: var(--radius); padding: 7px 12px;
}
.storage .bar {
  position: relative; width: 120px; height: 7px; border-radius: 4px;
  background: var(--line); overflow: hidden;
}
.storage .bar > i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--navy); }
.storage .bar > i.warn { background: var(--amber); }
.storage .bar > i.high { background: var(--danger); }
.storage b { color: var(--ink); font-weight: 500; }

/* ---- Project job board ---- */
.board {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.job-card {
  position: relative; text-align: left;
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 16px 16px 12px;
  cursor: pointer; box-shadow: var(--shadow-1);
  transition: transform .1s ease, box-shadow .14s ease, border-color .14s ease;
}
.job-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--line-2); }
.job-card:focus-visible { transform: translateY(-2px); }
.job-card .eyebrow { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.job-card .count-badge {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(184,134,46,.14); color: var(--amber-2);
  border: 1px solid rgba(184,134,46,.35);
  border-radius: 2px; padding: 2px 7px; font-weight: 500;
}
.job-card .addr {
  font-family: var(--font-mono); font-weight: 500;
  font-size: 16.5px; line-height: 1.25; letter-spacing: .01em;
  text-transform: uppercase; color: var(--ink);
  word-break: break-word;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--amber);
}
.job-card .updated {
  font-family: var(--font-mono); font-size: 11px; color: var(--ink-2);
  letter-spacing: .04em; margin-top: 10px;
}
.job-card .card-actions {
  display: flex; gap: 6px; margin-top: 12px; padding-top: 10px;
  border-top: 1px solid var(--line);
}
.job-card .card-actions .iconbtn { color: var(--ink-2); min-width: 40px; min-height: 40px; }
.job-card .card-actions .iconbtn:hover { background: rgba(29,53,87,.08); color: var(--navy); }
.job-card .card-actions .iconbtn.del:hover { background: rgba(155,44,44,.1); color: var(--danger); }
.job-card .thumbstrip { display: flex; gap: 3px; margin: 12px 0 2px; height: 44px; overflow: hidden; }
.job-card .thumbstrip img { width: 44px; height: 44px; object-fit: cover; border-radius: 2px; border: 1px solid var(--line); }
.job-card .thumbstrip .more {
  display: flex; align-items: center; justify-content: center;
  min-width: 44px; height: 44px; border-radius: 2px;
  background: var(--paper); border: 1px dashed var(--line-2);
  font-family: var(--font-mono); font-size: 11px; color: var(--ink-2);
}

/* Empty state */
.empty {
  text-align: center; padding: 56px 20px; color: var(--ink-2);
  border: 1.5px dashed var(--line-2); border-radius: var(--radius-lg);
  background: var(--panel);
}
.empty svg { width: 46px; height: 46px; color: var(--line-2); margin-bottom: 12px; }
.empty h3 { font-family: var(--font-head); text-transform: uppercase; letter-spacing: .04em; color: var(--ink); margin: 0 0 6px; }
.empty p { margin: 0 auto 18px; max-width: 380px; font-size: 14px; }

/* ---- Project detail: photo grid ---- */
.subhead {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 18px;
}
.subhead .grow { flex: 1 1 auto; min-width: 0; }
.photo-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.photo-tile {
  position: relative; aspect-ratio: 1 / 1;
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; background: var(--panel); cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: transform .1s ease, box-shadow .14s ease;
}
.photo-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; }
.photo-tile .idx {
  position: absolute; top: 6px; left: 6px;
  font-family: var(--font-mono); font-size: 11px; font-weight: 500;
  background: rgba(22,40,63,.82); color: var(--paper);
  border-radius: 2px; padding: 2px 6px; letter-spacing: .04em;
}
.photo-tile .marked {
  position: absolute; top: 6px; right: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--amber); color: #241a05;
}
.photo-tile .marked svg { width: 13px; height: 13px; }
.photo-tile .selbox {
  position: absolute; top: 6px; right: 6px; width: 24px; height: 24px;
  border-radius: 50%; background: rgba(255,255,255,.9); border: 1.5px solid var(--line-2);
  display: none; align-items: center; justify-content: center; color: #fff;
}
/* The checkmark only appears once the tile is actually selected. An empty
   circle in select mode reads as "not yet chosen"; a check means chosen. */
.photo-tile .selbox svg { display: none; }
.photo-tile.selectmode .marked { display: none; }
.photo-tile.selectmode .selbox { display: flex; }
.photo-tile.sel { outline: 3px solid var(--navy); outline-offset: -3px; }
.photo-tile.sel .selbox { background: var(--navy); border-color: var(--navy); }
.photo-tile.sel .selbox svg { display: block; }

.addtile {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; aspect-ratio: 1/1; cursor: pointer; color: var(--navy);
  border: 1.5px dashed var(--line-2); border-radius: var(--radius);
  background: var(--panel); font-family: var(--font-mono); font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .06em; text-align: center; padding: 8px;
  transition: border-color .14s ease, background .14s ease;
}
.addtile:hover { border-color: var(--navy); background: rgba(29,53,87,.05); }
.addtile svg { width: 30px; height: 30px; }

/* ============================================================
   Editor (full-bleed)
   ============================================================ */
.editor {
  position: fixed; inset: 0; z-index: 50;
  display: flex; background: var(--graphite-bg);
  /* landscape / wide default: vertical rail on the left */
  flex-direction: row;
}
.rail {
  flex: none; z-index: 2;
  background: var(--navy); color: var(--paper);
  display: flex; flex-direction: column; align-items: center;
  gap: 4px; padding: 8px 6px;
  padding-top: calc(8px + env(safe-area-inset-top));
  width: 62px; overflow-y: auto; overflow-x: hidden;
  border-right: 1px solid var(--navy-2);
  -webkit-overflow-scrolling: touch;
}
.rail .sep { width: 34px; height: 1px; background: rgba(255,255,255,.16); margin: 4px 0; flex: none; }
.rail .spacer { flex: 1 1 auto; }

.tool {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; flex: none;
  background: transparent; border: 1.5px solid transparent; color: var(--paper);
  border-radius: var(--radius); cursor: pointer;
  transition: background .12s ease, transform .06s ease, border-color .12s ease;
}
.tool svg { width: 23px; height: 23px; pointer-events: none; }
.tool:hover { background: rgba(255,255,255,.12); }
.tool:active { transform: scale(.92); }
.tool[aria-pressed="true"], .tool.active {
  background: var(--amber); color: #241a05; border-color: var(--amber);
}
.tool:disabled { opacity: .38; pointer-events: none; }
.tool .tag { /* tiny label under icon on wider rails / bottom bar */
  display: none;
}
/* color chip tool */
.tool.color-tool { padding: 0; }
.tool.color-tool .chip {
  width: 26px; height: 26px; border-radius: 4px;
  border: 2px solid rgba(255,255,255,.85);
  box-shadow: 0 0 0 1px rgba(0,0,0,.25) inset;
}
/* "Finish line" confirm action — always amber, not a toggle */
.tool.confirm { background: var(--amber); color: #241a05; border-color: var(--amber); }
.tool.confirm:hover { background: var(--amber-2); border-color: var(--amber-2); }
/* Next-pin-number badge */
.tool.pin-badge {
  font-family: var(--font-mono); font-size: 12px; font-weight: 600;
  letter-spacing: .01em; width: 48px; padding: 0 2px;
}
/* Text font/style button ("Aa") */
.tool.text-fmt-btn {
  font-family: Georgia, 'Times New Roman', serif; font-size: 19px; font-weight: 700;
}

/* Text font/style popover */
.text-popover { width: 244px; }
.font-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.font-btn {
  padding: 10px 8px; border: 1.5px solid var(--line-2); border-radius: var(--radius);
  background: var(--paper); color: var(--ink); cursor: pointer; font-size: 14px;
  line-height: 1.1; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.font-btn[aria-pressed="true"] {
  border-color: var(--navy); background: rgba(29,53,87,.08); box-shadow: inset 0 0 0 1px var(--navy);
}
.text-style-row { display: flex; gap: 8px; }
.style-btn {
  flex: 1 1 0; min-height: 44px; border: 1.5px solid var(--line-2); border-radius: var(--radius);
  background: var(--paper); color: var(--ink); cursor: pointer; font-size: 19px; line-height: 1;
}
.style-btn:active { transform: scale(.96); }
.style-btn[aria-pressed="true"] { background: var(--navy); color: var(--paper); border-color: var(--navy); }

.canvas-area {
  flex: 1 1 auto; position: relative; min-width: 0; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  touch-action: none; /* we manage gestures on the canvas */
}
.canvas-area canvas { touch-action: none; }
.canvas-host { position: relative; }

/* Editor status pill (tool hint / saved) */
.editor-status {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  z-index: 5; pointer-events: none;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: .05em;
  text-transform: uppercase;
  background: rgba(22,40,63,.86); color: var(--paper);
  padding: 6px 12px; border-radius: 100px;
  border: 1px solid rgba(255,255,255,.14);
  opacity: 0; transition: opacity .18s ease;
}
.editor-status.show { opacity: 1; }

.editor-title {
  position: absolute; top: 10px; left: 12px; z-index: 5; pointer-events: none;
  max-width: 40vw;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: .05em;
  color: var(--paper); background: rgba(22,40,63,.7);
  padding: 5px 10px; border-radius: var(--radius);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Portrait: rail becomes a collapsible bottom bar */
@media (orientation: portrait) and (max-width: 900px) {
  .editor { flex-direction: column; }
  .rail {
    width: 100%; flex-direction: row; align-items: center;
    gap: 4px; padding: 6px 8px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
    order: 2; border-right: none; border-top: 1px solid var(--navy-2);
    overflow-x: auto; overflow-y: hidden; justify-content: flex-start;
  }
  .rail .sep { width: 1px; height: 34px; margin: 0 4px; }
  .rail .spacer { display: none; }
  .rail.collapsed .tool:not(.keep-collapsed) { display: none; }
  .canvas-area { order: 1; }
  .rail-collapse { display: inline-flex; }
}
.rail-collapse { display: none; }

/* ============================================================
   Style popover (color wheel + stroke width)
   ============================================================ */
.popover {
  position: fixed; z-index: 60;
  width: 268px; max-width: calc(100vw - 24px);
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2); padding: 14px;
}
.popover h4 {
  font-family: var(--font-head); text-transform: uppercase; letter-spacing: .05em;
  font-size: 13px; margin: 0 0 10px; color: var(--ink-2);
}
.wheel-wrap { display: flex; gap: 12px; align-items: stretch; }
.wheel-holder { position: relative; width: 168px; height: 168px; flex: none; touch-action: none; }
.wheel-holder canvas { position: absolute; inset: 0; border-radius: 50%; cursor: crosshair; }
.wheel-cursor {
  position: absolute; width: 16px; height: 16px; margin: -8px 0 0 -8px;
  border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1.5px rgba(0,0,0,.5);
  pointer-events: none;
}
.value-slider {
  position: relative; width: 26px; flex: none; border-radius: 4px;
  border: 1px solid var(--line-2); overflow: hidden; touch-action: none; cursor: pointer;
}
.value-slider .grad { position: absolute; inset: 0; }
.value-slider .knob {
  position: absolute; left: -2px; right: -2px; height: 4px; margin-top: -2px;
  background: transparent; border: 2px solid #fff; box-shadow: 0 0 0 1.5px rgba(0,0,0,.55);
  border-radius: 3px; pointer-events: none;
}
.swatch-row { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; align-items: center; }
.swatch {
  width: 26px; height: 26px; border-radius: 4px; border: 1.5px solid rgba(0,0,0,.15);
  cursor: pointer; padding: 0;
}
.swatch:active { transform: scale(.9); }
.hex-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.hex-row label { font-family: var(--font-mono); font-size: 11px; color: var(--ink-2); text-transform: uppercase; }
.hex-row .cur { width: 26px; height: 26px; border-radius: 4px; border: 1.5px solid var(--line-2); flex: none; }
.hex-row input {
  flex: 1 1 auto; min-width: 0; font-family: var(--font-mono); font-size: 13px;
  padding: 7px 9px; border: 1px solid var(--line-2); border-radius: var(--radius);
  color: var(--ink); background: var(--paper); text-transform: uppercase;
}
.stroke-block { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.stroke-block .row { display: flex; align-items: center; gap: 10px; }
.stroke-block label { font-family: var(--font-mono); font-size: 11px; color: var(--ink-2); text-transform: uppercase; white-space: nowrap; }
.stroke-block output { font-family: var(--font-mono); font-size: 12px; color: var(--ink); min-width: 34px; text-align: right; }

input[type="range"] {
  -webkit-appearance: none; appearance: none; height: 6px; border-radius: 4px;
  background: var(--line); flex: 1 1 auto; outline-offset: 4px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--navy); border: 2px solid #fff; box-shadow: var(--shadow-1); cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--navy); border: 2px solid #fff; cursor: pointer;
}

/* ============================================================
   Modals / dialogs / forms / toasts
   ============================================================ */
.overlay {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(20,28,36,.55); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  width: 100%; max-width: 440px; background: var(--panel);
  border-radius: var(--radius-lg); border: 1px solid var(--line);
  box-shadow: var(--shadow-2); overflow: hidden;
  max-height: calc(100dvh - 32px); display: flex; flex-direction: column;
}
.modal header {
  padding: 16px 18px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
}
.modal header h3 {
  font-family: var(--font-head); text-transform: uppercase; letter-spacing: .04em;
  font-size: 18px; margin: 0; color: var(--ink);
}
.modal header .eyebrow { margin: 0 0 3px; }
.modal .body { padding: 18px; overflow: auto; }
.modal .foot {
  padding: 14px 18px; border-top: 1px solid var(--line);
  display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap;
}

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field label {
  display: block; font-family: var(--font-mono); font-size: 11px;
  letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); margin-bottom: 6px;
}
.field input[type="text"], .field textarea, .field select {
  width: 100%; font-family: var(--font-body); font-size: 16px;
  padding: 11px 12px; color: var(--ink); background: var(--paper);
  border: 1.5px solid var(--line-2); border-radius: var(--radius);
}
.field input[type="text"]:focus, .field textarea:focus, .field select:focus {
  border-color: var(--navy);
}
.field .hint { font-size: 12px; color: var(--ink-2); margin-top: 6px; }

.segmented {
  display: inline-flex; border: 1.5px solid var(--line-2); border-radius: var(--radius);
  overflow: hidden; background: var(--paper);
}
.segmented button {
  border: none; background: transparent; cursor: pointer;
  font-family: var(--font-mono); font-size: 12px; letter-spacing: .05em; text-transform: uppercase;
  padding: 9px 14px; color: var(--ink-2); min-height: 40px;
}
.segmented button + button { border-left: 1.5px solid var(--line-2); }
.segmented button[aria-pressed="true"] { background: var(--navy); color: var(--paper); }
.segmented button[disabled] { opacity: .35; cursor: not-allowed; }

.export-progress {
  font-family: var(--font-mono); font-size: 12px; color: var(--ink-2);
  display: flex; align-items: center; gap: 10px; margin-top: 4px;
}
.export-progress .bar { flex: 1 1 auto; height: 7px; background: var(--line); border-radius: 4px; overflow: hidden; }
.export-progress .bar > i { display: block; height: 100%; width: 0; background: var(--amber); transition: width .2s ease; }

/* Toast */
.toast-stack {
  position: fixed; z-index: 90; left: 50%; bottom: 24px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  font-family: var(--font-mono); font-size: 12.5px; letter-spacing: .03em;
  background: var(--ink); color: var(--paper);
  padding: 10px 16px; border-radius: 100px; box-shadow: var(--shadow-2);
  display: flex; align-items: center; gap: 8px;
  animation: toast-in .18s ease;
}
.toast.good { background: #1E4A34; }
.toast.err  { background: var(--danger-2); }
.toast svg { width: 15px; height: 15px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Loading splash */
.splash {
  position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px; background: var(--navy); color: var(--paper);
}
.splash img { width: 84px; height: 84px; border-radius: 18px; }
.splash .name { font-family: var(--font-head); text-transform: uppercase; letter-spacing: .1em; font-size: 22px; }
.spinner { width: 30px; height: 30px; border-radius: 50%; border: 3px solid rgba(255,255,255,.25); border-top-color: var(--paper); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   Sign-in gate (Milestone 2) — a card on the navy shell, matching
   the splash. Reuses .btn; inputs mirror the .field styling.
   ============================================================ */
.authscreen {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; overflow: auto;
  background: var(--navy); color: var(--ink);
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
.authcard {
  width: 100%; max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 28px 24px; box-shadow: 0 18px 50px rgba(0,0,0,.35);
}
.authbrand { text-align: center; margin-bottom: 22px; }
.authbrand img { width: 64px; height: 64px; border-radius: 14px; }
.authname { font-family: var(--font-head); text-transform: uppercase; letter-spacing: .1em; font-size: 22px; margin-top: 12px; color: var(--navy); }
.authtag { font-family: var(--font-mono); text-transform: uppercase; letter-spacing: .06em; font-size: 11px; color: var(--ink-2); margin-top: 4px; }
.authform { display: flex; flex-direction: column; gap: 14px; }
.authform label { display: block; font-family: var(--font-mono); font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-2); margin-bottom: 6px; }
.authform input {
  width: 100%; box-sizing: border-box; min-height: var(--tap);
  padding: 0 12px; font-size: 16px; font-family: var(--font-body);
  color: var(--ink); background: var(--paper);
  border: 1.5px solid var(--line-2); border-radius: var(--radius);
}
.authform input:focus { outline: none; border-color: var(--navy); }
.authform .btn { width: 100%; margin-top: 4px; }
.autherr { font-family: var(--font-mono); font-size: 12.5px; line-height: 1.45; color: var(--danger); }
.autherr:empty { display: none; }
.authtoggle {
  display: block; width: 100%; margin-top: 16px; padding: 8px;
  background: none; border: none; cursor: pointer;
  font-family: var(--font-mono); font-size: 12px; letter-spacing: .03em;
  color: var(--navy); text-decoration: underline; text-underline-offset: 3px;
}
.account-btn { max-width: 190px; }
.account-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============================================================
   Video — import buttons, grid tiles, player + process dialog.
   Same palette/typography as the rest of the field tool.
   ============================================================ */

/* Outline button that reads on the navy topbar (Add Video) */
.btn.ghost.invert { --bg: transparent; --fg: var(--paper); --bd: rgba(255,255,255,.5); }
.btn.ghost.invert:hover { background: rgba(255,255,255,.12); border-color: var(--paper); }

/* Home card: a video count badge next to the photo badge (navy, to distinguish) */
.job-card .count-badge.vid {
  background: rgba(29,53,87,.1); color: var(--navy);
  border-color: rgba(29,53,87,.28);
}

/* Storage pill: unprocessed-video chip */
.storage .pending-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(184,134,46,.16); color: var(--amber-2);
  border: 1px solid rgba(184,134,46,.4);
  border-radius: 2px; padding: 2px 7px;
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 500;
  letter-spacing: .04em; text-transform: uppercase; white-space: nowrap;
}
.storage .pending-chip svg { width: 13px; height: 13px; }

/* Video-flavored "add" tile */
.addtile.addtile-video { color: var(--amber-2); border-color: rgba(184,134,46,.5); }
.addtile.addtile-video:hover { border-color: var(--amber); background: rgba(184,134,46,.07); }

/* Video grid tile — shares the photo tile's footprint */
.video-tile {
  position: relative; aspect-ratio: 1 / 1;
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; background: #10161d; cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: transform .1s ease, box-shadow .14s ease;
}
.video-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.video-tile img { width: 100%; height: 100%; object-fit: cover; }
/* Unprocessed videos get an amber dashed frame — clearly "not final yet" */
.video-tile.pending { border: 1.5px dashed var(--amber); }
.video-tile .vid-noposter {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,.4); background: #10161d;
}
.video-tile .vid-noposter svg { width: 40px; height: 40px; }
.video-tile .vid-kind {
  position: absolute; top: 6px; left: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 3px;
  background: rgba(16,22,29,.78); color: var(--paper);
}
.video-tile .vid-kind svg { width: 14px; height: 14px; }
.video-tile .vid-play {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(16,22,29,.55); color: #fff; border: 1.5px solid rgba(255,255,255,.7);
  pointer-events: none;
}
.video-tile .vid-play svg { width: 18px; height: 18px; margin-left: 2px; }
.video-tile .vid-dur {
  position: absolute; bottom: 6px; right: 6px;
  font-family: var(--font-mono); font-size: 11px; font-weight: 500;
  background: rgba(16,22,29,.82); color: var(--paper);
  border-radius: 2px; padding: 2px 6px; letter-spacing: .04em;
}
.video-tile .vid-status {
  position: absolute; top: 6px; right: 6px;
  display: inline-flex; align-items: center; gap: 4px;
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase;
  border-radius: 2px; padding: 2px 6px;
}
.video-tile .vid-status svg { width: 12px; height: 12px; }
.video-tile .vid-status.pending { background: var(--amber); color: #241a05; }
.video-tile .vid-status.done { background: rgba(29,53,87,.9); color: var(--paper); }

/* Player + process modal */
.modal.video-modal { max-width: 560px; }
.vid-stage {
  background: #10161d; border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 12px;
  display: flex; align-items: center; justify-content: center;
}
.vid-preview { width: 100%; max-height: 44vh; display: block; background: #10161d; }
.vid-meta {
  font-family: var(--font-mono); font-size: 12px; color: var(--ink-2);
  letter-spacing: .03em; text-transform: uppercase; margin: 0 0 4px;
}
.vid-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.vid-actions .btn { flex: 1 1 auto; }

/* Trim controls */
.trim-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.trim-row:last-child { margin-bottom: 0; }
.trim-tag {
  font-family: var(--font-mono); font-size: 11px; font-weight: 500; letter-spacing: .08em;
  color: var(--ink-2); width: 32px; flex: none;
}
.trim-row input[type="range"] { flex: 1 1 auto; }
.trim-row output {
  font-family: var(--font-mono); font-size: 12px; color: var(--ink);
  min-width: 52px; text-align: right; flex: none;
}
/* Target-size option grid */
.size-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.opt-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 10px 12px; text-align: left; cursor: pointer;
  border: 1.5px solid var(--line-2); border-radius: var(--radius);
  background: var(--paper); color: var(--ink);
}
.opt-btn strong {
  font-family: var(--font-mono); font-size: 12.5px; font-weight: 600;
  letter-spacing: .02em; text-transform: uppercase;
}
.opt-btn span { font-family: var(--font-mono); font-size: 11px; color: var(--ink-2); }
.opt-btn[aria-pressed="true"] {
  border-color: var(--navy); background: rgba(29,53,87,.08);
  box-shadow: inset 0 0 0 1px var(--navy);
}
.opt-btn:active { transform: scale(.99); }

.custom-size { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.custom-size input[type="number"] {
  width: 110px; font-family: var(--font-mono); font-size: 15px;
  padding: 9px 10px; color: var(--ink); background: var(--paper);
  border: 1.5px solid var(--line-2); border-radius: var(--radius);
}
.custom-size span { font-family: var(--font-mono); font-size: 12px; color: var(--ink-2); }

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important; scroll-behavior: auto !important;
  }
}
