/* ============================================================
   Soprano Checker — "Quiet ledger"
   Monochrome graphite; colour is reserved for meaning.
   ============================================================ */

/* ---------- tokens: light ---------- */
:root {
  --ground: #EDEEF0;
  --surface: #FFFFFF;
  --surface-2: #F6F7F8;
  --hair: rgba(31, 35, 40, .10);
  --hair-2: rgba(31, 35, 40, .18);
  --ink: #1F2328;
  --ink-2: #5B6168;
  --ink-3: #8B9299;
  --primary: #1F2328;
  --primary-ink: #FFFFFF;
  --ok: #1F7A4D;
  --bad: #B23A3A;
  --warn: #A16207;
  --ok-soft: rgba(31, 122, 77, .10);
  --bad-soft: rgba(178, 58, 58, .10);
  --warn-soft: rgba(161, 98, 7, .12);
  --scrim: rgba(31, 35, 40, .45);
  --dlg-shadow: 0 24px 64px rgba(31, 35, 40, .18);

  --r-surface: 10px;
  --r-control: 10px;
  --r-seg: 8px;

  --font: 'Hanken Grotesk', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  /* legacy aliases referenced by scripts */
  --muted: var(--ink-3);
  --green: var(--ok);
  --red: var(--bad);
  --amber: var(--warn);
}

/* ---------- tokens: dark ---------- */
body:not(.light) {
  --ground: #1D2026;
  --surface: #262A31;
  --surface-2: #2C3038;
  --hair: rgba(232, 234, 237, .10);
  --hair-2: rgba(232, 234, 237, .20);
  --ink: #E8EAED;
  --ink-2: #AEB4BC;
  --ink-3: #7E858E;
  --primary: #E8EAED;
  --primary-ink: #1D2026;
  --ok: #58C48A;
  --bad: #F08A8A;
  --warn: #E2B33C;
  --ok-soft: rgba(88, 196, 138, .14);
  --bad-soft: rgba(240, 138, 138, .14);
  --warn-soft: rgba(226, 179, 60, .14);
  --scrim: rgba(0, 0, 0, .55);
  --dlg-shadow: 0 24px 64px rgba(0, 0, 0, .45);
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html, body { height: 100%; }
body {
  background: var(--ground);
  color: var(--ink);
  font: 400 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; }
h1, h2, h3 { font-weight: 500; line-height: 1.3; }
::selection { background: var(--ink); color: var(--ground); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 4px; }

/* ---------- utilities ---------- */
.is-hidden { display: none; }
.d-none { display: none !important; }
.text-muted { color: var(--ink-3); }
.form-text { display: block; margin-top: 6px; }
#proxyConfigStatus { margin-top: 10px; }
#generatorMessage { margin-top: 16px; }
#cardTypeBadge, #binCheckResult { margin-top: 6px; }
#binCheckResult { color: var(--ink-3); }

/* ---------- auth visibility gating ---------- */
.shell { display: none; }
#authGate { display: none; }
#expiredOverlay { display: none; }
body.authed .shell { display: flex; }
body.unauth #authGate { display: grid; }
body.expired #expiredOverlay { display: grid; }

#viewNav { display: none; }
body.role-admin #viewNav { display: flex; }
.tab-solo { display: inline-flex; }
body.role-admin .tab-solo { display: none; }
.session-pill { display: none; }
body.role-user #sessionPill { display: inline-flex; }
#adminView { display: none; }
body.admin-view-active #checkerView { display: none; }
body.admin-view-active #adminView { display: block; }
#settingsView { display: none; }
body.settings-view-active #checkerView { display: none; }
body.settings-view-active #settingsView { display: block; }

/* ============================================================
   shell + header
   ============================================================ */
.shell { flex-direction: column; height: 100vh; height: 100dvh; }

.header { background: var(--surface); border-bottom: 1px solid var(--hair); flex: none; }
.header-inner { max-width: 1200px; margin: 0 auto; padding: 0 32px; }
.wordrow { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 16px; }
.wordmark { display: flex; align-items: center; gap: 12px; font-weight: 500; font-size: 19px; letter-spacing: -.01em; white-space: nowrap; }
.wordmark-logo { width: 26px; height: 26px; border-radius: 7px; }

.session-pill {
  align-items: center; gap: 8px; color: var(--ink-2); font-weight: 300; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.session-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.session-pill.warn { color: var(--warn); }
.session-pill.warn::before { background: var(--warn); }
.session-pill.crit { color: var(--bad); }
.session-pill.crit::before { background: var(--bad); }

.tabbar { display: flex; align-items: stretch; gap: 4px; height: 44px; }
.tab-group { display: flex; gap: 4px; }
.tab {
  display: inline-flex; align-items: center; gap: 8px; padding: 0 14px;
  background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px;
  color: var(--ink-2); font-weight: 400; white-space: nowrap; border-radius: 0;
}
.tab i { font-size: 12px; opacity: .75; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 500; }
.tab.active i { opacity: 1; }
.tab:focus-visible { outline-offset: -2px; }
.tab-spacer { flex: 1; }
/* These two buttons have their innerHTML replaced by script.js (icon only), so the label lives in CSS. */
.tab-theme::after { content: "Theme"; }
.tab-fullscreen::after { content: "Full screen"; }

/* ============================================================
   main layout
   ============================================================ */
.main { flex: 1; min-height: 0; width: 100%; max-width: 1200px; margin: 0 auto; padding: 28px 32px 32px; display: flex; flex-direction: column; }
#checkerView { flex: 1; min-height: 0; display: grid; grid-template-columns: 380px 1fr; gap: 28px; }
.col { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

.sect-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; gap: 12px; }
.sect-head h2 { font-size: 15px; font-weight: 500; }
.sect-head .meta { color: var(--ink-3); font-weight: 300; font-variant-numeric: tabular-nums; }

.surface { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--r-surface); }

/* ---------- queue column ---------- */
#cardList {
  width: 100%; flex: 1; min-height: 200px; resize: none;
  padding: 16px 18px; border: 1px solid var(--hair); border-radius: var(--r-surface);
  background: var(--surface); color: var(--ink); line-height: 1.75;
  font-variant-numeric: tabular-nums; letter-spacing: .01em;
}
#cardList::placeholder { color: var(--ink-3); font-weight: 300; }
#cardList:focus { outline: none; border-color: var(--hair-2); }

.gate { margin-top: 20px; }
.gate-list { display: flex; flex-direction: column; border: 1px solid var(--hair); border-radius: var(--r-surface); overflow: hidden; background: var(--surface); }
.gate-btn {
  display: flex; align-items: center; justify-content: space-between; padding: 11px 16px;
  background: none; border: 0; border-bottom: 1px solid var(--hair); border-radius: 0;
  text-align: left; color: var(--ink-2);
}
.gate-btn:last-child { border-bottom: 0; }
.gate-btn:hover { color: var(--ink); background: var(--surface-2); }
.gate-btn.active { color: var(--ink); font-weight: 500; }
.gate-btn.active::after { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ink); }
.gate-btn:focus-visible { outline-offset: -2px; }

.actions { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 12px 18px; border-radius: var(--r-control); border: 1px solid transparent;
  font-weight: 500; line-height: 1.2; text-decoration: none;
}
.btn i { font-size: .9em; }
.btn-primary, .btn-success { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover, .btn-success:hover { opacity: .9; }
.btn-quiet, .btn-secondary, .btn-outline-light { background: transparent; color: var(--ink-2); border-color: var(--hair-2); }
.btn-quiet:hover, .btn-secondary:hover, .btn-outline-light:hover { color: var(--ink); background: var(--surface-2); }
.btn-outline-light.active { color: var(--ink); }
.btn-stop, .btn-danger { color: var(--bad); background: transparent; border-color: var(--hair-2); }
.btn-stop:hover, .btn-danger:hover { background: var(--bad-soft); color: var(--bad); }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }

.textbtn {
  display: inline-flex; align-items: center; gap: 8px;
  background: none; border: 0; padding: 8px 10px; border-radius: var(--r-seg);
  color: var(--ink-2); font-weight: 400;
}
.textbtn:hover { color: var(--ink); background: var(--surface-2); }
.textbtn.active { color: var(--ink); }

/* ---------- results column ---------- */
.status-line { display: flex; justify-content: space-between; align-items: baseline; color: var(--ink-2); font-weight: 300; margin-bottom: 10px; gap: 16px; }
.status-text { display: inline-flex; align-items: baseline; gap: 10px; min-width: 0; }
#status { color: var(--ink); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 320px; }
.status-count { white-space: nowrap; }
.status-count b { font-weight: 500; color: var(--ink); font-variant-numeric: tabular-nums; }

.progress { height: 2px; background: var(--hair); border-radius: 2px; overflow: hidden; margin: 0 0 14px; flex: none; }
#progressBar { height: 100%; width: 0; background: var(--ink); }

.results { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.results-head { display: flex; align-items: center; padding: 6px 10px 6px 6px; border-bottom: 1px solid var(--hair); gap: 4px; flex-wrap: wrap; }
.seg-tabs { display: flex; gap: 2px; }
.seg-tab {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px;
  border-radius: var(--r-seg); background: none; border: 0; color: var(--ink-2); white-space: nowrap;
}
.seg-tab:hover { color: var(--ink); }
.seg-tab.active { background: var(--surface-2); color: var(--ink); font-weight: 500; }
.seg-tab .n { font-variant-numeric: tabular-nums; color: var(--ink-3); font-weight: 400; }
.seg-tab.active .n { color: var(--ink); }
.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.dot-ok { background: var(--ok); }
.dot-bad { background: var(--bad); }
.dot-warn { background: var(--warn); }
.results-tools { margin-left: auto; display: flex; gap: 2px; }

.results-pane { display: none; flex: 1; min-height: 0; overflow: auto; }
.results-pane.active { display: block; }
.list { min-height: 100%; }

.item {
  display: grid; grid-template-columns: 64px 26px 1fr auto auto; align-items: center; gap: 14px;
  padding: 0 18px; min-height: 46px; border-bottom: 1px solid var(--hair);
  font-variant-numeric: tabular-nums; cursor: pointer;
}
.item:hover { background: var(--surface-2); }
.item .ts { grid-column: 1; grid-row: 1; color: var(--ink-3); font-weight: 300; font-size: 13px; }
.item > svg { grid-column: 2; grid-row: 1; width: 24px; height: 16px; border-radius: 3px; }
.item .card-text { grid-column: 3; grid-row: 1; font-size: 14px; letter-spacing: .02em; word-break: break-all; min-width: 0; }
.item .ms { grid-column: 4; grid-row: 1; color: var(--ink-3); font-weight: 300; font-size: 13px; white-space: nowrap; }
.item::after { grid-column: 5; grid-row: 1; font-size: 13px; font-weight: 500; padding: 3px 10px; border-radius: 999px; white-space: nowrap; justify-self: end; }
.item.approved::after { content: "Approved"; color: var(--ok); background: var(--ok-soft); }
.item.declined::after { content: "Declined"; color: var(--bad); background: var(--bad-soft); }
.item.error::after { content: "Error"; color: var(--warn); background: var(--warn-soft); }
/* rows whose brand icon is absent still get the full grid: the svg slot collapses to empty */
.item .item-detail {
  grid-column: 1 / -1; grid-row: 2; padding: 0 0 12px 104px; margin-top: -6px;
  color: var(--ink-2); font-size: 13px; font-weight: 300; white-space: pre-wrap; word-break: break-all; cursor: text;
}

.list:empty::after { display: block; padding: 40px 18px; color: var(--ink-3); font-weight: 300; text-align: center; }
#approved-pane .list:empty::after { content: "Approved cards will appear here."; }
#declined-pane .list:empty::after { content: "Declined cards will appear here."; }
#error-pane .list:empty::after { content: "Cards that could not be checked will appear here."; }

/* ============================================================
   forms
   ============================================================ */
.form-group { margin-bottom: 16px; }
.form-label { display: block; color: var(--ink-2); font-size: 13px; margin-bottom: 6px; }
.form-control {
  display: block; width: 100%; padding: 11px 14px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--hair-2); border-radius: var(--r-control);
}
.form-control::placeholder { color: var(--ink-3); font-weight: 300; }
.form-control:focus { outline: none; border-color: var(--ink-3); }
select.form-control { appearance: none; -webkit-appearance: none; padding-right: 36px; background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: calc(100% - 19px) 50%, calc(100% - 14px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.form-text, .dlg-body .text-muted { font-size: 13px; color: var(--ink-3); font-weight: 300; }
#binInput, #quantityInput, #proxyStringModal, #loginToken { font-variant-numeric: tabular-nums; letter-spacing: .02em; }
#cardTypeBadge, #binCheckResult { font-size: 13px; }
.control-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.checkbox-row { display: flex; align-items: center; gap: 10px; color: var(--ink); cursor: pointer; margin-bottom: 10px; }
.checkbox-row input { width: 16px; height: 16px; margin: 0; accent-color: var(--ink); }
.gate-checks .checkbox-row { margin: 0 0 6px; font-size: 13.5px; }

.alert { border-radius: var(--r-seg); padding: 10px 14px; font-size: 13.5px; }
.alert-danger { background: var(--bad-soft); color: var(--bad); }
.alert-success { background: var(--ok-soft); color: var(--ok); }
.alert-info { background: var(--surface-2); color: var(--ink-2); }
#proxyTestResult { font-size: 13px; }

.pw-wrap { position: relative; }
.pw-wrap .form-control { padding-right: 44px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; border: 0; background: none; color: var(--ink-3); border-radius: 8px; }
.pw-toggle:hover { color: var(--ink); background: var(--surface-2); }

/* ============================================================
   dialogs
   ============================================================ */
dialog.dlg {
  margin: auto; padding: 0; width: min(520px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--hair); border-radius: 14px; box-shadow: var(--dlg-shadow);
}
dialog.dlg::backdrop { background: var(--scrim); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 0; }
.dlg-title { font-size: 17px; font-weight: 500; }
.dlg-close { width: 34px; height: 34px; border: 0; background: none; color: var(--ink-3); font-size: 24px; line-height: 1; border-radius: 8px; margin-right: -8px; }
.dlg-close:hover { color: var(--ink); background: var(--surface-2); }
.dlg-body { padding: 20px 24px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 0 24px 24px; }
.dlg-foot .btn { padding: 10px 16px; }

.settings-section { max-width: 520px; }
.settings-foot { margin-top: 20px; display: flex; justify-content: flex-end; }

/* ============================================================
   login + expired
   ============================================================ */
#authGate { position: fixed; inset: 0; background: var(--ground); place-items: center; z-index: 5000; padding: 24px; }
#loginCard { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--hair); border-radius: 14px; padding: 32px; }
.login-wordmark { margin-bottom: 6px; }
.login-sub { color: var(--ink-2); font-weight: 300; margin-bottom: 24px; }
.login-field { margin-bottom: 16px; }
.login-submit { width: 100%; margin-top: 8px; }
#loginError { margin-bottom: 14px; }

.seg { display: flex; gap: 2px; padding: 3px; background: var(--surface-2); border-radius: var(--r-control); margin-bottom: 20px; }
.seg .seg-btn { flex: 1; padding: 8px 12px; border: 0; background: none; border-radius: 8px; color: var(--ink-2); }
.seg .seg-btn.active { background: var(--surface); color: var(--ink); font-weight: 500; }

#expiredOverlay { position: fixed; inset: 0; background: var(--scrim); place-items: center; z-index: 6000; padding: 24px; }
.overlay-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--hair); border-radius: 14px; padding: 32px; box-shadow: var(--dlg-shadow); }
.overlay-title { font-size: 17px; font-weight: 500; margin-bottom: 8px; }
.overlay-text { color: var(--ink-2); font-weight: 300; margin-bottom: 24px; }

/* ============================================================
   admin
   ============================================================ */
#adminView { overflow-y: auto; display: none; gap: 24px; }
body.admin-view-active #adminView { display: flex; flex-direction: column; }
.admin-section { padding: 24px; }
.admin-gen { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; }
.admin-field { min-width: 150px; }
.admin-field-grow { flex: 1; min-width: 220px; }
.admin-gen .btn { padding: 11px 18px; }
.new-token { margin-top: 18px; padding: 16px 18px; background: var(--surface-2); border-radius: var(--r-control); }
.new-token .nt-label { font-size: 13px; color: var(--ink-2); font-weight: 300; margin-bottom: 8px; }
.new-token .nt-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.new-token .nt-value { font-size: 16px; font-weight: 500; letter-spacing: .06em; font-variant-numeric: tabular-nums; }

.table-wrap { overflow-x: auto; }
#tokensTable { width: 100%; border-collapse: collapse; font-size: 13.5px; }
#tokensTable th { text-align: left; color: var(--ink-3); font-weight: 400; font-size: 13px; padding: 8px 12px; border-bottom: 1px solid var(--hair); white-space: nowrap; }
#tokensTable td { padding: 11px 12px; border-bottom: 1px solid var(--hair); vertical-align: middle; }
#tokensTable tr:last-child td { border-bottom: 0; }
#tokensTable .tok-value { font-variant-numeric: tabular-nums; letter-spacing: .03em; }
#tokensTable .tok-left { font-variant-numeric: tabular-nums; }
#tokensTable .tok-ip { font-variant-numeric: tabular-nums; white-space: nowrap; }
#tokensTable .tok-sub { display: block; color: var(--ink-3); font-size: 12px; font-weight: 300; white-space: nowrap; }
#tokensTable .col-actions, #tokensTable td.col-actions { text-align: right; }
#tokensTable .row-actions { display: inline-flex; gap: 4px; }
#tokensTable .row-actions .btn { border-color: transparent; }

.status-badge { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; text-transform: capitalize; }
.status-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-unused { color: var(--ink-3); }
.status-active { color: var(--ok); }
.status-expired { color: var(--bad); }
.status-revoked { color: var(--warn); }
.gate-tag { display: inline-block; padding: 2px 8px; margin: 1px 2px 1px 0; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-size: 12px; }
.admin-empty { color: var(--ink-3); font-weight: 300; padding: 24px; text-align: center; }

/* ============================================================
   toast + motion
   ============================================================ */
.duplicate-alert {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 12px);
  display: flex; align-items: center; gap: 10px; padding: 11px 16px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--hair-2); border-radius: var(--r-control);
  box-shadow: var(--dlg-shadow); opacity: 0; z-index: 7000; pointer-events: none; font-size: 13.5px;
}
.duplicate-alert i { color: var(--ink-2); }
.duplicate-alert.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes value-pop { 0% { transform: scale(1.18); opacity: .5; } 100% { transform: scale(1); opacity: 1; } }
.value-pop { display: inline-block; }

@media (prefers-reduced-motion: no-preference) {
  #progressBar { transition: width .3s ease-out; }
  .duplicate-alert { transition: opacity .2s, transform .2s; }
  .value-pop { animation: value-pop .3s cubic-bezier(.34, 1.56, .64, 1); }
  .tab, .gate-btn, .btn, .textbtn, .seg-tab { transition: color .15s, background-color .15s, border-color .15s; }
}

/* ============================================================
   responsive
   ============================================================ */
@media (max-width: 960px) {
  .header-inner { padding: 0 18px; }
  .tabbar { overflow-x: auto; scrollbar-width: none; }
  .tabbar::-webkit-scrollbar { display: none; }
  .main { padding: 20px 18px 24px; overflow: auto; display: block; }
  #checkerView { display: block; }
  .col-queue { margin-bottom: 24px; }
  #cardList { min-height: 160px; flex: none; }
  .results { min-height: 440px; }
  .results-pane { max-height: 60vh; }
  .item { grid-template-columns: 54px 1fr auto; }
  .item > svg, .item .ms { display: none; }
  .item .card-text { grid-column: 2; }
  .item::after { grid-column: 3; }
  .item .item-detail { padding-left: 0; }
}
@media (max-width: 600px) {
  .wordrow { height: 54px; }
  .wordmark { font-size: 17px; }
  .tab-fullscreen { display: none; }
  .btn-row { flex-wrap: wrap; }
  .btn-row .btn { flex: 1 1 calc(50% - 5px); }
  .status-line { flex-wrap: wrap; }
  #status { max-width: 200px; }
  .results-head { padding: 6px; }
  .results-tools { margin-left: 0; width: 100%; justify-content: flex-end; }
  .control-row { grid-template-columns: 1fr; }
  #loginCard, .overlay-card { padding: 24px; }
  .admin-section { padding: 18px; }
}
