/* main.css — Global variables + base. Aletheia brand (dark-first). */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap');

:root {
  --bg-primary: #0B0F1A;        /* Aletheia dark */
  --bg-secondary: #141a28;
  --bg-card: #161d2c;
  --accent: #7B2DFF;            /* Aletheia primary */
  --accent-hover: #9a5cff;
  --teal: #00E6C7;              /* tagline / highlights */
  --text-primary: #e8eaed;
  --text-muted: #9aa0ac;
  --border: #2a2f3a;

  --green: #2ecc71;
  --yellow: #f1c40f;
  --red: #e74c3c;
  --grey: #7f8c8d;
  /* Aletheia palette (available for brand accents; semantic status colors above unchanged) */
  --brand-pink: #FF4DDB;
  --brand-orange: #FF9A3C;
  --brand-lime: #A8FF5C;
  --brand-blue: #208BFF;

  --radius: 10px;
  --gap: 16px;
}

/* Light theme (toggled via top nav; persisted in localStorage). Same accents, inverted surfaces. */
:root[data-theme="light"] {
  --bg-primary: #f5f6f8;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --accent: #7B2DFF;
  --accent-hover: #6322d6;
  --text-primary: #1a1d23;
  --text-muted: #5c6470;
  --border: #d8dce3;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
.muted { color: var(--text-muted); }
h1, h2, h3 { font-weight: 600; }

/* Layout: sidebar + main */
.layout { display: flex; min-height: 100vh; }
#nav {
  width: 220px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
}
.nav-brand { font-weight: 700; font-size: 16px; padding: 0 8px 16px; }
/* Aletheia brand lockup (sidebar header + login). Logo mark wrapped in #aletheia-logo-mark for swap. */
.aletheia-brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px 16px; }
.aletheia-brand svg { display: block; }
.aletheia-name { font-family: 'Poppins', sans-serif; font-weight: 600; font-size: 20px; color: #fff; line-height: 1.05; }
.aletheia-tag { font-family: 'Poppins', sans-serif; font-weight: 400; font-size: 8px; color: var(--teal); letter-spacing: 2px; margin-top: 2px; }
.aletheia-login { text-align: center; }
.aletheia-login .aletheia-brand { flex-direction: column; gap: 12px; padding-bottom: 8px; }
.aletheia-login .aletheia-name { font-size: 30px; }
.aletheia-login .aletheia-tag { font-size: 11px; letter-spacing: 3px; }
.nav-links { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-link {
  padding: 9px 12px; border-radius: 8px; color: var(--text-muted);
}
.nav-link:hover { background: var(--bg-card); color: var(--text-primary); }
.nav-link.active { background: var(--accent); color: #fff; }
.nav-logout {
  background: transparent; border: 1px solid var(--border); color: var(--text-muted);
  padding: 8px; border-radius: 8px; cursor: pointer; margin-top: 12px;
}
.nav-logout:hover { color: var(--text-primary); border-color: var(--text-muted); }

main { flex: 1; padding: 28px 32px; max-width: 1200px; }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: var(--gap);
}
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--gap); }

/* Forms */
label { display: block; margin: 12px 0 4px; color: var(--text-muted); font-size: 13px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; background: var(--bg-primary);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text-primary);
  font-size: 14px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

/* Buttons */
.btn {
  display: inline-block; background: var(--accent); color: #fff; border: none;
  padding: 9px 16px; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 500;
}
.btn:hover { background: var(--accent-hover); color: #fff; }
.btn-secondary { background: transparent; border: 1px solid var(--border); color: var(--text-primary); }
.btn-secondary:hover { border-color: var(--accent); }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: var(--bg-secondary); }
.highlight-green { color: var(--green); font-weight: 600; }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.badge-green { background: rgba(46,204,113,.15); color: var(--green); }
.badge-yellow { background: rgba(241,196,15,.15); color: var(--yellow); }
.badge-red { background: rgba(231,76,60,.15); color: var(--red); }
.badge-orange { background: rgba(230,126,34,.16); color: #e67e22; }
.badge-grey { background: rgba(127,140,141,.15); color: var(--grey); }
.badge-blue { background: rgba(123,45,255,.15); color: var(--accent); }

/* Pills (editable taxonomy) */
.pill { display: inline-flex; align-items: center; gap: 6px; background: var(--bg-secondary);
  border: 1px solid var(--border); padding: 4px 10px; border-radius: 999px; margin: 3px; }

/* Login centered */
.auth-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-card { width: 340px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab { padding: 9px 16px; cursor: pointer; color: var(--text-muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--text-primary); border-bottom-color: var(--accent); }

.metric { font-size: 32px; font-weight: 700; }
.metric-label { color: var(--text-muted); font-size: 13px; }
.build-tag { position: fixed; bottom: 6px; right: 10px; font-size: 11px; color: var(--text-muted); opacity: .5; }

/* ---------- Inspections list view (tenant + admin) ---------- */
.insp-stats { display: flex; gap: 28px; flex-wrap: wrap; margin: 14px 0; }
.insp-stats-admin { padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 14px; }
.insp-stat { display: flex; flex-direction: column; }
.insp-stat-n { font-size: 22px; font-weight: 700; line-height: 1.1; }
.insp-stat-n.green { color: var(--green); }
.insp-stat-n.yellow { color: var(--yellow); }
.insp-stat-n.red { color: var(--red); }
.insp-stat-l { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.insp-toolbar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.insp-filters { display: flex; gap: 8px; flex-wrap: wrap; }
.insp-actions { display: flex; gap: 8px; }
.insp-table { width: 100%; }
.insp-table th, .insp-table td { white-space: nowrap; }
.insp-row { cursor: pointer; }
.insp-row:hover { background: var(--bg-secondary); }

/* Safari renders SVG-wrapped raster logos poorly; we now serve real PNGs (extracted from */
/* the Illustrator SVGs) and give Safari a GPU layer + contrast hint for the downscaled mark. */
img.splash-icon, img.aletheia-mark {
  image-rendering: -webkit-optimize-contrast;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

/* --- Brand splash intro (login pages: app/index.html, admin/index.html) --- */
/* OPACITY ONLY — no transform/scale/size animation, so nothing can pixelate a raster asset. */
/* Gated once-per-session by an inline <head> script that sets .splash-active / .splash-seen on <html>. */
/* Sequence: icon fades in (0s) → wordmark (1.6s) → tagline (3.2s) → overlay fades out (4.2s) → content at 5s. */
#brand-splash {
  position: fixed; inset: 0; z-index: 10000;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px;
  background: var(--bg-primary);
  animation: splashOut 0.8s ease 4.2s forwards;   /* collective fade-out reveals content at ~5s */
}
#brand-splash .bs-icon { width: 96px; height: 96px; object-fit: contain; opacity: 0; animation: splashIn 0.8s ease 0s forwards; }
#brand-splash .bs-word { opacity: 0; animation: splashIn 0.8s ease 1.6s forwards; }
#brand-splash .bs-tag  { opacity: 0; animation: splashIn 0.8s ease 3.2s forwards; }
@keyframes splashIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes splashOut { to { opacity: 0; visibility: hidden; } }
/* Page content stays hidden until the splash hands off at 5s (visibility only — no motion). */
.splash-active .auth-wrap { visibility: hidden; animation: splashReveal 0s linear 5s forwards; }
@keyframes splashReveal { to { visibility: visible; } }
/* Already seen this session: skip the splash, content shows immediately. */
.splash-seen #brand-splash { display: none; }
/* Accessibility: honour reduced-motion by skipping the splash entirely. */
@media (prefers-reduced-motion: reduce) {
  #brand-splash { display: none; }
  .splash-active .auth-wrap { visibility: visible; animation: none; }
}

/* ============================================================================
   RESPONSIVE LAYERS — Galaxy Z Fold 7 (folded phone + unfolded near-square) and
   small screens generally. Desktop-first: the rules above are untouched between
   1024px and 1600px, so a 1280px laptop renders EXACTLY as before. These layers
   only add behaviour below 1024px and above 1600px.
   Breakpoints: ≤768 folded phone · 768–1024 transition · ≥1600 unfolded/full-width.
   ============================================================================ */

/* FIX 6 — Foldable safe-area insets. env() resolves to 0 on devices without a
   cutout (all desktops), so this is a no-op on desktop; on the Fold it keeps
   content clear of the hinge/camera. Fixed-position UI (toolbar, panels) is
   viewport-anchored and unaffected by body padding. */
body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* FIX 5 — Opt-in wrapper so a wide table scrolls inside its container instead of
   widening the page. Global (no existing elements use it → zero desktop impact);
   the automatic `main table` override is scoped to ≤1024px below. */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* FIX 4 — Unfolded near-square tablet uses the full width instead of a 1200px
   column floating in space. Laptops (<1600px) keep the existing 1200px cap. */
@media (min-width: 1600px) {
  main { max-width: none; padding: 28px 48px; }
}

/* FIX 3 — Sidebar (#nav, filled by renderNav/renderAdminNav) collapses to a
   horizontal, scrollable nav strip on tablet/folded widths. Desktop (>1024px)
   keeps the 220px vertical rail untouched.
   FIX 5 (cont.) — wide tables scroll horizontally rather than overflow the page. */
@media (max-width: 1024px) {
  .layout { flex-direction: column; }
  #nav {
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: sticky;
    top: 0;
    z-index: 50;
    padding: max(env(safe-area-inset-top), 8px) 12px 8px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  #nav .aletheia-brand { flex: 0 0 auto; padding: 0 6px 0 0; }
  #nav .nav-links { flex-direction: row; gap: 4px; flex: 1 1 auto; }
  #nav .nav-link { flex: 0 0 auto; white-space: nowrap; }
  #nav .nav-logout { flex: 0 0 auto; margin-top: 0; }
  main { padding: 16px; }
  main table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* FIX 7 + FIX 8 — Folded phone: full-width AI toolbar and full-width detail
   panels. #ai-toolbar-wrap and .pd-panel are inline-styled, so !important is
   required to override them at this breakpoint. */
@media (max-width: 768px) {
  #ai-toolbar-wrap {
    left: 12px !important;
    right: 12px !important;
    width: auto !important;
    max-width: none !important;
    transform: none !important;
  }
  .slide-panel,
  .atm-panel,
  .task-panel,
  .pd-panel {
    width: 100vw !important;
    max-width: 100vw !important;
  }
}
