:root {
  color-scheme: light dark;
  --bg: #f4f5f6;
  --surface: #ffffff;
  --text: #1a1d21;
  --muted: #5d6670;
  --border: #d5d9de;
  --accent: #1f6f54;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --warn-bg: #fff4d6;
  --warn-text: #5c4300;
  --selected: #e4f1ec;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1b1f24;
    --text: #e8eaed;
    --muted: #a0a8b2;
    --border: #363c44;
    --accent: #3fa883;
    --accent-text: #08120e;
    --danger: #f2877f;
    --warn-bg: #3d3214;
    --warn-text: #f4dc9c;
    --selected: #1f3a30;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
button, input, select { font: inherit; color: inherit; }
input, select {
  width: 100%;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
button {
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--danger); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); }
.form-error { min-height: 1.2em; margin: 8px 0; color: var(--muted); }

/* Sign-in */
.signin-dialog { width: min(92vw, 360px); padding: 22px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.signin-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.signin-logo { display: block; height: 72px; width: auto; margin: 0 auto 12px; }
.signin h2 { margin: 0 0 14px; font-size: 18px; text-align: center; }
.signin label { display: block; margin-bottom: 8px; font-weight: 600; }
.signin input { margin-top: 4px; font-weight: 400; font-size: 16px; }
.signin button { width: 100%; }

/* Capture page */
body.capture { display: flex; flex-direction: column; height: 100dvh; background: #000; color: #fff; overflow: hidden; }
.viewfinder { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.viewfinder video { width: 100%; height: 100%; object-fit: cover; display: block; }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.on { animation: flash 0.25s ease-out; }
@keyframes flash { from { opacity: 0.8; } to { opacity: 0; } }
.no-camera { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center; color: #d5d9de; }
.capture-bar { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: #111418; text-align: center; }
.capture-status { min-height: 1.4em; margin: 0 0 10px; color: #d5d9de; }
.capture-controls { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; justify-items: center; }
.shutter { width: 74px; height: 74px; padding: 0; background: #fff; border: 5px solid #111418; border-radius: 50%; box-shadow: 0 0 0 3px #fff; touch-action: manipulation; }
.shutter:active { transform: scale(0.92); }
.round-button { display: inline-flex; align-items: center; padding: 9px 13px; color: #fff; background: #2a3037; border-radius: 999px; font-size: 14px; cursor: pointer; }
.round-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.round-button:focus-within { outline: 2px solid #fff; outline-offset: 2px; }
.capture-link { display: inline-block; margin-top: 10px; padding: 4px; color: #d5d9de; }

/* Review page */
.topbar { display: flex; align-items: center; gap: 6px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar h1 { margin: 0 14px 0 0; font-size: 16px; line-height: 0; }
.brand-logo { height: 34px; width: auto; }
.topbar nav { display: flex; flex-shrink: 0; }
@media (max-width: 480px) {
  .topbar { flex-wrap: wrap; }
  .topbar nav { order: 3; width: 100%; }
}
.tab { padding: 6px 12px; background: none; border: 0; border-radius: 6px; }
.tab[aria-selected="true"] { background: var(--selected); font-weight: 600; }
.spacer { flex: 1; }
.review-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr) 330px; height: calc(100dvh - 53px); }
.queue-list { margin: 0; padding: 0; overflow-y: auto; list-style: none; background: var(--surface); border-right: 1px solid var(--border); }
.queue-item { display: block; width: 100%; padding: 10px 14px; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; }
.queue-item[aria-current="true"] { background: var(--selected); }
.queue-item strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-item small { color: var(--muted); }
.photo-pane { display: flex; flex-direction: column; min-width: 0; padding: 12px; overflow: hidden; }
.photo-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.photo-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.crop-frame { position: relative; display: inline-block; max-width: 100%; max-height: 100%; overflow: hidden; touch-action: none; user-select: none; line-height: 0; }
.crop-frame img { display: block; max-width: 100%; max-height: calc(100dvh - 130px); }
.crop-box { position: absolute; border: 2px solid #4fd1a5; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5); cursor: move; }
.crop-handle { position: absolute; width: 20px; height: 20px; background: #4fd1a5; border: 2px solid #fff; border-radius: 50%; }
.crop-handle.nw { left: -10px; top: -10px; cursor: nwse-resize; }
.crop-handle.ne { right: -10px; top: -10px; cursor: nesw-resize; }
.crop-handle.sw { left: -10px; bottom: -10px; cursor: nesw-resize; }
.crop-handle.se { right: -10px; bottom: -10px; cursor: nwse-resize; }
.detail-pane { padding: 16px; overflow-y: auto; background: var(--surface); border-left: 1px solid var(--border); }
.field { display: block; margin-bottom: 12px; font-weight: 600; }
.field input, .field select { margin-top: 4px; font-weight: 400; }
.notice { margin: 0 0 12px; padding: 8px 10px; color: var(--warn-text); background: var(--warn-bg); border-radius: 6px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.actions .primary { flex: 1 1 100%; padding: 10px; }
.hint { margin: 12px 0 0; color: var(--muted); font-size: 13px; }
.empty { padding: 48px 20px; color: var(--muted); text-align: center; }
.message { margin: 10px 0 0; color: var(--danger); min-height: 1.2em; }
.message.ok { color: var(--accent); }

/* Filed and settings pages */
.page { max-width: 1040px; margin: 0 auto; padding: 18px 16px; overflow-y: auto; height: calc(100dvh - 53px); }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.filters label { font-weight: 600; }
.filters select { display: block; width: auto; min-width: 150px; margin-top: 4px; font-weight: 400; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 13px; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
.link-button { padding: 0; color: var(--accent); background: none; border: 0; text-decoration: underline; }
.settings-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 24px; }
.settings-grid h2 { margin: 0 0 4px; font-size: 16px; }
.settings-grid .sub { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.setting-row { display: grid; gap: 8px; align-items: center; margin-bottom: 8px; }
.setting-row.business { grid-template-columns: 110px minmax(0, 1fr) auto; }
.setting-row.category { grid-template-columns: minmax(0, 1fr) auto; }
.setting-row label { display: inline-flex; gap: 5px; align-items: center; font-size: 13px; }
.setting-row input[type="checkbox"] { width: auto; }
.save-bar { display: flex; align-items: center; gap: 12px; margin-top: 18px; }
.correct-dialog { width: min(92vw, 420px); padding: 20px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.correct-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.correct-dialog h2 { margin: 0 0 12px; font-size: 17px; }

@media (max-width: 900px) {
  .review-layout { display: block; height: auto; }
  .queue-list { max-height: 170px; border-right: 0; border-bottom: 1px solid var(--border); }
  .crop-frame img { max-height: 60vh; }
  .detail-pane { border-left: 0; }
  .settings-grid { grid-template-columns: 1fr; }
  .page { height: auto; }
}
