/*
 * Admin dashboard styles. Kept in their own file rather than appended to
 * styles.css: this is an operator-only page, and every customer would
 * otherwise download it on every app page load. Inherits the app's tokens
 * (--accent, --card, --border, …) from styles.css, which loads first.
 */

.admin-page {
  --admin-max-width: 1440px;
  /* Design-system card rule: flat, border-only, 10px. Was 14px + a drop
     shadow. Every consumer of --admin-shadow now needs an explicit border,
     since the shadow was the only thing separating cards from the page. */
  --admin-radius: 10px;
  --admin-shadow: none;
  --admin-hairline: 1px solid var(--border);

  /* Design-system tokens the handoff assumes are global. They are NOT in
     styles.css, and styles.css is shared with the customer app — so they're
     defined here, console-scoped. Aliased to the existing token wherever the
     handoff lists the two as equivalent, so they can't drift apart. */
  --color-neutral-0: var(--card);
  --color-neutral-50: #f9fafb;
  --color-neutral-75: #f8fafc;
  --color-neutral-300: var(--border);
  --color-neutral-400: #94a3b8;
  --color-neutral-500: var(--muted);
  /* The one value the handoff uses (§3.5) but never tabulates; sits between
     --muted (500) and --text (800). */
  --color-neutral-600: #4b5563;
  --color-neutral-800: var(--text);
  --color-brand-500: var(--success);
  --color-brand-600: #16a34a;
  --color-brand-700: var(--accent);
  --color-brand-800: var(--accent-hover);
  --color-brand-tag-bg: #e8f5e9;
  --color-brand-tag-fg: #2e7d32;
  --radius-lg: 10px;
  --radius-pill: 999px;
  /* Modals keep a heavy shadow — they float over a scrim. */
  --shadow-modal: 0 25px 60px rgba(15, 23, 42, 0.2);
  min-height: 100vh;
  padding: 1.25rem clamp(0.75rem, 2vw, 2rem) 4rem;
  background: var(--page-bg-gradient);
}

.admin-shell {
  max-width: var(--admin-max-width);
  margin: 0 auto;
}

/* styles.css styles bare <button> for the app's stacked auth forms, including
   a margin-top that only makes sense in a vertical stack. This console lays
   controls out in rows, so clear it everywhere rather than per-component.
   Scoped to .admin-page, so confirm dialogs (appended to <body> by app.js)
   keep the app's own styling. */
.admin-page button {
  margin: 0;
}

/* Pills sitting inside a table cell — they're inline-block with no whitespace
   between them, so without this they touch. */
.admin-pill-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
}

/* ---------- header ---------- */

.admin-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.admin-header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-right: auto;
}

/* The cropped logo has no baked-in transparent margin, so at 68px the smiley
   is visually LARGER than the old 112px padded file. */
.admin-header-brand img {
  height: 68px;
  width: auto;
  display: block;
}

.admin-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.admin-subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

/* The console polls itself every 30s but never said so. */
.admin-header-refresh {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-pill);
  background: var(--card);
  border: 1px solid var(--border);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
}

.admin-header-refresh::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--success);
}

.admin-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/*
 * One button box, whatever the element.
 *
 * Three things here are load-bearing, and each was a real bug:
 *   - inline-flex + explicit line-height, so <a class="admin-button">
 *     ("Back to app") renders as a button instead of an underlined inline
 *     link inheriting the app's anchor styling;
 *   - a transparent 1px border on the base, so the outlined variant isn't 2px
 *     taller than the solid ones sitting beside it;
 *   - a shared min-height, so buttons align with the text inputs next to them
 *     (the extend-trial row) regardless of font metrics.
 * Adjust padding/border here, not per-variant, or the sizes drift apart again.
 */
.admin-button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  /* styles.css gives every bare <button> margin-top: 0.5rem for the app's
     stacked auth forms. In a horizontal row that pushed <button> variants 4px
     below the <a> and <input> beside them — the visible cause of every
     "these buttons don't line up" report. Reset it here; this console lays
     controls out in rows, not stacks. */
  margin: 0;
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--success);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.2;
  padding: 0.5rem 0.95rem;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  transition: filter 0.15s ease, opacity 0.15s ease;
}

.admin-button:hover:not(:disabled) {
  filter: brightness(0.95);
}

.admin-button:disabled {
  opacity: 0.55;
  cursor: default;
}

.admin-button-secondary {
  background: var(--card);
  color: var(--text);
  border-color: rgba(15, 23, 42, 0.08);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.admin-button-secondary:hover:not(:disabled) {
  background: var(--color-neutral-50);
  filter: none;
}

/* Outlined, not solid: Suspend and Reset 2FA are the most dangerous actions
   on the page and shouldn't carry the most visual weight. */
.admin-button-danger {
  background: var(--card);
  color: var(--danger);
  border-color: #fca5a5;
}

.admin-button-danger:hover:not(:disabled) {
  background: #fef2f2;
  /* The shared .admin-button brightness filter reads as "greyed out" on a
     white button. */
  filter: none;
}

.admin-button-small {
  min-height: 30px;
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
  border-radius: 8px;
}

/* ---------- tabs ---------- */

.admin-tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: var(--admin-hairline);
  margin-bottom: 1.25rem;
  overflow-x: auto;
}

.admin-tab {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 0.6rem 0.9rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}

/* An author-origin `display` beats the UA stylesheet's [hidden] rule at any
   specificity, so adding display:inline-flex above un-hid the superadmin-only
   Admins tab. Same guard the badge and overlays already carry. */
.admin-tab[hidden] {
  display: none;
}

.admin-tab[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* A fixed 20x20 circle, not a min-width pill. Matches the support widget's
   launcher badge. */
.admin-tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 20px;
  height: 20px;
  flex: none;
  padding: 0;
  border-radius: 999px;
  background: var(--trash-red);
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
}

.admin-tab-badge[hidden] {
  display: none;
}

/* ---------- cards + grids ---------- */

.admin-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

/* At desktop width the six Overview KPIs form one clean band instead of
   4-then-2; below 1200px the auto-fit fallback above takes over. */
@media (min-width: 1200px) {
  .admin-kpi-grid-6 {
    grid-template-columns: repeat(6, 1fr);
  }

  .admin-kpi-grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
}

.admin-kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--admin-radius);
  box-shadow: var(--admin-shadow);
  padding: 1rem 1.1rem;
}

.admin-kpi-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.admin-kpi-value {
  display: block;
  margin-top: 0.35rem;
  font-family: var(--font-amount);
  font-size: 1.85rem;
  font-weight: 700;
  line-height: 1.1;
}

/* For KPIs whose value is a date or a word rather than a figure — the
   headline size is tuned for numerals and looks wrong on prose. */
.admin-kpi-value-text {
  font-family: var(--font-ui);
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.35;
}

.admin-kpi-sub {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.admin-panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 0.85rem;
  /* Cards sized to content left ragged gaps under the short ones. */
  align-items: stretch;
}

.admin-panel-grid > .admin-panel {
  margin-bottom: 0;
}

.admin-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--admin-radius);
  box-shadow: var(--admin-shadow);
  padding: 1.1rem 1.15rem;
  margin-bottom: 0.85rem;
}

.admin-panel-title {
  margin: 0 0 0.7rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

/* The trailing count/qualifier ("most recent 100") must NOT inherit the
   uppercase treatment. */
.admin-panel-title small {
  font-weight: 400;
  font-size: 0.72rem;
  letter-spacing: 0;
  text-transform: none;
  color: var(--color-neutral-400);
}

/* ---------- stat rows ---------- */

/* gap: 0 so the rows read as one list rather than N floating pairs. */
.admin-stat-list {
  display: grid;
  gap: 0;
}

.admin-stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.86rem;
  padding: 0.45rem 0;
  /* No dashed dividers in the design system — dashes are reserved for the
     "+ Add" affordance and drag handles. */
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
}

.admin-stat:last-child {
  border-bottom: none;
}

.admin-stat-label {
  color: var(--muted);
}

.admin-stat-value {
  font-family: var(--font-amount);
  font-weight: 700;
  white-space: nowrap;
}

/* ---------- bar chart ---------- */

.admin-chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 110px;
  padding-top: 0.5rem;
}

.admin-chart-bar {
  flex: 1 1 0;
  min-width: 4px;
  background: var(--success);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  opacity: 0.85;
}

.admin-chart-bar.is-empty {
  background: var(--border);
  opacity: 0.6;
}

.admin-chart-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 0.4rem;
  font-size: 0.7rem;
  color: var(--muted);
}

/* ---------- tables ---------- */

.admin-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--admin-radius);
  background: var(--card);
  box-shadow: var(--admin-shadow);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  min-width: 720px;
}

.admin-table th {
  text-align: left;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 0.7rem 0.85rem;
  border-bottom: var(--admin-hairline);
  white-space: nowrap;
  background: var(--card);
}

.admin-table td {
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
  vertical-align: middle;
}

.admin-table tbody tr:last-child td {
  border-bottom: none;
}

.admin-table tbody tr.is-clickable {
  cursor: pointer;
}

.admin-table tbody tr.is-clickable:hover {
  background: rgba(34, 197, 94, 0.06);
}

.admin-cell-strong {
  font-weight: 600;
}

.admin-cell-muted {
  color: var(--muted);
  font-size: 0.78rem;
}

.admin-cell-amount {
  font-family: var(--font-amount);
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
}

.admin-empty {
  padding: 1.75rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.86rem;
}

/* ---------- pills ---------- */

.admin-pill {
  display: inline-block;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
  white-space: nowrap;
}

.admin-pill-neutral {
  background: rgba(107, 114, 128, 0.12);
  color: #4b5563;
}

.admin-pill-good {
  background: rgba(34, 197, 94, 0.14);
  color: #15803d;
}

.admin-pill-warn {
  background: rgba(234, 179, 8, 0.16);
  color: #a16207;
}

.admin-pill-bad {
  background: rgba(239, 68, 68, 0.13);
  color: #b91c1c;
}

.admin-pill-info {
  background: rgba(20, 128, 60, 0.1);
  color: var(--accent);
}

/* ---------- toolbar ---------- */

.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.85rem;
}

/* Same min-height as .admin-button so controls sitting in one row line up. */
.admin-search {
  flex: 1 1 260px;
  min-width: 200px;
  box-sizing: border-box;
  min-height: 36px;
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
  border: var(--admin-hairline);
  background: var(--card);
  font-size: 0.88rem;
}

.admin-select {
  box-sizing: border-box;
  min-height: 36px;
  padding: 0.5rem 1.9rem 0.5rem 0.6rem;
  border-radius: 10px;
  border: var(--admin-hairline);
  background-color: var(--card);
  font-size: 0.85rem;
  /* One rounded chevron, not a pair of linear-gradient triangles. */
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  background-size: 14px 14px;
}

.admin-pagination {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  justify-content: flex-end;
  margin-top: 0.85rem;
  font-size: 0.82rem;
  color: var(--muted);
}

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

.admin-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  display: flex;
  justify-content: flex-end;
  z-index: 60;
}

.admin-drawer-overlay[hidden] {
  display: none;
}

.admin-drawer {
  width: min(560px, 100%);
  height: 100%;
  overflow-y: auto;
  background: var(--page-bg-gradient);
  box-shadow: -12px 0 30px rgba(15, 23, 42, 0.16);
  padding: 1.25rem 1.25rem 3rem;
  /* A flex column with a growing body: position:sticky alone only pins the
     footer once content overflows, so on a short tab (e.g. Support with no
     thread) the bar would float mid-drawer with empty space beneath it. */
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.admin-drawer-body {
  flex: 1 0 auto;
}

/* Sticky so that 2,000px down the panel you still know whose account you're
   editing. Negative margins cancel the drawer's own padding. */
.admin-drawer-header {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: -1.25rem -1.25rem 0;
  padding: 1rem 1.15rem 0.8rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.admin-drawer-header-top {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.admin-drawer-monogram {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: var(--radius-pill);
  background: var(--success);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

/* Grid-centred caps-only text reads high: the line box reserves descender
   space below the baseline. Nudge it back down. */
.admin-drawer-monogram span {
  transform: translateY(1.5px);
}

.admin-drawer-identity {
  min-width: 0;
}

.admin-drawer-header h3 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.admin-drawer-email {
  margin-top: 0.1rem;
  font-size: 0.82rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* Answers "are they paying, are they active" without scrolling. */
.admin-drawer-vitals {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-top: 0.85rem;
}

.admin-drawer-vital {
  background: var(--color-neutral-75);
  border: 1px solid #dbe2ea;
  border-radius: var(--admin-radius);
  padding: 0.5rem 0.6rem 0.55rem;
}

.admin-drawer-vital-label {
  display: block;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-neutral-400);
}

.admin-drawer-vital-value {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.2;
}

.admin-drawer-vital-value.is-amount {
  font-family: var(--font-amount);
  font-variant-numeric: tabular-nums;
  color: var(--success);
}

.admin-drawer-vital-value.is-count {
  font-family: var(--font-amount);
  font-variant-numeric: tabular-nums;
}

/* Four sub-tabs replace ~2,000px of stacked panels. */
.admin-drawer-tabs {
  display: flex;
  gap: 0.25rem;
  margin-top: 0.85rem;
}

.admin-drawer-tabs .admin-tab {
  padding: 0.55rem 0.85rem;
  border-bottom-width: 2px;
  font-size: 0.82rem;
}

.admin-drawer-body {
  padding-top: 1rem;
}

/* Header and footer must not shrink when the body grows. */
.admin-drawer-header,
.admin-drawer-footer {
  flex: none;
}

.admin-drawer-close {
  margin-left: auto;
  appearance: none;
  border: none;
  background: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0.1rem 0.35rem;
}

.admin-action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.admin-drawer-pills {
  margin-top: 0.6rem;
}

/* Always-reachable actions. The destructive one is separated onto its own
   row: at 560px the three safe buttons total ~426px, so a fourth would wrap
   and `margin-left:auto` would strand it against the edge like a bug. */
.admin-drawer-footer {
  position: sticky;
  bottom: 0;
  margin: 0 -1.25rem -3rem;
  padding: 0.75rem 1.15rem 0.8rem;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.admin-drawer-footer-safe {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.admin-drawer-footer-danger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  padding-top: 0.7rem;
  border-top: 1px solid rgba(15, 23, 42, 0.07);
}

.admin-drawer-footer-danger p {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--color-neutral-400);
}

.admin-inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.6rem;
}

/* Matches .admin-button-small so the day-count box and the buttons beside it
   are the same height. */
.admin-inline-form input {
  width: 5.5rem;
  box-sizing: border-box;
  min-height: 30px;
  padding: 0.3rem 0.55rem;
  border-radius: 8px;
  border: var(--admin-hairline);
  font-size: 0.85rem;
}

/* The default inline-form width is sized for a day count; an email address
   needs room to be read back before it's confirmed. */
.admin-inline-form input.admin-input-wide {
  width: 16rem;
  max-width: 100%;
}

.admin-inline-form-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.4rem;
}

.admin-inline-group + .admin-inline-group {
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid rgba(15, 23, 42, 0.07);
}

/* Input + unit inside a single border, so it reads as one control. */
.admin-inline-form-stepper {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  overflow: hidden;
}

.admin-inline-form-stepper {
  min-height: 30px;
}

/* 3rem clipped the max value (3650). */
.admin-inline-form-stepper input {
  width: 4rem;
  min-height: 0;
  padding: 0.25rem 0 0.25rem 0.6rem;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-amount);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

/* outline:none above removes the only focus affordance — put it back on the
   wrapper so the whole control lights up. */
.admin-inline-form-stepper:focus-within {
  border-color: var(--success);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18);
}

.admin-inline-form-stepper span {
  padding: 0 0.7rem 0 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
}

/* Explanatory copy on a surface — as a bare muted paragraph it read as just
   another secondary label and disappeared. */
.admin-note-block {
  margin: 0.75rem 0 0;
  padding: 0.6rem 0.75rem;
  background: var(--color-neutral-75);
  border: 1px solid #dbe2ea;
  border-radius: var(--admin-radius);
  font-size: 0.75rem;
  line-height: 1.55;
  color: var(--color-neutral-600);
}

.admin-note {
  margin: 0.6rem 0 0;
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.45;
}

.admin-message {
  margin: 0 0 0.85rem;
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  font-size: 0.85rem;
  display: none;
}

.admin-message.is-visible {
  display: block;
}

.admin-message.is-error {
  background: rgba(239, 68, 68, 0.1);
  color: #b91c1c;
}

.admin-message.is-success {
  background: rgba(34, 197, 94, 0.13);
  color: #15803d;
}

.admin-gate {
  max-width: 440px;
  margin: 15vh auto 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--admin-radius);
  box-shadow: var(--admin-shadow);
  padding: 2rem;
  text-align: center;
}

.admin-gate h2 {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
}

.admin-gate p {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.admin-loading {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 640px) {
  .admin-kpi-value {
    font-size: 1.5rem;
  }

  .admin-header-brand img {
    height: 48px;
  }

  .admin-title {
    font-size: 1.15rem;
  }
}

/* ------------------------------------------------------------------ inbox */

.admin-inbox-layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 0.85rem;
  align-items: start;
}

.admin-inbox-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 70vh;
  overflow-y: auto;
  padding-right: 0.15rem;
}

/* A thread row is a <button> so it's keyboard-reachable, but it should read
   as a card, not a control. */
.admin-inbox-item {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: var(--admin-hairline);
  border-radius: var(--admin-radius);
  padding: 0.7rem 0.8rem;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

/* A 1.5px border, not an inset ring — the ring read as a focus artifact. */
.admin-inbox-item.is-selected {
  border-color: var(--accent);
  border-width: 1.5px;
}

.admin-inbox-item-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.admin-inbox-item-preview {
  font-size: 0.85rem;
  color: var(--muted);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 0.35rem;
  overflow-wrap: anywhere;
}

.admin-inbox-convo {
  background: var(--card);
  border: var(--admin-hairline);
  border-radius: var(--admin-radius);
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  min-height: 340px;
}

.admin-inbox-convo-title {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.admin-chat-messages {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  overflow-y: auto;
  max-height: 52vh;
  padding: 0.2rem 0.1rem;
}

.admin-chat-msg {
  max-width: 78%;
  border-radius: 12px;
  padding: 0.5rem 0.7rem;
  font-size: 0.9rem;
}

.admin-chat-msg-user {
  align-self: flex-start;
  background: #f1f5f9;
  border: var(--admin-hairline);
}

.admin-chat-msg-admin {
  align-self: flex-end;
  background: #dcfce7;
  border: 1px solid #bbf7d0;
}

.admin-chat-msg-system {
  align-self: center;
  max-width: 90%;
  background: none;
  color: var(--muted);
  font-size: 0.8rem;
  font-style: italic;
  text-align: center;
  padding: 0.1rem 0.4rem;
}

.admin-chat-msg-meta {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

.admin-chat-msg-quote {
  border-left: 3px solid #cbd5e1;
  padding-left: 0.5rem;
  margin-bottom: 0.3rem;
  font-size: 0.8rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.admin-chat-msg-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Composer matches the customer AI widget: pill input, circular green
   paper-plane send inside it, circular mic beside it. */
.admin-chat-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.admin-chat-composer {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  background: #f9fafb;
  border: var(--admin-hairline);
  border-radius: 23px;
  padding: 5px 5px 5px 16px;
  min-height: 46px;
  min-width: 0;
  box-sizing: border-box;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.admin-chat-composer:focus-within {
  background: var(--card);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.12);
}

.admin-chat-form .admin-chat-input {
  flex: 1;
  box-sizing: border-box;
  border: none;
  background: transparent;
  outline: none;
  resize: none;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.35;
  padding: 8px 0;
  min-width: 0;
  height: 35px;
  max-height: 132px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.admin-chat-form .admin-chat-input::-webkit-scrollbar { width: 0; height: 0; }

.admin-chat-send {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: none;
  background: var(--success);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  align-self: flex-end;
  padding: 0;
  transition: filter 0.15s, transform 0.15s, opacity 0.15s;
}

.admin-chat-send:hover:not(:disabled) { filter: brightness(0.95); }
.admin-chat-send:active { transform: scale(0.96); }
.admin-chat-send.is-empty { opacity: 0.7; }
.admin-chat-send:disabled { cursor: default; }
.admin-chat-send.is-checking { animation: admin-send-pulse 1s ease-in-out infinite; }
.admin-chat-send svg {
  width: 16px;
  height: 16px;
  transform: translate(-1px, 1px);
}

@keyframes admin-send-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.admin-chat-mic {
  width: 46px;
  height: 46px;
  border-radius: 999px;
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: var(--danger);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.admin-chat-mic[hidden] { display: none; }
.admin-chat-mic svg { width: 18px; height: 18px; }
.admin-chat-mic:hover { background: #fee2e2; border-color: var(--danger); }
.admin-chat-mic:active { transform: scale(0.96); }
.admin-chat-mic.is-listening {
  background: #fee2e2;
  border-color: #f87171;
  animation: admin-mic-pulse 1.4s ease-in-out infinite;
}

@keyframes admin-mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.35); }
  50% { box-shadow: 0 0 0 7px rgba(239, 68, 68, 0); }
}

.admin-inbox-count {
  font-size: 0.85rem;
  color: var(--muted);
  margin-right: auto;
}

@media (max-width: 900px) {
  .admin-inbox-layout {
    grid-template-columns: 1fr;
  }
  .admin-inbox-list {
    max-height: 34vh;
  }
}

/* The polish-approval dialog previews a whole reply in the shared confirm
   modal; keep its line breaks. Scoped to pages that load admin.css. */
.modal-subtitle {
  white-space: pre-wrap;
}

/* ---------- inbox: snippets, notes, context ---------- */

.admin-snippet-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.admin-select-small {
  min-height: 30px;
  font-size: 0.78rem;
}

.admin-note-toggle {
  margin-left: auto;
  min-height: 30px;
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
  border-radius: 8px;
  border: 1px solid #fcd34d;
  background: #fffbeb;
  color: #92400e;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s;
}

.admin-note-toggle:hover { background: #fef3c7; }
.admin-note-toggle.is-active {
  background: #fde68a;
  border-color: #f59e0b;
}

/* Note mode tints the whole composer so there's no mistaking which
   audience the text has. */
.admin-chat-composer.is-note {
  background: #fffbeb;
  border-color: #fcd34d;
}
.admin-chat-composer.is-note:focus-within {
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15);
}
.admin-chat-composer.is-note .admin-chat-send { background: #f59e0b; }

.admin-chat-msg-note {
  align-self: stretch;
  max-width: 100%;
  background: #fffbeb;
  border: 1px dashed #fcd34d;
}

.admin-inbox-context {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
  font-size: 0.8rem;
}

/* ---------- inbox: attachments ---------- */

.admin-chat-attach {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  align-self: flex-end;
  padding: 0;
}

.admin-chat-attach:hover { background: #f1f5f9; color: var(--text); }
.admin-chat-attach svg { width: 16px; height: 16px; }

.admin-chat-composer.is-dragover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}

.admin-attach-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.admin-attach-chips[hidden] { display: none; }

.admin-attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  background: #f1f5f9;
  border: var(--admin-hairline);
  border-radius: 999px;
  padding: 0.15rem 0.3rem 0.15rem 0.55rem;
  max-width: 100%;
}

.admin-attach-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}

.admin-attach-chip-remove {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1;
  padding: 0 0.15rem;
}

.admin-chat-att-img {
  display: block;
  max-width: 240px;
  max-height: 180px;
  border-radius: 10px;
  margin-top: 0.35rem;
  object-fit: cover;
}

.admin-chat-att-file {
  display: inline-block;
  margin-top: 0.35rem;
  font-size: 0.8rem;
  text-decoration: underline;
  overflow-wrap: anywhere;
}

/* Pending-attachment thumbnails: big enough to recognize the screenshot,
   small enough not to crowd the composer. */
.admin-attach-thumb {
  position: relative;
  display: inline-block;
}

.admin-attach-thumb-img {
  display: block;
  height: 84px;
  max-width: 140px;
  border-radius: 10px;
  object-fit: cover;
  border: var(--admin-hairline);
}

.admin-attach-thumb-remove {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  border: var(--admin-hairline);
  background: var(--card);
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.admin-attach-thumb-remove:hover { color: var(--danger); border-color: var(--danger); }

/* ---------- image lightbox ---------- */

/* Above the user drawer (z 60) so an attachment opened from a conversation
   sits over everything. */
.admin-lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(15, 23, 42, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3vmin;
  overscroll-behavior: contain;
}

.admin-lightbox[hidden] { display: none; }

.admin-lightbox-frame {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  max-width: 100%;
  max-height: 100%;
}

.admin-lightbox-img {
  max-width: 92vw;
  max-height: 84vh;
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  background: #fff;
  cursor: zoom-out;
}

.admin-lightbox-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  color: #e2e8f0;
  font-size: 0.85rem;
}

.admin-lightbox-open {
  color: #fff;
  text-decoration: underline;
}

.admin-lightbox-open[hidden] { display: none; }

.admin-lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(15, 23, 42, 0.6);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.admin-lightbox-close:hover { background: rgba(15, 23, 42, 0.85); }

/* The click affordance on anything that opens the viewer. */
.admin-chat-att-img,
.admin-attach-thumb-img {
  cursor: zoom-in;
}

/* ---------- design refresh: remaining components ---------- */

/* §2.3 — the amber block gave no indication of what it was. */
.admin-chat-msg-note-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  color: #92400e;
  margin-bottom: 0.25rem;
}

/* §2.5 — the revenue chart is taller and wider-gapped than the signups one. */
.admin-chart-revenue {
  height: 120px;
  gap: 6px;
}

/* §2.5 — refunds are red; an absent refund is an em-dash, never parentheses. */
.admin-cell-refund {
  color: var(--trash-red);
}

.admin-cell-empty {
  color: var(--color-neutral-400);
}

/* §2.7 — pending invites: an operator could not previously see or cancel an
   outstanding invite. */
.admin-invite-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  background: var(--color-neutral-75);
  border: 1px solid #dbe2ea;
  border-radius: var(--admin-radius);
  padding: 0.6rem 0.75rem;
}

.admin-invite-row + .admin-invite-row {
  margin-top: 0.5rem;
}

.admin-invite-row-main {
  min-width: 0;
  margin-right: auto;
}

.admin-invite-row-email {
  font-weight: 600;
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.admin-invite-row-meta {
  font-size: 0.75rem;
  color: var(--color-neutral-400);
}

/* §3.6 — institutions nest under the Bank connections count instead of
   forming a second, unlabelled stat list. */
/* Institutions nest under the Bank connections count: the row above them
   drops its divider, and the last subline carries it instead — otherwise the
   line lands between the count and the items it groups. */
.admin-stat-subline {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0.1rem 0 0.45rem;
}

.admin-stat.has-sublines {
  border-bottom: none;
}

.admin-stat-subline.is-last {
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
}

/* The drawer's vitals grid gets cramped on a narrow phone. */
@media (max-width: 480px) {
  .admin-drawer-vitals {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* §3.7 — an empty value is an em-dash in neutral-400, everywhere. */
.admin-stat-value.is-empty,
.admin-cell-muted.is-empty {
  color: var(--color-neutral-400);
}
