/* Dark theme carried over from the svarstykliu-pwa prototype so the two feel
   like one product. Same tokens, same radii, same accent. */
:root {
  color-scheme: dark;
  --bg: #0f172a;
  --surface: #1a2438;
  --surface-2: #232f47;
  --border: #2f3d5c;
  --text: #e6ebf5;
  --text-muted: #93a2c2;
  --accent: #38bdf8;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  min-height: 100vh;
  padding-bottom: 24px;
}

/* ---- top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar__title { font-weight: 700; font-size: 1.05rem; }
.topbar__status { display: flex; align-items: center; gap: 10px; }

.pill {
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.pill--warn { background: rgba(251,191,36,0.15); color: var(--warn); }
.pill--good { background: rgba(52,211,153,0.15); color: var(--good); }

.inline-form { margin: 0; }
.linkbtn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 6px 4px;
  font-family: inherit;
}
.linkbtn:hover { color: var(--text); text-decoration: underline; }

/* ---- layout ---- */
main { max-width: 560px; margin: 0 auto; padding: 16px; }

h1 { font-size: 1.35rem; margin: 8px 0 4px; }
.lede { color: var(--text-muted); font-size: 0.92rem; margin: 0 0 20px; line-height: 1.5; }

/* ---- cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
}
.card__title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 12px;
  font-weight: 600;
}

.kv { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 7px 0; }
.kv + .kv { border-top: 1px solid var(--border); }
.kv__k { color: var(--text-muted); font-size: 0.88rem; }
.kv__v { font-weight: 600; text-align: right; word-break: break-word; }
.kv__v--mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }

/* The derived initials, the one thing the sibling API is given. */
.initials {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  padding: 10px 14px;
  background: rgba(56,189,248,0.15);
  color: var(--accent);
  border: 1px solid rgba(56,189,248,0.3);
  border-radius: 12px;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

/* ---- buttons ---- */
.primary-btn, .secondary-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 14px;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
}
.primary-btn { background: var(--accent); color: #04121f; }
.secondary-btn { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.primary-btn:disabled, .secondary-btn:disabled {
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.6;
}

/* ---- fields ---- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.field__error { color: var(--bad); font-size: 0.82rem; line-height: 1.4; }
.field__error:empty { display: none; }
.field input.input-validation-error { border-color: var(--bad); }

.field input, .field select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

/* ---- notices ---- */
.notice {
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.88rem;
  line-height: 1.5;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.notice--good { background: rgba(52,211,153,0.12); color: var(--good); border-color: rgba(52,211,153,0.3); }
.notice--warn { background: rgba(251,191,36,0.12); color: var(--warn); border-color: rgba(251,191,36,0.3); }
.notice--bad  { background: rgba(248,113,113,0.12); color: var(--bad);  border-color: rgba(248,113,113,0.3); }

.footnote { color: var(--text-muted); font-size: 0.78rem; line-height: 1.5; margin-top: 20px; }

/* ---- sign-in ---- */
.signin { max-width: 380px; margin: 48px auto 0; text-align: center; }
.signin h1 { margin-bottom: 8px; }
.signin .lede { margin-bottom: 28px; }
.ms-logo { width: 18px; height: 18px; flex: none; }

/* ---- screens ---- */
.screen--hidden { display: none; }

/* ---- capture ---- */
.capture-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 18px;
  background: var(--accent);
  color: #04121f;
  font-size: 1.1rem;
  font-weight: 700;
  border-radius: 16px;
  cursor: pointer;
  margin: 16px 0 12px;
}
.capture-btn--pick { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }

.picker-row { display: flex; gap: 8px; }
.picker-row select { flex: 1; min-width: 0; }

.queue-summary {
  display: flex;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  margin: 16px 0 12px;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.queue-summary strong { color: var(--text); font-size: 1.05rem; }

/* ---- queue list ---- */
.queue-list { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.queue-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
}
/* A button, not an image: tapping it opens the full view. */
.queue-item__photo {
  position: relative;
  width: 56px; height: 56px;
  flex: none;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: none;
  cursor: pointer;
}
.queue-item__photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.queue-item__count {
  position: absolute; right: 2px; bottom: 2px;
  min-width: 16px; padding: 0 4px;
  border-radius: 8px;
  background: rgba(3,8,20,0.8);
  color: var(--text);
  font-size: 0.65rem; font-weight: 600; line-height: 16px; text-align: center;
}
.queue-item__body { flex: 1; min-width: 0; }
.queue-item__title { font-weight: 600; font-size: 0.95rem; }
.queue-item__meta { color: var(--text-muted); font-size: 0.8rem; margin-top: 2px; }
.queue-item__seq { color: var(--good); font-size: 0.85rem; font-weight: 600; margin-top: 4px; }
.queue-item__error { color: var(--bad); font-size: 0.8rem; margin-top: 4px; }

.badge { font-size: 0.72rem; padding: 4px 9px; border-radius: 999px; font-weight: 600; flex: none; }
.badge--pending  { background: rgba(147,162,194,0.15); color: var(--text-muted); }
.badge--accepted { background: rgba(56,189,248,0.15); color: var(--accent); }
.badge--done     { background: rgba(52,211,153,0.15); color: var(--good); }
.badge--failed   { background: rgba(248,113,113,0.15); color: var(--bad); }

.pill--offline { background: rgba(248,113,113,0.15); color: var(--bad); }
.pill--user { background: rgba(56,189,248,0.15); color: var(--accent); font-family: ui-monospace, monospace; }

.iconbtn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 34px; height: 34px;
  border-radius: 10px;
  font-size: 0.95rem;
  cursor: pointer;
}

/* ---- review ---- */
.preview-wrap { border-radius: 14px; overflow: hidden; background: var(--surface); border: 1px solid var(--border); }
.preview-wrap img { display: block; width: 100%; max-height: 46vh; object-fit: contain; }

.photo-strip { list-style: none; margin: 10px 0 0; padding: 0; display: flex; gap: 8px; flex-wrap: wrap; }
.photo-strip:empty { display: none; }
.photo-strip__item { position: relative; }
.photo-strip__btn { width: 60px; height: 60px; padding: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: none; cursor: pointer; }
.photo-strip__btn img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-strip__remove {
  position: absolute; top: -6px; right: -6px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--bad); color: #1b0606; border: none;
  font-size: 0.85rem; line-height: 1; cursor: pointer;
}

.photo-add-row { display: flex; gap: 8px; margin: 12px 0 16px; }
.photo-add {
  flex: 1;
  text-align: center;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.9rem;
  cursor: pointer;
}

.ocr-status { color: var(--text-muted); font-size: 0.85rem; margin: 4px 0 12px; }
.field__hint { color: var(--text-muted); font-size: 0.78rem; }

.review-actions { display: flex; gap: 10px; margin-top: 8px; }
.review-actions button { flex: 1; }

/* ---- viewer ---- */
.viewer {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(3,8,20,0.95);
  display: flex; align-items: center; justify-content: center;
}
.viewer[hidden] { display: none; }
.viewer__img { max-width: 96vw; max-height: 88vh; object-fit: contain; }
.viewer__close {
  position: absolute; top: 14px; right: 14px;
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); font-size: 1rem; cursor: pointer;
}

.field--toggle { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.field--toggle input[type="checkbox"] { flex: none; width: 22px; height: 22px; accent-color: var(--accent); cursor: pointer; }

/* ---- quality feedback ---- */
.preview-wrap--warn { border-color: var(--warn); }
.photo-strip__btn--warn { border-color: var(--warn); border-width: 2px; }

.queue-item__flags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.flag {
  font-size: 0.68rem;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(251,191,36,0.15);
  color: var(--warn);
  font-weight: 600;
}

/* ---- read-only values ---- */
.readout {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  color: var(--text-muted);
  font-size: 0.95rem;
  min-height: 45px;
}
.readout--found {
  color: var(--text);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-weight: 600;
  border-color: rgba(56,189,248,0.4);
}
.readout--muted { color: var(--text-muted); }

/* ---- viewer navigation ---- */
.viewer__bar {
  position: absolute;
  bottom: 18px; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}
.viewer__nav {
  width: 46px; height: 46px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.5rem; line-height: 1;
  cursor: pointer;
}
.viewer__nav[hidden] { display: none; }
.viewer__count { color: var(--text-muted); font-size: 0.85rem; min-width: 52px; text-align: center; }

/* ---- serial conflict ----
   Red beats yellow: these rules come after the --warn ones deliberately, so a
   photo that is both blurred and contradictory shows the harder problem. */
.preview-wrap--conflict { border-color: var(--bad); }
.photo-strip__btn--conflict { border-color: var(--bad); border-width: 2px; }
.readout--conflict {
  color: var(--bad);
  border-color: rgba(248,113,113,0.5);
  font-weight: 600;
}

/* ---- retry / give-up ---- */
.queue-item__attempts { color: var(--text-muted); font-size: 0.75rem; margin-top: 3px; }
.queue-item__retry {
  margin-top: 6px;
  padding: 7px 12px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
}
.queue-item__retry:disabled { color: var(--text-muted); opacity: 0.6; cursor: not-allowed; }
.badge--blocked { background: rgba(248,113,113,0.15); color: var(--bad); }

/* ---- picker search ----
   Sits above its <select>, never replaces it: the native mobile picker has
   bigger targets and system scrolling than anything hand-rolled. */
.picker-search { margin-bottom: 8px; }
.picker-search[hidden] { display: none; }

/* Server findings, visually distinct from the local OCR hint. */
.queue-item__found {
  color: var(--good);
  font-size: 0.8rem;
  margin-top: 5px;
  padding-left: 8px;
  border-left: 2px solid rgba(52,211,153,0.5);
}
