/* Admin-specific styles — layered on the shared design system (styles.css). */
.nav-badge { margin-left: auto; background: var(--st-disputed); color: #1a1206; font-size: 11px;
  font-weight: 700; border-radius: var(--r-pill); padding: 1px 7px; }

.admin-scroll { height: 100%; overflow-y: auto; }
.admin-pad { max-width: 1000px; margin: 0 auto; padding: 24px 28px 60px; }

.card { background: var(--bg-panel); border: 1px solid var(--border-subtle); border-radius: var(--r);
  padding: 18px; margin-bottom: 16px; }
.card h3 { font-family: var(--serif); margin: 0 0 14px; font-size: 16px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .4px; }
select.input { appearance: none; cursor: pointer; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); cursor: pointer; }

.runlist { display: flex; flex-direction: column; gap: 8px; }
.run-row { display: flex; align-items: center; gap: 12px; padding: 13px 15px; border-radius: var(--r);
  background: var(--bg-panel); border: 1px solid var(--border-subtle); cursor: pointer; transition: all .14s; }
.run-row:hover { border-color: var(--accent); transform: translateX(2px); }
.run-row .rtopic { font-weight: 600; }
.run-row .rmeta { color: var(--text-dim); font-size: 12px; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--st-accepted); box-shadow: 0 0 8px var(--st-accepted); animation: pz 1.4s infinite; }
@keyframes pz { 50% { opacity: .4; } }

.meter { display: flex; gap: 18px; flex-wrap: wrap; margin: 4px 0 2px; }
.meter .m { font-size: 12.5px; color: var(--text-muted); }
.meter .m b { color: var(--text); font-size: 15px; font-weight: 600; }
.bar { height: 6px; background: var(--bg-elevated); border-radius: 4px; overflow: hidden; margin-top: 5px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-bright)); }

.tree { font-size: 13.5px; }
.tnode { display: flex; align-items: center; gap: 9px; padding: 7px 0; border-bottom: 1px solid var(--border-subtle); }
.tnode .tindent { color: var(--text-dim); white-space: pre; font-family: var(--mono); }
.tnode .tcounts { color: var(--text-dim); font-size: 11.5px; margin-left: auto; }
.tnode .gate-btns { display: flex; gap: 6px; margin-left: auto; }
.st-ico { width: 18px; text-align: center; }
.st-approved { color: var(--st-accepted); } .st-saturated { color: var(--accent-2); }
.st-gated { color: var(--st-disputed); } .st-rejected { color: var(--st-superseded); }
.st-pending { color: var(--text-dim); } .st-running { color: var(--accent-bright); }
.st-budgeted_out { color: var(--text-dim); }

.ptable { width: 100%; border-collapse: collapse; font-size: 13px; }
.ptable th { text-align: left; color: var(--text-dim); font-weight: 500; font-size: 11px;
  text-transform: uppercase; letter-spacing: .4px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.ptable td { padding: 9px 10px; border-bottom: 1px solid var(--border-subtle); vertical-align: middle; }
.ptable .key-input { width: 200px; }
.dot-on { color: var(--st-accepted); } .dot-off { color: var(--text-dim); }
.toggle { cursor: pointer; user-select: none; }

.events { font-family: var(--mono); font-size: 11.5px; color: var(--text-muted); max-height: 220px; overflow-y: auto; }
.events .ev { padding: 3px 0; border-bottom: 1px solid var(--border-subtle); }
.events .ev .k { color: var(--accent); }
.back { color: var(--text-muted); cursor: pointer; font-size: 13px; margin-bottom: 12px; display: inline-block; }
.back:hover { color: var(--text); }
.empty-sm { color: var(--text-dim); font-size: 13px; padding: 12px 0; }

/* ============================================================ operator sign-in
   A real credential screen, replacing the window.prompt() the console used to rely on. */
body.signed-out .sidebar { display: none; }          /* nothing to navigate to until signed in */
body.signed-out .app { grid-template-columns: 1fr; }

/* The login OWNS THE VIEWPORT rather than sitting inside the console shell.
   `.view` is `position:absolute; inset:0` in styles.css (the shared stylesheet this console also
   loads) and `.app` is a named-area grid, so a card rendered inside it was laid out into the
   content column and pushed out of the viewport — Playwright caught it as "element is outside of
   the viewport / .app intercepts pointer events", i.e. the sign-in button was literally
   unclickable. Fixed positioning sidesteps every inherited rule instead of trying to unpick them.
   overflow-y:auto so a short window (or the taller password-change form) can still scroll. */
.login-wrap { position: fixed; inset: 0; z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; overflow-y: auto; background: var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: 14px; padding: 30px 28px;
  box-shadow: 0 18px 50px rgba(0,0,0,.14); }
.login-brand { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center;
  font-size: 21px; margin-bottom: 14px; color: #fff;
  background: linear-gradient(135deg, #7aa2ff, #4f7bd6); }
.login-title { margin: 0 0 4px; font-size: 20px; font-weight: 650; color: var(--text); }
.login-sub { margin: 0 0 20px; font-size: 13px; color: var(--text-muted); }
.login-label { display: block; margin: 12px 0 5px; font-size: 12.5px; font-weight: 600;
  color: var(--text-muted); }
.login-card .input { width: 100%; }
.login-card .btn-block { margin-top: 18px; }
.login-msg { margin: 12px 0 0; padding: 9px 12px; border-radius: 8px; font-size: 13px; }
.login-msg.err { background: rgba(143,36,24,.10); color: var(--danger); border: 1px solid rgba(143,36,24,.25); }
.login-msg.warn { background: var(--accent-soft); color: var(--text); border: 1px solid var(--accent); }
.login-fine { margin: 16px 0 0; font-size: 11.5px; line-height: 1.5; color: var(--text-dim); }

/* operator chip in the sidebar foot */
.op-chip { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px;
  padding-bottom: 10px; border-bottom: 1px solid var(--border-subtle); }
.op-chip .op-name { flex: 1 1 100%; font-size: 12.5px; font-weight: 600; color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ================================================================ page gutter
   `.view` is `position:absolute; inset:0` (styles.css) with NO padding, so a view that renders
   straight into it starts flush against the sidebar's right border — measured at exactly 0px of
   gap on all six membership pages, against 24px on the older ones, which happened to wrap their
   content in `.admin-pad`. Putting the gutter on `.view` fixes every page at once, including any
   added later, instead of depending on each render function remembering a wrapper.

   `overflow-y: auto` is the other half and is not cosmetic: `.main` is `overflow:hidden`, so
   before this, content taller than the window was CLIPPED with no way to scroll to it — the Email
   health and Audit pages already exceeded it.

   Scoped to admin.css, so the public site's `.view` is untouched. */
.view { padding: 26px 34px 64px; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* A grid item's automatic minimum size is its MIN-CONTENT width, so a `1fr` column refuses to
   shrink below the widest thing inside it. `.adm-table` sets `min-width: 520px` (a member table
   is unreadable narrower), and that propagated all the way out: the content column grew to 941px
   inside a 390px screen, which in turn stretched the sidebar and made the whole console render
   zoomed-out on a phone — the horizontal-overflow check missed it because the LAYOUT viewport had
   expanded to match, so nothing technically overflowed.
   `min-width: 0` restores the ability to shrink, which is what lets `.adm-table-wrap`'s own
   `overflow-x: auto` do the scrolling it was added for. */
.main { min-width: 0; }

/* The older autopilot views already centre themselves in here; drop their own padding so the
   gutter above is not applied twice. */
.admin-pad { max-width: 1180px; margin: 0 auto; padding: 0; }

/* Membership views render their blocks directly into `.view`, so constrain them the same way —
   a 20-column member table stretched across an ultrawide monitor is unreadable. */
#admin-view > .view-head,
#admin-view > .adm-stats,
#admin-view > .adm-card,
#admin-view > .adm-table-wrap,
#admin-view > p { max-width: 1180px; margin-left: auto; margin-right: auto; }

/* ================================================================ membership views */
.nav-group { margin: 14px 0 5px; padding: 0 12px; font-size: 10.5px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-dim); font-weight: 700; }
.nav-group:first-child { margin-top: 0; }

.view-head { margin-bottom: 18px; }
.view-head h2 { margin: 0 0 4px; font-size: 21px; }
.adm-toolbar { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; margin-top: 10px; }

.adm-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 11px; margin-bottom: 22px; }
.adm-stat { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 11px;
  padding: 14px 15px; }
.adm-stat-v { font-size: 25px; font-weight: 650; line-height: 1.1; color: var(--text); }
.adm-stat-l { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.adm-stat.ok .adm-stat-v { color: var(--st-accepted); }
.adm-stat.warn .adm-stat-v { color: var(--danger); }

.adm-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px 20px; margin-bottom: 18px; }
.adm-card-title { margin: 0 0 12px; font-size: 15px; font-weight: 650; }

/* Tables scroll INSIDE their own container. The console is regularly opened on a phone, and a
   member table that widens the page turns every other control into a horizontal-scroll hunt. */
.adm-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 0 6px; }
.adm-table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 520px; }
.adm-table th { text-align: left; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-dim); padding: 8px 11px; border-bottom: 1px solid var(--border); }
.adm-table td { padding: 9px 11px; border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle; }
.adm-table tr:last-child td { border-bottom: 0; }
.adm-empty { color: var(--text-dim); font-style: italic; text-align: center; padding: 20px 0; }

.adm-kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px 18px;
  margin-bottom: 18px; }
.adm-kv .k { display: block; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-dim); }
.adm-kv .v { display: block; font-size: 14px; color: var(--text); word-break: break-word; }

.adm-actions { display: flex; flex-wrap: wrap; gap: 9px; align-items: center;
  padding: 13px 0; border-top: 1px solid var(--border-subtle); }
.adm-actions strong { flex: 1 1 100%; font-size: 12.5px; color: var(--text-muted); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px;
  font-weight: 600; background: var(--bg-hover); color: var(--text-muted);
  border: 1px solid var(--border); }
.pill.ok { background: rgba(20,83,43,.10); color: var(--st-accepted); border-color: rgba(20,83,43,.28); }
.pill.warn { background: rgba(143,36,24,.10); color: var(--danger); border-color: rgba(143,36,24,.28); }
.pill.plan-premium { background: var(--accent-soft); color: var(--link); border-color: var(--accent); }
.pill.plan-basic { background: rgba(15,118,110,.10); color: var(--link-2); border-color: rgba(15,118,110,.3); }

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { filter: brightness(1.08); }

@media (max-width: 900px) {
  /* THE AREAS MUST BE REDECLARED, not just the columns. `grid-template-areas` in styles.css is
     "sidebar topbar" / "sidebar main" — two columns. Setting `grid-template-columns: 1fr` alone
     leaves the second column to be created implicitly, so `.main` was laid out to the RIGHT of the
     viewport: measured at left=406px on a 390px screen, i.e. every admin page was entirely
     off-screen and unreachable on a phone. The horizontal-overflow check missed it because the
     document itself did not scroll — only the absolutely-positioned view was displaced. */
  .app {
    /* minmax(0, …), not a bare 1fr — see the `.main { min-width: 0 }` note above. Both are needed:
       this lets the TRACK shrink, that lets the ITEM shrink. */
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    grid-template-areas: "sidebar" "topbar" "main";
    height: auto; min-height: 100vh;
  }
  .sidebar { position: static; width: auto; min-width: 0; height: auto; overflow: visible; }
  /* Ten nav items in a HORIZONTALLY SCROLLING strip, not a wrapping grid.
     Wrapping was tried and abandoned: getting ten variable-width items to tile inside 365px needs
     min-width juggling on every one, and when it got it wrong the overflow did not clip — it
     widened the layout viewport (measured: nav scrollWidth 472 in a 365px box) and rendered the
     whole console zoomed out. A strip that scrolls INSIDE ITSELF cannot do that whatever the
     labels say, and a vertical list of ten would push the content a screen and a half down.
     `min-width: 0` is still required: a flex item's automatic minimum is its content width, so
     without it the strip refuses to be narrower than its contents and overflows anyway. */
  .nav {
    display: flex; flex-wrap: nowrap; gap: 6px;
    min-width: 0; overflow-x: auto; -webkit-overflow-scrolling: touch;
    padding-bottom: 6px; scrollbar-width: thin;
  }
  .nav-item { flex: 0 0 auto; white-space: nowrap; }
  .nav-item .ico { flex: none; }
  /* Section headings ("Membership" / "Content") cannot read as headings inside a horizontal
     strip — they would just look like unclickable items. */
  .nav-group { display: none; }
  /* With the sidebar stacked ABOVE the content, `.view` no longer needs to be an absolutely
     positioned internal scroller — let the page itself grow and scroll, which is also what makes
     momentum scrolling feel right on iOS. */
  .main { position: static; overflow: visible; }
  .view { position: static; padding: 18px 16px 56px; }
  .adm-stats { grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); }
  /* ≥16px or iOS zooms the page on focus and never zooms back */
  .login-card .input, .adm-toolbar .input, .adm-actions .input { font-size: 16px; }
}
