/* Dashboard chrome and components (login, merchant, admin).
   Rule order is load-bearing in at least one place: `.modal .foot` below sits
   AFTER `.qr-modal .foot` and, at equal specificity, wins. Splitting this file
   further would flip that and move the QR modal's Close button. */

body { font-feature-settings: "cv05", "cv11"; }

.topbar { display: flex; align-items: center; gap: 24px; padding: 16px 32px; border-bottom: 1px solid var(--rule-strong); }
.brand { font-family: "Geist", sans-serif; font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.brand em { font-style: normal; border-bottom: 3px solid var(--lime); padding-bottom: 1px; }
.topbar .role { font-size: 11px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--mute); }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 13px; color: var(--mute); }
@media (max-width: 640px) { .topbar { padding: 12px 16px; gap: 12px; } .topbar .who { display: none; } }

/* 1440 rather than 1160. The wide column carries tables up to ten columns
   across (the operators table), and at the old width those columns had ~56px
   of usable space each, so headers held their width with `white-space: nowrap`
   and the table scrolled sideways inside .tablewrap instead of fitting. The
   extra 280px goes entirely to the data: cell padding is deliberately NOT
   reduced to claw back space, because whitespace between columns is what makes
   a dense table readable - tightening it would have traded one kind of clutter
   for another. */
.wrap { max-width: 1440px; margin: 0 auto; padding: 40px 32px 96px; }
@media (max-width: 640px) { .wrap { padding: 24px 16px 64px; } }

/* Tables own the wide column; figures and tools sit in the rail.

   THE BREAKPOINT IS ONE DECISION IN THREE PLACES. The stack-vs-columns query
   below, the sticky-rail query under it, and the lead-rail block further down
   all pivot on 1024px and have to move together. Split them and you get the
   exact bug the lead-rail rules exist to prevent: a stacked layout that still
   thinks it is a two-column one.

   1024 rather than 900 because 901-1024px was the worst of both worlds - too
   narrow for a 320px rail beside a table, too wide to collapse. A small laptop
   was giving the operators table 568px. Stacked, it gets the full width. */
.workgrid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 48px; align-items: start; }
@media (max-width: 1080px) { .workgrid { grid-template-columns: minmax(0, 1fr); gap: 40px; } }
.rail { display: grid; gap: 40px; }
@media (min-width: 1025px) { .rail { position: sticky; top: 24px; } }

/* Merchant dashboard: the generator leads once the layout stacks.
   
   The panel is FIRST IN THE DOM (see merchant-dashboard.ejs), not merely moved
   with `order`. That distinction is the whole point: `order` moves pixels and
   leaves focus order behind, so a keyboard or screen-reader user would have
   seen Generate at the top of the page and then had to pass every voucher
   row's button and both pager controls - around thirteen tab stops - before
   reaching it. Stacked, the thing you see first is now the thing you reach
   first.

   Wide screens then rebuild the original arrangement with `order`: the rail
   back to the right, figures back above the generator. Reordering the two rail
   sections is safe in a way that reordering the page was not, because the
   figures block contains nothing focusable - there is no focus order inside it
   to contradict. */
@media (min-width: 1025px) {
	.workgrid.lead-rail > .rail { order: 1; }
	.workgrid.lead-rail .rail > .rail-lead { order: 1; }
}

.section { margin-bottom: 48px; }
.section:last-child { margin-bottom: 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.section-head .hint { color: var(--faint); font-size: 12px; }

@media (prefers-reduced-motion: no-preference) {
	tr.fresh { animation: fadein .35s ease; }
	@keyframes fadein { from { opacity: 0; } }
	.toast { animation: toastin .18s ease; }
	@keyframes toastin { from { transform: translateY(8px); opacity: 0; } }
}

/* Figures: numerals on hairlines rather than a row of boxes. */
.figures { display: grid; }
.figures .fig { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--rule); }
.figures .fig:first-child { border-top: 1px solid var(--rule-strong); }
.fig .k { font-size: 11px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--mute); }
.fig .v { font-family: "Geist", sans-serif; font-size: 28px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.fig .v .d { font-size: 14px; color: var(--faint); font-weight: 450; }
.figures.row { grid-auto-flow: column; grid-auto-columns: 1fr; border-top: 1px solid var(--rule-strong); border-bottom: 1px solid var(--rule); }
.figures.row .fig { flex-direction: column; align-items: flex-start; gap: 2px; border-bottom: 0; border-left: 1px solid var(--rule); padding: 16px 20px; }
.figures.row .fig:first-child { border-top: 0; border-left: 0; padding-left: 0; }
@media (max-width: 720px) { .figures.row { grid-auto-flow: row; grid-template-columns: 1fr 1fr; } .figures.row .fig:nth-child(odd) { border-left: 0; padding-left: 0; } .figures.row .fig { border-bottom: 1px solid var(--rule); } }

.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; padding: 8px 16px 8px 0; font-size: 11px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--mute); border-bottom: 1px solid var(--rule-strong); white-space: nowrap; }
td { padding: 12px 16px 12px 0; border-bottom: 1px solid var(--rule); vertical-align: middle; }
th:last-child, td:last-child { padding-right: 0; }
td.num { font-family: "Geist", sans-serif; font-variant-numeric: tabular-nums; }
.empty-row td { color: var(--faint); padding: 32px 0; text-align: left; font-size: 13px; }

/* Status labels. No dot: the colour and the word carry the state on their own,
   and a column of dots was noise at this density. */
.badge { font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; white-space: nowrap; }
.st-active, .st-redeemed, .st-approved { color: var(--ok); }
.st-pending, .st-requesting { color: var(--warn); }
.st-expired, .st-denied, .st-unavailable { color: var(--mute); }
.st-voided, .st-inactive { color: var(--bad); }
/* Secondary line under a cell value: a pool figure under a merchant's own count, a group name under its badge. */
td .sub { display: block; margin-top: 2px; color: var(--faint); font-size: 12px; font-weight: 450; letter-spacing: 0; text-transform: none; font-variant-numeric: tabular-nums; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 16px; border: 1px solid var(--ink); border-radius: 4px; background: transparent; color: var(--ink); font-size: 13.5px; font-weight: 550; text-decoration: none; transition: background .12s ease, color .12s ease; }
.btn:hover { background: var(--ink); color: var(--paper); }
.btn.primary { background: var(--lime); border-color: var(--lime); color: var(--lime-ink); font-weight: 600; }
.btn.primary:hover { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn.danger:hover { background: var(--bad); color: #fff; }
.btn.ghost { border-color: var(--rule); color: var(--mute); }
.btn.ghost:hover { border-color: var(--ink); background: transparent; color: var(--ink); }
.btn.sm { padding: 5px 12px; font-size: 12.5px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.actions { display: flex; gap: 8px; }

label { display: block; font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--mute); margin-bottom: 6px; }
input, select { width: 100%; padding: 9px 12px; border: 1px solid var(--rule); border-radius: 4px; background: var(--surface); color: var(--ink); }
input:focus, select:focus { outline: none; border-color: var(--ink); }
.check { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--ink); text-transform: none; letter-spacing: 0; font-weight: 450; }
.check input { width: auto; accent-color: var(--pine); }
.formgrid { display: grid; gap: 16px; }
.note { margin: 0; color: var(--faint); font-size: 12px; }

.value-line { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--rule); }

/* Shared-pool status under the generate button (merchants in a voucher group).
   The state class is rendered server-side and rewritten live from pool.updated. */
.pool-status { display: grid; gap: 6px; }
.pool-status .pool-warn { display: none; font-weight: 550; }
.pool-status.low .pool-warn { display: block; color: var(--warn); }
.pool-status.out .pool-warn { display: block; color: var(--bad); }
.pool-status.low #pool-remaining { color: var(--warn); font-weight: 650; }
.pool-status.out #pool-remaining { color: var(--bad); font-weight: 650; }

.qr-result { display: none; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--rule); gap: 20px; }
.qr-result.show { display: flex; flex-wrap: wrap; }
.qr-result img { width: 168px; height: 168px; object-fit: contain; border: 1px solid var(--rule); background: #fff; cursor: zoom-in; }
.modal.qr-modal { max-width: none; width: auto; text-align: center; }
.qr-modal img { display: block; width: min(82vw, 560px); max-height: 76vh; object-fit: contain; background: #fff; border: 1px solid var(--rule); }
.qr-modal .caption { margin-top: 12px; }
.qr-modal .foot { justify-content: center; margin-top: 16px; }
.qr-meta { display: grid; gap: 10px; align-content: start; font-size: 13.5px; min-width: 0; }
.qr-meta .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; min-width: 0; }
.qr-meta code { word-break: break-all; }

.modal-back { display: none; position: fixed; inset: 0; background: rgba(10, 16, 12, .5); z-index: 50; align-items: center; justify-content: center; padding: 16px; }
.modal-back.show { display: flex; }
.modal { background: var(--paper); border: 1px solid var(--rule); border-radius: 6px; box-shadow: var(--shadow); padding: 28px; width: 100%; max-width: 440px; max-height: 90vh; overflow-y: auto; }
.modal h2 { margin-bottom: 20px; }
.modal .grid { display: grid; gap: 16px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.secret-box { border-top: 1px solid var(--rule-strong); padding-top: 12px; margin-top: 4px; font-size: 13.5px; display: none; }
.secret-box.show { display: block; }
.secret-box .row { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.secret-box .once { color: var(--warn); font-weight: 600; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; }

.feed { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule-strong); max-height: 380px; overflow-y: auto; font-size: 13.5px; }
.feed li { padding: 10px 0; border-bottom: 1px solid var(--rule); display: flex; gap: 14px; align-items: baseline; }
.feed .t { font-family: "Geist", sans-serif; color: var(--faint); font-variant-numeric: tabular-nums; font-size: 12px; white-space: nowrap; }
.feed .empty { color: var(--faint); padding: 28px 0; }
.live-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--lime); margin-right: 8px; vertical-align: 1px; }

.pager { display: flex; align-items: center; gap: 16px; margin-top: 16px; }
.pager-label { font-family: "Geist", sans-serif; font-size: 12.5px; color: var(--mute); font-variant-numeric: tabular-nums; }

.toast-zone { position: fixed; right: 24px; bottom: 24px; display: grid; gap: 8px; z-index: 100; width: min(420px, calc(100vw - 48px)); max-height: calc(100vh - 48px); overflow-y: auto; }
.toast { background: var(--ink); color: var(--paper); border-radius: 4px; padding: 12px 16px; font-size: 13.5px; max-width: 360px; }
.toast.err { background: var(--bad); color: #fff; }
.toast.request-toast { display: grid; gap: 10px; width: 100%; max-width: none; }
.toast.request-toast .btn.danger { background: var(--bad); color: #fff; }
.request-toast-copy { display: grid; gap: 2px; }
.request-toast-copy strong { font-family: "Geist", sans-serif; font-size: 14px; font-weight: 650; }
.request-toast-actions { display: flex; justify-content: flex-end; gap: 8px; }
@media (max-width: 640px) { .toast-zone { right: 16px; bottom: 16px; width: calc(100vw - 32px); max-height: calc(100dvh - 32px); } }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 32px 24px; }
.login-card { width: 100%; max-width: 320px; }
.login-card .brand { display: block; font-size: 20px; margin-bottom: 28px; }
.login-card h1 { font-size: 22px; margin-bottom: 24px; }
.login-card .grid { display: grid; gap: 18px; }
.login-card .btn { width: 100%; padding: 11px; }
.form-err { display: none; color: var(--bad); font-size: 13px; margin: 0; }
.form-err.show { display: block; }

/* Voucher logo: the thumbnail in the operators table, and the before/after
   preview inside the create and edit modals. Both letterbox rather than crop -
   the admin is checking whether the artwork reads correctly at a glance, and a
   cropped preview would not tell them the truth about what customers see. */
.logo-thumb { height: 28px; max-width: 84px; object-fit: contain; display: block;
	background: var(--rule); border: 1px solid var(--rule); border-radius: 3px; }
.logo-preview { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.logo-preview img { height: 44px; max-width: 130px; object-fit: contain;
	background: var(--rule); border: 1px solid var(--rule); border-radius: 4px; }
.logo-preview span { color: var(--mute); font-size: 12px; }
/* A custom logo gets a visible outline so "this merchant has their own" is
   readable without comparing against the default from memory. */
.logo-preview.custom img { border-color: var(--pine); }

/* Bulk QR selection (admin voucher table) */
.bulkbar { display: flex; align-items: center; gap: 16px; padding: 10px 0; border-top: 1px solid var(--rule-strong); }
.bulkbar .hint { color: var(--faint); font-size: 12px; flex: 1; font-variant-numeric: tabular-nums; }
td.pick, th:first-child:empty { width: 32px; }
td.pick input { accent-color: var(--pine); }

/* Pre-generation panel */
.batch-status { display: none; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--rule); font-size: 13.5px; }
.batch-status.show { display: block; }
.batch-status .row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.batch-status .k { font-size: 11px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--mute); }
.progress { height: 4px; background: var(--rule); border-radius: 2px; overflow: hidden; margin-top: 10px; }
.progress span { display: block; height: 100%; width: 0; background: var(--lime); transition: width .3s ease; }

/* QR modal: the image is fetched, so there is a real loading state to show */
.qr-stage { min-height: 120px; display: grid; place-items: center; }
.qr-stage img:not([src]) { display: none; }
.qr-status { color: var(--mute); font-size: 13px; max-width: 42ch; text-align: center; margin: 24px 0; }
.qr-status:empty { display: none; margin: 0; }
.qr-modal .caption code { word-break: break-all; font-size: 12px; }
