:root {
  --green: #1a6b3c;
  --green-dark: #144d2c;
  --bg: #f4f4f1;
  --card: #ffffff;
  --text: #1f2422;
  --muted: #6b716e;
  --border: #dddad2;
  --red: #b3261e;
  --amber: #9a6200;
}

* { box-sizing: border-box; }

html { font-size: 17px; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: var(--green);
  color: #fff;
}
.topbar a.brand { color: #fff; font-weight: 700; font-size: 1.2rem; text-decoration: none; }
.topnav { display: flex; align-items: center; gap: 0.9rem; }
.topnav a { color: #e8f3ec; font-weight: 600; text-decoration: none; }
.whoami { font-size: 0.85rem; opacity: 0.9; }

.container { max-width: 640px; margin: 0 auto; padding: 1rem; }

.footer {
  max-width: 640px;
  margin: 0 auto;
  padding: 0.2rem 1rem 1.4rem;
  text-align: center;
}
.footer a { text-decoration: none; }
.footer a:hover { text-decoration: underline; }

h1 { font-size: 1.4rem; margin: 0.6rem 0; }
h2 { font-size: 1.15rem; margin: 1rem 0 0.4rem; }
h3 { font-size: 1.05rem; margin: 0 0 0.6rem; }
h4 { margin: 0.8rem 0 0.3rem; }

.stack { display: flex; flex-direction: column; gap: 0.8rem; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem;
  margin-bottom: 0.9rem;
}
.card-pending { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.card-error { border-color: var(--red); }

/* Buttons: big tap targets with clear affordances */
.btn, button.btn {
  display: inline-block;
  min-height: 48px;
  padding: 0.55rem 1.1rem;
  font-size: 1.05rem;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  background: #e9e7e0;
  border-color: #d6d3c9;
  color: inherit;
  font-weight: 600;
  transition: background 0.1s ease, transform 0.05s ease;
}
.btn:hover { background: #dfdcd3; }
.btn:active { background: #d6d3c9; transform: translateY(1px); }
.btn:disabled, .btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  filter: none;
}
.btn:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 2px;
}

/* Variant selectors are .btn.btn-* (or button.btn-*): they must
   out-rank the `button.btn` base rule above, or every styled
   <button> renders grey at rest and only shows its color on
   hover (bug fixed in v1.11.3). */
.btn.btn-primary, button.btn-primary {
  background: var(--green);
  color: #fff !important;
}
.btn.btn-primary:hover, button.btn-primary:hover { background: #1e7c47; }
.btn.btn-primary:active, button.btn-primary:active {
  background: var(--green-dark);
  transform: translateY(1px);
}

.btn.btn-secondary, button.btn-secondary {
  background: #fff;
  border-color: #a9a496;
}
.btn.btn-secondary:hover, button.btn-secondary:hover { background: #f3f2ee; }
.btn.btn-secondary:active, button.btn-secondary:active {
  background: #eae8e1;
  transform: translateY(1px);
}

.btn.btn-approve, button.btn-approve { background: var(--green); color: #fff; }
.btn.btn-approve:hover, button.btn-approve:hover { background: #1e7c47; }
.btn.btn-approve:active, button.btn-approve:active {
  background: var(--green-dark);
  transform: translateY(1px);
}

.btn.btn-reject, button.btn-reject { background: var(--red); color: #fff; }
.btn.btn-reject:hover, button.btn-reject:hover { background: #c74039; }
.btn.btn-reject:active, button.btn-reject:active {
  background: #8f1f19;
  transform: translateY(1px);
}

.btn.btn-danger, button.btn-danger {
  background: #fff;
  border-color: var(--red);
  color: var(--red);
}
.btn.btn-danger:hover, button.btn-danger:hover { background: #fbe0dc; }
.btn.btn-danger:active, button.btn-danger:active {
  background: #f4d1ca;
  transform: translateY(1px);
}

.btn-small { min-height: 40px; font-size: 0.9rem; padding: 0.3rem 0.7rem; }
/* Busy state: spinner + disabled while the request is in flight. */
.btn.loading { cursor: progress; opacity: 0.85; }
.btn.loading::before {
  content: "";
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  margin-right: 0.45em;
  vertical-align: -0.12em;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.8s linear infinite;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }
.btn-link {
  min-height: 0;
  padding: 0.2rem 0;
  background: none;
  border: none;
  color: #e8f3ec;
  font-weight: 600;
  text-decoration: underline;
}
.btn-big { font-size: 1.25rem; padding: 0.9rem; width: 100%; }

.upload-cta { display: block; text-align: center; margin-top: 0.5rem; }

.camera-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  min-height: 220px;
  font-size: 1.2rem;
  font-weight: 700;
  border: 2px dashed var(--green);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  padding: 1rem;
  transition: background 0.1s ease, border-color 0.1s ease;
}
.camera-btn:hover { background: #fafaf7; border-color: var(--green-dark); }
.camera-btn:active { background: #eef3ee; border-style: solid; }
.camera-icon { font-size: 3rem; }

.gallery-btn { width: 100%; margin-top: 0.6rem; }

.pdf-badge, .pdf-card {
  width: 90px;
  height: 90px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #e9e7e0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
}
.pdf-card { width: 110px; height: 140px; display: flex; align-items: center; justify-content: center; }

.preview { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.6rem 0; }
.preview img { width: 90px; height: 90px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }

label, .check { font-weight: 600; display: block; margin: 0.6rem 0 0.25rem; }
input[type="text"], input[type="password"], textarea, select {
  width: 100%;
  min-height: 48px;
  padding: 0.5rem 0.7rem;
  font-size: 1.05rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: inherit;
}
textarea { resize: vertical; }

.login-card { max-width: 420px; margin: 3rem auto 0; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1.2rem; }
.login-card h1 { text-align: center; }
.login-card button[type="submit"] { margin-top: 1rem; }

.row { display: flex; gap: 0.5rem; align-items: stretch; }
.row input { flex: 1; }
.row button { flex-shrink: 0; }

.order-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.order-row { display: flex; gap: 0.5rem; align-items: center; }
.order-row .order-card { flex: 1; }
.order-card {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem;
  text-decoration: none;
  color: inherit;
}
.order-main { display: flex; flex-direction: column; gap: 0.15rem; }
.order-id { font-weight: 700; }
.order-desc { font-size: 0.95rem; }
.order-side { display: flex; flex-direction: column; align-items: flex-end; gap: 0.3rem; flex-shrink: 0; }
.order-amount { font-weight: 700; font-size: 0.95rem; }
.order-thumb {
  width: 3.2rem;
  height: 3.2rem;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.chip {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: #e6e6e1;
  color: #444;
}
.chip-pending { background: #fdf0d3; color: var(--amber); }
.chip-analyzed { background: #d9ecfd; color: #14507e; }
.chip-approved { background: #d7f0dd; color: var(--green-dark); }
.chip-rejected { background: #f8d7d5; color: var(--red); }
.chip-failed { background: #f8d7d5; color: var(--red); }
.chip-flag { background: #fbe0dc; color: var(--red); }

.photos { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.thumb { width: 110px; height: 140px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.photo-item { display: flex; flex-direction: column; align-items: center; gap: 0.25rem; max-width: 110px; }
.source-link { font-size: 0.72rem; text-decoration: none; color: var(--muted, #666); word-break: break-word; }
.source-link:hover { text-decoration: underline; }

.badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-ok { background: #d7f0dd; color: var(--green-dark); }
.badge-bad { background: #f8d7d5; color: var(--red); }
.badge-exception { background: #fdf0d3; color: var(--amber); }

.flag-action { margin: 0.25rem 0 0.1rem; display: flex; gap: 0.35rem; flex-wrap: wrap; }
.flag-action input[type="text"] { flex: 1; min-width: 9rem; padding: 0.25rem 0.5rem; }

.items { width: 100%; border-collapse: collapse; font-size: 1rem; }
.items th, .items td { padding: 0.35rem 0.4rem; text-align: left; border-bottom: 1px solid var(--border); }
.items .num { text-align: right; white-space: nowrap; }
.items th.num { text-align: right; }

.totals { margin-top: 0.8rem; }
.total-row { display: flex; justify-content: space-between; padding: 0.25rem 0; }
.total-big { font-size: 1.2rem; font-weight: 800; border-top: 2px solid var(--text); margin-top: 0.3rem; padding-top: 0.4rem; }

.verdict { margin-top: 0.8rem; padding: 0.6rem; border-radius: 8px; }
.verdict-ok { background: #d7f0dd; }
.verdict-bad { background: #fdf0d3; }
.verdict ul { margin: 0.3rem 0 0 1.1rem; }

.flags, .missing { margin: 0.2rem 0; padding-left: 1.1rem; }
.flags li, .missing li { margin-bottom: 0.4rem; }

.alert { padding: 0.7rem; border-radius: 8px; margin-bottom: 0.8rem; }
.alert-error { background: #fbe0dc; color: var(--red); font-weight: 600; }
.alert-ok { background: #d7f0dd; color: var(--green-dark); font-weight: 600; }
.banner-duplicate {
  background: #fbe0dc;
  border: 2px solid var(--red);
  color: var(--red);
  font-weight: 600;
  padding: 0.9rem;
  border-radius: 10px;
  margin-bottom: 0.9rem;
}
.banner-info {
  background: #e6e6e1;
  color: var(--text, #333);
  font-weight: 600;
  padding: 0.9rem;
  border-radius: 10px;
  margin-bottom: 0.9rem;
}
.banner-info a { font-weight: 700; }
.banner-form { display: inline-block; margin-top: 0.4rem; }
.banner-form button {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.25rem 0.7rem;
}

/* Photo lightbox (order pages) */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 100%;
  max-height: 88vh;
  border-radius: 8px;
}
.lightbox button {
  position: absolute;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 2rem;
  line-height: 1;
  width: 3rem;
  height: 3rem;
  cursor: pointer;
}
.lightbox button:hover { background: rgba(0, 0, 0, 0.8); }
.lightbox-prev { left: 0.5rem; }
.lightbox-next { right: 0.5rem; }
.lightbox-close {
  top: 0.5rem;
  right: 0.5rem;
  font-size: 1.5rem;
  width: 2.5rem;
  height: 2.5rem;
}
.one-time-password { font-size: 1.25rem; letter-spacing: 0.06em; }

.users-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; margin-top: 0.8rem; }
.changelog-archive { margin-top: 0.8rem; }
.changelog-archive summary { cursor: pointer; font-weight: 600; padding: 0.6rem 0; }
.changelog-archive summary:hover { color: var(--green); }
.changelog-archive[open] summary { margin-bottom: 0.4rem; }
.user-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; justify-content: space-between; }
.user-main { display: flex; flex-direction: column; }
.user-reset { display: flex; gap: 0.4rem; align-items: center; }
.user-reset input { width: 12rem; }

.qa-form textarea { margin-bottom: 0.5rem; }

/* Touch devices: the green focus ring is for keyboards only. */
@media (hover: none) and (pointer: coarse) {
  .btn:focus-visible { outline: none; }
  .btn:focus-visible:active { transform: translateY(1px); }
}

/* Admin item-amount editing */
.edit-items summary { cursor: pointer; font-weight: 600; margin-top: 0.8rem; }
.edit-items input {
  width: 7rem;
  padding: 0.3rem;
  font: inherit;
  border: 1px solid #a9a496;
  border-radius: 6px;
  text-align: right;
}
.checker-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.checker-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.checker-row .chip { flex-shrink: 0; }
.checker-item { font-weight: 700; }
.checker-row .muted { flex: 1; min-width: 12rem; }
.checker-swap { color: var(--green); font-weight: 600; }
.swaps-aside { margin-top: 0.4rem; }
.swaps-button {
  background: none; border: none; padding: 0;
  color: var(--muted); font: inherit; font-size: 0.9rem;
  text-decoration: underline; cursor: pointer;
}
.swaps-button:hover { color: var(--text); }
.swap-list { margin: 0.5rem 0 0; padding-left: 1.2rem; color: var(--green); }
.swap-list li { margin: 0.25rem 0; }
.swap-list .muted { color: var(--text); }
.qa-list { list-style: none; margin: 0.8rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.qa { display: flex; flex-direction: column; padding: 0.5rem 0.7rem; border-radius: 8px; }
.qa-user { background: #e6e6e1; }
.qa-assistant { background: #d9ecfd; }
.qa-role { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; opacity: 0.7; }
.qa-body { white-space: pre-wrap; overflow-wrap: anywhere; }

.back { font-weight: 600; text-decoration: none; color: var(--green); }
.order-header { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.6rem; }

.admin-header { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; }
.filters { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-bottom: 0.8rem; }
.filters select { width: auto; }
.filters .check { display: flex; align-items: center; gap: 0.3rem; margin: 0; }
.filters .check input { min-height: 0; }
.tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.tab {
  padding: 0.3rem 0.7rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--card);
  color: var(--text); text-decoration: none; font-size: 0.9rem;
}
.tab:hover { border-color: var(--green); }
.tab-active { background: var(--green); border-color: var(--green); color: var(--card); }
.tab-count { font-size: 0.8rem; opacity: 0.75; }
.filter-chips { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.25rem 0.6rem; border-radius: 999px;
  background: var(--card); border: 1px solid var(--border);
  font-size: 0.85rem;
}
.chip-x { text-decoration: none; color: var(--red); font-weight: 700; }
.filter-panel summary { cursor: pointer; margin-bottom: 0.4rem; }

/* Queue multi-select: checkbox beside each card, bulk bar on top. */
.bulk-bar { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 0.6rem; }
.bulk-bar .check { display: flex; align-items: center; gap: 0.3rem; margin: 0; }
.bulk-bar .check input { min-height: 0; }
.bulk-row { display: flex; align-items: center; gap: 0.5rem; }
.bulk-row .order-card { flex: 1; }
.bulk-check { display: flex; align-items: center; }
.bulk-check input { min-height: 0; }

/* Payouts: total + copy + per-user pay side by side. */
.payout-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.inline-form { display: inline; }

.decision-form { display: flex; gap: 0.6rem; }
.decision-form .btn { flex: 1; }
.decision-form + .decision-form { margin-top: 0.6rem; align-items: center; }

.rule-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; margin-bottom: 0.6rem; }
.rule-form input[name="pattern"],
.rule-form input[name="reason"] { grid-column: 1 / -1; }
.rules-list { list-style: none; margin: 0; padding: 0; }
.rules-list li { border: 1px solid var(--border); border-radius: 10px; padding: 0.6rem; margin-bottom: 0.6rem; }
.rule-add { margin-top: 0.5rem; }
.rule-generate { display: grid; grid-template-columns: 1fr auto; gap: 0.4rem; margin-top: 0.5rem; align-items: stretch; }
.rule-generate textarea { flex: 1; }
#rule-generate-note.toast-error { color: var(--red); }
@media (max-width: 480px) {
  .rule-form { grid-template-columns: 1fr; }
  .rule-form .btn { width: 100%; }
}

.spinner {
  display: inline-block;
  width: 1.1rem; height: 1.1rem;
  border: 3px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translateX(-50%) translateY(20px);
  background: #222;
  color: #fff;
  padding: 0.8rem 1.2rem;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  max-width: 90vw;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-error { background: var(--red); }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
