/**
 * Hyperion Portal — plain-CSS port of hyperion-frontend's design tokens
 * (src/styles/theme.css, "Night Instrument" + "Bracketed Technical").
 *
 * This service is server-rendered Jinja with no build pipeline — no
 * Tailwind, no @tailwind directives, no `hsl(var(--x))` opacity-modifier
 * trick that needs bare channels. Only what a plain <style> block can use
 * is ported: the :root custom properties (kept as full `hsl(...)` values
 * here, not channels), the dark-only base layer, the focus ring, and the
 * bracket-corner utility. The full token set (light-mode variants,
 * severity/status colours the portal has no use for) is deliberately not
 * copied — this file should stay small and hand-auditable, not a mirror
 * of the frontend's own file.
 *
 * v1.0 is dark-only in the frontend too, so this is pinned to dark
 * unconditionally (`_base.html` sets `color-scheme: dark`, not
 * `light dark`) rather than following the OS preference.
 *
 * 2026-09-22 redesign — direction locked with the user via a live
 * preview artifact (five structural options compared, then iterated):
 * split brand/content panel on desktop ("Split Instrument Panel"),
 * collapsing to a single bracket-cornered console card on mobile
 * ("Single Console Card"). The faint schematic grid introduced for a
 * full-bleed bezel concept became the shared background texture across
 * every surface instead — login, sites, and admin, desktop and mobile
 * alike. Scope: login/sites/admin markup and this stylesheet only; no
 * route, form field, or server-side behaviour changed.
 */

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/static/fonts/inter-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'Space Grotesk';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/static/fonts/space-grotesk-latin.woff2') format('woff2');
}

:root {
  --background: hsl(225 46% 7%);
  --foreground: hsl(226 62% 96%);
  --card: hsl(227 45% 8%);
  --card-foreground: hsl(226 62% 96%);
  --primary: hsl(221 83% 53%);
  --primary-foreground: hsl(226 62% 96%);
  --primary-hover: hsl(221 83% 47%);
  --secondary: hsl(227 39% 14%);
  --muted-foreground: hsl(227 26% 69%);
  --destructive: hsl(347 100% 71%);
  --status-success: hsl(165 79% 54%);

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --bracket-color: hsl(204 100% 65%); /* blue-400 */
  --grid-line: rgba(255, 255, 255, 0.035);

  --shadow-elevated: 0 8px 24px rgba(0, 0, 0, 0.4);
  --focus-ring: 0 0 0 2px var(--background), 0 0 0 4px var(--primary);

  --radius-md: 3px;
  --radius-lg: 4px;

  --dur-base: 150ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
  background: var(--background);
}

body {
  background: var(--background);
  /* The schematic grid is the redesign's one shared visual motif and
     lives on `body` directly rather than as a class some wrapper has
     to remember to carry — it's the instrument backdrop everywhere, not
     a per-page opt-in. `.page`'s max-width leaves solid margin either
     side of the centered column on a wide viewport; if the grid only
     lived on `.page`, that margin would read as a plain solid gutter
     instead of the same backdrop. Deliberately faint: texture, not
     pattern. `.grid-bg` (below) exists only for a panel that sets its
     own opaque fill — e.g. `.login-brand`'s `--card` background — which
     would otherwise occlude this and needs to reassert the grid itself. */
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 26px 26px;
  color: var(--foreground);
  font-family: 'Inter', ui-sans-serif, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  margin: 0;
  line-height: 1.5;
  min-height: 100vh;
}

h1, h2 {
  font-family: 'Space Grotesk', ui-sans-serif, system-ui, sans-serif;
  font-weight: 600;
}
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.05rem; }

a {
  color: var(--bracket-color);
}

/* Reasserts the grid over an element that set its own opaque
   background (see the `body` rule above for why this exists at all). */
.grid-bg {
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 26px 26px;
}

/* Page shell for sites/admin — login uses its own full-bleed .login-shell
   instead, since it needs the split panel, not a centered column. */
.page {
  max-width: 900px;
  margin: 0 auto;
  padding: 3rem 1.5rem 4rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.brand img { width: 28px; height: 28px; }
.brand span {
  font-family: 'Space Grotesk', ui-sans-serif, system-ui, sans-serif;
  font-weight: 600;
  font-size: 1.05rem;
}
.brand .section-tag {
  font-family: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, monospace;
  font-weight: 500;
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--bracket-color);
  background: var(--secondary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 0.15rem 0.45rem;
}

.nav-back {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--muted-foreground);
  text-decoration: none;
  font-size: 0.85rem;
  transition: color var(--dur-base) var(--ease-out);
}
.nav-back:hover { color: var(--bracket-color); }

/* Bracket-corner treatment — Bracketed Technical's one signature move,
   drawn corners, never a full glow/box. Only on flat, non-replaced
   elements (a <div>, not an <input> or <select> — those don't reliably
   render ::before/::after). Shared by `.card` (a row-shaped tile: a
   site, a grant) and `.panel` (a block-shaped container: a table, a
   form group) so both read as the same family of object. */
.card,
.panel {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}
.card::before,
.card::after,
.panel::before,
.panel::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  pointer-events: none;
  border-color: var(--bracket-color);
}
.card::before,
.panel::before {
  top: -1px;
  left: -1px;
  border-left: 1.5px solid;
  border-top: 1.5px solid;
}
.card::after,
.panel::after {
  bottom: -1px;
  right: -1px;
  border-right: 1.5px solid;
  border-bottom: 1.5px solid;
}

.card {
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.panel {
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.75rem;
}
.panel h2 {
  margin-bottom: 1rem;
}

input, select, button {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--secondary);
  color: var(--foreground);
}

input::placeholder {
  color: var(--muted-foreground);
}

select[multiple] {
  padding: 0.35rem;
}
select[multiple] option {
  padding: 0.35rem 0.5rem;
}

button {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-foreground);
  cursor: pointer;
  font-weight: 500;
  transition: background var(--dur-base) var(--ease-out);
}
button:hover {
  background: var(--primary-hover);
}
button.secondary {
  background: var(--secondary);
  border-color: var(--border-strong);
  color: var(--foreground);
}
button.danger {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--destructive);
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

form.inline { display: inline; }

.error {
  color: var(--destructive);
  background: rgba(255, 107, 138, 0.1);
  border: 1px solid rgba(255, 107, 138, 0.3);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.85rem;
  font-size: 0.9rem;
}

.hint {
  color: var(--status-success);
  background: rgba(46, 230, 184, 0.1);
  border: 1px solid rgba(46, 230, 184, 0.3);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.95rem;
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}
.hint strong { display: block; margin-bottom: 0.25rem; }

.muted { color: var(--muted-foreground); font-size: 0.9rem; }
.mono { font-family: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, monospace; }

.table-scroll { width: 100%; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; min-width: 420px; margin-bottom: 0; }
th, td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border-subtle);
  /* a bare URL/email is one unbroken string — without this it overflows
     the cell (and the panel's bracket corners) instead of wrapping. */
  overflow-wrap: anywhere;
}
th { color: var(--muted-foreground); font-weight: 500; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.02em; }
tr:last-child td { border-bottom: none; }

.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.status-active { color: var(--status-success); }
.status-revoked { color: var(--muted-foreground); }

form.grant-form,
form.site-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-start;
  margin-top: 1rem;
  margin-bottom: 0;
  max-width: 100%;
}
/* Inputs carry a `size`/intrinsic width for a sane default, but a flex
   item won't shrink below that on its own — on a narrow panel that
   pushes the row wider than the panel and out past its border instead
   of wrapping. flex-basis + min-width:0 lets them actually shrink. */
form.grant-form input,
form.grant-form select,
form.site-form input {
  flex: 1 1 160px;
  min-width: 0;
}

/* ---- Login: split instrument panel (desktop) / console card (mobile) ---- */

.login-shell {
  display: flex;
  min-height: 100vh;
}

.login-brand {
  flex: 0 0 40%;
  min-width: 280px;
  padding: 2.5rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--card);
  border-right: 1px solid var(--border-subtle);
}
.login-brand .tagline {
  font-size: 1.5rem;
  line-height: 1.2;
  margin-top: 1.75rem;
}
.login-brand .foot {
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  color: var(--muted-foreground);
}

.login-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Extra bottom padding lifts the card above true centre — a form
     centred exactly reads as sitting low against the brand panel's
     top-anchored mark and tagline. Mobile resets padding below, so the
     single console card there stays truly centred. */
  padding: 2rem 1.5rem 14vh;
}

.login-card {
  position: relative;
  width: 100%;
  max-width: 320px;
}
/* Bracket corners exist on the card at every width, but only read as a
   real card — background, border, padding — once the split collapses.
   On desktop the fields sit directly on the grid, matching the locked
   comp; the corners alone would be too quiet a signal there, so they
   stay invisible until the mobile card actually forms. */
.login-card::before,
.login-card::after {
  content: '';
  position: absolute;
  width: 9px;
  height: 9px;
  pointer-events: none;
  border-color: var(--bracket-color);
  opacity: 0;
}
.login-card::before { top: -1px; left: -1px; border-left: 1.5px solid; border-top: 1.5px solid; }
.login-card::after { bottom: -1px; right: -1px; border-right: 1.5px solid; border-bottom: 1.5px solid; }

.login-eyebrow {
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  margin-bottom: 0.3rem;
}

.login-card h1 { font-size: 1.2rem; margin-bottom: 1.25rem; }

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.login-card button { margin-top: 0.25rem; }

.login-mobile-brand {
  display: none;
  text-align: center;
  margin-bottom: 1.5rem;
}
.login-mobile-brand img { width: 30px; height: 30px; margin-bottom: 0.6rem; }

@media (max-width: 760px) {
  .login-shell { flex-direction: column; min-height: auto; }
  .login-brand { display: none; }
  .login-content { min-height: 100vh; padding: 1.5rem; }
  .login-card {
    background: var(--card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 2rem 1.75rem;
  }
  .login-card::before,
  .login-card::after { opacity: 1; }
  .login-mobile-brand { display: block; }
}

@media (max-width: 720px) {
  .page { padding: 2rem 1.25rem 3rem; }
  .card { flex-wrap: wrap; }
  form.grant-form select[multiple],
  form.site-form input { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}
