/* ============================================================================
   NietzX portal — design tokens + auth styles
   ----------------------------------------------------------------------------
   Self-hosted fonts only (../fonts); no external requests. The page runs under
   a strict CSP (no scripts), so every interaction here is HTML/CSS only.

   Every shared value is a custom property in :root. New auth pages (issue
   token, sign release, etc.) should reuse these tokens and component classes
   so the whole surface stays visually consistent.
   ============================================================================ */

/* ---- Fonts -------------------------------------------------------------- */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/inter-latin-400-normal.73aaa95eab31.woff2") format("woff2");
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/inter-latin-500-normal.96948ea7ac03.woff2") format("woff2");
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/inter-latin-600-normal.0bf7eadca131.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/ibm-plex-mono-latin-400-normal.4cc7b4398540.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/ibm-plex-mono-latin-500-normal.bc5ccab82723.woff2") format("woff2");
}

/* ---- Design tokens ------------------------------------------------------ */
:root {
  color-scheme: light;

  /* Colour */
  --color-page: #f3f4f6;
  --color-surface: #ffffff;
  --color-surface-alt: #f9fafb;
  --color-border: #d1d5db;
  --color-border-strong: #6b7280;
  --color-text: #111827;
  --color-text-muted: #4b5563;
  --color-text-subtle: #374151;
  --color-accent: #174e42;
  --color-accent-hover: #0f3b32;
  --color-link: #1d4ed8;
  --color-action: #000000;
  --color-action-hover: #1f2937;
  --color-on-action: #ffffff;
  --color-focus-ring: rgba(29, 78, 216, 0.18);
  --color-overlay: rgba(17, 24, 39, 0.5);

  /* Type families — swap the whole surface by re-pointing these two. */
  --font-sans: "Inter", "Helvetica Neue", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", "Cascadia Mono", Consolas, monospace;
  --font-body: var(--font-sans);
  --font-label: var(--font-mono);

  /* Type scale */
  --text-2xs: 9px;
  --text-xs: 11px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-md: 16px;
  --text-lg: 20px;
  --text-xl: 23px;

  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;

  --leading-tight: 1.2;
  --leading-snug: 1.4;
  --leading-normal: 1.5;

  --tracking-tight: -0.04em;
  --tracking-label: 0.08em;

  /* Spacing — 4px base scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 28px;
  --space-8: 32px;
  --space-11: 44px;

  /* Sizing / layout */
  --layout-max: 896px;
  --form-max: 384px;
  --modal-max: 440px;
  --gutter: 16px;
  --control-height: 40px;
  --button-height: 42px;

  /* Borders / radius */
  --border-width: 1px;
  --radius: 0px;

  /* Effects */
  --ring-focus: 0 0 0 3px var(--color-focus-ring);
  --shadow-modal: 0 24px 64px rgba(17, 24, 39, 0.28);
  --transition: 0.15s ease;

  /* Layers */
  --z-modal: 100;
}

/* ---- Base --------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--color-page);
  text-size-adjust: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--color-text);
  background: var(--color-page);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input,
textarea {
  font: inherit;
}

a {
  color: var(--color-link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ---- Field label (shared system treatment) ----------------------------- */
.field-label {
  display: block;
  margin-bottom: var(--space-1);
  color: var(--color-text-subtle);
  font-family: var(--font-label);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}

/* ---- Form controls (shared) -------------------------------------------- */
.control {
  display: block;
  width: 100%;
  padding: 0 var(--space-3);
  height: var(--control-height);
  color: var(--color-text);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

textarea.control {
  height: auto;
  min-height: calc(var(--control-height) * 2);
  padding: var(--space-2) var(--space-3);
  line-height: var(--leading-snug);
  resize: vertical;
}

.control:hover {
  border-color: var(--color-accent);
}

.control:focus-visible {
  border-color: var(--color-link);
  box-shadow: var(--ring-focus);
}

.field-group {
  margin-bottom: var(--space-4);
}

.field-hint {
  margin: var(--space-1) 0 0;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

/* ---- Button (shared) ---------------------------------------------------- */
.button {
  display: block;
  width: 100%;
  min-height: var(--button-height);
  padding: var(--space-2) var(--space-4);
  color: var(--color-on-action);
  background: var(--color-action);
  border: var(--border-width) solid var(--color-action);
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: var(--weight-semibold);
  transition: background var(--transition), border-color var(--transition);
}

.button:hover {
  background: var(--color-action-hover);
  border-color: var(--color-action-hover);
  text-decoration: none;
}

.button:focus-visible {
  outline: 2px solid var(--color-link);
  outline-offset: 3px;
}

/* ---- Layout ------------------------------------------------------------- */
.portal-page {
  display: grid;
  min-height: 100vh;
  min-height: 100svh;
  place-items: start center;
  padding: var(--space-11) var(--gutter);
}

.portal-shell {
  width: min(100%, var(--layout-max));
}

/* ---- Header + brand ----------------------------------------------------- */
.portal-header {
  display: flex;
  min-height: 62px;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  padding: var(--space-3) 0;
  border-bottom: var(--border-width) solid var(--color-border);
}

.site-brand {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-3);
  color: var(--color-accent);
  text-decoration: none;
  white-space: nowrap;
}

.site-brand:hover {
  text-decoration: none;
}

.site-brand-name {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
}

.site-brand small {
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.header-help {
  margin: 0;
  font-size: var(--text-sm);
  white-space: nowrap;
}

/* ---- Login section ------------------------------------------------------ */
.login-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-8) 0 var(--space-5);
}

.login-section h1 {
  margin: 0 0 25px;
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
}

.login-form {
  width: min(100%, var(--form-max));
}

.form-options {
  display: flex;
  min-height: 28px;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  margin-bottom: var(--space-4);
}

.remember-option {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
}

.remember-option input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--color-accent);
}

.remember-option span,
.form-forgot {
  font-size: var(--text-sm);
}

/* ---- Access notice ------------------------------------------------------ */
.access-notice {
  margin-top: var(--space-6);
  text-align: center;
}

.access-notice-lead {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
}

.access-notice-lead span {
  display: block;
}

.access-notice-body {
  margin: var(--space-5) auto 0;
  color: var(--color-text-subtle);
  font-size: var(--text-xs);
  font-style: italic;
  font-weight: var(--weight-regular);
  line-height: var(--leading-normal);
}

/* ---- Modal (JS driven) -------------------------------------------------
   Opened by macunix.js adding .is-open (data-modal-open / data-modal-close
   hooks), so showing a dialog no longer rewrites the URL fragment. The
   :target selector is kept as a no-JS fallback: an id in the fragment still
   opens the matching modal. */
.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-6) var(--gutter);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.modal:target,
.modal.is-open {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  padding: 0;
  border: 0;
  background: var(--color-overlay);
  cursor: default;
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(100%, var(--modal-max));
  max-height: calc(100vh - var(--space-8));
  max-height: calc(100svh - var(--space-8));
  overflow-y: auto;
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-modal);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-bottom: var(--border-width) solid var(--color-border);
}

.modal-title {
  margin: 0;
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
}

.modal-close {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-right: calc(var(--space-2) * -1);
  padding: 0;
  color: var(--color-text-muted);
  background: none;
  border: var(--border-width) solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
}

.modal-close:hover {
  color: var(--color-text);
  background: var(--color-surface-alt);
  text-decoration: none;
}

.modal-close:focus-visible {
  outline: 2px solid var(--color-link);
  outline-offset: 1px;
}

.modal-close svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.modal-body {
  padding: var(--space-5);
}

.modal-intro {
  margin: 0 0 var(--space-5);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}

.modal-body .button {
  margin-top: var(--space-1);
}

/* ---- Responsive: tablet & phone ---------------------------------------- */
@media (max-width: 600px) {
  .portal-page {
    display: block;
    padding-top: var(--space-5);
    padding-bottom: var(--space-6);
  }

  .portal-header {
    min-height: 0;
    align-items: flex-start;
  }

  .site-brand {
    display: grid;
    gap: 2px;
  }

  .site-brand-name {
    font-size: var(--text-lg);
  }

  .site-brand small {
    font-size: 8px;
  }

  .header-help {
    max-width: 130px;
    font-size: var(--text-sm);
    line-height: var(--leading-snug);
    text-align: right;
    white-space: normal;
  }

  .login-section {
    padding-top: var(--space-7);
  }

  .access-notice {
    margin-top: 30px;
  }

  .access-notice-body {
    text-align: left;
  }

  /* Modals become a bottom-anchored sheet on phones: scroll from the top,
     tighter gutters, and slightly smaller heading/intro type. */
  .modal {
    align-items: flex-start;
    padding: var(--space-3);
  }

  .modal-panel {
    max-height: calc(100vh - var(--space-6));
    max-height: calc(100svh - var(--space-6));
  }

  .modal-head {
    padding: var(--space-3) var(--space-4);
  }

  .modal-title {
    font-size: var(--text-base);
  }

  .modal-body {
    padding: var(--space-4);
  }

  .modal-intro {
    font-size: var(--text-xs);
  }
}

/* ---- High-contrast / forced colours ------------------------------------ */
@media (forced-colors: active) {
  .control,
  .button,
  .modal-panel {
    border: var(--border-width) solid CanvasText;
  }

  .control:focus-visible,
  .button:focus-visible,
  .modal-close:focus-visible {
    outline: 2px solid Highlight;
    outline-offset: 2px;
  }

  .button {
    color: ButtonText;
    background: ButtonFace;
  }
}
/* ---- Authenticated operator page --------------------------------------- */
/* This page deliberately inherits the login page's portal, brand, form,
   control, and button styles. Only the authenticated navigation and layout
   below are new. */

.operator-page .portal-shell {
  display: flex;
  min-height: calc(100vh - var(--space-11) - var(--space-11));
  min-height: calc(100svh - var(--space-11) - var(--space-11));
  flex-direction: column;
}

.operator-session {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.operator-session .header-help {
  color: var(--color-text-muted);
}

.session-form {
  margin: 0;
}

.session-action {
  padding: var(--space-2) var(--space-3);
  color: var(--color-text-subtle);
  background: transparent;
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition:
    color var(--transition),
    background var(--transition),
    border-color var(--transition);
}

.session-action:hover {
  color: #991b1b;
  background: #fef2f2;
  border-color: #fca5a5;
}

.session-action:focus-visible {
  outline: 2px solid var(--color-link);
  outline-offset: 2px;
}

.operator-nav {
  display: flex;
  gap: var(--space-6);
  border-bottom: var(--border-width) solid var(--color-border);
}

.operator-nav-link {
  padding: var(--space-4) 0 var(--space-3);
  color: var(--color-text-muted);
  border-bottom: 2px solid transparent;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-decoration: none;
}

.operator-nav-link:hover {
  color: var(--color-text);
  text-decoration: none;
}

/* Active tab. JS (macunix.js) toggles .is-active on click so switching tabs
   never rewrites the URL or pushes a history entry; the server also renders it
   so a fresh load / post-back lands on the right tab with no flash. */
.operator-nav-link.is-active {
  color: var(--color-text);
  border-bottom-color: var(--color-accent);
}

.operator-panels {
  flex: 1;
  padding: var(--space-8) 0 var(--space-6);
}

.operator-section {
  display: none;
  flex-direction: column;
  align-items: center;
}

.operator-section.is-active {
  display: flex;
}

.operator-section h1 {
  margin: 0 0 var(--space-3);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
}

.operator-intro {
  max-width: 520px;
  margin: 0 0 var(--space-6);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  text-align: center;
}

.operator-form {
  width: min(100%, var(--form-max));
}

.control-mono {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.operator-placeholder {
  width: min(100%, var(--form-max));
  padding: var(--space-5);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  text-align: center;
}

.operator-placeholder p {
  margin: 0 0 var(--space-4);
}

.operator-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  padding: var(--space-5) 0;
  color: var(--color-text-muted);
  border-top: var(--border-width) solid var(--color-border);
  font-size: var(--text-xs);
}

.operator-footer p {
  margin: 0;
}

@media (max-width: 600px) {
  .operator-page .portal-shell {
    min-height: calc(100vh - var(--space-5) - var(--space-6));
    min-height: calc(100svh - var(--space-5) - var(--space-6));
  }

  .operator-session .header-help {
    display: none;
  }

  .operator-nav {
    gap: var(--space-5);
    overflow-x: auto;
  }

  .operator-nav-link {
    flex: 0 0 auto;
  }

  .operator-panels {
    padding-top: var(--space-7);
  }

  .operator-footer {
    display: block;
    text-align: center;
  }

  .operator-footer p + p {
    margin-top: var(--space-2);
  }
}

@media (forced-colors: active) {
  .session-action,
  .operator-placeholder {
    border: var(--border-width) solid CanvasText;
  }

  .session-action:focus-visible {
    outline: 2px solid Highlight;
    outline-offset: 2px;
  }
}

/* Accessibility skip link rendered by the shared base template. Off-screen
   until keyboard-focused. */
.skip-link {
  position: absolute;
  top: 8px;
  left: -9999px;
  z-index: 100;
  padding: 8px 14px;
  background: #14181d;
  color: #fdfdfd;
  font-size: 13px;
  text-decoration: none;
}

.skip-link:focus {
  left: 8px;
}

/* ---- Issued-token result (operator console) ---------------------------- */
.issue-result {
  margin-top: var(--space-6);
}

.issue-result .field-label {
  margin: var(--space-4) 0 var(--space-2);
}

.issue-fingerprint {
  margin: 0;
}

/* The machine code is one long unbroken string: wrap it inside a box instead
   of letting it overflow the panel. */
.issue-fingerprint code {
  display: block;
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface, rgba(0, 0, 0, 0.03));
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  word-break: break-all;
}

.issue-token {
  width: 100%;
  resize: vertical;
  word-break: break-all;
}

.issue-copy {
  display: inline-flex;
  width: auto;
  margin-top: var(--space-3);
}

.issue-note {
  margin: var(--space-4) 0 0;
  padding: var(--space-3);
  color: var(--color-text-subtle);
  background: var(--color-surface, rgba(0, 0, 0, 0.03));
  border-left: 2px solid var(--color-accent);
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
}

/* Signed-manifest details inside the sign-result modal. */
.sign-details {
  margin: 0 0 var(--space-4);
}

.sign-details dt {
  margin-top: var(--space-3);
  color: var(--color-text-subtle);
  font-family: var(--font-label);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sign-details dd {
  margin: var(--space-1) 0 0;
  font-size: var(--text-sm);
}

.sign-details dd code {
  display: block;
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface-alt, rgba(0, 0, 0, 0.03));
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  word-break: break-all;
}

/* Verify report: one line per app-acceptance check, pass/fail marked. */
.verify-checks {
  margin: 0 0 var(--space-4);
  padding: 0;
  list-style: none;
}

.verify-checks li {
  position: relative;
  padding: var(--space-1) 0 var(--space-1) var(--space-6);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
}

.verify-checks li::before {
  position: absolute;
  left: 0;
  font-weight: var(--weight-semibold);
}

.verify-checks li.pass::before {
  content: "\2713";  /* check mark */
  color: #15803d;
}

.verify-checks li.fail {
  color: #b91c1c;
}

.verify-checks li.fail::before {
  content: "\2715";  /* cross */
  color: #b91c1c;
}

/* Modal footer: primary action + quiet close, side by side. */
.modal-actions {
  display: flex;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

.modal-actions form {
  flex: 1;
}

.modal-actions form .button {
  width: 100%;
  margin-top: 0;
}

.modal-actions > .button {
  width: auto;
  margin-top: 0;
}

.button-quiet {
  color: var(--color-text);
  background: none;
  border-color: var(--color-border-strong);
}

.button-quiet:hover {
  background: var(--color-surface-alt);
  border-color: var(--color-border-strong);
}
