/*
 * Portal app components — layered on top of the shared brand stylesheet
 * (styles.css). Only app-specific UI lives here: the app header, auth cards,
 * form controls, data tables and status pills. Everything uses the shared
 * design tokens so the portal matches the marketing site.
 */

/* ===== APP HEADER ===== */
.site-logo { gap: 10px; }
.site-logo img { height: 32px; width: 32px; }
.portal-wordmark {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--navy-deep);
}
.portal-wordmark span { color: var(--blue); font-weight: 700; }

/* Role-aware primary nav */
.portal-nav { display: flex; align-items: center; gap: 4px; margin-left: 28px; margin-right: auto; }
.portal-nav-link {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-soft);
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}
.portal-nav-link:hover { background: var(--bg-tint); color: var(--navy-deep); }
.portal-nav-link.is-active { color: var(--blue); background: rgba(46, 99, 198, 0.08); }

/* Mobile nav toggle (hamburger) — hidden on desktop, shown when the nav collapses */
.portal-nav-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  flex-shrink: 0;
}
.portal-nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--ink-soft);
  border-radius: 2px;
  transition: background 0.15s ease;
}
.portal-nav-toggle:hover span { background: var(--navy-deep); }
.portal-nav-toggle:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.portal-user { display: flex; align-items: center; gap: 12px; }
.portal-user-email { font-size: 13.5px; color: var(--ink-soft); }
.portal-user-role {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--blue);
  background: rgba(46, 99, 198, 0.08);
  padding: 3px 9px;
  border-radius: 999px;
}

/* Collapse the primary nav into a disclosure menu once it no longer fits inline.
 * The full nav + user block intrinsically needs ~1080px of viewport, so below
 * that the header would overflow (pre-existing behaviour). Wide desktop
 * (>=1080px) keeps the inline nav unchanged; narrower viewports get the
 * hamburger so the header never overflows. */
@media (max-width: 1079px) {
  /* Hamburger sits at the far right; the user block is pushed over by margin-auto
   * and the toggle's order keeps it last in the row. */
  .portal-nav-toggle { display: flex; order: 3; margin-left: 8px; }
  .portal-nav { display: none; margin: 0; }
  .portal-user { margin-left: auto; }

  .portal-nav--open {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    position: absolute;
    top: 64px;
    left: calc(-1 * var(--gutter));
    right: calc(-1 * var(--gutter));
    background: var(--bg, #fff);
    border-bottom: 1px solid var(--hairline);
    padding: 10px 16px 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  }
  .portal-nav--open .portal-nav-link {
    display: block;
    padding: 11px 12px;
    font-size: 15px;
  }
}

/* ===== APP CONTAINER =====
 * The portal is a data app (tables, dashboards, dense forms), so its chrome and
 * content use a wider container than the marketing site's `.shell` (1180px).
 * `.app-shell` fills the viewport — minus comfortable gutters — and caps at
 * 1760px on ultra-wide screens. Below the cap the gutter comes from the padding,
 * so small/mobile screens keep full-width-minus-gutter behaviour (no regression).
 * Report views and auth cards keep their own narrower widths. */
.app-shell {
  max-width: min(1760px, 92vw);
  margin: 0 auto;
  padding: 0 var(--gutter);
}
@media (max-width: 720px) {
  /* Reclaim the side air on narrow screens: full width minus the gutter padding. */
  .app-shell { max-width: none; }
}

/* ===== MAIN ===== */
.portal-main { padding-top: 40px; padding-bottom: 64px; }
.portal-main h1 { margin-bottom: 6px; }
.portal-main h2 { margin: 32px 0 14px; }
.muted { color: var(--grey); font-size: 14px; }
code {
  background: var(--bg-tint);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.92em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
/* Report identifier: monospace for legibility, but flush-left and unpadded so
   it lines up under its column header (no chip background — see #221). */
.report-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92em;
}

/* ===== AUTH (login / enrol / verify) ===== */
.auth-wrap { max-width: 440px; margin: 7vh auto 0; }
.auth-card { padding: 36px 32px; }
.auth-card h1 { font-size: 1.4rem; }
.auth-error {
  color: var(--pain-label);
  background: var(--pain-bg);
  border: 1px solid rgba(178, 58, 46, 0.2);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 14px;
  margin: 16px 0 0;
}
/* In-progress banner + spinner (#262) — a navy/blue ring, animated to signal the page is still
   auto-refreshing while a report generates. Shared by the company detail + scan detail views so the
   "report is running" state reads identically on both (#263 follow-up). The global
   prefers-reduced-motion rule freezes the rotation for users who opt out (the text still conveys
   state). */
.report-progress { display: flex; align-items: center; gap: 10px; }
.spinner {
  flex: none; width: 15px; height: 15px;
  border: 2px solid color-mix(in srgb, var(--blue) 22%, transparent);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: report-spin 0.7s linear infinite;
}
@keyframes report-spin { to { transform: rotate(360deg); } }

/* Reassuring, non-alarming status banner — e.g. the friendly "temporarily unavailable" state a
   client sees instead of a raw provider error (issue #263). Amber/gold, not the red .auth-error. */
.notice {
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 14px;
}
.notice--warn {
  color: #7a5f12;
  background: var(--gold-faint);
  border: 1px solid rgba(160, 125, 24, 0.25);
}
.qr-frame {
  display: block;
  margin: 18px auto;
  width: 200px;
  height: 200px;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 8px;
  background: #fff;
}
.manual-key { text-align: center; }

/* Password field with an inline show/hide toggle. */
.pw-field { position: relative; }
.pw-field input { padding-right: 64px; }
.pw-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--blue);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 6px;
}
.pw-toggle:hover { background: var(--bg-tint); }
.pw-toggle:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }

/* Secondary link under a form field (e.g. "Forgot password?"). */
.auth-aside { margin: 10px 0 0; font-size: 14px; }
.auth-aside a { color: var(--blue); text-decoration: none; }
.auth-aside a:hover { text-decoration: underline; }

/* ===== FORMS ===== */
.portal-main label,
.auth-card label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin: 16px 0 8px;
}
.portal-main label .optional { font-weight: 400; color: var(--grey); }
.portal-main input[type="text"],
.portal-main input[type="email"],
.portal-main input[type="password"],
.portal-main select,
.portal-main textarea {
  width: 100%;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 12px 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.portal-main textarea { resize: vertical; min-height: 130px; }
.portal-main input:focus,
.portal-main select:focus,
.portal-main textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46, 99, 198, 0.15);
}
.btn--block { display: flex; width: 100%; justify-content: center; margin-top: 22px; }
.btn--sm { padding: 7px 14px; font-size: 13.5px; }
/* Searchable combobox (Reports hub Company filter). */
.combo { position: relative; }
.combo-input { width: 100%; }
.combo-list {
  position: absolute;
  z-index: 30;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 260px;
  overflow-y: auto;
  margin: 4px 0 0;
  padding: 4px;
  list-style: none;
  background: #fff;
  border: 1px solid var(--hairline, #e2e2e6);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
}
.combo-list li {
  padding: 7px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.combo-list li:hover { background: var(--surface-muted, #f1f1f2); }
.combo-list li[hidden] { display: none; }
.combo-list li[data-value=""] { color: var(--grey, #6b7280); }

/* Company/contact intake forms (issue #256): two labelled sections, inline per-field errors. */
.intake-form fieldset {
  border: 1px solid var(--hairline, #e2e2e6);
  border-radius: 10px;
  padding: 14px 16px 18px;
  margin: 0 0 16px;
}
.intake-form legend {
  padding: 0 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--grey, #6b7280);
}
.intake-form textarea { width: 100%; }
.intake-form .span-2 { grid-column: 1 / -1; }
.field-error { margin: 4px 0 0; font-size: 12.5px; color: var(--danger, #c0392b); }

/* Date-range filter (Reports hub) — a single control matching the Company combo: a trigger button
   that opens a panel of quick presets + a custom From/To. */
.daterange-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  /* Match the .portal-main input/select box so it sits flush with the other filters. */
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.daterange-trigger:hover { border-color: var(--blue); }
.daterange-trigger[aria-expanded="true"] {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46, 99, 198, 0.15);
}
.daterange-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.daterange-caret { color: var(--grey); font-size: 11px; flex: none; }
/* Fixed, comfortably-wide panel anchored to the left edge (override .combo-list's left/right:0 so the
   width doesn't jitter with the trigger's contents). */
/* Tall enough to show presets + custom without a scrollbar (overrides .combo-list's max-height). */
.daterange-panel { padding: 8px; left: 0; right: auto; width: 300px; max-height: none; overflow: visible; }
.daterange-presets { display: flex; flex-direction: column; gap: 2px; }
.daterange-preset {
  appearance: none;
  text-align: left;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
}
.daterange-preset:hover { background: var(--surface-muted, #f1f1f2); }
.daterange-custom {
  display: flex;
  flex-direction: column;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--rule, #e5e9f2);
}
/* Header for the custom range — same padding/size as a preset row (so it lines up with them), just
   bold to read as a section label. */
.daterange-heading {
  padding: 7px 10px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 2px;
}
/* Indent the From/To fields to line up with the preset rows + Custom header (all at 10px). */
.daterange-fields { display: flex; gap: 8px; padding: 0 10px; }
.daterange-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; margin: 0; flex: 1; min-width: 0; }
.daterange-field .muted { font-weight: 600; }
/* Native date inputs aren't in the base .portal-main input rule, so give them the portal font + box
   here (otherwise the value renders in the browser's default monospace and looks off-brand). */
.daterange-custom input[type="date"] {
  width: 100%;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 8px 10px;
}
.daterange-custom input[type="date"]:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46, 99, 198, 0.15);
}
/* Compact, right-aligned Apply — content-width (not full-bleed) with its label centred. */
.daterange-custom .dr-apply { align-self: flex-end; width: auto; justify-content: center; margin: 12px 10px 0; }

/* Disabled link-button: clearly inert (greyed, no hover, not clickable). */
.btn.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
  background: var(--surface-muted, #f1f1f2);
  color: var(--muted, #8a8a8f);
  border-color: transparent;
}

/* Two-column form layout (admin user-create) */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.grid-2 > div { min-width: 0; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

/* Inline per-row update form (admin user table) */
.row-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-form select { width: auto; padding: 7px 10px; font-size: 13.5px; margin: 0; }
.inline-check { display: inline-flex; align-items: center; gap: 5px; margin: 0; font-weight: 500; font-size: 13px; }
.inline-check input { width: auto; }

.form-ok {
  color: var(--fix-label);
  background: var(--fix-bg);
  border: 1px solid rgba(31, 122, 76, 0.2);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 14px;
  margin: 16px 0 0;
}

/* Surface checkboxes (scan console) */
.checks { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 10px; }
.checks label { display: flex; align-items: center; gap: 6px; margin: 0; font-weight: 500; }
.checks input { width: auto; }

/* ===== DATA TABLES ===== */
.data-table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.data-table th, .data-table td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}
.data-table thead th {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--grey);
}
.data-table tr:last-child td { border-bottom: 0; }
.data-table th[scope="row"] { color: var(--ink-soft); font-weight: 600; white-space: nowrap; }

/* ===== STATUS PILLS ===== */
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.s-queued, .s-running { background: var(--gold-faint); color: var(--gold); }
.s-complete { background: var(--fix-bg); color: var(--fix-label); }
.s-failed { background: var(--pain-bg); color: var(--pain-label); }

/* ===== RENDERED MARKDOWN ===== */
/* Applied to containers populated from markdown-it (scan responses, risk details). */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 2px 0; }
.md li > p { margin: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 14px 0 6px; line-height: 1.25; }
.md h1 { font-size: 18px; }
.md h2 { font-size: 16px; }
.md h3, .md h4 { font-size: 15px; }
.md strong { font-weight: 700; }
.md code {
  background: var(--gold-faint);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.92em;
}
.md pre {
  background: var(--gold-faint);
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0 0 10px;
}
.md pre code { background: none; padding: 0; }
.md blockquote {
  margin: 0 0 10px;
  padding-left: 12px;
  border-left: 3px solid var(--rule);
  color: var(--ink-soft);
}

@media (max-width: 640px) {
  .auth-card { padding: 28px 22px; }
  .portal-user-email { display: none; }
}
