/*
 * Operator console. Everything derives from the tokens below — no raw hex or
 * one-off spacing past this block.
 */

:root {
  /* Spacing, on a 4px scale. */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 20px; --s6: 24px; --s7: 32px; --s8: 40px;

  /* Type — dense, so a screenful holds a working set of numbers. */
  --fs-xs: 11px; --fs-sm: 12px; --fs-md: 13px; --fs-lg: 15px; --fs-xl: 19px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;

  /* Neutral ramp. */
  --n0: #ffffff;
  --n25: #fcfcfd;
  --n50: #f7f8fa;
  --n100: #eff1f4;
  --n200: #e3e6eb;
  --n300: #cfd4dc;
  --n500: #8b93a1;
  --n600: #667085;
  --n700: #475061;
  --n900: #16191f;

  --accent: #2563eb;

  --ok: #17683f;      --ok-bg: #e7f4ec;
  --warn: #8a5a08;    --warn-bg: #fdf3e0;
  --danger: #a3231d;  --danger-bg: #fdeceb;

  --r-sm: 4px; --r-md: 6px; --r-lg: 10px;
  --shadow-sm: 0 1px 2px rgb(16 24 40 / 6%);
  --shadow-lg: -8px 0 32px rgb(16 24 40 / 12%);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.45;
  color: var(--n900);
  background: var(--n50);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, ul, figure { margin: 0; }
ul { padding: 0; list-style: none; }

/* One focus treatment for everything interactive. Buttons had none at all. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.mono {
  font-family: var(--font-mono);
  /* IDs and expiry dates read as columns when the digits align. */
  font-variant-numeric: tabular-nums;
}

.hint { color: var(--n600); font-size: var(--fs-xs); }
.hint--ok { color: var(--ok); }
.hint--warn { color: var(--warn); }

/* ---------- buttons ---------- */

.btn {
  font: inherit;
  font-weight: 500;
  padding: 6px var(--s3);
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}

.btn--sm { font-size: var(--fs-sm); padding: 4px var(--s2); }

/* Near-black, not Facebook blue: this is a tool, not a demo. */
.btn--primary { background: var(--n900); color: var(--n0); }
.btn--primary:hover:not(:disabled) { background: #000; }

.btn--ghost { background: var(--n0); color: var(--n700); border-color: var(--n300); }
.btn--ghost:hover:not(:disabled) { background: var(--n50); }

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

.icon-btn {
  font: inherit;
  font-size: var(--fs-xs);
  color: var(--n600);
  background: transparent;
  border: 1px solid var(--n200);
  border-radius: var(--r-sm);
  padding: 1px var(--s2);
  cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--n100); color: var(--n900); }
.icon-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- inputs ---------- */

input {
  font: inherit;
  color: var(--n900);
  background: var(--n0);
  border: 1px solid var(--n300);
  border-radius: var(--r-md);
  padding: 6px var(--s2);
}
input::placeholder { color: var(--n500); }

/* ---------- frame ---------- */

.appbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  padding: var(--s3) var(--s6);
  background: var(--n0);
  border-bottom: 1px solid var(--n200);
}

.appbar__brand { font-weight: 600; letter-spacing: -0.01em; }

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: var(--s6);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  flex-wrap: wrap;
  margin-bottom: var(--s4);
}

.toolbar__title { display: flex; align-items: baseline; gap: var(--s2); }
.toolbar__title h1 { font-size: var(--fs-xl); letter-spacing: -0.02em; }
.toolbar__count { color: var(--n600); font-size: var(--fs-sm); }
.toolbar__actions { display: flex; align-items: center; gap: var(--s2); }
.filter { width: 220px; }

/* ---------- numbers table ---------- */

.panel {
  background: var(--n0);
  border: 1px solid var(--n200);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/*
 * One data-state attribute drives which of the table / loading / empty /
 * no-matches / error views is on screen.
 */
.panel__state { display: none; padding: var(--s8) var(--s6); text-align: center; }
.panel[data-state='loading'] .panel__state--loading,
.panel[data-state='empty'] .panel__state--empty,
.panel[data-state='no-matches'] .panel__state--no-matches,
.panel[data-state='error'] .panel__state--error { display: block; }
.panel:not([data-state='ready']) .numbers { display: none; }

.state__title { font-weight: 600; }
.state__body { color: var(--n600); max-width: 46ch; margin: var(--s2) auto var(--s4); }
.panel__state--loading { padding: var(--s3) var(--s6); }

.skeleton {
  height: 20px;
  margin: var(--s3) 0;
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--n100), var(--n50), var(--n100));
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

.numbers { width: 100%; border-collapse: collapse; }

.numbers th {
  text-align: left;
  font-size: var(--fs-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--n600);
  padding: var(--s2) var(--s4);
  background: var(--n25);
  border-bottom: 1px solid var(--n200);
}

.numbers td {
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--n100);
  vertical-align: middle;
}
.numbers tbody tr:last-child td { border-bottom: 0; }
.numbers tbody tr:hover { background: var(--n25); cursor: pointer; }

.cell-number { line-height: 1.3; }
.cell-sub {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--n500);
}
.cell-muted { color: var(--n600); font-size: var(--fs-sm); }

/* The number itself is the row's accessible open control. */
.row-open {
  font: inherit;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--n900);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.row-open:hover { text-decoration: underline; }

.chip {
  display: inline-block;
  font-size: var(--fs-xs);
  font-weight: 500;
  padding: 1px var(--s2);
  border-radius: 999px;
  white-space: nowrap;
}
.chip--ok { color: var(--ok); background: var(--ok-bg); }
.chip--warn { color: var(--warn); background: var(--warn-bg); }
.chip--danger { color: var(--danger); background: var(--danger-bg); }
.chip--neutral { color: var(--n700); background: var(--n100); }

/* Step progress as one dot per step — the row's triage signal. */
.dots { display: inline-flex; gap: 3px; }
.dots--empty { color: var(--n500); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--n300); }
.dot--done { background: var(--ok); }
.dot--failed { background: var(--danger); }
.dot--skipped { background: var(--n300); }

.expiry { font-size: var(--fs-sm); }
.expiry--warn { color: var(--warn); }
.expiry--danger { color: var(--danger); font-weight: 500; }
.expiry--neutral { color: var(--n600); }

/* ---------- drawer ---------- */

.drawer {
  /* A <dialog> pinned to the right edge: Esc, the focus trap, the inert
     background and ::backdrop all come free. */
  margin: 0 0 0 auto;
  width: min(520px, 100%);
  max-width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--n200);
  background: var(--n0);
  box-shadow: var(--shadow-lg);
  color: inherit;
}
.drawer::backdrop { background: rgb(16 24 40 / 30%); }

.drawer__head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s4);
  padding: var(--s4) var(--s5);
  background: var(--n0);
  border-bottom: 1px solid var(--n200);
}
.drawer__title { font-size: var(--fs-lg); margin-bottom: var(--s1); }
.drawer__close { font-size: var(--fs-lg); line-height: 1; padding: 0 6px; }

.drawer__body { padding: var(--s5); display: grid; gap: var(--s6); }
.drawer__section { display: grid; gap: var(--s3); }

.section__title {
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--n600);
}
.section__note { color: var(--n600); font-size: var(--fs-sm); }

.facts { display: grid; gap: var(--s1); }
.fact {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) auto;
  align-items: baseline;
  gap: var(--s2);
  padding: var(--s1) 0;
  border-bottom: 1px solid var(--n100);
}
.fact__label { color: var(--n600); font-size: var(--fs-sm); }
.fact__value { overflow-wrap: anywhere; }
/* Copy controls recede until the row is hovered — opacity, not visibility, so
   they stay reachable by keyboard. */
.fact .icon-btn { opacity: 0; transition: opacity .1s; }
.fact:hover .icon-btn,
.fact:focus-within .icon-btn { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .fact .icon-btn { transition: none; } }
.token-value { font-size: var(--fs-sm); }

.steps { display: grid; gap: var(--s2); }
.step {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: var(--s2);
  padding: var(--s2);
  border: 1px solid var(--n200);
  border-radius: var(--r-md);
}
.step__body { display: grid; gap: 2px; min-width: 0; }
.step__label { font-weight: 500; }
.step__detail, .step__blocked { color: var(--n600); font-size: var(--fs-sm); }
.step__error { color: var(--danger); font-size: var(--fs-sm); overflow-wrap: anywhere; }

.template { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s2); }
.template .mono { font-size: var(--fs-sm); }

.field { display: grid; gap: var(--s1); }
.field__label { color: var(--n600); font-size: var(--fs-sm); }

.send-row { display: flex; align-items: center; gap: var(--s3); }

.result {
  padding: var(--s2) var(--s3);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}
.result--ok { color: var(--ok); background: var(--ok-bg); }
.result--err { color: var(--danger); background: var(--danger-bg); }
.result code, .step code { font-family: var(--font-mono); }

.raw summary { cursor: pointer; color: var(--n600); font-size: var(--fs-sm); }
.raw pre {
  margin: var(--s2) 0 0;
  padding: var(--s3);
  max-height: 320px;
  overflow: auto;
  background: var(--n50);
  border-radius: var(--r-md);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--n700);
}

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  right: var(--s5);
  bottom: var(--s5);
  z-index: 20;
  display: grid;
  gap: var(--s2);
  width: min(380px, calc(100vw - var(--s8)));
}

.toast {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: var(--s2);
  padding: var(--s3);
  background: var(--n0);
  border: 1px solid var(--n200);
  border-left: 3px solid var(--n300);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
}
.toast--ok { border-left-color: var(--ok); }
.toast--err { border-left-color: var(--danger); }
.toast--warn { border-left-color: var(--warn); }
.toast--info { border-left-color: var(--accent); }

.toast__body { min-width: 0; }
.toast__icon { font-weight: 600; color: var(--n600); }
.toast--ok .toast__icon { color: var(--ok); }
.toast--err .toast__icon { color: var(--danger); }
.toast--warn .toast__icon { color: var(--warn); }
.toast__text { font-size: var(--fs-sm); overflow-wrap: anywhere; }
.toast__meta {
  margin-top: var(--s1);
  display: flex;
  gap: var(--s2);
  color: var(--n500);
  font-size: var(--fs-xs);
}
.toast__meta code { font-family: var(--font-mono); }
.toast__close {
  font: inherit;
  font-size: var(--fs-lg);
  line-height: 1;
  color: var(--n500);
  background: none;
  border: 0;
  cursor: pointer;
}

/* ---------- sign-in ---------- */

.centered {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--s6);
}

.auth-card {
  width: min(360px, 100%);
  display: grid;
  gap: var(--s3);
  padding: var(--s6);
  background: var(--n0);
  border: 1px solid var(--n200);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.auth-card h1 { font-size: var(--fs-xl); letter-spacing: -0.02em; }
.auth-card .sub { color: var(--n600); font-size: var(--fs-sm); }
.auth-card form { display: grid; gap: var(--s3); }
.auth-card input { width: 100%; }
.btn--wide { width: 100%; padding: var(--s2); }

.notice {
  padding: var(--s2) var(--s3);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  color: var(--danger);
  background: var(--danger-bg);
}

/* ---------- narrow ---------- */

@media (max-width: 720px) {
  .page { padding: var(--s4); }
  .toolbar__actions { width: 100%; }
  .filter { flex: 1; width: auto; }
  /* Steps and connected date are the first things to go; status and number
     are what the list is for. */
  .numbers th:nth-child(3), .numbers td:nth-child(3),
  .numbers th:nth-child(5), .numbers td:nth-child(5) { display: none; }
  .drawer { width: 100%; }
  .fact { grid-template-columns: minmax(0, 1fr) auto; }
  .fact__label { grid-column: 1 / -1; }
  .toasts { right: var(--s3); left: var(--s3); bottom: var(--s3); width: auto; }
}
