/**
 * styles.css — Main stylesheet for Presidio
 *
 * Covers: Landing page, Login page, Inbox.
 * Report and Builder pages have their own stylesheets.
 * Design tokens (colors, radii, shadow, font) live in tokens.css.
 *
 * Page-specific anchors:
 *   Cards:       --color-surface with --radius-3xl, --shadow-card
 *   Max-width:   1200px (inbox), 420px (login card)
 *
 * Responsive breakpoints:
 *   1200px — tile grid: 3 cols
 *   1100px — hide hero image
 *   600px  — tile grid: 1 col, compact spacing
 */


/* ═══════════════════════════════════════════════════
   RESET & BASE
   ═══════════════════════════════════════════════════ */

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

body {
  background-color: var(--color-bg-page);
  font-family: var(--font-sans);
  color: var(--color-fg);
  line-height: 1.5;
}

/* Search filter: hides tiles without breaking grid */
.hidden { display: none !important; }

/* The HTML [hidden] attribute is meant to apply `display: none` via the UA
   stylesheet, but ANY author rule with higher specificity that sets `display`
   (e.g. `.menu-item { display: block }`, `.back-link { display: inline-flex }`)
   silently overrides it. This rule restores [hidden] as the single source of
   truth for show/hide across the app, so JS can rely on `el.hidden = true/false`
   without fighting per-element styling. Specific selectors below add a second
   layer of defense so even a !important-stripped browser stylesheet can't
   reveal admin-only menu items. */
[hidden] { display: none !important; }
.menu-item[hidden],
.back-link[hidden],
.avatar-menu[hidden] { display: none !important; }


/* ═══════════════════════════════════════════════════
   LANDING PAGE — Header
   ═══════════════════════════════════════════════════ */

.site-header {
  max-width: 1200px;
  margin: 2.5rem auto 0;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 1.75rem;
  font-weight: 700;
}

.sign-in-link {
  text-decoration: none;
  color: var(--color-fg);
  font-size: 1rem;
  font-weight: 500;
}


/* ═══════════════════════════════════════════════════
   LANDING PAGE — Hero section
   ═══════════════════════════════════════════════════ */

.hero {
  display: flex;
  align-items: center;
  max-width: 1200px;
  margin: 7rem auto 2rem;
  padding: 0 1.5rem;
  gap: 2rem;
}

.hero-text     { flex: 1 1 50%; max-width: 600px; }
.hero-text h1  { font-size: 3.5rem; line-height: 1.15; margin-bottom: 1rem; font-weight: 700; }
.subheading    { font-size: 1.125rem; color: var(--color-fg-secondary); margin-bottom: 1.5rem; }

.cta-button {
  display: inline-flex;
  align-items: center;
  background: var(--color-fg);
  color: #fff;
  border: none;
  font-size: 1rem;
  padding: .75rem 1.5rem;
  border-radius: var(--radius-xl);
  cursor: pointer;
  margin-top: 2rem;
  text-decoration: none;
  transition: background .2s;
}
.cta-button:hover { background: var(--color-fg-secondary); }

.hero-image     { flex: 1 1 50%; display: flex; justify-content: center; }
.hero-image img { max-width: 100%; height: auto; max-height: 500px; }

/* Word-by-word fade-in animation on hero text */
.fade-word,
.fade-subheading {
  opacity: 0;
  animation: fadeInUp .5s ease forwards;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}


/* ═══════════════════════════════════════════════════
   LANDING PAGE — Responsive
   ═══════════════════════════════════════════════════ */

/* Tablet: stack hero vertically, image above text */
@media (max-width: 1100px) {
  .hero         { margin-top: 5rem; flex-direction: column; text-align: center; }
  .hero-text    { max-width: 100%; }
  .hero-text h1 { font-size: 2.75rem; }
  .subheading   { font-size: 1rem; }
  .cta-button   { margin-left: auto; margin-right: auto; }
  .hero-image   { order: -1; max-width: 70%; }
  .hero-image img { max-height: 300px; }
}

/* Phone: tighter spacing, smaller image */
@media (max-width: 600px) {
  .site-header  { margin-top: 1.5rem; }
  .hero         { margin-top: 3rem; gap: 1.5rem; }
  .hero-text h1 { font-size: 2rem; }
  .subheading   { font-size: .95rem; }
  .cta-button   { font-size: .9rem; padding: .65rem 1.25rem; }
  .hero-image   { max-width: 80%; }
  .hero-image img { max-height: 220px; }
}


/* ═══════════════════════════════════════════════════
   LOGIN PAGE
   ═══════════════════════════════════════════════════ */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;  /* prevents card from touching screen edges on mobile */
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--color-surface);
  border-radius: var(--radius-3xl);
  padding: 2.5rem 2rem 3rem;
  box-shadow: 0 10px 30px rgba(0,0,0,.05);
}

.login-home-link {
  display: block;
  font-size: .85rem;
  color: var(--color-fg-subtle);
  text-decoration: none;
  margin-bottom: 1rem;
  transition: color .15s;
}
.login-home-link:hover { color: var(--color-fg); }

.login-card h2 {
  font-size: 1.5rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-card label {
  display: block;
  font-size: .875rem;
  font-weight: 500;
  margin-bottom: .25rem;
}

.login-card input {
  width: 100%;
  padding: .75rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-size: 1rem;
  font-family: inherit;
  background: var(--color-surface-input);
  margin-bottom: 1rem;
  transition: border-color .15s, background-color .15s;
}
.login-card input:focus {
  border-color: var(--color-fg);
  background: var(--color-surface);
  outline: none;
}

/* Shared button used on login + reset panels */
.primary-btn {
  width: 100%;
  background: var(--color-fg);
  color: #fff;
  border: none;
  border-radius: var(--radius-xl);
  padding: .8rem;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  transition: background .2s;
}
.primary-btn:hover    { background: var(--color-fg-secondary); }
.primary-btn:disabled { background: var(--color-fg-disabled); cursor: not-allowed; }

/* "Forgot password" / "Request invitation" links */
.secondary-actions {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-top: 1rem;
}
.secondary-link {
  font-size: .875rem;
  color: var(--color-fg-muted);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.secondary-link:hover { text-decoration: underline; }

/* Inline error message below password field */
.form-error {
  font-size: .875rem;
  color: var(--color-error);
  margin-bottom: .75rem;
  text-align: center;
}

/* Success/info message (used in reset panel) */
.form-message {
  font-size: .875rem;
  margin: .75rem 0;
  text-align: center;
}
.form-message.ok { color: var(--color-success); }

/* Forgot-password inline panel (toggles with login form) */
.reset-panel {
  margin-top: 1.5rem;
  text-align: center;
}
.reset-panel p:first-child {
  font-size: .9rem;
  color: var(--color-fg-muted);
  margin-bottom: 1rem;
}
.reset-panel input {
  width: 100%;
  padding: .75rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-size: 1rem;
  font-family: inherit;
  background: var(--color-surface-input);
  margin-bottom: .75rem;
}
.reset-panel input:focus {
  border-color: var(--color-fg);
  background: var(--color-surface);
  outline: none;
}
.reset-actions {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  align-items: center;
}
.reset-actions .primary-btn { max-width: 280px; }


/* ═══════════════════════════════════════════════════
   INBOX — Layout
   ═══════════════════════════════════════════════════ */

.dashboard-body {
  background: var(--color-bg-page);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Dashboard header ────────────────────────────── */
.dash-header {
  width: 100%;
  max-width: 1200px;
  margin: 1.5rem auto 0;
  padding: 0 1.5rem;
  height: 64px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dash-logo { font-size: 1.75rem; font-weight: 700; color: inherit; text-decoration: none; }

/* Right side: "+ New" button (admin-only) + avatar */
.dash-actions {
  display: flex;
  align-items: center;
  gap: .75rem;
}

/* Admin-only "new report" button + dropdown wrap (hidden by default, shown via JS).
   The dropdown menu itself reuses .avatar-menu / .menu-item from below. */
.new-report-wrap { position: relative; }
.new-report-btn {
  font-size: .875rem;
  font-weight: 600;
  color: var(--color-fg);
  background: transparent;
  text-decoration: none;
  font-family: inherit;
  cursor: pointer;
  padding: .5rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  transition: background .15s, border-color .15s;
}
.new-report-btn:hover { background: var(--color-surface); border-color: var(--color-fg); }

/* Avatar button (doubles as sign-out) */
.avatar-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--color-fg);
  cursor: pointer;
  position: relative;
  transition: background .2s;
}
.avatar-btn:hover { background: var(--color-fg-secondary); }
.avatar-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M20 21v-2a4 4 0 0 0-3-3.87'/%3E%3Cpath d='M4 21v-2a4 4 0 0 1 3-3.87'/%3E%3Ccircle cx='12' cy='7' r='4'/%3E%3C/svg%3E") center/20px 20px no-repeat;
}

/* ── Dashboard search bar (full-width, Google-style) ── */
.dash-search {
  width: 100%;
  max-width: 1200px;
  margin: 2rem auto 0;
  padding: 0 1.5rem;
}

.dash-search form {
  width: 100%;
  display: flex;
}

.dash-search input[type="search"] {
  flex: 1 1 auto;
  padding: 1rem 1.25rem;
  border: 1px solid var(--color-border);
  border-right: none;
  border-radius: var(--radius-4xl) 0 0 var(--radius-4xl);
  font-size: 1rem;
  font-family: inherit;
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
}
.dash-search input[type="search"]:focus {
  outline: none;
  border-color: var(--color-fg-disabled);
  box-shadow: 0 2px 12px rgba(0,0,0,.08);
}

.dash-search button {
  flex: 0 0 56px;
  display: grid;
  place-items: center;
  background: var(--color-fg);
  color: #fff;
  border: 1px solid var(--color-fg);
  border-radius: 0 var(--radius-4xl) var(--radius-4xl) 0;
  cursor: pointer;
  transition: background .2s;
}
.dash-search button:hover { background: var(--color-fg-secondary); }

/* ── Dashboard tile grid ─────────────────────────── */

/* Responsive columns: 3 → 2 → 1 */
.tile-grid {
  width: 100%;
  max-width: 1200px;
  margin: 2rem auto 3rem;
  padding: 0 1.5rem;
  display: grid;
  gap: 1.5rem;
}

@media (min-width: 1200px)                       { .tile-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 600px) and (max-width:1199px) { .tile-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 599px)                        { .tile-grid { grid-template-columns: 1fr; } }

/* ── Individual tile ─────────────────────────────── */

/*
 * Each tile is an <a> wrapping the entire card.
 * --bg CSS variable is set per-tile for the background image.
 * The ::after pseudo-element adds a bottom-to-top dark gradient
 * so white text stays readable over any background image.
 */
.tile {
  position: relative;
  padding: 1.5rem;
  border-radius: var(--radius-4xl);
  overflow: hidden;
  aspect-ratio: 3 / 2;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  background: var(--bg) center/cover no-repeat, var(--color-fg-secondary);
  transition: transform .25s ease;
  text-decoration: none;
  color: inherit;
}

.tile::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0) 0%, rgba(0,0,0,1) 100%);
  pointer-events: none;
}

/* Keep text above the gradient overlay */
.tile > * { position: relative; z-index: 1; }

.tile-label {
  /* Pushed down so the absolutely-positioned .tile-type chip (top:1rem,
     ~1.4rem tall) doesn't overlap the company name. */
  margin-top: 1.5rem;
  font-size: clamp(.8rem, 1vw + .4rem, 1rem);
  font-weight: 500;
  color: #fff;
}

.tile-headline {
  font-size: clamp(1.1rem, 1.2vw + .8rem, 1.6rem);
  font-weight: 700;
  line-height: 1.25;
  margin-top: .25rem;
  color: #fff;
}

.tile-read {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  font-size: .9rem;
  font-weight: 500;
  color: #fff;
  opacity: .9;
  transition: opacity .25s;
  z-index: 1;
}
/* Admin-only edit link (bottom-left of tile) — legacy. Kept around so a
   stale inbox.js still has something to style; new code uses the
   .tile-actions gear menu below. */
.tile-edit {
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  font-size: .8rem;
  font-weight: 500;
  color: rgba(255,255,255,.7);
  text-decoration: none;
  z-index: 1;
  transition: color .15s;
}
.tile-edit:hover { color: #fff; }

/* ── Tile gear menu (admin/editor) ────────────────
   Replaces the .tile-edit text link with an icon button that opens
   a small popup of actions (Edit + Insights for admin). The popup
   stays within the tile bounds so overflow:hidden doesn't clip it,
   and uses the same surface/radius tokens as the avatar dropdown
   so it feels native to the rest of the app. */
.tile-actions {
  position: absolute;
  bottom: .85rem;
  left: .85rem;
  z-index: 3;
}

.tile-gear {
  width: 32px;
  height: 32px;
  border: 1px solid rgba(255, 255, 255, .35);
  border-radius: 50%;
  background: rgba(0, 0, 0, .35);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background .15s, transform .12s;
}
.tile-gear:hover  { background: rgba(0, 0, 0, .55); }
.tile-gear:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
.tile-gear:active { transform: scale(.94); }
@media (prefers-reduced-motion: reduce) {
  .tile-gear:active { transform: none; }
}

.tile-action-menu {
  position: absolute;
  bottom: calc(100% + .5rem);
  left: 0;
  min-width: 140px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  padding: .25rem 0;
  z-index: 4;
  white-space: nowrap;
  animation: tileMenuIn .14s ease-out;
}
@keyframes tileMenuIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .tile-action-menu { animation: none; }
}

.tile-action-item {
  display: block;
  padding: .55rem 1rem;
  color: var(--color-fg);
  text-decoration: none;
  font: 500 .875rem var(--font-sans);
  background: none;
  border: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  box-sizing: border-box;
}
.tile-action-item:hover { background: var(--color-surface-hover); }
.tile-action-item:focus-visible {
  outline: 2px solid var(--color-fg);
  outline-offset: -2px;
}

.tile:hover .tile-read { opacity: 1; }
.tile:hover { transform: translateY(-4px); }

/* ── Unread dot (Phase 3) ────────────────────────── */
/* Small filled dot in the top-right corner of tiles the viewer has
   not yet opened. Sits at the same top-1rem/right-1rem anchor as the
   draft badge — but drafts shouldn't be marked unread (they're not
   surfaced to viewers in the first place), so they never collide. */
.tile-unread {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 2;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 2px rgba(0,0,0,.4);
  pointer-events: none;
}

/* ── Draft state ─────────────────────────────────── */
.tile.draft { opacity: .72; }
.tile.draft:hover { opacity: 1; }
.tile-badge {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 2;
  padding: .25rem .6rem;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #fff;
  background: rgba(0,0,0,.55);
  border: 1px solid rgba(255,255,255,.3);
  border-radius: var(--radius-pill);
  backdrop-filter: blur(4px);
}

/* ── Type chip (top-left of tile) ────────────────── */
/* Sits opposite the draft badge so the two never collide. */
.tile-type {
  position: absolute;
  top: 1rem;
  left: 1rem;
  z-index: 2;
  padding: .2rem .55rem;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #fff;
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.35);
  border-radius: var(--radius-pill);
  backdrop-filter: blur(4px);
}

/* ── Empty inbox state ───────────────────────────── */
/* Spans the full grid width so the message sits centered in the page
   rather than squeezed into one column. */
.inbox-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 1rem;
  color: var(--color-fg-muted);
}
.inbox-empty h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: .5rem;
  color: var(--color-fg);
}
.inbox-empty p {
  font-size: .95rem;
  color: var(--color-fg-muted);
}
.inbox-empty a {
  color: var(--color-fg);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ── Skeleton loading placeholders ───────────────── */
.tile-skeleton {
  border-radius: var(--radius-4xl);
  aspect-ratio: 3 / 2;
  background: linear-gradient(110deg, #e8e3db 30%, #f0ebe3 50%, #e8e3db 70%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Inbox auth fade-in ──────────────────────────── */
/*
 * Body starts invisible and fades in once requireAuth() in firebase.js
 * adds the `ready` class. Prevents an unauthenticated flash of the
 * inbox before the redirect to /login.html. The body class is kept as
 * `dashboard-body` to avoid churning every page; only the visible UI
 * was renamed Inbox.
 */
body.dashboard-body { opacity: 0; transition: opacity .15s; }
body.dashboard-body.ready { opacity: 1; }

/* ─────────────────────────────────────────────────
   Avatar paint variants
   Set by $avatar.paintAvatar() in /shared/avatar.js.
   .has-custom-avatar hides the default person ::after
   so we can render uploads / icons / initials underneath.
   ───────────────────────────────────────────────── */
.avatar-btn.has-custom-avatar::after { display: none; }

.avatar-btn.avatar--upload {
  background-repeat: no-repeat;   /* set in JS: image, cover, center */
}
.avatar-btn.avatar--icon,
.avatar-btn.avatar--initials {
  color: #fff;
  display: grid;
  place-items: center;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: .875rem;
}
.avatar-btn.avatar--icon svg { display: block; }

/* Larger avatar slot used on the profile page (and elsewhere). */
.avatar {
  border-radius: 50%;
  background: var(--color-fg);
  color: #fff;
  display: grid;
  place-items: center;
  overflow: hidden;
  font-family: var(--font-sans);
  font-weight: 600;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
}
.avatar.avatar--upload  { /* image set inline */ }
.avatar.avatar--icon svg { display: block; }
.avatar.avatar--initials {
  font-size: 2.25rem;
  letter-spacing: .02em;
}

/* ── Avatar dropdown menu (inbox header) ─────────── */
.avatar-wrap { position: relative; }
.avatar-menu {
  position: absolute; top: calc(100% + .5rem); right: 0;
  background: var(--color-surface);
  border: 1px solid #e5e5e5;
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 16px rgba(0,0,0,.08);
  min-width: 180px; z-index: 10; padding: .25rem 0;
}
.menu-item {
  display: block; width: 100%; padding: .65rem 1rem; text-align: left;
  background: none; border: none; cursor: pointer;
  font-family: inherit; font-size: .9rem; color: var(--color-fg);
  box-sizing: border-box;
}
.menu-item:hover { background: var(--color-surface-hover); }

/* Anchor variant of .menu-item (Settings). Explicit selector bump over
   the class-only rule above so visited/focus/active states from the
   user-agent stylesheet can't reintroduce the underline. */
a.menu-item,
a.menu-item:link,
a.menu-item:visited,
a.menu-item:hover,
a.menu-item:focus,
a.menu-item:active {
  text-decoration: none;
  color: var(--color-fg);
}

/* ── Dashboard mobile ────────────────────────────── */
@media (max-width: 600px) {
  .dash-header { margin-top: 1rem; }
  .dash-search { margin-top: 1.5rem; }
}

/* ─────────────────────────────────────────────────
   Flash toast (shared/toast.js → $toast.flash)
   Floating, auto-dismissing banner. One host element
   created lazily; stacks vertically. CSS-driven so the
   helper doesn't need inline styles (CSP-friendly).
   ───────────────────────────────────────────────── */
.flash-toast-host {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  pointer-events: none;
  max-width: min(420px, calc(100vw - 2.5rem));
}
.flash-toast {
  pointer-events: auto;
  padding: .65rem 1rem;
  background: var(--color-fg, #111);
  color: var(--color-bg, #fff);
  border-radius: var(--radius-lg, 8px);
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
  font-size: .9rem;
  line-height: 1.35;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity .2s ease, transform .2s ease;
}
.flash-toast.show {
  opacity: 1;
  transform: translateY(0);
}
.flash-toast.ok  { background: #1f7a3a; color: #fff; }
.flash-toast.err { background: #b3261e; color: #fff; }
@media (max-width: 600px) {
  .flash-toast-host { top: .75rem; right: .75rem; left: .75rem; max-width: none; }
}
