/* ==========================================================================
   TraceFlow — Shared Design System
   ==========================================================================
   One file, used by every page, so the whole app looks and behaves the
   same everywhere.

   BRAND NOTE FOR WHOEVER PICKS THIS UP LATER:
   These are NorthernSky Studios' real brand colors, taken from the
   official Brand Guidelines PDF (section 04, Color Palette): Accent
   Teal, Ink, Paper, and Surface Gray. Teal is the one primary action
   color — links, buttons, highlights, the logo's darker swoosh stroke.
   Navy is not a guideline-specified UI color; it's kept here only as
   the dark surface behind the reversed (white-on-navy) logo lockup, on
   the sidebar and the Stakeholder View header, matching the guideline's
   own logo-variation rule for dark backgrounds. Because every color in
   this app is a CSS variable, changing them here updates the whole
   product — no hunting through pages.
   ========================================================================== */

:root {
  /* --- Brand palette (NorthernSky Studios Brand Guidelines, section 04) --- */
  --color-navy-900: #1b2a45;   /* dark surface behind the reversed logo lockup — sidebar, public header */
  --color-navy-800: #24375c;
  --color-navy-700: #2f4670;
  --color-teal-600: #0088b0;   /* Accent Teal — primary actions, links, highlights */
  --color-teal-500: #17a0c9;
  --color-teal-100: #dceff4;
  /* Old names kept as aliases so nothing else in this file has to change. */
  --color-blue-600: var(--color-teal-600);
  --color-blue-500: var(--color-teal-500);
  --color-blue-100: var(--color-teal-100);

  /* --- Neutrals / surfaces --- */
  --color-bg: #f3f2f2;         /* Paper */
  --color-surface: #ffffff;
  --color-surface-alt: #eae9e9; /* Surface Gray — separates page sections */
  --color-border: #e3e1e1;
  --color-border-strong: #cfcdcd;

  /* --- Text --- */
  --color-text: #201e1d;       /* Ink */
  --color-text-muted: #5c5957;
  --color-text-faint: #8c8988;
  --color-text-on-dark: #eef2f6;
  --color-text-on-dark-muted: #aeb8c9;

  /* --- Status colors --- */
  --color-success: #15803d;
  --color-success-bg: #e7f6ec;
  --color-warning: #b45309;
  --color-warning-bg: #fef3e2;
  --color-danger: #b91c1c;
  --color-danger-bg: #fdeaea;
  --color-info: #1d4ed8;
  --color-info-bg: #e8f0ff;

  /* --- Priority colors --- */
  --color-priority-high: #b91c1c;
  --color-priority-medium: #b45309;
  --color-priority-low: #15803d;

  /* --- Typography ---
     "Urbanist" everywhere (headings, body, UI), per the NorthernSky
     Studios Brand Guidelines (section 05). A free Google Font, weights
     400-800 loaded by every page. System-font fallbacks keep the site
     usable even if the Google Fonts request is blocked. */
  --font-heading: "Urbanist", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --font-body: "Urbanist", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;

  /* --- Spacing scale --- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* --- Misc --- */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(27, 42, 69, 0.06);
  --shadow-md: 0 4px 16px rgba(27, 42, 69, 0.10);
  --shadow-lg: 0 12px 32px rgba(27, 42, 69, 0.16);
  --sidebar-width: 236px;
  --header-height: 64px;
  --transition-fast: 120ms ease;
}

/* ==========================================================================
   Reset / base
   ========================================================================== */

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

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  color: var(--color-navy-900);
  margin: 0 0 var(--space-2);
  line-height: 1.25;
}

h1 { font-size: 1.75rem; font-weight: 700; }
h2 { font-size: 1.375rem; font-weight: 700; }
h3 { font-size: 1.125rem; font-weight: 600; }
h4 { font-size: 1rem; font-weight: 600; }

p { margin: 0 0 var(--space-3); color: var(--color-text-muted); }

a { color: var(--color-blue-600); text-decoration: none; }
a:hover { text-decoration: underline; }

ul, ol { margin: 0; padding: 0; list-style: none; }

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

img, svg { max-width: 100%; display: block; }

/* Base size for every icon rendered by TraceFlowApp.Icon() (js/app.js).
   Icon() also sets width/height="18" directly on the <svg>, so this is a
   CSS backstop — without either, an inline <svg> with no size defaults to
   100% of its container per the SVG spec, which is how an icon can blow
   up to fill a whole banner instead of sitting small and inline. Specific
   contexts (e.g. .app-nav__icon, .btn svg) override this size below. */
.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Visible, consistent focus states everywhere — keyboard accessibility */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--color-blue-500);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  background: var(--color-navy-900);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  z-index: 1000;
  transition: top var(--transition-fast);
}
.skip-link:focus { top: 8px; }

/* ==========================================================================
   App shell — sidebar + header, shared by every logged-in page
   ========================================================================== */

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

.app-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-navy-900);
  color: var(--color-text-on-dark);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  height: 100vh;
  z-index: 40;
  transition: transform var(--transition-fast);
}

.app-sidebar__brand {
  display: flex;
  align-items: center;
  padding: var(--space-5) var(--space-4);
}

/* The real logo file (public/assets/logo-traceflow.png), rendered by
   TraceFlowApp.logoLockup() (js/app.js). Its width/height attributes are
   set inline per call to preserve its exact aspect ratio at any size —
   this rule is just a display/shrink backstop. Used here (sidebar), on
   the sign-in page, and on the public Stakeholder View header — all
   three sit on the dark navy surface the logo's white wordmark needs. */
.brand-lockup__img {
  display: block;
  flex-shrink: 0;
  max-width: 100%;
}

.app-sidebar__project {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0 var(--space-3) var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--color-text-on-dark);
}

.app-sidebar__project:hover {
  background: rgba(255, 255, 255, 0.1);
  text-decoration: none;
}

.app-sidebar__project-icon { color: var(--color-blue-500); flex-shrink: 0; }

.app-sidebar__project-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-sidebar__project-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-on-dark-muted);
}

.app-sidebar__project-name {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-sidebar__project-switch { color: var(--color-text-on-dark-muted); flex-shrink: 0; }

.app-nav {
  flex: 1;
  padding: var(--space-3) var(--space-3);
  overflow-y: auto;
}

.app-nav__link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-text-on-dark-muted);
  font-weight: 500;
  margin-bottom: var(--space-1);
}

.app-nav__link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  text-decoration: none;
}

.app-nav__link.is-active {
  background: var(--color-blue-600);
  color: #fff;
}

.app-nav__icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.app-sidebar__footer {
  padding: var(--space-4);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.8rem;
  color: var(--color-text-on-dark-muted);
}

.app-sidebar__user {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.app-sidebar__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-blue-600);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.app-sidebar__user-name { color: #fff; font-weight: 600; font-size: 0.85rem; }
.app-sidebar__user-role { color: var(--color-text-on-dark-muted); font-size: 0.75rem; }

.link-button {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--color-text-on-dark);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  width: 100%;
  font-weight: 600;
  transition: background var(--transition-fast);
}
.link-button:hover { background: rgba(255, 255, 255, 0.08); }

.app-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Trial banner — the first thing inside .app-main, above .app-topbar, on
   every signed-in page for as long as the trial is running (see
   wireBillingBanner() in js/app.js). Not sticky on its own; .app-topbar
   right below it is already sticky, so this simply scrolls away with the
   rest of the page rather than permanently eating header height. */
.trial-banner {
  background: var(--color-teal-100);
  border-bottom: 1px solid var(--color-teal-500);
  color: var(--color-navy-900);
  font-size: 0.85rem;
  text-align: center;
  padding: var(--space-2) var(--space-4);
}
.trial-banner a { color: var(--color-teal-600); font-weight: 600; }
.trial-banner--urgent {
  background: var(--color-danger-bg);
  border-bottom-color: var(--color-danger);
  color: var(--color-danger);
}
.trial-banner--urgent a { color: var(--color-danger); text-decoration: underline; }

/* Holds the mobile menu toggle, the global search bar, and the
   notification bell — never a page title/description, which stays each
   page's own job (its .page-header, in js/app.js's renderAppShell). */
.app-topbar {
  display: flex;
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-5);
  position: sticky;
  top: 0;
  z-index: 30;
}

.menu-toggle {
  display: none;
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  width: 38px;
  height: 38px;
  cursor: pointer;
  color: var(--color-navy-900);
}

/* --------------------------------------------------------------------
   Global search (Feature 4) — the middle of the topbar. A page with no
   open project (Projects, Stakeholders) gets an empty placeholder in its
   place instead, so the notification bell still lands on the right.
   -------------------------------------------------------------------- */

.app-search {
  position: relative;
  flex: 1;
  max-width: 420px;
  display: flex;
  align-items: center;
}

.app-search--placeholder { visibility: hidden; }

.app-search__icon {
  position: absolute;
  left: var(--space-3);
  width: 16px;
  height: 16px;
  color: var(--color-text-faint);
  pointer-events: none;
}

.app-search input[type="search"] {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  padding: var(--space-2) var(--space-3) var(--space-2) calc(var(--space-3) * 2 + 16px);
  font-size: 0.85rem;
  color: var(--color-text);
}

.app-search input[type="search"]:focus {
  border-color: var(--color-blue-500);
  background: var(--color-surface);
}

.app-search__results {
  position: absolute;
  top: calc(100% + var(--space-2));
  left: 0;
  right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 360px;
  overflow-y: auto;
  z-index: 40;
}

.app-search__empty {
  padding: var(--space-4);
  font-size: 0.85rem;
  color: var(--color-text-faint);
}

.app-search__group-label {
  padding: var(--space-2) var(--space-3) var(--space-1);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-faint);
}

.app-search__result {
  display: block;
  padding: var(--space-2) var(--space-3);
  font-size: 0.86rem;
  color: var(--color-text);
  border-top: 1px solid var(--color-border);
}

.app-search__group:first-child .app-search__result:first-of-type { border-top: none; }
.app-search__result:hover { background: var(--color-surface-alt); text-decoration: none; }

/* --------------------------------------------------------------------
   Notification bell (Feature 2) — right side of the topbar.
   -------------------------------------------------------------------- */

.app-notifications { position: relative; flex-shrink: 0; margin-left: auto; }

.app-notif-bell {
  position: relative;
  background: none;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--color-navy-900);
}

.app-notif-bell:hover { background: var(--color-surface-alt); }

.app-notif-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--color-danger);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.app-notif-dropdown {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  width: 340px;
  max-width: 90vw;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 40;
}

.app-notif-dropdown__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--color-navy-900);
}

.app-notif-markall {
  background: none;
  border: none;
  color: var(--color-blue-600);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.app-notif-empty {
  padding: var(--space-5) var(--space-4);
  text-align: center;
  font-size: 0.85rem;
  color: var(--color-text-faint);
}

.app-notif-list { max-height: 360px; overflow-y: auto; }

.app-notif-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border);
  color: var(--color-text);
}

.app-notif-item:first-child { border-top: none; }
.app-notif-item:hover { background: var(--color-surface-alt); text-decoration: none; }

.app-notif-item__dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  background: transparent;
}

.app-notif-item.is-unread .app-notif-item__dot { background: var(--color-blue-600); }
.app-notif-item.is-unread .app-notif-item__message { font-weight: 700; color: var(--color-navy-900); }

.app-notif-item__message { display: block; font-size: 0.85rem; }
.app-notif-item__time { display: block; font-size: 0.74rem; color: var(--color-text-faint); margin-top: 2px; }

/* .app-content is a flex item of .app-main's flex-direction:column
   layout — without min-width:0, a flex item's default min-width:auto
   refuses to shrink below its content's natural (unwrapped) width, so
   wide content (e.g. a data table) pushes .app-content, and the whole
   page, wider than the viewport instead of staying put and scrolling
   internally. */
.app-content {
  padding: var(--space-5);
  width: 100%;
  max-width: 1240px;
  min-width: 0;
  margin: 0 auto;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(27, 42, 69, 0.45);
  z-index: 35;
}

/* ==========================================================================
   Local-storage notice banner (required across the app)
   ========================================================================== */

.storage-notice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  background: var(--color-info-bg);
  border: 1px solid #c3d7ff;
  color: var(--color-navy-900);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-5);
  font-size: 0.85rem;
}

.storage-notice strong { color: var(--color-navy-900); }
.storage-notice svg { margin-top: 2px; color: var(--color-blue-600); }

.pending-invites-banner {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  background: var(--color-teal-100);
  border: 1px solid var(--color-teal-500);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-5);
}

.pending-invite-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  font-size: 0.88rem;
  color: var(--color-navy-900);
}

/* ==========================================================================
   Cards, grids, generic layout
   ========================================================================== */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  /* Cards sit as grid/flex items in several layouts (e.g. .section-grid).
     Without this, a card's min-content size — driven by its widest
     unbreakable child content — can force its grid track/flex basis wider
     than the viewport instead of wrapping/shrinking to fit. */
  min-width: 0;
}

.card + .card { margin-top: var(--space-4); }

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}

.page-header p { margin: 0; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-sm);
}

.stat-card__label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-faint);
  margin-bottom: var(--space-2);
}

.stat-card__value {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-navy-900);
  line-height: 1;
}

.stat-card__meta {
  margin-top: var(--space-2);
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.stat-card--warning .stat-card__value { color: var(--color-warning); }
.stat-card--success .stat-card__value { color: var(--color-success); }

.section-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: var(--space-4);
}

/* ==========================================================================
   Projects landing page
   ========================================================================== */

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-4);
}

/* A <div>, not the link itself — .project-card__link (below) is the
   clickable "open this project" area, and .project-card__actions (the
   Rename/Delete buttons, owner/Admin only) is a sibling of it rather than
   nested inside an <a>, which HTML doesn't allow for interactive elements. */
.project-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
}

.project-card:hover {
  border-color: var(--color-blue-500);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.project-card__link {
  display: block;
  color: inherit;
}

.project-card__link:hover { text-decoration: none; }

.project-card__actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
}

.project-card__name {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-navy-900);
  margin-bottom: var(--space-2);
}

.project-card__desc {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-bottom: var(--space-4);
  min-height: 1.2em;
}

.project-card__stat {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
}

.project-card__stat-value {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-blue-600);
}

.project-card__stat-label {
  font-size: 0.78rem;
  color: var(--color-text-faint);
}

/* ==========================================================================
   Stakeholders card (Dashboard) — one personal link per assigned person
   ========================================================================== */

.stakeholder-card-item {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
}

.stakeholder-card-item + .stakeholder-card-item { margin-top: var(--space-3); }

.stakeholder-card-item__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
  flex-wrap: wrap;
}

.stakeholder-card-item__name { font-weight: 600; color: var(--color-navy-900); }
.stakeholder-card-item__role { font-size: 0.8rem; color: var(--color-text-muted); }

.stakeholder-link-row {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.stakeholder-link-input {
  flex: 1;
  min-width: 220px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface-alt);
  color: var(--color-text);
  font-family: monospace;
  font-size: 0.82rem;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: var(--space-2) var(--space-4);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
  white-space: nowrap;
}

.btn-primary { background: var(--color-blue-600); color: #fff; }
.btn-primary:hover { background: var(--color-navy-700); text-decoration: none; }

.btn-secondary { background: var(--color-surface); color: var(--color-navy-900); border-color: var(--color-border-strong); }
.btn-secondary:hover { background: var(--color-surface-alt); text-decoration: none; }

.btn-danger { background: var(--color-surface); color: var(--color-danger); border-color: #f0c6c6; }
.btn-danger:hover { background: var(--color-danger-bg); text-decoration: none; }

.btn-ghost { background: none; color: var(--color-blue-600); border-color: transparent; padding: var(--space-1) var(--space-2); }
.btn-ghost:hover { background: var(--color-blue-100); text-decoration: none; }

.btn-sm { padding: var(--space-1) var(--space-3); font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn svg { width: 16px; height: 16px; }

/* ==========================================================================
   Forms
   ========================================================================== */

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.form-field { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-4); }
.form-field--full { grid-column: 1 / -1; }

.form-field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-navy-900);
}

.form-field .hint { font-size: 0.76rem; color: var(--color-text-faint); font-weight: 400; }

.form-field input[type="text"],
.form-field input[type="email"],
.form-field input[type="password"],
.form-field input[type="date"],
.form-field input[type="number"],
.form-field select,
.form-field textarea {
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  color: var(--color-text);
  width: 100%;
}

.form-field textarea { resize: vertical; min-height: 84px; }

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  border-color: var(--color-blue-500);
}

.member-role-select {
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.82rem;
  font-family: inherit;
}

.member-role-select:focus { border-color: var(--color-blue-500); }

.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  background: var(--color-surface-alt);
}

.checkbox-list label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.85rem;
  font-weight: 500;
}

.checkbox-list .empty { color: var(--color-text-faint); font-size: 0.82rem; font-weight: 400; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-4);
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-4);
}

.form-error {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border: 1px solid #f0c6c6;
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font-size: 0.82rem;
  margin-bottom: var(--space-3);
}

.field-error {
  color: var(--color-danger);
  font-size: 0.76rem;
}

/* ==========================================================================
   Badges / pills / tags
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge-priority-high { background: var(--color-danger-bg); color: var(--color-priority-high); }
.badge-priority-medium { background: var(--color-warning-bg); color: var(--color-priority-medium); }
.badge-priority-low { background: var(--color-success-bg); color: var(--color-priority-low); }

.badge-status-draft { background: #eef0f5; color: var(--color-text-muted); }
.badge-status-inreview { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-status-approved { background: var(--color-success-bg); color: var(--color-success); }

.badge-status-notstarted { background: #eef0f5; color: var(--color-text-muted); }
.badge-status-inprogress { background: var(--color-info-bg); color: var(--color-info); }
.badge-status-atrisk { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-status-blocked { background: var(--color-danger-bg); color: var(--color-danger); }
.badge-status-complete { background: var(--color-success-bg); color: var(--color-success); }

.badge-orphan { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-linked { background: var(--color-success-bg); color: var(--color-success); }

.badge-role-admin { background: var(--color-surface-alt); color: var(--color-navy-700); }
.badge-role-owner { background: var(--color-surface-alt); color: var(--color-navy-700); }
.badge-role-full_access { background: var(--color-info-bg); color: var(--color-info); }
.badge-role-contributor { background: var(--color-teal-100); color: var(--color-teal-600); }

.badge-access-active { background: var(--color-success-bg); color: var(--color-success); }
.badge-access-pending { background: var(--color-warning-bg); color: var(--color-warning); }

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--color-blue-100);
  color: var(--color-navy-700);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.76rem;
  font-weight: 600;
}

/* --------------------------------------------------------------------
   Tags (Feature 5) — visually distinct from .tag-chip above (which marks
   a *linked* requirement/task), since a tag is a free label someone
   typed, not a traceability link.
   -------------------------------------------------------------------- */

.tag-pill-row { display: flex; flex-wrap: wrap; gap: var(--space-1); }

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border-strong);
  color: var(--color-text-muted);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 0.74rem;
  font-weight: 600;
}

.tag-pill--removable { padding-right: 4px; background: var(--color-teal-100); border-color: transparent; color: var(--color-teal-600); }

.tag-pill--removable button {
  background: none;
  border: none;
  padding: 1px;
  display: inline-flex;
  cursor: pointer;
  color: inherit;
}
.tag-pill--removable button svg { width: 12px; height: 12px; }
.tag-pill--removable button:hover { opacity: 0.7; }

.tag-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
}

.tag-input__pills { display: flex; flex-wrap: wrap; gap: var(--space-1); }

.tag-input__field {
  border: none;
  outline: none;
  flex: 1;
  min-width: 120px;
  font-size: 0.85rem;
  font-family: inherit;
  color: var(--color-text);
}

/* --------------------------------------------------------------------
   Comments (Feature 1)
   -------------------------------------------------------------------- */

.comments-empty { color: var(--color-text-faint); font-size: 0.85rem; }

.comment-list { display: flex; flex-direction: column; gap: var(--space-3); max-height: 260px; overflow-y: auto; }

.comment-item {
  border-bottom: 1px solid var(--color-border);
  padding-bottom: var(--space-3);
}
.comment-item:last-child { border-bottom: none; padding-bottom: 0; }

.comment-item__meta { font-size: 0.76rem; color: var(--color-text-faint); margin-bottom: 2px; }
.comment-item__meta strong { color: var(--color-navy-900); }
.comment-item__body { font-size: 0.87rem; color: var(--color-text); white-space: pre-wrap; }

.comment-composer { display: flex; flex-direction: column; gap: var(--space-2); margin-top: var(--space-3); }
.comment-composer textarea { min-height: 60px; resize: vertical; }

/* --------------------------------------------------------------------
   Detail view (Requirements/Tasks) — a read-oriented modal, wider than
   the add/edit forms, viewable by anyone with project access (including
   a Contributor on Requirements, who can't open the edit form at all).
   -------------------------------------------------------------------- */

.detail-modal { max-width: 640px; }

.detail-modal__field { margin-bottom: var(--space-4); }
.detail-modal__field-label { font-size: 0.76rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--color-text-faint); margin-bottom: 2px; }
.detail-modal__field-value { font-size: 0.9rem; color: var(--color-text); }

.detail-modal__section {
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
}

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* ==========================================================================
   Tables
   ========================================================================== */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

table { width: 100%; border-collapse: collapse; min-width: 640px; }

thead th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-faint);
  font-weight: 700;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface-alt);
}

tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
  font-size: 0.88rem;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--color-surface-alt); }

td.cell-title { font-weight: 600; color: var(--color-navy-900); }
td.cell-actions { text-align: right; white-space: nowrap; }
.row-actions { display: inline-flex; gap: var(--space-2); }

.empty-state {
  text-align: center;
  padding: var(--space-7) var(--space-4);
  color: var(--color-text-muted);
}

.empty-state h3 { color: var(--color-navy-900); margin-bottom: var(--space-2); }

.empty-state .btn { margin-top: var(--space-2); }

/* ==========================================================================
   Onboarding — first-time welcome screen + Dashboard checklist
   ========================================================================== */

.onboarding-welcome {
  max-width: 560px;
  margin: var(--space-7) auto;
  text-align: center;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-7) var(--space-6);
  box-shadow: var(--shadow-md);
}

.onboarding-welcome__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-teal-100);
  color: var(--color-teal-600);
  margin-bottom: var(--space-4);
}

.onboarding-welcome__badge svg { width: 26px; height: 26px; }

.onboarding-welcome h1 { margin-bottom: var(--space-5); }

.onboarding-welcome__points {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.onboarding-welcome__points li {
  color: var(--color-text-muted);
  padding-left: var(--space-4);
  position: relative;
}

.onboarding-welcome__points li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-teal-600);
}

.onboarding-welcome__actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.onboarding-welcome__skip {
  background: none;
  border: none;
  padding: var(--space-2) var(--space-3);
  color: var(--color-text-muted);
  cursor: pointer;
  text-decoration: underline;
}

.onboarding-welcome__skip:hover { color: var(--color-text); }

.onboarding-checklist {
  position: fixed;
  right: var(--space-5);
  bottom: var(--space-5);
  width: 260px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-4);
  z-index: 50;
}

.onboarding-checklist h4 {
  font-family: var(--font-heading);
  font-size: 0.9rem;
  margin: 0 0 var(--space-3);
  padding-right: var(--space-5);
}

.onboarding-checklist ul { display: flex; flex-direction: column; gap: var(--space-2); }

.onboarding-checklist li {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.onboarding-checklist li.is-done { color: var(--color-text); text-decoration: line-through; text-decoration-color: var(--color-border-strong); }

.onboarding-checklist__check {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--color-border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: #fff;
}

.onboarding-checklist li.is-done .onboarding-checklist__check {
  background: var(--color-success);
  border-color: var(--color-success);
}

.onboarding-checklist__close {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  background: none;
  border: none;
  padding: 2px;
  cursor: pointer;
  color: var(--color-text-faint);
}

.onboarding-checklist__close svg { width: 14px; height: 14px; }
.onboarding-checklist__close:hover { color: var(--color-text); }

@media (max-width: 560px) {
  .onboarding-welcome { margin: var(--space-4); padding: var(--space-5) var(--space-4); }
  .onboarding-checklist { left: var(--space-4); right: var(--space-4); width: auto; }
}

/* ==========================================================================
   Invite landing page (public/invite.html) — same centered-card shape as
   .onboarding-welcome above, reused here for a second "here's one focused
   thing to decide" screen.
   ========================================================================== */

.invite-card {
  max-width: 480px;
  margin: var(--space-7) auto;
  text-align: center;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-7) var(--space-6);
  box-shadow: var(--shadow-md);
}

.invite-card__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-teal-100);
  color: var(--color-teal-600);
  margin-bottom: var(--space-4);
}

.invite-card__badge svg { width: 26px; height: 26px; }

.invite-card h1 { margin-bottom: var(--space-3); }

.invite-card__role-blurb {
  color: var(--color-text-muted);
  font-size: 0.88rem;
  margin-bottom: var(--space-5);
}

/* The sign-in/sign-up action sits below .invite-card as its own sibling
   box (see js/invite.js) — same width and centering trick as
   .auth-clerk-wrap on the main sign-in page, so Clerk's own card (and,
   in test mode, its full-height "Secured by Clerk" ribbon) has room to
   render without crossing another card's border. */
.invite-clerk-wrap {
  max-width: 480px;
  margin: var(--space-4) auto 0;
  text-align: center;
}

.invite-clerk-wrap #inviteClerkMount {
  width: 100%;
  min-height: 80px;
  display: flex;
  justify-content: center;
}

/* Clerk applies its own width as an inline style, which beats a plain
   CSS rule regardless of selector — !important is what's actually
   needed here, not a specificity fix. */
.invite-clerk-wrap .cl-rootBox,
.invite-clerk-wrap .cl-card {
  width: 100% !important;
  box-sizing: border-box;
}

@media (max-width: 560px) {
  .invite-card { margin: var(--space-4); padding: var(--space-5) var(--space-4); }
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

.filter-row { display: flex; gap: var(--space-2); flex-wrap: wrap; }

.filter-row select, .toolbar input[type="search"] {
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
}

/* ==========================================================================
   View toggle (List / Board) — Tasks & Timeline page (Feature 3)
   ========================================================================== */

.view-toggle {
  display: inline-flex;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.view-toggle__btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: var(--color-surface);
  color: var(--color-text-muted);
  padding: var(--space-2) var(--space-3);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.view-toggle__btn + .view-toggle__btn { border-left: 1px solid var(--color-border-strong); }

.view-toggle__btn.is-active { background: var(--color-teal-100); color: var(--color-teal-600); }

/* ==========================================================================
   Kanban board — Tasks & Timeline page (Feature 3). Columns are the same
   statuses as the List view; dragging a card to another column updates
   that task's status the same way the inline status dropdown does.
   ========================================================================== */

.kanban-board {
  display: flex;
  gap: var(--space-3);
  overflow-x: auto;
  padding-bottom: var(--space-2);
  align-items: flex-start;
}

.kanban-column {
  flex: 0 0 260px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  transition: background-color .12s ease, border-color .12s ease;
}

.kanban-column.is-dragover { background: var(--color-teal-100); border-color: var(--color-teal-500); }

.kanban-column__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--color-navy-900);
  margin-bottom: var(--space-3);
}

.kanban-column__count {
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.74rem;
  color: var(--color-text-muted);
}

.kanban-column__body { display: flex; flex-direction: column; gap: var(--space-2); min-height: 40px; }

.kanban-column__empty { font-size: 0.78rem; color: var(--color-text-faint); padding: var(--space-2) 0; }

.kanban-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  padding: var(--space-3);
  cursor: grab;
}

.kanban-card.is-dragging { opacity: 0.4; }

.kanban-card__title { font-weight: 600; color: var(--color-navy-900); font-size: 0.88rem; margin-bottom: 6px; }

.kanban-card__meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.76rem;
  color: var(--color-text-faint);
  margin-top: var(--space-2);
}

.kanban-card__meta .icon { width: 14px; height: 14px; }

.kanban-card__view { margin-top: var(--space-2); padding-left: 0; }

/* ==========================================================================
   Modal / dialog
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(27, 42, 69, 0.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--space-6) var(--space-4);
  overflow-y: auto;
  z-index: 100;
}

.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 640px;
  padding: var(--space-5);
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.modal__close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
}
.modal__close:hover { background: var(--color-surface-alt); }

/* ==========================================================================
   Timeline (Tasks page)
   ========================================================================== */

.timeline {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.timeline-row {
  display: grid;
  grid-template-columns: 200px 1fr;
  align-items: center;
  gap: var(--space-3);
}

.timeline-row__label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-navy-900);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timeline-track {
  position: relative;
  height: 28px;
  background: var(--color-surface-alt);
  border-radius: 999px;
  border: 1px solid var(--color-border);
}

.timeline-bar {
  position: absolute;
  top: 3px;
  bottom: 3px;
  border-radius: 999px;
  background: var(--color-blue-600);
  min-width: 8px;
}

.timeline-bar.status-complete { background: var(--color-success); }
.timeline-bar.status-atrisk { background: var(--color-warning); }
.timeline-bar.status-blocked { background: var(--color-danger); }
.timeline-bar.status-notstarted { background: var(--color-text-faint); }

.timeline-scale {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: var(--space-3);
  font-size: 0.72rem;
  color: var(--color-text-faint);
  margin-bottom: var(--space-1);
}

.timeline-scale__labels { display: flex; justify-content: space-between; }

/* ==========================================================================
   Traceability map
   ========================================================================== */

.map-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.map-legend { display: flex; gap: var(--space-4); flex-wrap: wrap; font-size: 0.8rem; color: var(--color-text-muted); }
.map-legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.legend-dot--linked { background: var(--color-blue-600); }
.legend-dot--orphan { background: var(--color-warning); }

.map-wrap {
  position: relative;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  overflow: hidden;
}

.map-columns {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 120px 1fr;
  gap: 0;
  align-items: start;
}

.map-column__header {
  font-family: var(--font-heading);
  font-weight: 700;
  color: var(--color-navy-900);
  margin-bottom: var(--space-3);
  font-size: 0.95rem;
}

.map-column {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  z-index: 2;
}

.map-node {
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

.map-node:hover { border-color: var(--color-blue-500); box-shadow: var(--shadow-sm); }

.map-node.is-orphan { border-style: dashed; border-color: #e3b579; background: var(--color-warning-bg); }

.map-node.is-active {
  border-color: var(--color-blue-600);
  box-shadow: 0 0 0 3px var(--color-blue-100);
  background: var(--color-blue-100);
}

.map-node.is-linked-preview {
  border-color: var(--color-blue-500);
  background: var(--color-blue-100);
}

.map-node__id {
  font-size: 0.68rem;
  color: var(--color-text-faint);
  font-weight: 700;
  letter-spacing: 0.03em;
  margin-bottom: 2px;
}

.map-node__title { font-weight: 600; font-size: 0.88rem; color: var(--color-navy-900); margin-bottom: 6px; }

.map-node__meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.map-connectors {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.map-connectors path {
  stroke: var(--color-border-strong);
  stroke-width: 1.5;
  fill: none;
}
.map-connectors path.is-active { stroke: var(--color-blue-600); stroke-width: 2.5; }

.map-linked-inline {
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px dashed var(--color-border);
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.map-linked-inline ul { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }

/* ==========================================================================
   Decision log
   ========================================================================== */

.decision-list { display: flex; flex-direction: column; gap: var(--space-4); }

.decision-entry {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-blue-600);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}

.decision-entry.action-deleted { border-left-color: var(--color-danger); }
.decision-entry.action-created { border-left-color: var(--color-success); }
.decision-entry.action-updated { border-left-color: var(--color-blue-600); }

.decision-entry__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
  flex-wrap: wrap;
}

.decision-entry__what { font-weight: 700; color: var(--color-navy-900); }
.decision-entry__date { font-size: 0.78rem; color: var(--color-text-faint); white-space: nowrap; }

.decision-entry__lenses {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  margin-top: var(--space-3);
}

.lens-block {
  background: var(--color-surface-alt);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
}

.lens-block__label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-faint);
  margin-bottom: 4px;
}

.lens-block p { margin: 0; font-size: 0.84rem; color: var(--color-text); }

/* ==========================================================================
   Auth pages (sign in / sign up)
   ========================================================================== */

/* Sticky-footer wrapper for the sign-in page: at least one viewport tall,
   a flex column, so the footer (margin-top:auto, below) sits right at the
   bottom of the screen when .auth-page is short, and flows naturally after
   it otherwise — instead of always being stacked below a full 100vh block,
   which forced a scroll on every screen height. */
.auth-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.auth-page {
  flex: 1;
  display: flex;
}

.auth-visual {
  flex: 1.1;
  background: linear-gradient(160deg, var(--color-navy-900), var(--color-navy-700) 70%);
  color: #fff;
  padding: var(--space-7);
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  overflow: hidden;
}


/* Positioned independently of the centered pitch content below it, so
   only the logo itself lines up with the sign-in card's top edge (see
   .auth-form-side) — the headline/pitch text stays vertically centered
   in the panel like before, not pulled up to sit under the logo. */
.auth-visual__brand {
  position: absolute;
  top: var(--space-7);
  left: var(--space-7);
}

.auth-visual__pitch h1 { color: #fff; font-size: 2.1rem; max-width: 480px; }
.auth-visual__pitch p { color: var(--color-text-on-dark-muted); max-width: 440px; font-size: 1rem; }

.auth-visual__diagram {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-6);
}

.diagram-node {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: 0.82rem;
  font-weight: 600;
}

.auth-form-side {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  background: var(--color-bg);
}

/* Clerk's <SignIn/> renders its own card, themed to match this palette via
   the `appearance` option passed to Clerk.mountSignIn() in js/auth.js — this
   wrapper just controls width/centering so it sits neatly in our layout. */
.auth-clerk-wrap {
  width: 100%;
  max-width: 400px;
}

/* justify-content:center is the part that actually matters: whatever
   width Clerk's real card renders at (its exact internal DOM/class names
   aren't ours to rely on), centering it here guarantees its horizontal
   center matches .auth-note's below — instead of it defaulting to the
   left edge of #clerkSignIn like a normal block-level child would. */
.auth-clerk-wrap #clerkSignIn {
  width: 100%;
  min-height: 80px;
  display: flex;
  justify-content: center;
}

/* Belt-and-suspenders: also ask Clerk's card to fill the full width when
   it can (so its edges line up with .auth-note too, not just its center).
   Clerk applies its own width as an inline style, which beats a plain CSS
   rule regardless of selector, so !important is what's actually needed
   here — not a specificity fix, an inline-style override. */
.auth-clerk-wrap .cl-rootBox,
.auth-clerk-wrap .cl-card {
  width: 100% !important;
  box-sizing: border-box;
}

.auth-note {
  margin-top: var(--space-4);
  font-size: 0.78rem;
  color: var(--color-text-faint);
  text-align: center;
  max-width: 100%;
}

/* ==========================================================================
   Stakeholder (public) page
   ========================================================================== */

.public-header {
  background: var(--color-navy-900);
  color: #fff;
  padding: var(--space-5);
}

.public-header__inner {
  max-width: 1080px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}


/* Same sticky-footer wrapper as .auth-body, for the public Stakeholder
   View: at least one viewport tall, flex column, so the footer sits at
   the bottom of the screen on short projects instead of needing a scroll. */
.public-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
}

/* .public-main is a flex item of .public-body's flex-direction:column
   layout. Centering it with margin:0 auto (rather than an explicit
   width, as .app-content above does) turns off that item's default
   cross-axis "stretch to fill" sizing in favor of auto-margin alignment
   — so instead of filling the viewport width, it shrinks to fit its own
   content, which on a narrow screen means a long, unwrapped heading
   pushes it (and the whole page) wider than the viewport. An explicit
   width:100% restores normal stretch-to-fill sizing; max-width still
   caps it on wide screens exactly as before. */
.public-main { width: 100%; max-width: 1080px; margin: 0 auto; padding: var(--space-6) var(--space-5); }

.progress-ring-wrap { display: flex; align-items: center; gap: var(--space-5); flex-wrap: wrap; }

.progress-ring { flex-shrink: 0; }

.progress-ring__value { font-family: var(--font-heading); font-size: 2.6rem; font-weight: 700; fill: var(--color-navy-900); }

.milestone-list { display: flex; flex-direction: column; gap: var(--space-3); }

.milestone-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.milestone-item__date {
  font-family: var(--font-heading);
  font-weight: 700;
  color: var(--color-navy-900);
  font-size: 0.85rem;
  width: 84px;
  flex-shrink: 0;
}

.milestone-item__title { flex: 1; min-width: 0; }

.risk-item {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-warning-bg);
  border: 1px solid #f0d9ae;
  margin-bottom: var(--space-2);
}

.risk-item svg { color: var(--color-warning); margin-top: 2px; }

.public-footer {
  text-align: center;
  padding: var(--space-5);
  color: var(--color-text-faint);
  font-size: 0.78rem;
}

/* Shared branding credit — built once by TraceFlowApp.footerHtml() (js/app.js)
   and appended on every page, signed-in or public. Small and muted on
   purpose, so it never competes with the page's real content. */
.site-footer {
  text-align: center;
  padding: var(--space-4) var(--space-5);
  color: var(--color-text-faint);
  font-size: 0.78rem;
  /* Pins the footer to the bottom of the screen when the page above it is
     shorter than the viewport (its flex-column parent — .app-main,
     .auth-body, or .public-body — is at least one viewport tall), while
     still flowing naturally right after the content when there's enough
     of it to need scrolling anyway. Not fixed/floating, so it never
     overlaps content — it's a normal part of the page's layout. */
  margin-top: auto;
  flex-shrink: 0;
}

.site-footer a {
  color: var(--color-text-faint);
  text-decoration: underline;
}

.site-footer a:hover {
  color: var(--color-teal-600);
}

/* ==========================================================================
   Toast (lightweight confirmation feedback)
   ========================================================================== */

.toast {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  background: var(--color-navy-900);
  color: #fff;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.85rem;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  transform: translateY(12px);
  opacity: 0;
  transition: transform var(--transition-fast), opacity var(--transition-fast);
}

.toast.is-visible { transform: translateY(0); opacity: 1; }
.toast svg { color: var(--color-success); }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 960px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .section-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .map-columns { grid-template-columns: 1fr; }
  .map-columns .map-connectors { display: none; }
  .map-column--tasks { margin-top: var(--space-5); padding-top: var(--space-5); border-top: 1px dashed var(--color-border); }
  .decision-entry__lenses { grid-template-columns: 1fr; }
  .progress-ring-wrap { justify-content: center; text-align: center; }
}

@media (max-width: 768px) {
  .app-sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .app-shell.nav-open .app-sidebar { transform: translateX(0); }
  .app-shell.nav-open .sidebar-backdrop { display: block; }
  .app-main { margin-left: 0; }
  .app-topbar { display: flex; }
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .app-content { padding: var(--space-4); }
  .stat-grid { grid-template-columns: 1fr; }
  .auth-visual { display: none; }
  .timeline-row { grid-template-columns: 1fr; }
  .timeline-scale { grid-template-columns: 1fr; }
  .timeline-row__label { white-space: normal; }

  /* Touch targets — at mouse-driven desktop widths these stay their
     normal compact size, but under 768px (where a visitor is far more
     likely tapping with a finger than clicking with a mouse) every
     interactive control gets a ~44px minimum, per WCAG's touch-target
     guidance. Only min-height/min-width, so existing padding still
     centers each control's label/icon rather than stretching it. */
  .menu-toggle, .app-notif-bell { min-width: 44px; min-height: 44px; }
  .btn, .btn-sm { min-height: 44px; } /* .btn already centers its content via flex */
  .view-toggle__btn { min-height: 44px; }
  .filter-row select, .toolbar input[type="search"] { min-height: 44px; }
  .kanban-card__view { min-height: 44px; }
  .app-search input { min-height: 44px; }
  .member-role-select { min-height: 44px; }
  .app-notif-markall { min-height: 44px; display: flex; align-items: center; }
  .link-button { min-height: 44px; display: flex; align-items: center; justify-content: center; }
  .modal__close { min-width: 44px; min-height: 44px; }
  .stakeholder-link-input { min-height: 44px; }
  .form-field input[type="text"],
  .form-field input[type="email"],
  .form-field input[type="password"],
  .form-field input[type="date"],
  .form-field input[type="number"],
  .form-field select { min-height: 44px; }
}

@media (max-width: 560px) {
  .page-header { flex-direction: column; align-items: stretch; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .modal { padding: var(--space-4); }

  /* A milestone row packs date + title + status badge into one flex line.
     On a narrow phone, giving the title only what's left over after the
     fixed-width date and the badge squeezes it down to a sliver, forcing
     the title into a tall stack of single-word lines with the (vertically
     centered) badge floating in the middle of it, looking like it
     overlaps the text. Wrapping the row and pushing the title onto its
     own full-width line fixes both the cramped wrapping and the
     overlap. */
  .milestone-item { flex-wrap: wrap; align-items: flex-start; }
  .milestone-item__title { flex-basis: 100%; order: 3; margin-top: var(--space-2); }
}
