/* ChiefLogs UI — navy/orange brand, mobile-first, zero external assets.
   System fonts + one cached CSS file keep first paint fast on weak cell signal. */

:root {
  --navy: #162032;
  --navy-d: #0d1624;
  --navy-l: #243349;
  --accent: #FF6200;
  --accent-d: #e25600;
  --accent-soft: #fff1e7;
  --green: #1f7a44;
  --green-d: #176338;
  --green-soft: #e7f4ec;
  --red: #c0392b;
  --red-soft: #fdecea;
  --amber: #d4a017;
  --bg: #f2f4f7;
  --card: #ffffff;
  --line: #dde3ea;
  --text: #1c2733;
  --muted: #5f7081;
  --r: 14px;
  --r-sm: 10px;
  --shadow: 0 1px 2px rgba(22,32,50,.06), 0 2px 8px rgba(22,32,50,.05);
  --shadow-up: 0 4px 14px rgba(22,32,50,.12);
  --tap: rgba(22,32,50,.05);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- chrome: top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--navy); color: #fff; padding: 10px 16px;
  position: sticky; top: 0; z-index: 10;
  padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 3px solid var(--accent);
}
.brand { display: flex; align-items: center; text-decoration: none; }
.brand-logo { height: 40px; width: auto; display: block; }
.topnav { display: flex; align-items: center; gap: 2px; }
.gear {
  color: #e7ebf1; text-decoration: none; font-size: 15px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 10px; border-radius: 10px;
}
.gear .ic { width: 18px; height: 18px; }
.gear:hover, .gear:active { background: var(--navy-l); color: #fff; }
/* On touch the bottom tab bar owns navigation; hide the top-bar links. */
body.touch .topnav { display: none; }

.wrap { max-width: 760px; margin: 0 auto; padding: 16px; padding-bottom: 40px; }
body.touch .wrap { padding-bottom: calc(86px + env(safe-area-inset-bottom)); }

/* ---------- chrome: bottom tab bar (touch only) ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 10px rgba(22,32,50,.06);
}
body.fine .tabbar { display: none; }
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 0 7px; text-decoration: none; color: var(--muted);
  font-size: 11.5px; font-weight: 600; letter-spacing: .02em;
}
.tabbar a .ic { width: 24px; height: 24px; }
.tabbar a.active { color: var(--accent); }
.tabbar a:active { background: var(--tap); }

/* ---------- icons (inline sprite, stroke = currentColor) ---------- */
.ic { width: 22px; height: 22px; flex: none; stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: block; }

/* ---------- type ---------- */
h1 { font-size: 23px; line-height: 1.2; margin: 10px 0 14px; letter-spacing: -.01em; }
h2 { font-size: 17.5px; margin: 26px 0 10px; letter-spacing: -.005em; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.pagehead { margin-bottom: 14px; }
.pagehead h1 { margin-bottom: 2px; }
.pagehead .sub { color: var(--muted); font-size: 14.5px; margin: 0; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
a.card { display: block; text-decoration: none; color: inherit; }
.job-card { display: block; text-decoration: none; color: inherit;
  transition: transform .12s ease, box-shadow .12s ease; }
.job-card:active { transform: scale(.985); background: #fbfcfd; }
body.fine .job-card:hover { box-shadow: var(--shadow-up); transform: translateY(-1px); }
.job-card .jobname { font-size: 17px; font-weight: 700; }
.job-card .afe { color: var(--muted); font-size: 14px; margin-top: 2px; }

.row { display: flex; align-items: center; gap: 12px; }
.spread { justify-content: space-between; }
.wrapflex { flex-wrap: wrap; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  background: var(--navy); color: #fff; border: none; border-radius: 12px;
  padding: 15px 20px; font-size: 16.5px; font-weight: 650; text-decoration: none;
  cursor: pointer; width: 100%; margin-top: 8px; min-height: 50px;
  transition: transform .08s ease, background .12s ease;
}
.btn .ic { width: 20px; height: 20px; }
.btn:active { background: var(--navy-d); transform: scale(.985); }
.btn.accent { background: var(--accent); box-shadow: 0 2px 8px rgba(255,98,0,.28); }
.btn.accent:active { background: var(--accent-d); }
.btn.green { background: var(--green); }
.btn.green:active { background: var(--green-d); }
.btn.red { background: var(--red); }
.btn.ghost { background: #fff; color: var(--navy); border: 1.5px solid var(--line);
  box-shadow: var(--shadow); font-weight: 600; }
.btn.ghost:active { background: var(--tap); }
.btn.danger-link { background: none; border: none; box-shadow: none; color: var(--red); }
.btn.bigaction { padding: 20px; font-size: 18px; margin-top: 14px; }
.btn.sm { width: auto; padding: 9px 14px; font-size: 14.5px; min-height: 40px;
  border-radius: var(--r-sm); margin-top: 0; }
.btn.sm .ic { width: 16px; height: 16px; }
.btn:disabled { opacity: .45; cursor: default; }
body.fine .btn:hover:not(:disabled) { filter: brightness(1.06); }

/* big action tiles (job page: scan / import / batch) */
.tile {
  display: flex; align-items: center; gap: 14px; width: 100%;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px; margin-top: 10px; text-decoration: none; color: inherit;
  box-shadow: var(--shadow); transition: transform .08s ease, box-shadow .12s ease;
}
.tile:active { transform: scale(.985); background: #fbfcfd; }
body.fine .tile:hover { box-shadow: var(--shadow-up); }
.tile .tile-ic {
  width: 48px; height: 48px; flex: none; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent);
}
.tile .tile-ic .ic { width: 26px; height: 26px; }
.tile.navy .tile-ic { background: #e8edf5; color: var(--navy); }
.tile .tile-tx { flex: 1; min-width: 0; }
.tile .tile-tx strong { display: block; font-size: 16.5px; }
.tile .tile-tx .small { margin-top: 1px; }
.tile > .ic.chev { color: var(--line); }

/* ---------- forms ---------- */
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=number], select, textarea {
  width: 100%; padding: 13px 14px; font-size: 16px; border: 1.5px solid var(--line);
  border-radius: var(--r-sm); background: #fff; margin-top: 6px; color: var(--text);
  transition: border-color .12s ease, box-shadow .12s ease;
  font-family: inherit; appearance: none; -webkit-appearance: none;
}
select { background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' fill='none'%3E%3Cpath d='M1 1l6 6 6-6' stroke='%235f7081' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center; padding-right: 36px; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,98,0,.15);
}
label { font-weight: 600; display: block; margin-top: 14px; font-size: 15px; }
textarea { min-height: 60px; }
input.invalid, select.invalid { border-color: var(--red); }
.field-error { color: var(--red); font-size: 13px; margin: 4px 0 0; }

/* ---------- badges & pills ---------- */
.badge {
  display: inline-block; min-width: 24px; text-align: center; padding: 3px 9px;
  border-radius: 999px; font-size: 13px; font-weight: 700; color: #fff;
}
.badge.green { background: var(--green); }
.badge.red { background: var(--red); }
.badge.gray { background: #8a98a8; }
.badge.amber { background: var(--amber); }
.badge.zero { background: #eef1f5; color: #9aa7b5; }

.pill { font-size: 13px; padding: 3px 11px; border-radius: 999px;
  background: #eef1f5; color: var(--muted); font-weight: 600; }
.pill.accent { background: var(--accent-soft); color: var(--accent-d); }
.conf-hi { color: var(--green); font-weight: 700; }
.conf-lo { color: var(--red); font-weight: 700; }

/* ---------- section rows ---------- */
.section-row {
  display: flex; align-items: center; gap: 10px;
  padding: 14px; border: 1px solid var(--line); border-radius: var(--r-sm);
  margin-bottom: 8px; text-decoration: none; color: inherit; background: #fff;
  box-shadow: var(--shadow); transition: transform .08s ease;
}
.section-row:active { transform: scale(.99); background: #fbfcfd; }
body.fine .section-row:hover { box-shadow: var(--shadow-up); }
.section-row .nm { flex: 1; min-width: 0; font-weight: 600; font-size: 15.5px; }
.section-row .ic.chev { color: #c2ccd6; width: 18px; height: 18px; }
.section-row.alert { border-color: var(--red); }

.checkrow { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0;
  border-bottom: 1px solid var(--line); }
.checkrow input[type=checkbox] { width: 22px; height: 22px; margin-top: 3px; accent-color: var(--accent); }
.checkrow .meta { flex: 1; }
.checkrow .hint { font-size: 13px; color: var(--muted); margin-top: 2px; }
input[type=checkbox] { accent-color: var(--accent); }

/* ---------- notices ---------- */
.active-banner {
  background: var(--accent-soft); border: 1px solid #ffc9a3; border-radius: var(--r);
  padding: 12px 14px; margin-bottom: 16px;
}
.notice { background: var(--red-soft); border: 1px solid #efb7b0; color: #7a241b;
  padding: 12px 14px; border-radius: var(--r-sm); margin-bottom: 10px; }
.ok { background: var(--green-soft); border: 1px solid #b3dcc3; color: #1d5436;
  padding: 12px 14px; border-radius: var(--r-sm); margin-bottom: 10px; }

/* empty state */
.empty {
  text-align: center; padding: 34px 18px;
}
.empty-ic {
  width: 64px; height: 64px; margin: 0 auto 4px; border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  background: #e8edf5; color: var(--navy);
}
.empty-ic .ic { width: 32px; height: 32px; }

/* ---------- media bits ---------- */
.thumbgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.thumbgrid img { width: 100%; height: 110px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; }
.thumbstrip { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0;
  -webkit-overflow-scrolling: touch; }
.thumbstrip img { height: 150px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; cursor: zoom-in; }
#preview { width: 100%; height: 420px; border: 1px solid var(--line); border-radius: var(--r-sm); }
#docframe { width: 100%; height: 70vh; border: 1px solid var(--line);
  border-radius: var(--r-sm); background: #fff; }
.capture-status { margin-top: 12px; }

/* ---------- breadcrumbs ---------- */
.crumbs { font-size: 13.5px; color: var(--muted); margin-bottom: 8px; }
.crumbs:empty { display: none; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover, .crumbs a:active { text-decoration: underline; }
.crumbs .sep { padding: 0 6px; color: #c2ccd6; }
.crumbs .here { color: var(--text); font-weight: 600; }

/* ---------- platform visibility ---------- */
body.fine .only-touch { display: none !important; }
body.touch .only-fine { display: none !important; }

/* ---------- touch ergonomics ---------- */
@media (max-width: 600px) {
  .btn.sm { min-height: 44px; }
  .actionlink { display: inline-flex; align-items: center; min-height: 44px; padding: 0 8px; }
  .corner::before { content: ''; position: absolute; inset: -7px; }
}
.actionlink { color: var(--accent-d); font-weight: 600; text-decoration: none; }
.actionlink:hover, .actionlink:active { text-decoration: underline; }

/* ---------- desktop ---------- */
@media (min-width: 860px) {
  .wrap { max-width: 1040px; padding: 24px; }
  .btn { max-width: 420px; }
  .tile { max-width: 480px; }
  h1 { font-size: 26px; }

  .home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
  .home-grid .card { margin-bottom: 0; }

  .section-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 8px; }
  .section-list .section-row { margin-bottom: 0; }

  .actions { display: flex; flex-wrap: wrap; gap: 10px; }
  .actions .btn, .actions .tile { width: auto; flex: 1 1 240px; margin-top: 0; }
}

/* ---------- in-app scanner (scan.js injects the markup; styles shared online + offline) ---------- */
.scanstage { position: relative; display: block; touch-action: none; line-height: 0; }
.scanstage canvas { display: block; max-width: 100%; border-radius: 6px; }
.scanstage .quad { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }
.scanstage .quad polygon { fill: rgba(40,120,220,0.12); stroke: #2878dc; stroke-width: 2; }
.corner {
  position: absolute; width: 30px; height: 30px; margin: -15px 0 0 -15px;
  border: 3px solid #2878dc; border-radius: 50%; background: rgba(255,255,255,0.85);
  box-shadow: 0 1px 5px rgba(0,0,0,.5); touch-action: none; cursor: grab; z-index: 2;
}
.scanstage .loupe {
  position: absolute; top: 6px; width: 130px; height: 130px; display: none;
  border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 10px rgba(0,0,0,.55);
  pointer-events: none; z-index: 4; background: #000;
}

/* ---------- offline capture: shell banner ---------- */
.oq-banner { border-radius: var(--r); padding: 12px 14px; margin-bottom: 14px;
  font-size: 14.5px; font-weight: 600; line-height: 1.35; }
.oq-banner.offline { background: var(--accent-soft); border: 1px solid #ffc9a3; color: #7a3c10; }
.oq-banner.online { background: var(--green-soft); border: 1px solid #b3dcc3; color: #1d5436; }

/* ---------- offline capture: pending-upload indicator (self-injected, all pages) ---------- */
.oq-indicator {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 16px; z-index: 30;
  display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 24px);
  background: var(--navy); color: #fff; padding: 9px 12px 9px 14px; border-radius: 16px;
  box-shadow: var(--shadow-up); font-size: 13.5px; font-weight: 600; line-height: 1.3;
}
body.touch .oq-indicator { bottom: calc(70px + env(safe-area-inset-bottom)); }
.oq-indicator.hidden { display: none; }
.oq-indicator .oq-dot { width: 9px; height: 9px; border-radius: 50%; background: #8a98a8; flex: none; }
.oq-indicator.offline .oq-dot { background: var(--amber); }
.oq-indicator.syncing .oq-dot { background: var(--accent); animation: oq-pulse 1s infinite; }
.oq-indicator.synced .oq-dot { background: var(--green); }
.oq-indicator.auth .oq-dot, .oq-indicator.cap .oq-dot { background: var(--accent); }
.oq-indicator.aging { box-shadow: 0 0 0 2px var(--amber), var(--shadow-up); }
.oq-indicator .oq-text { min-width: 0; }
.oq-indicator .oq-text a { color: #ffd9bf; text-decoration: underline; }
.oq-indicator .oq-retry {
  background: rgba(255,255,255,.16); color: #fff; border: none; border-radius: 999px;
  padding: 6px 12px; font-size: 13px; font-weight: 650; cursor: pointer; flex: none;
}
.oq-indicator .oq-retry:active { background: rgba(255,255,255,.28); }
@keyframes oq-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  html { scroll-behavior: auto; }
  .oq-indicator.syncing .oq-dot { animation: none; }
}
