/* ============================================================
   PlumeWatch — 16.S893 AI Agents for Engineering Research
   Kevin Gauld · Satellite-based emissions auditing
   ============================================================ */

:root {
  --bg: #f4f9fc;
  --bg-soft: #eaf3fb;
  --panel: #ffffff;
  --border: #e1ebf2;
  --text: #16232e;
  --muted: #5c7185;

  --blue: #1d7bd6;
  --blue-dark: #145a9e;
  --teal: #12b8a6;
  --orange: #f4a533;
  --green: #35b16a;
  --purple: #8b6bf0;
  --red: #ef5b5b;

  --shadow-sm: 0 2px 8px rgba(20, 50, 80, 0.06);
  --shadow-md: 0 10px 30px rgba(20, 50, 80, 0.10);
  --shadow-lg: 0 20px 50px rgba(20, 50, 80, 0.16);

  --radius: 16px;
  --radius-sm: 10px;
  --maxw: 1080px;

  --font-head: "Space Grotesk", "Segoe UI", sans-serif;
  --font-body: "Inter", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

/* The [hidden] attribute must always win over component classes like
   .btn (display: inline-flex) or .modal-backdrop (display: flex) —
   otherwise toggling `el.hidden = true` from JS silently does nothing
   because those classes have equal specificity to the UA [hidden] rule
   and come later in the sheet. */
[hidden] { display: none !important; }

/* ---------------------------- SITE PASSWORD LOCK ---------------------------- */
/* While html.pw-locked is present, hide every real page element so the
   lock screen is the only thing visible/interactive (and nothing behind
   it flashes before JS runs the check). */
html.pw-locked body > *:not(.site-lock-screen) { display: none !important; }

.site-lock-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #0b1120 0%, #101d33 100%);
  animation: fadeIn 0.2s ease;
}

.site-lock-box {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 34px 30px;
  text-align: center;
  animation: modalIn 0.28s cubic-bezier(.2,.9,.3,1.1);
}

.site-lock-icon { font-size: 34px; margin-bottom: 6px; }
.site-lock-box h1 { font-size: 1.3rem; margin-bottom: 6px; }
.site-lock-box p { margin: 0 0 18px; }

#site-lock-pass {
  width: 100%;
  padding: 11px 14px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 1rem;
  background: var(--bg-soft);
  color: var(--text);
}
#site-lock-pass:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29, 123, 214, 0.15);
}

.site-lock-error {
  color: var(--red);
  font-size: 0.88rem;
  margin: -4px 0 12px;
  text-align: left;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  overflow-x: hidden;
}

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

h1, h2, h3, h4 {
  font-family: var(--font-head);
  line-height: 1.15;
  margin: 0 0 0.5em;
}

h1 { font-size: clamp(2.1rem, 5vw, 3.2rem); }
h2 { font-size: clamp(1.5rem, 3vw, 2rem); }
h3 { font-size: 1.2rem; }

p { margin: 0 0 1em; color: var(--text); }
.muted { color: var(--muted); }

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

.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 24px;
}

/* ---------------- background canvas (stars/particulates) ---------------- */
#bg-canvas {
  position: fixed;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.55;
}

/* ---------------------------- NAVBAR ---------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(244, 249, 252, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 14px 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
}
.brand:hover { text-decoration: none; }

.brand-sat {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}

.nav-links {
  display: flex;
  gap: 6px;
  align-items: center;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-links a {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 8px 14px;
  border-radius: 999px;
  transition: all 0.2s ease;
}

.nav-links a:hover {
  background: var(--bg-soft);
  color: var(--blue-dark);
  text-decoration: none;
}

.nav-links a.active {
  background: var(--blue);
  color: white;
}

.nav-links a.secret-link {
  background: linear-gradient(135deg, var(--purple), var(--blue));
  color: #fff;
  animation: pulseGlow 2.4s ease-in-out infinite;
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(139, 107, 240, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(139, 107, 240, 0); }
}

.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
}
.nav-toggle span {
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: 0.25s;
}

@media (max-width: 720px) {
  .nav-toggle { display: flex; }
  .nav-links {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    padding: 12px;
    display: none;
    box-shadow: var(--shadow-md);
  }
  .nav-links.open { display: flex; }
  .nav-links a { display: block; width: 100%; text-align: left; }
}

/* ---------------------------- HERO ---------------------------- */
.hero {
  position: relative;
  padding: 70px 0 40px;
  overflow: hidden;
}

.hero-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 40px;
  align-items: center;
}

@media (max-width: 800px) {
  .hero-grid { grid-template-columns: 1fr; }
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--teal);
  background: rgba(18, 184, 166, 0.1);
  padding: 6px 14px;
  border-radius: 999px;
  margin-bottom: 18px;
}

.hero p.lead {
  font-size: 1.15rem;
  color: var(--muted);
  max-width: 500px;
}

.btn-row { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 26px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.btn:hover { transform: translateY(-2px); text-decoration: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--blue), var(--teal));
  color: white;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { box-shadow: var(--shadow-md); }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-ghost:hover { border-color: var(--blue); color: var(--blue-dark); }

/* --------------------- orbit / earth animation --------------------- */
.orbit-scene {
  position: relative;
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
  aspect-ratio: 1 / 1;
}

.orbit-ring {
  position: absolute;
  inset: 0;
  border: 1.5px dashed rgba(29, 123, 214, 0.35);
  border-radius: 50%;
}
.orbit-ring.r2 {
  inset: 40px;
  border-color: rgba(139, 107, 240, 0.3);
  animation: spin 40s linear infinite reverse;
}
.orbit-ring.r1 { animation: spin 55s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

.earth {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44%;
  height: 44%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #7fd6ff, #1d7bd6 55%, #145a9e 100%);
  box-shadow: 0 0 40px rgba(29, 123, 214, 0.35), inset -10px -10px 30px rgba(0,0,0,0.25);
  animation: rotateEarth 18s linear infinite;
  overflow: hidden;
}
.earth::before, .earth::after {
  content: "";
  position: absolute;
  background: rgba(53, 177, 106, 0.75);
  border-radius: 40%;
}
.earth::before { width: 55%; height: 35%; top: 15%; left: 5%; transform: rotate(15deg); }
.earth::after { width: 40%; height: 30%; bottom: 8%; right: 0%; transform: rotate(-10deg); }

@keyframes rotateEarth { to { background-position: 100px 0; } }

.orbiter {
  position: absolute;
  inset: 0;
  animation: spin 14s linear infinite;
}
.orbiter .sat {
  position: absolute;
  top: -4px;
  left: 50%;
  transform: translateX(-50%);
  animation: spin 14s linear infinite reverse;
}

.orbiter2 {
  position: absolute;
  inset: 40px;
  animation: spin 22s linear infinite reverse;
}
.orbiter2 .sat {
  position: absolute;
  top: -4px;
  left: 50%;
  transform: translateX(-50%) scale(0.75);
  animation: spin 22s linear infinite;
}

/* --------------------- smokestacks / plumes --------------------- */
.stack-row {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 28px;
  margin-top: 10px;
  height: 160px;
  position: relative;
}

.stack {
  position: relative;
  width: 20px;
  height: 70px;
  background: linear-gradient(180deg, #93a4b3, #5c7185);
  border-radius: 3px 3px 0 0;
}
.stack.tall { height: 95px; }
.stack.short { height: 50px; }

.stack .particle {
  position: absolute;
  left: 50%;
  bottom: 100%;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  opacity: 0;
  transform: translate(-50%, 0) scale(0.6);
  animation: rise 4.5s ease-in infinite;
}
.stack.c-orange .particle { background: radial-gradient(circle, rgba(244,165,51,0.9), rgba(244,165,51,0)); }
.stack.c-red .particle { background: radial-gradient(circle, rgba(239,91,91,0.85), rgba(239,91,91,0)); }
.stack.c-gray .particle { background: radial-gradient(circle, rgba(140,150,160,0.8), rgba(140,150,160,0)); }
.stack.c-purple .particle { background: radial-gradient(circle, rgba(139,107,240,0.85), rgba(139,107,240,0)); }

.stack .particle:nth-child(1) { animation-delay: 0s; }
.stack .particle:nth-child(2) { animation-delay: 1.1s; left: 40%; }
.stack .particle:nth-child(3) { animation-delay: 2.2s; left: 60%; }
.stack .particle:nth-child(4) { animation-delay: 3.3s; left: 45%; }

@keyframes rise {
  0% { opacity: 0; transform: translate(-50%, 0) scale(0.5); }
  15% { opacity: 0.85; }
  100% { opacity: 0; transform: translate(calc(-50% + 24px), -140px) scale(1.8); }
}

/* ---------------------------- SECTIONS ---------------------------- */
section { padding: 60px 0; }
section.alt { background: var(--bg-soft); }

.section-head { text-align: center; max-width: 640px; margin: 0 auto 40px; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 20px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }

.card .icon-badge {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
  font-size: 1.4rem;
}

.badge-blue { background: rgba(29,123,214,0.12); color: var(--blue); }
.badge-teal { background: rgba(18,184,166,0.12); color: var(--teal); }
.badge-orange { background: rgba(244,165,51,0.15); color: var(--orange); }
.badge-green { background: rgba(53,177,106,0.12); color: var(--green); }
.badge-purple { background: rgba(139,107,240,0.12); color: var(--purple); }
.badge-red { background: rgba(239,91,91,0.12); color: var(--red); }

/* -------- reveal-on-scroll -------- */
.reveal {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}
.reveal.in-view { opacity: 1; transform: translateY(0); }

.reveal-stagger > * { transition-delay: calc(var(--i, 0) * 90ms); }

/* ---------------------------- TABLE ---------------------------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: 14px 16px; border-bottom: 1px solid var(--border); font-size: 0.95rem; }
th { background: var(--bg-soft); font-family: var(--font-head); }
tr:last-child td { border-bottom: none; }

.tag {
  display: inline-block;
  padding: 3px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  border-radius: 999px;
  margin: 2px;
}

/* ---------------------------- TIMELINE ---------------------------- */
.timeline {
  position: relative;
  margin: 0;
  padding: 0;
  list-style: none;
  border-left: 3px solid var(--border);
}

.timeline li {
  position: relative;
  padding: 4px 0 34px 32px;
}

.timeline li::before {
  content: attr(data-n);
  position: absolute;
  left: -21px;
  top: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--blue);
  color: white;
  font-family: var(--font-head);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 4px var(--bg);
}

.timeline li:nth-child(2)::before { background: var(--teal); }
.timeline li:nth-child(3)::before { background: var(--orange); }
.timeline li:nth-child(4)::before { background: var(--purple); }
.timeline li:nth-child(5)::before { background: var(--green); }

/* ---------------------------- FOOTER ---------------------------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 36px 0 60px;
  margin-top: 20px;
  color: var(--muted);
  font-size: 0.9rem;
  position: relative;
}

.footer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.hidden-sat {
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0.35;
  width: 30px;
  height: 30px;
  transition: opacity 0.3s, transform 0.3s;
}
.hidden-sat:hover { opacity: 0.9; transform: scale(1.15) rotate(15deg); }

/* ---------------------------- TOAST ---------------------------- */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  max-width: 320px;
  background: linear-gradient(135deg, var(--purple), var(--blue));
  color: white;
  padding: 16px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  transform: translateY(140%);
  transition: transform 0.45s cubic-bezier(.2,.9,.3,1.2);
  z-index: 1000;
  font-size: 0.92rem;
}
#toast.show { transform: translateY(0); }
#toast a { color: white; font-weight: 700; text-decoration: underline; }

/* ---------------------------- MISC ---------------------------- */
.pill-list { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px;
}
@media (max-width: 720px) { .two-col { grid-template-columns: 1fr; } }

.avatar-frame {
  width: 220px;
  height: 220px;
  border-radius: 50%;
  margin: 0 auto 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 35% 30%, #eaf3fb, #d7e8f7);
  border: 4px solid white;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  position: relative;
}

.avatar-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px rgba(29, 123, 214, 0.15);
  pointer-events: none;
}

.avatar-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 25%;
  transition: transform 0.4s ease;
}

.avatar-frame:hover .avatar-photo {
  transform: scale(1.06);
}

.quote-block {
  border-left: 4px solid var(--teal);
  padding: 10px 20px;
  background: var(--bg-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-style: italic;
  color: var(--muted);
}

/* ---------------------------- DEV LOG ---------------------------- */
.log-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 26px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.log-count {
  font-family: var(--font-head);
  font-weight: 500;
  color: var(--muted);
  font-size: 0.92rem;
}

.btn-sm { padding: 9px 16px; font-size: 0.88rem; }

.log-feed { display: flex; flex-direction: column; gap: 22px; }

.log-empty {
  text-align: center;
  color: var(--muted);
  padding: 50px 20px;
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.log-entry.reveal { transition-delay: calc(var(--i, 0) * 70ms); }

.log-entry {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 20px;
  align-items: start;
}

/* date chip */
.log-date time {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 6px 10px;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 90px;
}

.log-date .log-day {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.55rem;
  line-height: 1;
  color: var(--blue-dark);
}
.log-date .log-mon {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--teal);
  margin-top: 3px;
}
.log-date .log-yr {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
  margin-top: 1px;
}

.log-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  border-radius: var(--radius);
  padding: 22px 24px 18px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.log-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }

.log-entry:nth-child(4n+2) .log-card { border-left-color: var(--teal); }
.log-entry:nth-child(4n+3) .log-card { border-left-color: var(--orange); }
.log-entry:nth-child(4n+4) .log-card { border-left-color: var(--purple); }

.log-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.log-card-head h3 { margin: 0; }

.log-stamp {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin: 4px 0 12px;
}

.log-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; }

.tag-blue   { background: rgba(29,123,214,0.12);  color: var(--blue-dark); }
.tag-teal   { background: rgba(18,184,166,0.14);  color: #0c8478; }
.tag-orange { background: rgba(244,165,51,0.18);  color: #9a6510; }
.tag-green  { background: rgba(53,177,106,0.14);  color: #1d7f47; }
.tag-purple { background: rgba(139,107,240,0.14); color: #5d41c0; }
.tag-red    { background: rgba(239,91,91,0.14);   color: #bd3535; }

.log-card p:last-of-type { margin-bottom: 0; }

.log-del {
  background: none;
  border: none;
  padding: 0;
  margin-top: 12px;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--red);
  cursor: pointer;
  opacity: 0.7;
}
.log-del:hover { opacity: 1; text-decoration: underline; }

@media (max-width: 640px) {
  .log-entry { grid-template-columns: 1fr; gap: 10px; }
  .log-date time {
    position: static;
    flex-direction: row;
    gap: 7px;
    align-items: baseline;
    width: fit-content;
    padding: 7px 14px;
  }
  .log-date .log-day { font-size: 1.15rem; }
  .log-date .log-mon, .log-date .log-yr { margin-top: 0; }
}

/* ---------------------------- MODAL / COMPOSER ---------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(11, 17, 32, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
  animation: fadeIn 0.2s ease;
}
.modal-backdrop[hidden] { display: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  position: relative;
  width: 100%;
  max-width: 560px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 30px 30px 26px;
  margin: auto;
  animation: modalIn 0.28s cubic-bezier(.2,.9,.3,1.1);
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(18px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

.modal.shake { animation: shake 0.4s ease; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-9px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  font-size: 1.7rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 8px;
}
.modal-close:hover { background: var(--bg-soft); color: var(--text); }

.field { display: block; margin-bottom: 15px; }
.field > span {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.field > span em { text-transform: none; letter-spacing: 0; font-weight: 500; }

.field input, .field textarea {
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field textarea { resize: vertical; line-height: 1.6; }
.field input:focus, .field textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29, 123, 214, 0.15);
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 520px) { .field-row { grid-template-columns: 1fr; gap: 0; } }

.form-error {
  color: var(--red);
  font-size: 0.86rem;
  font-weight: 600;
  margin: -6px 0 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 6px;
}

code {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 0.88em;
}

/* ============================================================
   DASHBOARD (dashboard.html)
   ============================================================ */

/* ---- run status strip ---- */
.status-strip {
  display: grid;
  grid-template-columns: 1.3fr 1.5fr auto;
  gap: 20px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 5px solid var(--green);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
}
.status-strip.status-warn  { border-left-color: var(--orange); }
.status-strip.status-bad,
.status-strip.status-error { border-left-color: var(--red); }
.status-loading { color: var(--muted); }
@media (max-width: 900px) {
  .status-strip { grid-template-columns: 1fr; gap: 12px; }
}

.status-main { display: flex; align-items: center; gap: 12px; }
.status-dot {
  width: 11px; height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 4px rgba(53, 177, 106, 0.16);
}
.status-title {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.02rem;
}
.status-cadence { font-weight: 500; color: var(--muted); font-size: 0.86rem; }
.status-sub { font-size: 0.86rem; color: var(--muted); }

.status-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 18px;
  font-size: 0.82rem;
}
.status-meta > div { display: flex; gap: 7px; align-items: baseline; }
.status-k {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  min-width: 74px;
}
.status-meta code { font-size: 0.74rem; background: var(--bg-soft); }

.status-runs { font-size: 0.84rem; }
.status-runs summary {
  cursor: pointer;
  color: var(--blue-dark);
  font-weight: 600;
  white-space: nowrap;
}
.status-runs ul { list-style: none; margin: 10px 0 0; padding: 0; }
.status-runs li {
  display: flex; gap: 8px; align-items: baseline;
  padding: 3px 0; font-size: 0.8rem;
}
.run-state {
  font-weight: 700; font-size: 0.68rem;
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 2px 7px; border-radius: 4px;
}
.run-ok       { background: rgba(53,177,106,.14); color: #1d7f47; }
.run-degraded { background: rgba(244,165,51,.18); color: #9a6510; }
.run-failed   { background: rgba(239,91,91,.14);  color: #bd3535; }

/* ---- KPI row ---- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
}
.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.kpi-v {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.9rem;
  line-height: 1.05;
  color: var(--blue-dark);
}
.kpi-red .kpi-v   { color: var(--red); }
.kpi-green .kpi-v { color: var(--green); }
.kpi-u { font-size: 0.82rem; font-weight: 500; color: var(--muted); margin-left: 5px; }
.kpi-l {
  font-weight: 600; font-size: 0.86rem;
  margin-top: 4px;
}
.kpi-s { font-size: 0.76rem; margin-top: 3px; line-height: 1.4; }

/* ---- generic panel ---- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px 24px;
  box-shadow: var(--shadow-sm);
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.panel-head h2 { font-size: 1.22rem; margin: 0 0 3px; }
.panel-sub { font-size: 0.86rem; margin: 0; max-width: 620px; }

/* ---- map ---- */
.map-shell { position: relative; }
#map-canvas {
  display: block;
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.map-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.8rem; }
.lg-item { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.lg-dot { width: 9px; height: 9px; border-radius: 50%; }

.map-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(22, 35, 46, 0.95);
  color: #fff;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  line-height: 1.45;
  max-width: 230px;
  box-shadow: var(--shadow-md);
  z-index: 20;
}
.map-tooltip .muted { color: #a9bccd; }
.map-tooltip .tip-q {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 500;
  margin-top: 3px;
}
.map-tooltip .tip-status { font-weight: 700; font-size: 0.74rem; margin-top: 2px; }

/* ---- data table ---- */
.data-table { font-size: 0.88rem; }
.data-table th {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.data-table th .unit {
  display: block;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  font-size: 0.7rem;
  opacity: 0.8;
}
.data-table th:hover { color: var(--blue-dark); }
.data-table th.sorted { color: var(--blue-dark); }
.data-table th.sorted::after {
  content: "";
  display: inline-block;
  margin-left: 5px;
  border: 4px solid transparent;
}
.data-table th.sorted[data-dir="asc"]::after  { border-bottom-color: var(--blue-dark); }
.data-table th.sorted[data-dir="desc"]::after { border-top-color: var(--blue-dark); }
.data-table td, .data-table th { padding: 11px 14px; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tbody tr { cursor: pointer; transition: background 0.15s; }
.data-table tbody tr:hover { background: var(--bg-soft); }
.data-table tbody tr.row-sel { background: rgba(29,123,214,.08); }
.data-table.compact td, .data-table.compact th { padding: 8px 12px; font-size: 0.83rem; }
.cell-warn { color: #bd3535; font-weight: 600; }

.row-link {
  background: none; border: none; padding: 0;
  font: inherit; font-weight: 600;
  color: var(--blue-dark); cursor: pointer; text-align: left;
}
.row-link:hover { text-decoration: underline; }
.row-sub { font-size: 0.75rem; margin-top: 1px; }
.pm { color: var(--muted); font-size: 0.82rem; }
.ratio { color: var(--muted); font-size: 0.78rem; margin-left: 5px; }

.sector-chip {
  display: inline-block;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.st {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}
.st-reported  { background: rgba(29,123,214,.12);  color: var(--blue-dark); }
.st-below     { background: rgba(92,113,133,.13);  color: var(--muted); }
.st-withheld  { background: rgba(244,165,51,.18);  color: #9a6510; }

.ex { font-size: 0.74rem; font-weight: 700; }
.ex-over   { color: #bd3535; }
.ex-likely { color: #9a6510; }
.ex-within { color: #1d7f47; }
.ex-none   { color: var(--muted); font-weight: 500; }

.conf-bar {
  display: inline-block;
  width: 54px; height: 6px;
  background: var(--bg-soft);
  border-radius: 3px;
  overflow: hidden;
  vertical-align: middle;
}
.conf-bar > span {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--orange), var(--teal));
}

.table-controls { display: flex; gap: 14px; align-items: center; }
.chk {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 0.84rem; color: var(--muted);
  font-weight: 600; cursor: pointer;
}
.table-foot { font-size: 0.78rem; margin: 12px 0 0; }

.facility-select {
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  max-width: 280px;
}

/* ---- detail figures ---- */
.detail-body { margin-top: 4px; }
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
  margin-bottom: 22px;
}
.detail-grid > .fig-wide { grid-column: 1 / -1; }
@media (max-width: 860px) {
  .detail-grid { grid-template-columns: 1fr; }
}

.fig { margin: 0; }
.fig figcaption {
  font-size: 0.86rem;
  margin-bottom: 9px;
  line-height: 1.45;
}
.fig figcaption strong { display: block; font-family: var(--font-head); }
.fig figcaption .muted { font-size: 0.78rem; }
.fig canvas {
  display: block;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.colorbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.cb-ramp {
  flex: 1;
  height: 9px;
  border-radius: 3px;
  border: 1px solid var(--border);
}
.cb-unit { flex-basis: 100%; text-align: center; }

/* ---- meta cards ---- */
.detail-meta { align-items: start; }
.meta-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  margin-bottom: 22px;
}
.meta-card h4 {
  font-family: var(--font-head);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0 0 12px;
}
.detail-meta .meta-card { margin-bottom: 0; }

.kv { margin: 0; font-size: 0.84rem; }
.kv-row {
  display: grid;
  grid-template-columns: 0.95fr 1.05fr;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid rgba(225,235,242,.7);
}
.kv-row:last-child { border-bottom: none; }
.kv dt { color: var(--muted); }
.kv dd {
  margin: 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}
.kv dd code { font-size: 0.78rem; }

/* ---- uncertainty budget bars ---- */
.budget { font-size: 0.82rem; }
.budget-row {
  display: grid;
  grid-template-columns: 1fr 76px 46px;
  gap: 10px;
  align-items: center;
  padding: 4px 0;
}
.budget-k { color: var(--muted); }
.budget-bar {
  height: 7px;
  background: var(--bg-soft);
  border-radius: 4px;
  overflow: hidden;
}
.budget-bar > span {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--purple));
}
.budget-v { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.budget-note { font-size: 0.78rem; margin: 10px 0 0; line-height: 1.5; }

/* ---- QC flags ---- */
.flag-list { list-style: none; margin: 0; padding: 0; }
.flag {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 8px 11px;
  border-radius: 7px;
  margin-bottom: 6px;
  font-size: 0.83rem;
  line-height: 1.5;
  border-left: 3px solid transparent;
}
.flag code {
  flex-shrink: 0;
  font-size: 0.72rem;
  border: none;
  background: rgba(255,255,255,.7);
}
.flag-error   { background: rgba(239,91,91,.09);  border-left-color: var(--red); }
.flag-warning { background: rgba(244,165,51,.11); border-left-color: var(--orange); }
.flag-info    { background: rgba(29,123,214,.08); border-left-color: var(--blue); }
.flag-clean   { background: rgba(53,177,106,.09); border-left-color: var(--green);
                color: #1d7f47; font-weight: 600; }

/* ---- validation stats ---- */
.stat-list { display: grid; gap: 12px; }
.stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 15px;
}
.stat-k {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 700;
}
.stat-v {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.32rem;
  color: var(--blue-dark);
  line-height: 1.2;
}
.stat-s { font-size: 0.76rem; line-height: 1.45; }

.callout {
  margin-top: 20px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-left: 4px solid var(--teal);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 15px 18px;
}
.callout h4 {
  font-family: var(--font-head);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0 0 9px;
}
.callout p { font-size: 0.85rem; margin: 0 0 8px; line-height: 1.6; }
.callout p:last-child { margin-bottom: 0; }

/* ---- pipeline stages ---- */
.stage-list { list-style: none; margin: 0; padding: 0; font-size: 0.83rem; }
.stage {
  display: grid;
  grid-template-columns: 74px 58px 1fr;
  gap: 10px;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px solid rgba(225,235,242,.7);
}
.stage:last-child { border-bottom: none; }
.stage-name {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 500;
  color: var(--blue-dark);
}
.stage-ok .stage-name::before { content: "✓ "; color: var(--green); }
.stage-time { font-variant-numeric: tabular-nums; color: var(--muted); }
.stage-detail { font-size: 0.78rem; }

/* ---- methods section ---- */
.method-steps { margin-top: 30px; }
.chain {
  margin: 0;
  padding-left: 22px;
  font-size: 0.88rem;
  line-height: 1.75;
  color: var(--muted);
}
.chain li { margin-bottom: 4px; }
.chain code { font-size: 0.82rem; }
.caveat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
  margin-top: 30px;
}
.caveat-grid .card p { font-size: 0.84rem; margin-bottom: 0; }
.caveat-grid .card h3 { font-size: 1.02rem; }
