/* ============================================================================
   portal.css — the portal shell, written against the estate brand.

   The palette is NOT defined here. brand/nkda-theme.css (linked at build time
   from NKDAgility.Hugo.Appearance/assets/css/nkda-theme.css, the estate's one
   definition of light and dark) loads first and supplies --nkd-* primitives
   and the semantic aliases (--color-*, --text-*, --surface-*, --border-*).
   This file only maps portal roles onto those properties. Do not add hex
   colours here; if the brand lacks a value, it belongs in nkda-theme.css.

   Brand rules: signature purple against generous white space; blue and
   orange as functional accents only; no gradients; purple headings; fluid
   clamp() sizing.
   ========================================================================= */
:root {
  --portal-font: "Open Sans", "Segoe UI", Calibri, -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  --portal-line: var(--border-subtle);
  --portal-gutter: clamp(1rem, 0.6rem + 1.6vw, 2rem);
  --portal-radius: 6px;
  --portal-focus: var(--color-secondary);
  --portal-topbar-height: 3.75rem;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--portal-font);
  font-size: clamp(1rem, 0.96rem + 0.2vw, 1.0625rem);
  line-height: 1.6;
  color: var(--text-body);
  background: var(--surface-page);
}

h1, h2, h3 { color: var(--text-heading); font-weight: 600; line-height: 1.2; margin: 0 0 0.75rem; }
h1 { font-size: clamp(1.75rem, 1.4rem + 1.4vw, 2.5rem); letter-spacing: -0.01em; margin-bottom: 1.25rem; }
h2 { font-size: clamp(1.25rem, 1.1rem + 0.6vw, 1.5rem); }
p { margin: 0 0 1rem; }

a { color: var(--text-link); text-underline-offset: 0.18em; }
a:hover { color: var(--color-secondary-hover); }

:focus-visible { outline: 3px solid var(--portal-focus); outline-offset: 2px; border-radius: 2px; }

/* ---- Top bar: the compact mark white on its purple tile, on a white bar ---- */
.portal-topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  min-height: var(--portal-topbar-height);
  padding: 0.5rem var(--portal-gutter);
  background: var(--surface-page);
  border-bottom: 3px solid var(--color-primary);
}
.portal-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--color-primary);
  text-decoration: none;
  white-space: nowrap;
}
.portal-brand:hover { color: var(--color-primary-active); }
.portal-brand-mark { display: block; width: 2.25rem; height: 2.25rem; }
.portal-spacer { flex: 1; }
.portal-user { color: var(--text-muted); overflow-wrap: anywhere; }

/* Sign in / sign out read as the brand's primary and outline buttons. */
.portal-link {
  display: inline-block;
  padding: 0.4rem 1rem;
  border: 2px solid var(--color-primary);
  border-radius: var(--portal-radius);
  background: var(--color-primary);
  color: var(--text-on-primary);
  font-weight: 600;
  text-decoration: none;
  line-height: 1.3;
}
.portal-link:hover { background: var(--color-primary-active); border-color: var(--color-primary-active); color: var(--text-on-primary); }

/* ---- Environment label: which API this site is talking to ---- */
.portal-env {
  padding: 0.1rem 0.65rem;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.5;
  color: var(--text-muted);
  background: var(--surface-page);
}
/* Live is the normal case, so it wears the brand purple; sandbox is the one an
   operator must notice, so it takes the orange accent on its own wash. The
   orange is a fill with dark ink, never orange text, to keep AA contrast. */
.portal-env-live { color: var(--color-primary); background: var(--surface-callout); }
.portal-env-sandbox { color: var(--nkd-ink); background: var(--color-accent); border-color: var(--color-accent); }

/* ---- Page frame ---- */
.portal-body { display: flex; min-height: calc(100vh - var(--portal-topbar-height)); }
.portal-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: var(--portal-gutter) 1rem;
  min-width: 12rem;
  background: var(--surface-muted);
  border-right: 1px solid var(--portal-line);
}
.portal-nav-link {
  padding: 0.45rem 0.75rem;
  border-radius: var(--portal-radius);
  border-left: 3px solid transparent;
  text-decoration: none;
  color: var(--text-body);
  font-weight: 600;
}
.portal-nav-link:hover { color: var(--color-primary); background: var(--surface-callout); }
.portal-nav-link.active { background: var(--color-primary); color: var(--text-on-primary); }
.portal-nav-section { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 0.75rem; }
.portal-nav-heading { padding: 0 0.75rem; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.04em; color: var(--text-muted); }

/* ---- Tabs inside an entry: one address each ---- */
.portal-tabs { display: flex; gap: 0.25rem; overflow-x: auto; margin: 0 0 1.5rem; border-bottom: 1px solid var(--portal-line); }
.portal-tab { padding: 0.5rem 0.9rem; white-space: nowrap; text-decoration: none; color: var(--text-muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.portal-tab:hover { color: var(--color-primary); }
.portal-tab.active { color: var(--text-heading); border-bottom-color: var(--color-primary); }
.portal-main { flex: 1; min-width: 0; padding: clamp(1.5rem, 1rem + 2vw, 3rem) var(--portal-gutter); max-width: 64rem; }

/* ---- Loading, empty and failure states ---- */
.portal-state {
  margin: 0 0 1.25rem;
  padding: 1rem 1.25rem;
  border-left: 4px solid var(--color-primary);
  border-radius: 0 var(--portal-radius) var(--portal-radius) 0;
  background: var(--surface-callout);
}
.portal-state > :last-child { margin-bottom: 0; }
.portal-state h2 { font-size: 1.15rem; }
/* Brand blue on the lilac/grey washes falls just under 4.5:1, so links inside a
   state panel take the purple, which clears AA comfortably. */
.portal-state a { color: var(--color-primary); font-weight: 600; }
.portal-state a:hover { color: var(--color-primary-active); }
/* Failure is flagged by the orange accent rule plus role="alert"; the text stays
   body ink so it meets AA on the muted surface. */
.portal-state-failure { border-left-color: var(--color-accent); background: var(--surface-muted); }

/* ---- Admin dashboard and lenses ---- */
.portal-lenses { list-style: none; padding: 0; margin: 0; display: grid; gap: 1rem; }
.portal-lenses li {
  padding: 1rem 1.25rem;
  border: 1px solid var(--portal-line);
  border-top: 3px solid var(--color-primary);
  border-radius: var(--portal-radius);
  background: var(--surface-card);
}
.portal-lenses a { font-weight: 600; }

.portal-table-wrap { overflow-x: auto; }
.portal-table { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
.portal-table th, .portal-table td { text-align: left; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--portal-line); }
.portal-table thead th { color: var(--text-heading); font-weight: 600; border-bottom: 2px solid var(--color-primary); white-space: nowrap; }
.portal-table tbody tr:nth-child(even) { background: var(--surface-muted); }

dl dt { font-weight: 600; color: var(--text-heading); }
dl dd { margin: 0 0 0.75rem; }

#blazor-error-ui { border-top: 3px solid var(--color-accent); background: var(--surface-muted); }

/* ---- Phone width ---- */
@media (max-width: 40rem) {
  .portal-body { flex-direction: column; }
  .portal-nav-section { flex-direction: row; flex-wrap: wrap; margin-bottom: 0.25rem; }
  .portal-nav { flex-direction: row; flex-wrap: wrap; min-width: 0; padding: 0.5rem var(--portal-gutter); border-right: 0; border-bottom: 1px solid var(--portal-line); }
  .portal-spacer { flex-basis: 0; }
}
