/* Thummer Consumer. Same design as the thummer admin console; served under a strict CSP:
   no inline styles anywhere. */

/* Theme: every color is a light-dark() pair; color-scheme picks the half. "System" follows the OS;
   theme.js sets data-theme="light"/"dark" on <html> for an explicit choice (before first paint). */
:root {
  color-scheme: light dark;
  --page: light-dark(#f9f9f7, #0d0d0d);
  --surface: light-dark(#fcfcfb, #1a1a19);
  --surface-2: light-dark(#f3f2ef, #232321);
  --ink: light-dark(#0b0b0b, #ffffff);
  --ink-2: light-dark(#52514e, #c3c2b7);
  --muted: light-dark(#6f6d68, #9d9b93);
  --axis: #898781;
  --grid: light-dark(#e1e0d9, #2c2c2a);
  --baseline: light-dark(#c3c2b7, #383835);
  --border: light-dark(rgba(11, 11, 11, 0.12), rgba(255, 255, 255, 0.12));
  --accent: light-dark(#2a78d6, #3987e5);
  --accent-ink: #ffffff;
  --accent-wash: light-dark(rgba(42, 120, 214, 0.10), rgba(57, 135, 229, 0.16));
  --danger: light-dark(#c23434, #e66767);
  --danger-wash: light-dark(rgba(208, 59, 59, 0.10), rgba(230, 103, 103, 0.14));
  --good: #0ca30c;
  --good-ink: light-dark(#006300, #0ca30c);
  --warn-ink: light-dark(#8a5a00, #fab219);
  --warn-wash: light-dark(rgba(250, 178, 25, 0.18), rgba(250, 178, 25, 0.14));
  --series-1: light-dark(#2a78d6, #3987e5); /* accepted / committed */
  --series-2: light-dark(#eb6834, #d95926); /* rejected */
  --series-3: light-dark(#1baf7a, #199e70); /* duplicate */
  --hover-band: light-dark(rgba(11, 11, 11, 0.05), rgba(255, 255, 255, 0.06));
  --shadow: 0 1px 2px light-dark(rgba(0, 0, 0, 0.06), rgba(0, 0, 0, 0.4)), 0 4px 16px light-dark(rgba(0, 0, 0, 0.06), transparent);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

:root { --topbar-h: 56px; --sidebar-w: 220px; }

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 650; margin: 0; }
h3 { font-size: 13px; font-weight: 600; margin: 0; color: var(--ink-2); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  height: var(--topbar-h); padding: 0 24px 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-logo { width: 28px; height: 28px; flex: none; }

/* Two logo artworks: a black outline for light backgrounds, a softer grey one for dark. Show the
   one for the theme in effect: data-theme when the user picked one, otherwise the OS setting. */
.logo-for-dark { display: none; }
:root[data-theme="dark"] .logo-for-light { display: none; }
:root[data-theme="dark"] .logo-for-dark { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo-for-light { display: none; }
  :root:not([data-theme="light"]) .logo-for-dark { display: block; }
}
.brand-sub { font-weight: 500; color: var(--muted); font-size: 13px; }
.icon-btn {
  display: grid; place-items: center; flex: none;
  width: 36px; height: 36px; padding: 0; border: none; border-radius: 8px;
  background: transparent; color: var(--ink-2);
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
:root[data-sidebar="closed"] .toggle-fill { opacity: 0; }

/* ---- menu column (left) ---- */
.shell { display: flex; align-items: flex-start; }
.sidebar {
  position: sticky; top: var(--topbar-h); flex: none;
  width: var(--sidebar-w); height: calc(100vh - var(--topbar-h));
  display: flex; flex-direction: column; gap: 2px;
  padding: 14px 10px 24px;
  overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
}
:root[data-sidebar="closed"] .sidebar { display: none; }
.sidebar a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 550;
}
.sidebar a svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.sidebar a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.sidebar a[aria-current="page"] { background: var(--accent-wash); color: var(--accent); }
/* The chosen consumer: a selector, then its pages. */
.nav-consumer { display: flex; flex-direction: column; gap: 2px; }
#nav-consumers:not([hidden]) + .nav-consumer { margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--grid); }
.nav-label { padding: 0 10px; margin: 0 0 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.nav-consumer select { width: auto; margin: 0 4px 8px; min-height: 34px; font-size: 13px; text-overflow: ellipsis; }
.nav-empty { padding: 4px 10px; margin: 0; }
.sidebar-backdrop { position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 25; background: rgb(0 0 0 / 0.35); }

main { flex: 1; min-width: 0; }

.topbar .spacer { flex: 1; }
/* Account menu: one button in the top bar opening who / theme / change password / log out. */
.user-menu { position: relative; }
.user-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px; border-radius: 999px;
  background: transparent; border-color: var(--border); color: var(--ink-2); font-size: 13px; font-weight: 550;
}
.user-btn:hover:not(:disabled), .user-btn[aria-expanded="true"] { background: var(--surface-2); }
.user-btn .email { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-btn .chev { flex: none; transition: transform 0.15s; }
.user-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }
.avatar {
  display: grid; place-items: center; flex: none;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-wash); color: var(--accent); font-weight: 700; font-size: 12.5px;
}
.user-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  width: min(280px, calc(100vw - 32px));
  padding: 6px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); box-shadow: var(--shadow), 0 8px 28px rgb(0 0 0 / 0.14);
}
.user-pop[hidden] { display: none; }
.user-head { padding: 8px 10px; display: grid; gap: 4px; justify-items: start; }
.user-email { font-weight: 600; overflow-wrap: anywhere; }
.menu-sep { height: 1px; background: var(--border); margin: 6px 0; }
.menu-label { padding: 4px 10px; font-size: 12px; color: var(--muted); }
.theme-seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; margin: 2px 8px 6px; padding: 2px; border-radius: 8px; background: var(--surface-2); }
.theme-seg button { border: none; background: transparent; padding: 5px 0; font-size: 12.5px; border-radius: 6px; color: var(--ink-2); }
.theme-seg button[aria-checked="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }
.menu-item {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border: none; border-radius: 6px;
  background: transparent; color: var(--ink); font-size: 13.5px; font-weight: 500;
}
.menu-item:hover, .menu-item:focus-visible, .theme-seg button:focus-visible { background: var(--surface-2); text-decoration: none; }
.menu-item:focus-visible, .theme-seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---- layout ---- */
main { max-width: 1240px; margin: 0 auto; padding: 24px 24px 72px; }
.page-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-bottom: 18px;
}
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stack { display: grid; gap: 18px; }
.grid-2 { display: grid; gap: 18px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-2.wide-right { grid-template-columns: minmax(0, 1fr) minmax(0, 1.7fr); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  min-width: 0;
}
.card-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-bottom: 12px;
}
.card-head .sub { color: var(--muted); font-size: 12.5px; }
.is-refreshing { opacity: 0.55; transition: opacity 0.2s; }

/* ---- buttons & forms ---- */
button, .btn {
  font: inherit; font-weight: 550; font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 32px; padding: 6px 12px;
  border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink);
  cursor: pointer; white-space: nowrap;
}
button:hover:not(:disabled) { background: var(--surface-2); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
button.danger:hover:not(:disabled) { background: var(--danger-wash); }
button.danger.solid { background: var(--danger); color: #fff; }
button.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
button.ghost:hover:not(:disabled) { background: var(--surface-2); }
button.small { min-height: 28px; padding: 3px 9px; font-size: 12.5px; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; padding: 2px; background: var(--surface); }
.segmented button { border: 0; min-height: 28px; padding: 3px 12px; border-radius: 6px; background: transparent; color: var(--ink-2); }
.segmented button[aria-pressed="true"] { background: var(--accent-wash); color: var(--accent); }

label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], select {
  font: inherit; font-size: 14px; color: var(--ink);
  width: 100%; min-height: 36px; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface);
}
select.inline { width: auto; min-height: 30px; padding: 3px 8px; font-size: 13px; }
input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); font-size: 13.5px; }
.check input { width: 16px; height: 16px; margin: 0; }
.field { min-width: 0; }
/* Password field with a Show/Hide toggle inside its right edge. */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 62px; }
button.reveal {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  min-height: 28px; padding: 2px 10px; font-size: 12px;
  border-color: transparent; background: transparent; color: var(--accent);
}
button.reveal:hover:not(:disabled) { background: var(--accent-wash); }
button.reveal:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); align-items: start; margin-bottom: 12px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.error-text { color: var(--danger); font-size: 13px; margin-top: 10px; }
input.search { width: 260px; max-width: 100%; }
.truncate.narrow { max-width: 190px; }


/* ---- auth screens ---- */
.auth-wrap { min-height: calc(100vh - 48px); display: grid; place-items: center; padding: 24px 0; }
.auth-card { width: min(400px, 100%); }
.auth-logo { width: 64px; height: 64px; margin-bottom: 12px; }
.auth-logo.logo-for-light { display: block; }
.auth-card h1 { margin-bottom: 4px; }
.auth-card .sub { color: var(--muted); margin-bottom: 18px; }
.auth-card .field + .field { margin-top: 12px; }
.auth-card .form-actions { justify-content: stretch; }
.auth-card .form-actions button { flex: 1; min-height: 38px; }
.auth-theme { display: flex; justify-content: center; margin-top: 14px; }
.notice {
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  background: var(--accent-wash); border-radius: 8px; padding: 10px 12px; margin-bottom: 16px;
  font-size: 13px; color: var(--ink);
}


/* ---- tables ---- */
/* position: relative keeps absolutely positioned children (e.g. .sr-only headers) inside the scroll box. */
.table-wrap { position: relative; overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--grid); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
th.num, td.num { text-align: right; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td .cell-main { font-weight: 550; }
td .cell-sub { color: var(--muted); font-size: 12px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: nowrap; }
.empty { padding: 26px 10px; text-align: center; color: var(--muted); }
.truncate { display: block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- badges (status: icon + label, never color alone) ---- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--ink-2); white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--axis); }
.badge.good { color: var(--good-ink); }
.badge.good .dot { background: var(--good); }
.badge.off .dot { background: transparent; border: 1.5px solid var(--axis); }
.badge.admin { color: var(--accent); border-color: var(--accent); }
.badge.warn { color: var(--warn-ink); }


/* ---- detail page ---- */
.back { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; margin-bottom: 10px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px 18px; }
.kv .k { font-size: 12px; color: var(--muted); }
.kv .v { font-weight: 550; margin-top: 2px; overflow-wrap: anywhere; }
.controls-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--grid); }
.controls-row .grow { flex: 1; }
.rating { display: inline-flex; align-items: baseline; gap: 4px; }
.rating strong { font-size: 14px; }

/* ---- dialog ---- */
dialog {
  border: 1px solid var(--border); border-radius: 12px; padding: 0;
  background: var(--surface); color: var(--ink);
  width: min(440px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog form { padding: 20px; }
dialog h2 { font-size: 17px; margin-bottom: 8px; }
dialog p { margin: 0 0 12px; color: var(--ink-2); }
dialog .form-actions { margin-top: 18px; }

/* ---- toast ---- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: grid; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-left: 4px solid var(--good);
  border-radius: 8px; padding: 10px 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  font-size: 13.5px;
}
.toast.error { border-left-color: var(--danger); }

/* ---- states ---- */
.loading { padding: 40px 0; text-align: center; color: var(--muted); }
.banner-error {
  border: 1px solid var(--danger); background: var(--danger-wash); color: var(--ink);
  border-radius: 8px; padding: 12px 14px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
}

/* ---- consumers ---- */
.id-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
button.copy { padding: 2px 8px; font-size: 12px; }
.card-head .grow { flex: 1; }
.card-head .toolbar { gap: 8px; }
.warn-text { color: var(--warn-ink); }
tr.clickable { cursor: pointer; }
tr.clickable a { color: var(--ink); font-weight: 600; }
tr.clickable a:hover { color: var(--accent); }
.fetch-err { color: var(--danger); }

/* Key and API key blocks. */
.cred-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px 28px; align-items: start; }
.cred { display: grid; gap: 8px; min-width: 0; align-content: start; }
.cred .k { font-size: 12px; color: var(--muted); }
.cred .v { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.cred code.big { font-size: 16px; font-weight: 600; letter-spacing: 0.04em; }
.cred code.break, code.break { overflow-wrap: anywhere; min-width: 0; }
.cred code.masked { color: var(--muted); letter-spacing: 0.06em; }
.cred code.small { font-size: 11.5px; }
.inline-form { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.inline-form .grow { flex: 1 1 260px; min-width: 0; }
.qr-wrap { display: flex; }
/* Drawn at a whole number of pixels per module (qrSvg); never rescale it, or scanners struggle. */
svg.qr { flex: none; box-sizing: content-box; border-radius: 6px; border: 1px solid var(--border); }
details.older { margin-top: 14px; }
details.older summary { cursor: pointer; color: var(--ink-2); font-size: 12.5px; }
details.older ul { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
details.older li { display: grid; gap: 2px; padding: 8px 10px; border: 1px solid var(--grid); border-radius: 8px; min-width: 0; }

/* Messages. */
.msg-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.msg-toolbar .grow { flex: 1; }
table.msgs td { vertical-align: top; }
table.msgs td.sel, table.msgs th.sel { width: 32px; padding-right: 0; }
table.msgs input[type="checkbox"] { width: 16px; height: 16px; margin: 2px 0 0; }
table.msgs td.text { min-width: 180px; overflow-wrap: anywhere; }
.msg-text { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
tr.expanded .msg-text { -webkit-line-clamp: unset; display: block; }
tr.msg-row { cursor: pointer; }
tr.msg-detail td { background: var(--surface-2); padding: 10px 14px 14px; }
tr.msg-detail:hover { background: transparent; }
.lock { font-size: 13px; }
td.nowrap { white-space: nowrap; }
/* Pages of messages: range, page numbers, page size. */
.msgs-card { scroll-margin-top: calc(var(--topbar-h) + 12px); }
.pager { display: flex; align-items: center; gap: 10px 16px; flex-wrap: wrap; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--grid); }
.pager .range { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.pager .pages { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-left: auto; }
.pager .pages button { min-width: 32px; padding: 3px 8px; font-variant-numeric: tabular-nums; }
.pager .pages button[aria-current="page"] { background: var(--accent-wash); border-color: var(--accent); color: var(--accent); }
.pager .gap { color: var(--muted); padding: 0 2px; }
.pager .size { display: flex; align-items: center; gap: 6px; }
.pager .size label { margin: 0; font-weight: 500; color: var(--muted); }

/* ---- responsive ---- */
@media (max-width: 640px) {
  main { padding: 16px 16px 72px; }
  .topbar { padding: 0 12px 0 8px; gap: 8px; }
  .user-btn .email { max-width: 120px; }
  .brand-sub { display: none; }
  .card { padding: 14px; }
  .table-wrap { margin: 0 -14px; padding: 0 14px; }
  .toolbar { width: 100%; }
  table.hide-narrow-cols .opt { display: none; }
  /* Keep a message row's Details/Delete in view: stacked, not past the right edge. */
  table.msgs .row-actions { flex-direction: column; align-items: flex-end; }
  table.msgs td.text { min-width: 0; }
}

/* Narrow screens: the menu column is a drawer over the page. */
@media (max-width: 760px) {
  .sidebar { position: fixed; left: 0; top: var(--topbar-h); z-index: 26; box-shadow: 0 8px 28px rgb(0 0 0 / 0.2); }
  .pager .pages { margin-left: 0; }
}

@media (forced-colors: active) {
  .badge .dot { forced-color-adjust: none; }
}

/* Sign-in: the link to setting up a consumer. */
.auth-alt { margin: 14px 0 0; font-size: 13px; color: var(--muted); }
code.big { font-size: 16px; font-weight: 600; letter-spacing: 0.04em; }

.empty-card { max-width: 560px; }

