/* Mobile-first, high-contrast layout with large touch targets. */

:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --ink: #14201b;
  --muted: #5b6a63;
  --brand: #0b6b4f;
  --brand-ink: #ffffff;
  --secondary: #e2e8e4;
  --secondary-ink: #14201b;
  --border: #c7d2cc;
  --error: #b3261e;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4e00;
  --focus: #1466c8;
  --radius: 14px;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must ALWAYS hide. An author `display:` rule on an
   element (e.g. `.update-bar { display: flex }`, `.preview { display: block }`)
   otherwise beats the UA stylesheet's `[hidden] { display: none }`, leaving the
   element permanently visible regardless of its `hidden` state — this is what
   made the update banner show on every load and "never disappear" (2026-08-03).
   `!important` guarantees `hidden` wins over any display rule, present or future. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.4 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

h1 {
  font-size: 1.5rem;
  margin: 8px 0 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

/* Buttons */
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.btn {
  flex: 1 1 auto;
  min-height: 52px;
  min-width: 44px;
  padding: 12px 18px;
  font-size: 1.05rem;
  font-weight: 600;
  border: 2px solid transparent;
  border-radius: 12px;
  cursor: pointer;
}

.btn-primary {
  background: var(--brand);
  color: var(--brand-ink);
}

.btn-secondary {
  background: var(--secondary);
  color: var(--secondary-ink);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Fields */
.field {
  display: block;
  margin-bottom: 14px;
}

.field:last-child { margin-bottom: 0; }

.label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}

select,
input[type="text"] {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  font-size: 1.05rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
}

/* Preview + info */
.preview {
  display: block;
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  background: #eef2f0;
  border-radius: 12px;
  margin-bottom: 12px;
}

.info {
  margin: 0;
  display: grid;
  gap: 6px;
}

.info > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.info dt {
  color: var(--muted);
  margin: 0;
}

.info dd {
  margin: 0;
  font-weight: 600;
  text-align: right;
  word-break: break-word;
}

/* New-version banner: non-blocking, brand-green, sits above the screens. */
.update-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 16px;
  padding: 12px 14px;
  background: #e6f4ec;
  color: #0b5b3f;
  border: 2px solid var(--brand);
  border-radius: 12px;
  font-weight: 600;
}

.update-bar #updateMsg { flex: 1 1 auto; }

.update-btn {
  min-height: 40px;
  padding: 8px 16px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--brand-ink);
  background: var(--brand);
  border: none;
  border-radius: 10px;
  cursor: pointer;
}

.update-btn:disabled { opacity: 0.6; cursor: default; }

/* Messages */
.error { color: var(--error); font-weight: 600; margin: 4px 0 0; }

.warning {
  margin: 12px 0 0;
  padding: 10px 12px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-radius: 10px;
  font-weight: 600;
}

.status {
  margin: 12px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Outcome banner: green = saved, amber = not saved but retryable by the user,
   red = error / nothing saved. Always makes "saved vs not saved" obvious. */
.banner {
  margin: 0;
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 700;
  border: 2px solid transparent;
}

.banner.ok {
  background: #e6f4ec;
  color: #0b5b3f;
  border-color: #0b6b4f;
}

.banner.warn {
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-color: #caa53a;
}

.banner.err {
  background: #fdecea;
  color: #8f1a13;
  border-color: var(--error);
}

.banner .sub {
  display: block;
  margin-top: 6px;
  font-size: 0.95rem;
  font-weight: 600;
}

summary {
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
  display: flex;
  align-items: center;
}

/* Accessibility: visible focus */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* Receipt viewer eye + lightbox (TZ §11) */
.eye-cell { text-align: right; width: 1%; white-space: nowrap; }
.eye-btn { border: 0; background: none; cursor: pointer; font-size: 1.15rem; line-height: 1;
  padding: 4px 6px; min-height: 40px; }
.lightbox { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.82);
  display: flex; align-items: center; justify-content: center;
  padding: max(env(safe-area-inset-top), 16px) 12px max(env(safe-area-inset-bottom), 16px); }
.lightbox-inner { position: relative; max-width: 100%; max-height: 100%;
  display: flex; align-items: center; justify-content: center; }
.lightbox-body { max-width: 100%; max-height: 88vh; display: flex; }
.lightbox-img { max-width: 96vw; max-height: 88vh; object-fit: contain; background: #fff;
  border-radius: 8px; }
.lightbox-close { position: absolute; top: -6px; right: -2px; z-index: 1; background: rgba(0,0,0,.5);
  color: #fff; border: 0; width: 40px; height: 40px; border-radius: 999px; font-size: 1.6rem;
  line-height: 1; cursor: pointer; }
.lightbox-msg { color: #fff; padding: 2rem; font-size: 1.05rem; text-align: center; }

/* My receipts list — clear row separation + individually tappable actions
   (2026-08-11). Rows previously blurred together and the action links ran on as
   one word ("👁RefundSplit into parts"). */
.mine { width: 100%; border-collapse: collapse; }
.mine th { text-align: left; font-size: .75rem; letter-spacing: .02em; text-transform: uppercase;
  color: var(--muted); font-weight: 700; padding: 6px 8px; border-bottom: 2px solid #dfe5e2; }
.mine td { padding: 12px 8px; border-bottom: 1px solid #e6ebe8; vertical-align: middle; }
.mine tbody tr:last-child td { border-bottom: 0; }
/* Refunds (2026-08): row actions, badge, modal */
/* Actions: a flex row of comfortably-sized, individually tappable controls,
   each ~44px so neighbouring links never merge into one tap target. Buttons never
   shrink below their content (flex:0 0 auto) and WRAP to a second line on narrow
   phones instead of squeezing/clipping their labels. */
.row-actions { display: flex; flex-wrap: wrap; gap: 8px 12px;
  justify-content: flex-end; align-items: center; }
.row-actions .btn-link, .row-actions .eye-btn {
  flex: 0 0 auto; min-height: 44px; min-width: 44px; display: inline-flex;
  align-items: center; justify-content: center; padding: 6px 8px; white-space: nowrap; }
.btn-link { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit;
  text-decoration: underline; }
.btn-link.danger { color: var(--err, #b00020); }
.refund-row td { background: #fff8ef; }
.badge-refund { display: inline-block; background: #fde8cf; color: #8a4b00; font-size: .72rem;
  font-weight: 600; padding: 1px 7px; border-radius: 999px; vertical-align: middle; }
.refund-modal { flex-direction: column; align-items: stretch; background: var(--card, #fff);
  color: inherit; border-radius: 12px; padding: 18px; width: min(94vw, 460px);
  max-height: 90vh; overflow: auto; }
.refund-modal h2 { margin: 0 0 4px; }
.refund-info { margin: 6px 0 12px; padding: 10px 12px; background: #f5f7f6; border-radius: 8px;
  font-size: .9rem; }
.refund-info div { display: flex; gap: 8px; margin: 2px 0; }
.refund-info dt { color: var(--muted); min-width: 80px; font-weight: 600; }
.refund-info dd { margin: 0; }
/* Amount is the hero field: large, full-width, prominent. */
.hero-amount { font-size: 2rem; font-weight: 700; height: 64px; text-align: center;
  width: 100%; }
.fully-refunded { font-size: .8rem; font-style: italic; }

/* Notes (2026-08-19) */
.req-mark { color: var(--err, #b00020); font-weight: 600; font-size: .82rem; }
#notes, #refundNotes { width: 100%; min-height: 44px; font: inherit; padding: 8px;
  border: 1px solid var(--line, #cfd8d3); border-radius: 8px; resize: vertical; }
.note-line { display: block; color: var(--muted); font-size: .8rem; margin-top: 2px; }

/* Complex orders / split receipts (2026-08) */
.complex-toggle { display: flex; align-items: flex-start; gap: 8px; margin-top: 10px;
  font-size: .9rem; color: var(--muted); cursor: pointer; }
.complex-toggle input { margin-top: 2px; }
/* "Split ×N" badge on a My-receipts row (click to expand the parts). */
.tag-split { display: inline-block; background: #e3effb; color: #14538a; font-size: .72rem;
  font-weight: 600; padding: 2px 9px; border-radius: 999px; border: 0; cursor: pointer;
  vertical-align: middle; }
.split-detail-row td { background: #f4f8fd; padding: 8px 10px; }
.split-lines { display: flex; flex-direction: column; gap: 4px; }
.split-line { display: grid; grid-template-columns: 56px 1fr auto auto; gap: 10px;
  align-items: baseline; font-size: .86rem; }
.split-line-part { color: var(--muted); font-weight: 600; }
.split-line-amt { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
/* The remainder-calculator modal (desktop-first table; stacks on phones). */
.split-modal { flex-direction: column; align-items: stretch; background: var(--card, #fff);
  color: inherit; border-radius: 12px; padding: 18px; width: min(96vw, 720px);
  max-height: 92vh; overflow: auto; }
.split-modal h2 { margin: 0 0 4px; }
.split-head, .split-part { display: grid;
  grid-template-columns: 1fr 1fr 1fr 120px 34px; gap: 8px; align-items: center; }
.split-head { font-size: .78rem; color: var(--muted); font-weight: 600; margin: 8px 0 4px;
  padding: 0 2px; }
.split-part { margin: 4px 0; }
.split-part select, .split-part input { min-height: 40px; width: 100%; }
.split-amount { text-align: right; font-variant-numeric: tabular-nums; }
.split-head .num, .split-amount { text-align: right; }
/* Line 1 — the pinned living remainder: computed (read-only) amount, no remove. */
.split-part-pinned { background: #eef4fb; border-radius: 10px; padding: 6px; }
.split-part-pinned input.split-amount { background: #e1eaf4; color: var(--muted); cursor: default; }
.split-pin { text-align: center; align-self: center; }
.split-cap-msg { color: var(--err, #b00020); font-size: .82rem; margin: 6px 0 0; }
.split-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 12px 0; flex-wrap: wrap; }
.split-note { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--brand, #24913c); }
@media (max-width: 640px) {
  /* Stack each part vertically on phones; the header row is hidden (each field
     is self-explanatory as a full-width control). */
  .split-head { display: none; }
  .split-part { grid-template-columns: 1fr; gap: 6px; border: 1px solid var(--line, #e2e6e4);
    border-radius: 10px; padding: 10px; margin: 8px 0; }
  .split-line { grid-template-columns: 48px 1fr auto; }
  .split-line-gl { display: none; }
}

/* Forgot-password link + sub text (open question #7) */
.forgot { text-align: center; margin: 14px 0 0; }
.link-btn { background: none; border: 0; color: var(--brand); text-decoration: underline;
  cursor: pointer; font: inherit; min-height: 44px; padding: 8px; }
.sub { color: var(--muted); margin: 0 0 14px; }
