/* ============================================================
   Shared styles for the ThreatTree app shell.

   Loaded by every /app page that is NOT part of the fully
   authenticated editor/dashboard shell: the auth-card screens
   (login, register, password reset, invite, SSO callback), and
   the "minimal app-header" screens (quote, help, membership).

   This exists so a component — a button, the header, the avatar
   dropdown — is defined once and shared, instead of copy-pasted
   into each page and left to drift.
   ============================================================ */

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

:root {
  --red:          #DC2626;
  --red-dark:     #B91C1C;
  --red-light:    #EF4444;
  --bg:           #F8FAFC;
  --surface:      #FFFFFF;
  --text:         #0F172A;
  --text-muted:   #64748B;
  --border:       #E2E8F0;
  --radius:       0.5rem;
  --shadow:       0 1px 3px rgba(0,0,0,.08);
  --shadow-md:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
  --shadow-glow:  0 8px 28px -6px rgba(220,38,38,.35);
  --gradient-red: linear-gradient(135deg, var(--red-light) 0%, var(--red) 55%, var(--red-dark) 100%);
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

[hidden] { display: none !important; }

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

/* ============================================================
   Buttons — one definition, every page.
   `.btn-primary` / `.btn-ghost` / `.btn-outline` is the naming
   convention already used across the app pages (as opposed to
   the marketing site's `.btn .btn--primary`). Kept as-is here
   rather than renamed, to converge the *definitions* first
   without a large, risky HTML find-and-replace across pages
   this session can't render live to verify.
   ============================================================ */

.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  background: var(--gradient-red);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: inherit;
  padding: 0.625rem 1.25rem;
  cursor: pointer;
  text-decoration: none;
  box-shadow: var(--shadow-glow);
  transition: box-shadow 0.2s, transform 0.15s;
}

.btn-primary:hover {
  box-shadow: 0 10px 32px -6px rgba(220,38,38,.45);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 4px 14px -4px rgba(220,38,38,.4);
}

.btn-primary:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-muted);
  padding: 0.35rem 0.875rem;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, color .15s, border-color .15s, transform .15s;
}

.btn-ghost:hover {
  background: var(--surface);
  color: var(--text);
  border-color: #CBD5E1;
  transform: translateY(-1px);
}

/* Compact inline primary CTA — for header/nav contexts, as opposed
   to .btn-primary's full-width form-submit sizing. */
.btn-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-red);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  text-decoration: none;
  box-shadow: var(--shadow-glow);
  transition: box-shadow 0.2s, transform 0.15s;
}

.btn-cta:hover {
  box-shadow: 0 10px 32px -6px rgba(220,38,38,.45);
  transform: translateY(-1px);
}

.btn-outline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  background: none;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: inherit;
  padding: 0.625rem 1.25rem;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, transform .15s;
}

.btn-outline:hover {
  background: var(--bg);
  border-color: #CBD5E1;
  transform: translateY(-1px);
}

@media (pointer: coarse) {
  .btn-primary, .btn-ghost, .btn-outline, .btn-cta { min-height: 44px; }
  .form-group input, .form-group select, .form-group textarea { min-height: 44px; }
}

/* ============================================================
   Auth card — login, register, password reset, invite, SSO callback
   ============================================================ */

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2.5rem;
  width: 100%;
  max-width: 360px;
}

.auth-card--wide { max-width: 380px; }

.logo-wrap {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  text-decoration: none;
}

.auth-card .logo-wrap { margin-bottom: 1.75rem; }

.auth-card h1 { font-size: 1.3rem; font-weight: 700; margin-bottom: 0.5rem; }
.auth-card .subtitle { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 1.5rem; }

.success-msg {
  font-size: 0.85rem;
  color: #16A34A;
  background: #F0FDF4;
  border: 1px solid #BBF7D0;
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  display: none;
}

.form-group { margin-bottom: 0.9rem; }
.form-group label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.35rem; }
.form-group label .opt { font-weight: 400; color: var(--text-muted); }
.form-group input,
.form-group select,
.form-group textarea {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--red); }
.form-group input.is-invalid,
.form-group input.error,
.form-group select.error,
.form-group textarea.error { border-color: var(--red); }
.form-group input[readonly] { background: var(--bg); color: var(--text-muted); }

.error-msg { font-size: 0.85rem; color: var(--red); min-height: 1.2rem; margin: 0.6rem 0; }
.field-error { font-size: 0.8rem; color: var(--red); min-height: 1rem; margin-top: 0.25rem; }

.otp-input { text-align: center; font-size: 1.5rem; letter-spacing: 0.5em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.otp-hint { font-size: 0.85rem; color: var(--text-muted); min-height: 1.2rem; margin: 0.6rem 0; text-align: center; }
.resend-row { text-align: center; margin-top: 0.9rem; font-size: 0.875rem; }
.resend-row a { color: var(--red); text-decoration: none; font-weight: 500; cursor: pointer; }
.resend-row a:hover { text-decoration: underline; }
.resend-row a.is-disabled { color: var(--text-muted); cursor: default; pointer-events: none; }

.state-msg { font-size: 0.9375rem; color: var(--text-muted); text-align: center; padding: 1rem 0; }
.btn-row { display: flex; gap: 0.6rem; margin-top: 0.5rem; }
.btn-row .btn-primary, .btn-row .btn-ghost, .btn-row .btn-outline { margin-top: 0; }

.footer-link { text-align: center; margin-top: 1.25rem; font-size: 0.875rem; color: var(--text-muted); }
.footer-link a { color: var(--red); text-decoration: none; font-weight: 500; cursor: pointer; }
.footer-link a:hover { text-decoration: underline; }
.footer-link a.is-disabled { color: var(--text-muted); cursor: default; pointer-events: none; }

.auth-page { display: flex; align-items: center; justify-content: center; padding: 1.5rem; }

@media (max-width: 400px) {
  .auth-page { padding: 1rem; }
  .auth-card { padding: 1.5rem; }
}

/* ============================================================
   Full marketing nav — used on membership, which (unlike quote
   and help) is reachable by logged-out visitors comparing plans,
   so it needs the complete nav rather than the minimal header.
   ============================================================ */

.nav { position: sticky; top: 0; z-index: 100; background: rgba(255,255,255,.92); border-bottom: 1px solid var(--border); transition: box-shadow 0.2s; }
.nav.scrolled { box-shadow: var(--shadow); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.nav__inner { display: flex; align-items: center; justify-content: space-between; height: 4rem; }
.nav__logo { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 800; font-size: 1.25rem; color: var(--text); text-decoration: none; letter-spacing: -0.03em; flex-shrink: 0; }
.nav__logo-icon { flex-shrink: 0; transition: transform 0.3s ease; }
.nav__logo:hover .nav__logo-icon { transform: rotate(-8deg) scale(1.08); }
.nav__menu { display: none; }
.nav__links { list-style: none; display: flex; flex-direction: column; gap: 0.875rem; }
.nav__links a { text-decoration: none; color: var(--text-muted); font-size: 0.9375rem; font-weight: 500; transition: color 0.15s; }
.nav__links a:hover, .nav__links a:focus-visible { color: var(--text); }
@media (min-width: 1024px) { .nav__links a.active { color: var(--red); font-weight: 600; } }
.nav__toggle { background: none; border: none; cursor: pointer; padding: 0.375rem; display: flex; flex-direction: column; gap: 5px; border-radius: 4px; }
.nav__toggle:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.nav__toggle span { display: block; width: 22px; height: 2px; background: var(--text); border-radius: 2px; transition: transform 0.2s, opacity 0.2s; }
@media (max-width: 1023px) {
  .nav.open .nav__menu { display: flex; flex-direction: column; align-items: stretch; gap: 0.5rem; position: absolute; top: 4rem; left: 0; right: 0; background: var(--surface); border-bottom: 1px solid var(--border); padding: 1.25rem; box-shadow: var(--shadow-md); z-index: 99; }
  .nav.open #nav-actions { flex-direction: column; align-items: stretch; width: 100%; margin-top: 0.5rem; gap: 0.5rem; }
  .nav.open .nav__toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .nav.open .nav__toggle span:nth-child(2) { opacity: 0; }
  .nav.open .nav__toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
}
@media (min-width: 1024px) {
  .nav__menu { display: flex; flex-direction: row; align-items: center; gap: 2rem; flex: 1; padding-left: 2.5rem; }
  .nav__links { flex-direction: row; gap: 1.75rem; align-items: center; }
  #nav-actions { margin-left: auto; gap: 2rem; }
  .nav__toggle { display: none; }
}
#nav-actions .btn-primary, #nav-actions .btn-ghost { width: auto; }

/* ============================================================
   Minimal app-header — quote, help, and the logged-in state of
   membership. A compact 3.5rem header: logo, then either the
   Sign in / Get started pair (logged out) or the avatar menu
   (logged in).
   ============================================================ */

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 3.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-menu { position: relative; }

.avatar-chip {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--gradient-red);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: .03em;
  transition: opacity .15s;
}
.avatar-chip:hover { opacity: .85; }

.user-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 0.5rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  min-width: 200px;
  z-index: 50;
  padding: 0.5rem 0;
}
.dropdown-user { padding: 0.625rem 1rem 0.5rem; }
.dropdown-name { font-size: 0.875rem; font-weight: 600; color: var(--text); }
.dropdown-email { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.1rem; }
.dropdown-divider { border: none; border-top: 1px solid var(--border); margin: 0.375rem 0; }
.dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  transition: background .12s;
  white-space: nowrap;
}
.dropdown-item:hover { background: var(--bg); }
.dropdown-item--danger { color: var(--red); }

@media (pointer: coarse) {
  .dropdown-item { min-height: 44px; display: flex; align-items: center; }
}

/* ============================================================
   Footer — used by quote, membership, and any other app-header
   page that ends on the shared marketing-style footer.
   ============================================================ */

.container { width: 100%; max-width: 1200px; margin-inline: auto; padding-inline: 1.25rem; }
.footer { background: var(--surface); border-top: 1px solid var(--border); padding: 3rem 0 1.5rem; }
.footer__inner { display: flex; flex-direction: column; gap: 1.5rem; align-items: flex-start; }
@media (min-width: 640px) { .footer__inner { flex-direction: row; justify-content: space-between; align-items: flex-start; } }
.footer__logo { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 1.125rem; font-weight: 800; color: var(--text); letter-spacing: -0.03em; }
.footer__brand p { margin-top: 0.3125rem; font-size: 0.875rem; color: var(--text-muted); }
.footer__links { list-style: none; display: flex; flex-wrap: wrap; gap: 0.375rem 1.25rem; align-items: center; }
.footer__links a { font-size: 0.875rem; color: var(--text-muted); text-decoration: none; transition: color 0.15s; }
.footer__links a:hover { color: var(--text); }
.footer__copy { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--border); font-size: 0.8125rem; color: var(--text-muted); }

/* ============================================================
   App header — the wider, content-page variant used by
   dashboard, forest, forest-report, risk-register, settings.
   Same 3.5rem compact header as the "minimal app-header" above,
   just with `.user-nav` as the historical wrapper name on a
   couple of pages — aliased here rather than renamed in markup.
   ============================================================ */

.user-nav { display: flex; align-items: center; gap: 0.75rem; }

/* ============================================================
   Modal — confirm dialogs, upgrade prompts, rename/delete
   forms. Identical across dashboard, forest, settings, and the
   admin dashboard.
   ============================================================ */

.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 100; }
.modal-overlay[hidden] { display: none; }
.modal-card { background: var(--surface); border-radius: calc(var(--radius) * 1.5); box-shadow: var(--shadow-md); width: 100%; max-width: 440px; padding: 1.75rem; }
.modal-card h2 { font-size: 1.125rem; font-weight: 700; margin-bottom: 0.75rem; }
.modal-card > p { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 1rem; line-height: 1.6; }
.modal-error { font-size: 0.85rem; color: var(--red); min-height: 1.2rem; margin-top: 0.5rem; }
.modal-actions { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.25rem; }
.confirm-modal-body { font-size: 0.9rem; color: var(--text-muted); line-height: 1.65; white-space: pre-line; }

/* ============================================================
   Toasts — replaces native alert(). Identical everywhere it's
   used: dashboard, editors, forest, settings, admin dashboard.
   ============================================================ */

.toast-stack { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); z-index: 500; display: flex; flex-direction: column; gap: 0.5rem; align-items: center; }
.toast { display: flex; align-items: flex-start; gap: 0.75rem; max-width: 420px; background: #1E293B; color: #F8FAFC; font-size: 0.85rem; line-height: 1.5; padding: 0.7rem 0.75rem 0.7rem 1rem; border-radius: var(--radius); box-shadow: var(--shadow-md); animation: toast-in .18s ease; }
.toast--warning { background: #78350F; }
.toast--error { background: #7F1D1D; }
.toast__msg { flex: 1; }
.toast__dismiss { flex-shrink: 0; border: none; background: none; color: rgba(255,255,255,.7); cursor: pointer; font-size: 1.05rem; padding: 0; line-height: 1.4; }
.toast__dismiss:hover { color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }
