:root {
  --ng-navy: #1a2332;
  --ng-orange: #f47c20;
  --ng-bg: #f6f7f9;
  --ng-card: #ffffff;
  --ng-text: #1a2332;
  --ng-muted: #6b7480;
  --ng-border: #e3e6eb;
  --ng-good: #2f9e44;
  --ng-warn: #e8a317;
  --ng-bad:  #d6336c;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.04);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--ng-bg); color: var(--ng-text); }
body { min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }

header {
  background: var(--ng-navy);
  color: white;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 10;
}
header h1 { font-size: 15px; margin: 0; flex: 1; font-weight: 600; }
header .logo { height: 22px; }
header .review-link { color: white; text-decoration: none; font-size: 13px; opacity: .85; }
header .review-link:hover { opacity: 1; }

main { padding: 10px 14px; max-width: 1200px; margin: 0 auto; }
body.capture-page main { max-width: 720px; }

/* ---------- capture page ---------- */
#stage {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 3 / 4;
  width: 100%;
  box-shadow: var(--shadow);
}
#preview, #overlay, #stage img.captured {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
#overlay { pointer-events: none; }
#guide {
  position: absolute;
  bottom: 12px; left: 12px; right: 12px;
  text-align: center;
  color: white;
  font-size: 13px;
  text-shadow: 0 1px 4px rgba(0,0,0,.6);
}
#quality {
  position: absolute;
  top: 12px; right: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(0,0,0,.55);
  color: white;
}
.quality-ok  { box-shadow: inset 0 0 0 1px var(--ng-good); }
.quality-warn{ box-shadow: inset 0 0 0 1px var(--ng-warn); }
.quality-bad { box-shadow: inset 0 0 0 1px var(--ng-bad); }

#controls {
  display: flex;
  gap: 10px;
  margin: 14px 0;
}
button {
  flex: 1;
  background: var(--ng-orange);
  color: white;
  border: 0;
  padding: 14px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
button:disabled { background: #c4c8cf; cursor: not-allowed; }
button.secondary { background: white; color: var(--ng-text); border: 1px solid var(--ng-border); }

#thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
#thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid var(--ng-border); }

#recent { background: var(--ng-card); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
#recent h2 { font-size: 14px; margin: 0 0 10px; color: var(--ng-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
#recentList { list-style: none; padding: 0; margin: 0; }
#recentList li { padding: 10px 0; border-top: 1px solid var(--ng-border); font-size: 14px; display: flex; gap: 10px; align-items: center; }
#recentList li:first-child { border-top: 0; }
.muted { color: var(--ng-muted); }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.pill-pending  { background: #eef0f3; color: var(--ng-muted); }
.pill-extracted{ background: #e8f1fb; color: #1971c2; }
.pill-awaiting { background: #fff3bf; color: #846100; }
.pill-ready    { background: #e6f7ec; color: var(--ng-good); }
.pill-approved { background: #d3f9d8; color: #2b8a3e; }
.pill-posted   { background: #e6f4ea; color: #1c7430; }
.pill-failed   { background: #ffe3e3; color: var(--ng-bad); }
.pill-rejected { background: #ffe3e3; color: var(--ng-bad); }

/* ---------- review page ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.tab {
  background: white; color: var(--ng-text);
  border: 1px solid var(--ng-border); padding: 5px 12px;
  border-radius: 999px; cursor: pointer; font-size: 12px; font-weight: 600;
  display: flex; gap: 6px; align-items: center;
}
.tab.active { background: var(--ng-navy); color: white; border-color: var(--ng-navy); }
.tab .count { background: rgba(0,0,0,.08); padding: 1px 7px; border-radius: 999px; font-size: 10px; }
.tab.active .count { background: rgba(255,255,255,.18); }

.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-bottom: 10px; }
.kpi {
  background: white; padding: 8px 10px; border-radius: 8px; box-shadow: var(--shadow);
}
.kpi .label { font-size: 10px; text-transform: uppercase; color: var(--ng-muted); letter-spacing: .04em; }
.kpi .value { font-size: 18px; font-weight: 700; margin-top: 2px; line-height: 1.1; }
.kpi.warn .value { color: var(--ng-warn); }
.kpi.good .value { color: var(--ng-good); }

.receipt-card {
  background: white; border-radius: 8px; box-shadow: var(--shadow);
  margin-bottom: 8px; overflow: hidden;
}
.receipt-card .head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--ng-border); cursor: pointer; font-size: 14px; }
.receipt-card .body { padding: 10px 12px; display: none; grid-template-columns: 180px 1fr; gap: 14px; }
.receipt-card.open .body { display: grid; }
.receipt-card .body img { width: 100%; border-radius: 6px; border: 1px solid var(--ng-border); cursor: zoom-in; transition: filter .15s; }
.receipt-card .body img:hover { filter: brightness(.95); }

#lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 1000;
  display: none; align-items: center; justify-content: center;
  padding: 20px; cursor: zoom-out;
}
#lightbox.open { display: flex; }
#lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; box-shadow: 0 4px 40px rgba(0,0,0,.5); }
#lightbox .lb-close {
  position: absolute; top: 16px; right: 20px; color: white; font-size: 28px;
  background: rgba(255,255,255,.12); width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}

.field { display: flex; flex-direction: column; gap: 3px; margin-bottom: 6px; }
.field label { font-size: 10px; text-transform: uppercase; color: var(--ng-muted); letter-spacing: .04em; }
.field input, .field select, .field textarea {
  border: 1px solid var(--ng-border); padding: 6px 8px; border-radius: 5px; font-size: 13px; font-family: inherit;
}
.field.low-confidence input { background: #fff8e1; border-color: var(--ng-warn); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.match-box { background: #f0f7ff; border: 1px solid #c5dcf5; padding: 6px 10px; border-radius: 5px; margin-bottom: 6px; font-size: 12px; }
.match-box.disagree { background: #fff4e6; border-color: #ffd8a8; }
.match-box code { background: rgba(0,0,0,.05); padding: 1px 4px; border-radius: 3px; font-size: 11px; }

.btn-row { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.btn-row button { flex: 0 1 auto; padding: 6px 12px; font-size: 13px; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--ng-navy); color: white; padding: 10px 16px; border-radius: 999px;
  font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 100;
}
#toast.show { opacity: 1; }

@media (max-width: 540px) {
  .receipt-card .body { grid-template-columns: 1fr; }
}

/* GL suggestion buttons — compact tappable confirmation step */
.gl-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 6px; margin: 6px 0 8px; }
.gl-btn {
  background: white; border: 1px solid var(--ng-border); border-radius: 8px;
  padding: 8px 10px; text-align: left; cursor: pointer; font-family: inherit;
  display: flex; flex-direction: column; gap: 2px; transition: border-color .12s, box-shadow .12s;
}
.gl-btn:hover { border-color: var(--ng-orange); box-shadow: var(--shadow); }
.gl-btn.primary { border-color: var(--ng-orange); background: #fff7ef; }
.gl-btn .gl-name { font-weight: 600; font-size: 13px; color: var(--ng-text); line-height: 1.25; }
.gl-btn .gl-source { font-size: 10px; color: var(--ng-muted); }
.gl-btn .gl-source strong { color: var(--ng-good); }
.gl-btn.other { background: white; border-style: dashed; align-items: center; justify-content: center; text-align: center; padding: 6px 10px; }
.gl-btn.other .gl-name { color: var(--ng-muted); font-size: 12px; }

.receipt-summary { display: flex; gap: 6px; flex-wrap: wrap; font-size: 12px; margin-bottom: 4px; }
.receipt-summary .chip { padding: 2px 8px; background: #eef0f3; border-radius: 999px; }
.receipt-summary .chip strong { color: var(--ng-text); }

.gl-search { display: none; margin-top: 6px; }
.gl-search.open { display: block; }
.gl-search input { width: 100%; padding: 7px 10px; border: 1px solid var(--ng-border); border-radius: 6px; font-size: 13px; }
.gl-search-results { max-height: 220px; overflow-y: auto; margin-top: 4px; border: 1px solid var(--ng-border); border-radius: 6px; background: white; }
.gl-search-results .res { padding: 6px 10px; cursor: pointer; border-bottom: 1px solid var(--ng-border); font-size: 12px; }
.gl-search-results .res:hover { background: #f6f7f9; }
.gl-search-results .res:last-child { border-bottom: none; }
