/* ============================================================
   XE — Portal
   The signed-in surface. Same Night Watch tokens, quieter:
   the marketing pages perform, the portal reports.
   No new palette, no new type scale.
   ============================================================ */

.portal {
  padding-top: var(--nav-h);
  min-height: 100svh;
}

.portal__grid {
  display: grid;
  grid-template-columns: 1fr;
}

@media (min-width: 980px) {
  .portal__grid {
    grid-template-columns: 236px minmax(0, 1fr);
    align-items: start;
  }
}

/* ---------- Rail ----------------------------------------- */

.portal__rail {
  border-bottom: 1px solid var(--line);
  padding-block: 18px 10px;
}

@media (min-width: 980px) {
  .portal__rail {
    position: sticky;
    top: var(--nav-h);
    align-self: start;
    max-height: calc(100svh - var(--nav-h));
    overflow-y: auto;
    border-bottom: 0;
    border-right: 1px solid var(--line);
    padding: 44px 26px 40px 0;
  }
}

.portal__group {
  margin-bottom: 10px;
}

.portal__group + .portal__group {
  margin-top: 26px;
}

.portal__group-title {
  display: block;
  margin-bottom: 8px;
  padding-left: 0;
}

.portal__nav {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}

.portal__nav::-webkit-scrollbar { display: none; }

/* A horizontal nav inside a grid column keeps its min-content width
   unless it is allowed to shrink, which pushed the whole portal wider
   than a phone screen. */
.portal__rail,
.portal__group,
.portal__nav {
  min-width: 0;
}

@media (min-width: 980px) {
  .portal__nav {
    display: block;
    overflow: visible;
  }
}

.portal__link {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 12px;
  border-left: 2px solid transparent;
  font-size: 13.5px;
  line-height: 1.35;
  color: var(--paper-2);
  white-space: nowrap;
  transition: color var(--dur-1) var(--ease-out), border-color var(--dur-1) var(--ease-out),
              background var(--dur-1) var(--ease-out);
}

.portal__link:hover {
  color: var(--paper);
  background: rgba(255, 255, 255, 0.02);
}

.portal__link[aria-current="page"] {
  color: var(--paper);
  border-left-color: var(--lime);
  background: rgba(163, 230, 53, 0.05);
}

.portal__count {
  font: 400 10px/1 var(--font-mono);
  color: var(--paper-4);
  margin-left: auto;
}

.portal__link[aria-current="page"] .portal__count { color: var(--lime); }

.portal__railfoot {
  margin-top: 30px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

/* `display: grid` above outranks the hidden attribute, so the foot has to be
   told. Without it a refused session leaves an empty bordered box behind. */
.portal__railfoot[hidden] { display: none; }

.portal__who {
  font-size: 12px;
  line-height: 1.5;
  color: var(--paper-3);
  overflow-wrap: anywhere;
}

/* ---------- Main ----------------------------------------- */

.portal__main {
  padding-block: clamp(32px, 4.5vw, 56px) clamp(72px, 9vw, 128px);
  min-width: 0;
  max-width: 78ch;
}

@media (min-width: 980px) {
  .portal__main { padding-left: clamp(32px, 4vw, 64px); }
}

.portal__head {
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.portal__title {
  font-size: var(--step-3);
  line-height: 1.05;
  letter-spacing: var(--track-snug);
  margin-top: 10px;
}

.portal__lead {
  margin-top: 14px;
  font-size: var(--step-0);
  line-height: 1.62;
  color: var(--paper-2);
  max-width: 64ch;
}

.portal__meta {
  margin-top: 14px;
  font: 400 10px/1.6 var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--paper-3);
}

.portal__stack {
  display: grid;
  gap: clamp(30px, 4vw, 46px);
  margin-top: clamp(28px, 3.5vw, 40px);
}

.portal__section > h2 {
  font-size: 15px;
  letter-spacing: var(--track-snug);
  margin-bottom: 12px;
}

/* ---------- Figures -------------------------------------- */

.portal__stats {
  display: grid;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

@media (min-width: 620px) {
  .portal__stats { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 1100px) {
  .portal__stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.portal__stat {
  background: var(--void);
  padding: 16px 18px 18px;
}

.portal__stat dt {
  font: 400 10px/1.4 var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--paper-3);
}

.portal__stat dd {
  margin: 8px 0 0;
  font-size: 21px;
  line-height: 1.15;
  letter-spacing: var(--track-snug);
  color: var(--paper);
}

.portal__stat p {
  margin-top: 6px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--paper-3);
}

/* ---------- Rows ----------------------------------------- */

.portal__list {
  border-top: 1px solid var(--line);
}

.portal__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 20px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.portal__row-title {
  font-size: 14px;
  line-height: 1.45;
  color: var(--paper);
  overflow-wrap: anywhere;
}

.portal__row-detail {
  grid-column: 1 / -1;
  /* The row detail is the sentence that explains what is held and why. It is
     read, so it is body text: 13.5px failed the Phase 6 gate. */
  font-size: 1rem;
  line-height: 1.6;
  color: var(--paper-2);
  max-width: 68ch;
}

.portal__row-meta {
  grid-column: 1 / -1;
  font: 400 10px/1.6 var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--paper-3);
}

.portal__state {
  font: 400 10px/1.6 var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--paper-2);
  white-space: nowrap;
  padding-top: 2px;
}

.portal__state--live { color: var(--sos); }
.portal__state--ok { color: var(--lime); }
/* "Needs you" is not an alarm. It is the one state that is white on purpose. */
.portal__state--bad { color: var(--paper); }

/* ---------- Panels --------------------------------------- */

.portal__panel {
  border: 1px solid var(--line);
  background: var(--surface-1);
  padding: clamp(20px, 2.4vw, 28px);
  border-radius: var(--radius-sm);
}

.portal__panel p {
  font-size: 1rem;
  line-height: 1.65;
  color: var(--paper-2);
  max-width: 62ch;
}

.portal__panel p + p { margin-top: 12px; }

.portal__alert {
  border-left: 2px solid var(--sos);
  padding: 10px 0 10px 16px;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--paper);
  max-width: 62ch;
}

.portal__status {
  font: 400 10px/1.7 var(--font-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--paper-3);
}

.portal__status[data-tone="ok"] { color: var(--lime); }
.portal__status[data-tone="bad"] { color: var(--sos); }

/* ---------- Table ---------------------------------------- */

.portal__tablewrap {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}

.portal__table {
  width: 100%;
  min-width: 34rem;
  border-collapse: collapse;
  text-align: left;
}

.portal__table th {
  font: 400 10px/1.4 var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--paper-3);
  padding: 12px 16px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.portal__table td {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--paper-2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.portal__table tr:last-child td { border-bottom: 0; }
.portal__table td:first-child { color: var(--paper); }

/* ---------- Auth panel ----------------------------------- */

.portal__auth {
  max-width: 420px;
  border: 1px solid var(--line);
  background: var(--surface-1);
  border-radius: var(--radius-sm);
  padding: clamp(22px, 3vw, 32px);
}

/* ---------- Sign-in passport ----------------------------- */

/* The sign-in page carried a single 420px card in a 1000px column,
   which left half the screen empty. The plate and ledger fill it with
   the one thing a reader wants before trusting a form: proof of what
   the account already holds. */

.portal__main[data-auth-page] {
  max-width: none;
}

.portal__passport {
  display: grid;
  gap: clamp(26px, 3.4vw, 44px);
  align-items: start;
}

@media (min-width: 900px) {
  .portal__passport {
    grid-template-columns: minmax(0, 420px) minmax(0, 1fr);
    gap: clamp(32px, 4vw, 64px);
  }
}

.portal__passport .portal__auth {
  max-width: none;
}

.portal__aside {
  min-width: 0;
}

.portal__plate {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  aspect-ratio: 16 / 11;
  background: var(--void);
}

.portal__plate img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.86) contrast(1.04) brightness(0.92);
}

.portal__plate::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.86), rgba(0, 0, 0, 0) 56%);
  pointer-events: none;
}

.portal__plate figcaption {
  position: absolute;
  left: 14px;
  bottom: 12px;
  z-index: 2;
  color: var(--paper-2);
}

.portal__ledger {
  margin-top: 18px;
  border-top: 1px solid var(--line);
}

.portal__ledger li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  font: 400 10px/1.5 var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--paper-3);
}

.portal__ledger b {
  font-weight: 400;
  letter-spacing: 0.04em;
  text-align: right;
  color: var(--paper);
}

.portal__ledger li:last-child b {
  color: var(--lime);
}

.portal__auth .form { max-width: none; }

/* ---------- Google sign-in ------------------------------- */

/* The G is the only mark on the site whose colours are not ours, so it keeps
them and is never retinted for the dark surface. The button itself is the
site's own ghost style at full width, which puts it in the same column as the
form; flex: none stops the mark being squashed in the narrow card. */
.portal__alt[hidden] { display: none; }

.portal__google {
  width: 100%;
  justify-content: center;
}

.portal__google svg {
  width: 16px;
  height: 16px;
  flex: none;
}

.portal__or {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 20px 0 0;
  font: 400 10px/1 var(--font-mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--paper-3);
}

.portal__or::before,
.portal__or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.portal__auth-head h2 {
  font-size: var(--step-1);
  letter-spacing: var(--track-snug);
}

.portal__auth-head p {
  margin-top: 10px;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--paper-2);
}

.portal__switch {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.portal__authfoot {
  margin-top: 18px;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--paper-3);
  max-width: 46ch;
}

/* ---------- Inline links --------------------------------- */

.portal a.portal__a {
  color: var(--paper);
  box-shadow: inset 0 -1px 0 var(--paper-4);
  transition: color var(--dur-1) var(--ease-out), box-shadow var(--dur-1) var(--ease-out);
}

.portal a.portal__a:hover {
  color: var(--lime);
  box-shadow: inset 0 -1px 0 var(--lime);
}

/* ---------- Config notice -------------------------------- */

.portal__env {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.portal__env code {
  font: 400 12px/1.9 var(--font-mono);
  color: var(--paper-2);
  overflow-wrap: anywhere;
}

/* ---------- Busy state ----------------------------------- */

.portal__spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 1px solid var(--paper-4);
  border-top-color: var(--lime);
  border-radius: 50%;
  animation: portal-spin 700ms linear infinite;
  vertical-align: -1px;
  margin-right: 8px;
}

@keyframes portal-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .portal__spinner { animation: none; border-top-color: var(--paper-4); }
}

/* ---------- Narrow -------------------------------------- */

@media (max-width: 979px) {
  .portal__rail { padding-bottom: 6px; }
  .portal__group { margin-bottom: 6px; }
  .portal__group-title { margin-bottom: 6px; }
  .portal__railfoot { margin-top: 14px; padding-top: 14px; }
  .portal__main { max-width: none; }
}

/* Evidence media: the View button fetches with the session token and
   swaps itself for the file. A note stands beside anything the rules
   refused or that was never stored. */
.portal__btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 1rem;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 6px;
  cursor: pointer;
}
.portal__btn:disabled { opacity: 0.6; cursor: default; }

/* ---------- Safety status band --------------------------- */

.portal__safety {
  display: grid;
  gap: clamp(18px, 2.5vw, 28px);
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--paper-4);
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  padding: clamp(20px, 3vw, 28px);
}
.portal__safety[data-tone="ok"] { border-left-color: var(--lime); }
.portal__safety[data-tone="bad"] { border-left-color: var(--paper-2); }
.portal__safety[data-tone="live"] { border-left-color: var(--sos); }

@media (min-width: 860px) {
  .portal__safety { grid-template-columns: minmax(0, 1fr) minmax(240px, 320px); align-items: center; }
}

.portal__safety-level {
  margin: 10px 0 0;
  font-size: var(--step-2);
  line-height: 1.1;
  letter-spacing: var(--track-snug);
  color: var(--paper);
}
.portal__safety-headline { margin: 10px 0 0; max-width: 46ch; color: var(--paper-2); }
.portal__safety-act { display: grid; gap: 12px; justify-items: start; }
.portal__btn--primary {
  border-color: var(--lime);
  background: var(--lime);
  color: #0b0f0c;
  font-weight: 600;
}
.portal__btn--primary:hover { background: var(--paper); border-color: var(--paper); }
.portal__safety-note { font-size: 1rem; color: var(--paper-3); margin: 0; }
.portal__safety-detail { grid-column: 1 / -1; }

.portal__media-wrap { margin: 4px 0; max-width: 320px; }
.portal__media {
  display: block;
  max-width: 100%;
  max-height: 300px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
}
.portal__media-wrap audio.portal__media { width: 260px; max-height: none; }
.portal__media-note { font-size: 12.5px; color: var(--paper-3); }
