/* Fonts are self-hosted from /fonts (Latin subset, WOFF2, SIL OFL — licences sit
   beside the files). Google Fonts can't be used here: the CSP in _headers only
   allows stylesheets and fonts from this origin. `swap` shows text in the system
   font straight away and switches once the file arrives (usually from cache). */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/inter-latin-400-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/fonts/inter-latin-500-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/inter-latin-600-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/fonts/inter-latin-700-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/poppins-latin-600-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/fonts/poppins-latin-700-normal.woff2') format('woff2');
}

/* Design tokens. The look follows Apple's HIG: quiet neutral surfaces, the brand
   colours used sparingly as a tint (primary actions, the active nav item, focus),
   hairline separators, soft layered depth and short eased motion. Components
   read these rather than literals, so a tweak here restyles the whole app. */
:root {
  /* neutrals */
  --color-bg: #f5f5f7;
  --color-surface: #ffffff;
  --color-surface-2: #fbfbfd;
  --color-text: #1d1d1f;
  --color-muted: #6e6e73;
  --color-border: #e3e3e8;
  --color-border-strong: #d2d2d7;
  /* translucent greys for button/control fills — they work over any background */
  --color-fill: rgba(118, 118, 128, 0.12);
  --color-fill-hover: rgba(118, 118, 128, 0.18);
  --color-fill-active: rgba(118, 118, 128, 0.24);
  --color-hover: rgba(118, 118, 128, 0.07);
  /* recessed area that cards sit in (kanban columns, chat thread) */
  --color-well: rgba(118, 118, 128, 0.09);

  /* nex2link brand — the tint */
  --color-primary: #2554a6;
  --color-primary-hover: #1c4488;
  --color-primary-light: #eaf0fb;
  --color-accent: #fcb036;
  --color-accent-hover: #e89b1f;
  --color-accent-light: #fef3e0;
  --color-on-accent: #92400e;
  --color-focus-ring: rgba(37, 84, 166, 0.35);

  --color-danger: #dc2626;
  --color-danger-hover: #b91c1c;
  --color-danger-light: #fee2e2;
  --color-success: #16a34a;
  --color-success-light: #dcfce7;

  /* status badges: background / foreground pairs */
  --status-blue-bg: #e3edfd;    --status-blue-fg: #1e4fa8;
  --status-indigo-bg: #e7e8fd;  --status-indigo-fg: #3730a3;
  --status-amber-bg: #fdf1dc;   --status-amber-fg: #92400e;
  --status-gray-bg: #efeff2;    --status-gray-fg: #4b4b52;
  --status-green-bg: #e1f5e7;   --status-green-fg: #166534;
  --status-red-bg: #fde8e8;     --status-red-fg: #991b1b;
  --status-violet-bg: #efe9fd;  --status-violet-fg: #5b21b6;
  --status-teal-bg: #dcf5f1;    --status-teal-fg: #115e59;

  /* type scale */
  --text-caption: 12px;
  --text-footnote: 13px;
  --text-body: 14px;
  --text-callout: 15px;
  --text-headline: 17px;
  --text-title3: 20px;
  --text-title2: 24px;
  --text-title1: 28px;

  /* 4pt spacing grid */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 1px rgba(0, 0, 0, 0.02);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.06), 0 24px 64px rgba(0, 0, 0, 0.16);

  /* motion — --ease-sheet is the curve iOS uses for sheets and drawers */
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-sheet: cubic-bezier(0.32, 0.72, 0, 1);
  --dur-fast: 120ms;
  --dur: 200ms;
  --dur-slow: 320ms;

  /* stacking order */
  --z-sticky: 40;
  --z-trigger: 45;
  --z-overlay: 50;
  --z-drawer-backdrop: 55;
  --z-drawer: 60;
  --z-menu: 70;
  --z-toast: 80;

  --overlay-bg: rgba(0, 0, 0, 0.32);
  /* frosted "material" for chrome that sits over content */
  --material-bg: rgba(255, 255, 255, 0.78);
  --material-blur: saturate(180%) blur(20px);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: 'Poppins', var(--font);

  /* app shell */
  --sidebar-width: 72px;
  --sidebar-width-expanded: 220px;
  --color-page-bg: var(--color-bg);

  /* avatar palette — decorative variety only, not brand tokens */
  --avatar-hue-1: var(--color-primary);
  --avatar-hue-2: var(--color-accent);
  --avatar-hue-3: #0d9488;
  --avatar-hue-4: #7c3aed;
  --avatar-hue-5: #db2777;
  --avatar-hue-6: #16a34a;
  --avatar-hue-7: #ea580c;
  --avatar-hue-8: #0891b2;
}

* { box-sizing: border-box; }

/* Stops iOS Safari inflating text in wide blocks when the phone is rotated. */
html {
  -webkit-text-size-adjust: 100%;
  scrollbar-color: rgba(0, 0, 0, 0.22) transparent;
}

/* Auth guard: page content stays hidden until requireAuthOrRedirect() confirms
   a valid session (or navigates away). Fails closed if JS errors/is blocked. */
html.auth-pending body { display: none; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--text-body);
  line-height: 1.45;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

::selection { background: var(--color-primary-light); }

h1, h2, h3 { font-family: var(--font-display); letter-spacing: -0.015em; line-height: 1.2; }
h1 { font-size: var(--text-title1); letter-spacing: -0.02em; }
h2 { font-size: var(--text-title3); }
h3 { font-size: var(--text-headline); }

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

/* Every :hover in this app is gated on a real pointer. On a touchscreen the
   hovered state latches after a tap and stays lit until you tap something else,
   which reads as "the row/button is stuck selected". */
@media (hover: hover) {
  a:hover { text-decoration: underline; }
}

/* One keyboard focus ring for everything. Mouse clicks don't show it
   (:focus-visible), and text fields keep their own ring below. */
:focus-visible {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: 2px;
}

.container {
  max-width: 1040px;
  margin: 0 auto;
  padding: 28px 24px 48px;
}

/* Authenticated app shell: sidebar (prepended by renderNavbar) + content pane.
   The existing .container in every authenticated page becomes the content
   pane purely via this rule — no page markup/JS needs to move. */
body.app-shell {
  margin: 0;
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--color-page-bg);
}
body.app-shell > .container {
  flex: 1;
  min-width: 0;
  max-width: none;
  margin: 0;
  padding: 32px 36px 56px;
  overflow-x: hidden;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}
/* A card in a vertical stack of cards. */
.card.section { margin-bottom: var(--space-4); }

/* Page and card headings — shared so every page reads with the same hierarchy. */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}
.page-title { margin: 0; font-size: var(--text-title1); }
.page-subtitle { margin: var(--space-1) 0 0; color: var(--color-muted); font-size: var(--text-callout); }
.card-title { margin: 0 0 var(--space-3); font-size: var(--text-headline); font-weight: 600; }
.toolbar .card-title { margin: 0; }
.detail-header { margin-top: var(--space-3); align-items: center; }
.auth-title { margin: 0 0 var(--space-1); font-size: var(--text-title2); }
.auth-subtitle { margin: 0 0 var(--space-6); color: var(--color-muted); font-size: var(--text-callout); }
.back-link { display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-footnote); font-weight: 500; }
.row { display: flex; align-items: center; gap: var(--space-2); }

.centered-screen {
  min-height: 100vh;
  min-height: 100dvh; /* mobile browser chrome shrinks/grows the viewport as you scroll */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background:
    radial-gradient(circle at 15% 15%, rgba(37, 84, 166, 0.08), transparent 45%),
    radial-gradient(circle at 85% 85%, rgba(252, 176, 54, 0.10), transparent 45%),
    var(--color-bg);
}
.centered-screen .card {
  border-radius: var(--radius-lg);
  padding: var(--space-7);
  box-shadow: var(--shadow-md);
  animation: scale-in var(--dur-slow) var(--ease-sheet);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--space-4);
}

.form-field label,
.field-label { font-size: var(--text-footnote); font-weight: 500; color: var(--color-muted); }

input, select, textarea {
  font-family: var(--font);
  font-size: var(--text-body);
  line-height: 1.35;
  padding: 9px 12px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}
input::placeholder, textarea::placeholder { color: #a1a1a6; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--color-primary); }

/* File inputs render an OS-native "Choose File" button + filename label whose
   width ignores the parent container — cap it so it can't push a card wider
   than itself, especially on narrow screens. */
input[type="file"] { max-width: 100%; padding: 6px; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-focus-ring);
}

button, .btn {
  font-family: var(--font);
  font-size: var(--text-body);
  font-weight: 600;
  line-height: 1.2;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-primary);
  background: var(--color-primary);
  color: #fff;
  cursor: pointer;
  transition: background var(--dur-fast) ease, border-color var(--dur-fast) ease,
    color var(--dur-fast) ease, opacity var(--dur-fast) ease, transform var(--dur-fast) var(--ease-out);
}

/* :active still fires on touch, so a tap keeps its press feedback. */
button:active, .btn:active { transform: scale(0.97); }

/* No pointer events rather than a :not(:disabled) guard on every hover rule — that
   guard would out-specify the component hover rules in components.css. */
button:disabled, button[aria-busy="true"] { opacity: 0.5; cursor: default; pointer-events: none; }

/* .btn is for the <a> that has to sit in a row of buttons (a link out to a deal
   beside a real action). An anchor is an inline box with an underline, so it
   otherwise sits at the wrong height and is the one item in the row that looks
   like a link. */
a.btn { display: inline-block; text-decoration: none; }

/* Secondary actions are a quiet grey fill — Apple's "gray" button — so the one
   tinted button on screen is the obvious next step. */
button.secondary {
  background: var(--color-fill);
  color: var(--color-text);
  border-color: transparent;
}

button.accent {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-text);
}

button.danger {
  background: var(--color-danger);
  border-color: var(--color-danger);
  color: #fff;
}

/* Round glyph-only button (the ✕ on sheets and dialogs). */
button.icon-button {
  width: 30px;
  height: 30px;
  min-height: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 50%;
  border-color: transparent;
  background: var(--color-fill);
  color: var(--color-muted);
  font-size: 13px;
  line-height: 1;
}

@media (hover: hover) {
  button:hover, .btn:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); }
  button.secondary:hover { background: var(--color-fill-hover); border-color: transparent; }
  button.accent:hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); }
  button.danger:hover { background: var(--color-danger-hover); border-color: var(--color-danger-hover); }
  button.icon-button:hover { background: var(--color-fill-hover); border-color: transparent; color: var(--color-text); }
}

.error-text { color: var(--color-danger); font-size: var(--text-footnote); min-height: 18px; }

.muted { color: var(--color-muted); font-size: var(--text-footnote); }

/* ---------- loading / error states ---------- */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid var(--color-fill-hover);
  border-top-color: var(--color-muted);
  animation: spin 0.8s linear infinite;
}
.loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--color-muted);
  font-size: var(--text-footnote);
  padding: var(--space-2) 0;
  animation: fade-in var(--dur-slow) ease backwards;
  /* A fast response never shows the spinner at all, rather than flashing it. */
  animation-delay: 150ms;
}
.table-wrap > .loading,
.table-wrap > .state-error { padding: var(--space-4); }
.state-error {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--color-danger);
  font-size: var(--text-footnote);
  padding: var(--space-2) 0;
}
.state-error button { padding: 5px 12px; font-size: var(--text-footnote); }

/* ---------- toast (HUD) ---------- */
.toast-region {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  width: max-content;
  max-width: calc(100vw - 32px);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px;
  border-radius: var(--radius-pill);
  background: rgba(29, 29, 31, 0.86);
  -webkit-backdrop-filter: var(--material-blur);
  backdrop-filter: var(--material-blur);
  color: #fff;
  font-size: var(--text-body);
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in var(--dur-slow) var(--ease-sheet) both;
}
.toast.is-leaving { animation: toast-out var(--dur) ease-in both; }
.toast-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: rgba(255, 255, 255, 0.25);
}
.toast.is-success .toast-icon { background: #30d158; }
.toast.is-error .toast-icon { background: #ff453a; }
.toast-action {
  all: unset;
  cursor: pointer;
  margin-left: var(--space-1);
  padding: 2px 8px;
  border-radius: 6px;
  color: #64d2ff;
  font-weight: 600;
}
.toast-action:hover { background: rgba(255, 255, 255, 0.12); }
.toast-action:focus-visible { outline: 2px solid #64d2ff; outline-offset: 1px; }

/* ---------- motion ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes scale-in {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: none; }
}
@keyframes rise-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(8px) scale(0.98); }
}

/* Page content settles in rather than snapping on. `backwards`, not `both`: a
   fill that outlives the animation keeps a stacking context on the container,
   which would trap every fixed/z-indexed thing inside it. */
body.app-shell > .container { animation: fade-in var(--dur-slow) ease backwards; }

/* Reduced motion: everything becomes (effectively) instant. 0.01ms rather than 0s
   because a zero-length transition never fires transitionend, and the overlay
   close code waits on that event. The spinner keeps turning — it's a status
   indicator, and a frozen one reads as a hang. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .spinner { animation-duration: 1.6s !important; animation-iteration-count: infinite !important; }
  button:active, .btn:active { transform: none; }
}

/* ---------- mobile (<=640px) ----------
   Plain element rules live here rather than in components.css because the login
   and accept-invite pages load only this stylesheet — they're the first screens
   a phone ever sees, so they can't be the two that miss out. Component-specific
   mobile layout (and the selectors that have to out-specify these) is in
   components.css. */
@media (max-width: 640px) {
  /* iOS Safari zooms the whole page in whenever a focused field is under 16px,
     and never zooms back out — so every text field has to clear that bar. */
  input, select, textarea { font-size: 16px; }

  /* Comfortable touch targets. 40px rather than the usual 44 — enough to hit
     reliably without visibly inflating the buttons. */
  button, .btn { min-height: 40px; }
  button.icon-button { width: 36px; height: 36px; min-height: 0; }
  input[type="checkbox"] { width: 20px; height: 20px; }

  /* The default h1 eats a phone's width on its own. */
  h1, .page-title { font-size: var(--text-title2); }
  .centered-screen .card { padding: var(--space-6); }
}
