/* ==========================================================================
   Earth Traits Ops Dashboard — Phase 4 Design Polish (new-style.css)
   Drop-in replacement for current-style.css using locked Earth Traits tokens
   (REQUIREMENTS.md §1: #F4F3EF light / #282725 dark, #D39E40 brand orange,
   #8A5710 accessible orange text on light, pure black text on orange buttons).
   Zero external dependencies, zero CDN requests, pure vanilla CSS.
   ========================================================================== */

@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: local("Manrope"), url("/static/fonts/manrope-latin-wght-normal.woff2") format("woff2-variations");
}

:root {
  /* Typography */
  --font-sans: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;

  /* Core Palette — Light Mode (REQUIREMENTS.md §1) */
  --bg: #f4f3ef;
  --card: #ffffff;
  --surface-subtle: #faf9f6;
  --surface-muted: #efece6;
  --surface-hover: #f7f6f2;

  --fg: #1c1b19;
  --fg-strong: #000000;
  --muted: #5e5c57; /* >= 5.7:1 contrast on both #F4F3EF and #FFFFFF */

  --line: #e3e1db;
  --line-strong: #ccc8be;

  /* Brand & Interactive Accents */
  --brand: #d39e40;        /* Primary brand orange (8.73:1 with #000000 text) */
  --brand-hover: #c08b2e;
  --brand-tint: rgba(211, 158, 64, 0.14);
  --accent: #8a5710;       /* Accessible orange for links/text on light (>= 5.48:1) */
  --accent-hover: #69410a;

  /* Semantic / Status Colors (all text pairs >= 4.5:1 WCAG AA) */
  --ok-fg: #1b632d;
  --danger: #b3261e;
  --danger-hover: #961d16;

  --st-ok-bg: #e6f2e5;
  --st-ok-fg: #1e5222;
  --st-ok-border: #c5e0c3;

  --st-good-bg: #dcf0e0;
  --st-good-fg: #145a29;
  --st-good-border: #b5dfbe;

  --st-run-bg: #f8ebd2;
  --st-run-fg: #6e4e0b;
  --st-run-border: #e6cda0;

  --st-pub-bg: #eae4f7;
  --st-pub-fg: #41307e;
  --st-pub-border: #cfc4ee;

  --st-wait-bg: #efece5;
  --st-wait-fg: #54524d;
  --st-wait-border: #dad6cc;

  --st-bad-bg: #fce8e6;
  --st-bad-fg: #9e1f18;
  --st-bad-border: #f3c2be;

  --dot-ok: #2e8540;
  --dot-off: #d5d2ca;
  --dot-bad: #c5281f;

  /* Radii & Subtle Card Elevation */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-pill: 999px;
  --shadow-card: 0 1px 2px rgba(28, 27, 25, 0.04);

  color-scheme: light;
}

/* Automatic Dark Mode (matches public site prefers-color-scheme behavior) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #282725;
    --card: #1f1e1c;
    --surface-subtle: #252421;
    --surface-muted: #312f2c;
    --surface-hover: #292825;

    --fg: #f4f3ef;
    --fg-strong: #ffffff;
    --muted: #a6a39b; /* >= 5.5:1 on #1F1E1C */

    --line: #383633;
    --line-strong: #4d4a45;

    /* On #282725 / #1F1E1C, #D39E40 measures >= 6.21:1 -> safe for text & links */
    --brand: #d39e40;
    --brand-hover: #e0ae52;
    --brand-tint: rgba(211, 158, 64, 0.16);
    --accent: #d39e40;
    --accent-hover: #e6b966;

    --ok-fg: #6dd58c;
    --danger: #f28b82;
    --danger-hover: #f6aea9;

    --st-ok-bg: rgba(63, 143, 79, 0.18);
    --st-ok-fg: #8ce09a;
    --st-ok-border: rgba(140, 224, 154, 0.28);

    --st-good-bg: rgba(46, 160, 67, 0.2);
    --st-good-fg: #7ee787;
    --st-good-border: rgba(126, 231, 135, 0.3);

    --st-run-bg: rgba(211, 158, 64, 0.18);
    --st-run-fg: #f0c265;
    --st-run-border: rgba(240, 194, 101, 0.3);

    --st-pub-bg: rgba(163, 133, 235, 0.18);
    --st-pub-fg: #cbb6f8;
    --st-pub-border: rgba(203, 182, 248, 0.3);

    --st-wait-bg: rgba(255, 255, 255, 0.07);
    --st-wait-fg: #b8b5ad;
    --st-wait-border: rgba(255, 255, 255, 0.14);

    --st-bad-bg: rgba(242, 139, 130, 0.16);
    --st-bad-fg: #f6aea9;
    --st-bad-border: rgba(242, 139, 130, 0.32);

    --dot-ok: #4cc366;
    --dot-off: #4a4844;
    --dot-bad: #f28b82;

    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.22);

    color-scheme: dark;
  }
}

/* ==========================================================================
   Base Reset & Typography
   ========================================================================== */

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  font: 14.5px/1.55 var(--font-sans);
  color: var(--fg);
  background: var(--bg);
}

h1,
h2,
h3 {
  color: var(--fg-strong);
  letter-spacing: -0.015em;
  line-height: 1.25;
}

h1 {
  margin: 0 0 18px;
  font-size: 22px;
  font-weight: 750;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
}

h2 {
  margin: 28px 0 10px;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
}

h3 {
  margin: 6px 0 10px;
  font-size: 14.5px;
  font-weight: 700;
}

p {
  margin: 0 0 12px;
}

a {
  color: var(--accent);
  text-decoration: none;
  text-underline-offset: 2px;
  transition: color 120ms ease, text-decoration-color 120ms ease;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

/* ==========================================================================
   App Shell & Sidebar Navigation
   ========================================================================== */

.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  padding: 20px 14px;
  background: var(--card);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.02em;
  color: var(--fg-strong);
  padding: 2px 10px 14px;
  border-bottom: 1px solid var(--line);
  line-height: 1.3;
}

.brand::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand);
  margin-right: 7px;
  vertical-align: 1px;
}

.brand span {
  display: block;
  font-weight: 500;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 3px;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sidebar nav a,
.sidebar nav button {
  display: flex;
  align-items: center;
  width: 100%;
  text-decoration: none;
  color: var(--fg);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

.sidebar nav a:hover,
.sidebar nav button:hover {
  background: var(--surface-muted);
  color: var(--fg-strong);
  text-decoration: none;
}

.sidebar nav a.active {
  background: var(--surface-muted);
  color: var(--fg-strong);
  font-weight: 650;
  box-shadow: inset 3px 0 0 var(--brand);
}

.sidebar nav a.ghost {
  color: var(--muted);
}

.nav-bottom {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.nav-bottom form.inline {
  display: block;
  width: 100%;
}

.nav-bottom button {
  color: var(--muted);
}

.nav-bottom button:hover {
  color: var(--danger);
  background: var(--st-bad-bg);
}

.content {
  flex: 1;
  min-width: 0;
  padding: 32px 38px 56px;
  max-width: 1060px;
}

form.inline {
  display: inline;
}

/* Empty-state paragraph directly inside main.content (e.g. feedback.html) */
.content > p.muted {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 20px 22px;
  margin-top: 12px;
  box-shadow: var(--shadow-card);
}

/* ==========================================================================
   Tables & Data Grids (.grid, .kv)
   ========================================================================== */

/* Optional wrapper if MARKUP-SUGGESTIONS.md #2 is applied */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--card);
  box-shadow: var(--shadow-card);
}

.table-wrap table.grid {
  margin-top: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  display: table;
}

table.grid {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  margin-top: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}

table.grid th,
table.grid td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  line-height: 1.45;
}

/* Top-align cells on rows that contain multi-line lists (e.g. failures.html) */
table.grid tr:has(ul) td {
  vertical-align: top;
}

table.grid tr:last-child th,
table.grid tr:last-child td {
  border-bottom: 0;
}

table.grid th {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.055em;
  color: var(--muted);
  background: var(--surface-subtle);
  white-space: nowrap;
}

/* Keep date/time/stage first columns from awkward mid-date wrapping */
table.grid td:first-child {
  white-space: nowrap;
}

/* Allow paper title column (when it contains a subtitle div) to wrap naturally */
table.grid td:first-child:has(div) {
  white-space: normal;
}

@media (hover: hover) and (pointer: fine) {
  table.grid:not(.kv) tr:hover td {
    background: var(--surface-hover);
  }
}

/* Key-Value Tables (inside .statuscard or standalone) */
table.kv th {
  width: 240px;
  text-transform: none;
  letter-spacing: 0;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
}

table.kv td {
  font-size: 14px;
}

/* Nested ul inside table cells (failures.html) */
table.grid td ul {
  margin: 0;
  padding-left: 16px;
}

table.grid td ul li {
  margin: 4px 0;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

table.grid td ul li:first-child {
  margin-top: 0;
}

table.grid td ul li:last-child {
  margin-bottom: 0;
}

/* ==========================================================================
   Text & Utility Classes
   ========================================================================== */

.muted {
  color: var(--muted);
}

.h-sub {
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0;
  margin-left: 2px;
  color: var(--muted);
}

.small {
  font-size: 12px;
  line-height: 1.45;
}

td > div.muted.small {
  margin-top: 3px;
}

.big {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.oktxt {
  color: var(--ok-fg);
  font-weight: 600;
}

.badtxt {
  color: var(--danger);
  font-weight: 600;
}

.abstract {
  white-space: pre-wrap;
  line-height: 1.65;
  font-size: 14.5px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin: 10px 0 18px;
}

/* ==========================================================================
   Status Card, Badges & Pipeline Dots (Phase 2)
   ========================================================================== */

.statuscard {
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 3px solid var(--brand);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin: 10px 0 22px;
  box-shadow: var(--shadow-card);
}

/* Seamless integration when table.grid.kv is nested inside .statuscard */
.statuscard table.grid.kv {
  margin-top: 10px;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}

.statuscard table.grid.kv th,
.statuscard table.grid.kv td {
  padding: 9px 4px;
}

.statuscard table.grid.kv th {
  padding-right: 16px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2.5px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.35;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
  white-space: nowrap;
  margin-bottom: 8px;
}

/* Remove bottom margin when badge sits inline inside flex rows or table cells */
.draftrow .badge,
table.grid td .badge,
h1 .badge,
h2 .badge,
h3 .badge {
  margin-bottom: 0;
}

.st-ok {
  background: var(--st-ok-bg);
  color: var(--st-ok-fg);
  border-color: var(--st-ok-border);
}

.st-run {
  background: var(--st-run-bg);
  color: var(--st-run-fg);
  border-color: var(--st-run-border);
}

.st-good {
  background: var(--st-good-bg);
  color: var(--st-good-fg);
  border-color: var(--st-good-border);
}

.st-pub {
  background: var(--st-pub-bg);
  color: var(--st-pub-fg);
  border-color: var(--st-pub-border);
}

.st-wait {
  background: var(--st-wait-bg);
  color: var(--st-wait-fg);
  border-color: var(--st-wait-border);
}

.st-bad {
  background: var(--st-bad-bg);
  color: var(--st-bad-fg);
  border-color: var(--st-bad-border);
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  vertical-align: middle;
}

.dot-ok {
  background: var(--dot-ok);
  box-shadow: 0 0 0 2px var(--st-ok-bg);
}

.dot-off {
  background: var(--dot-off);
}

.dot-bad {
  background: var(--dot-bad);
  box-shadow: 0 0 0 2px var(--st-bad-bg);
}

/* ==========================================================================
   Issue Cards & Draft Rows (Phase 2 & Phase 3 — drafts.html, papers.html)
   ========================================================================== */

.issuecard {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin: 12px 0;
  box-shadow: var(--shadow-card);
}

.issuecard h3 {
  margin: 0 0 8px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--line);
  font-size: 14.5px;
  font-weight: 700;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
}

.issuecard > ul {
  margin: 6px 0 2px;
  padding-left: 18px;
}

.issuecard > ul > li {
  margin: 5px 0;
  line-height: 1.5;
}

.draftrow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.draftrow:first-of-type {
  padding-top: 4px;
}

.draftrow:last-child {
  border-bottom: 0;
  padding-bottom: 2px;
}

.draftrow > strong {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-strong);
}

.draftrow > .small {
  margin-right: 2px;
}

/* Optional wrapper if MARKUP-SUGGESTIONS.md #3 is applied */
.draft-actions {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 10px;
  min-height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface-subtle);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fg);
  text-decoration: none;
  line-height: 1.2;
  white-space: nowrap;
  transition: border-color 120ms ease, background-color 120ms ease, color 120ms ease;
}

.btn:hover {
  border-color: var(--brand);
  background: var(--brand-tint);
  color: var(--fg-strong);
  text-decoration: none;
}

.thumb {
  height: 52px;
  width: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface-subtle);
  object-fit: cover;
  vertical-align: middle;
}

details.fail {
  flex: 0 0 100%;
  width: 100%;
  margin-top: 2px;
  font-size: 13px;
}

details.fail summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  font-size: 12.5px;
  padding: 3px 9px;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  user-select: none;
  transition: border-color 120ms ease, background-color 120ms ease;
}

details.fail summary:hover {
  border-color: var(--brand);
  background: var(--brand-tint);
}

details.fail[open] summary {
  margin-bottom: 6px;
  border-color: var(--line-strong);
}

details.fail ul {
  margin: 4px 0 4px;
  padding: 10px 14px 10px 28px;
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  border-left: 3px solid var(--danger);
  border-radius: var(--radius-sm);
}

details.fail li {
  margin: 6px 0;
  line-height: 1.55;
  color: var(--fg);
  overflow-wrap: anywhere;
}

details.fail li:first-child {
  margin-top: 0;
}

details.fail li:last-child {
  margin-bottom: 0;
}

/* ==========================================================================
   Buttons, Forms & Auth / Login / Setup / Sessions Pages
   ========================================================================== */

button,
.login-card button[type="submit"],
.login-card button {
  font: inherit;
  font-size: 13.5px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  /* NON-NEGOTIABLE site rule: brand orange fill + pure black text (8.73:1) */
  background: var(--brand);
  color: #000000;
  border: 1px solid rgba(0, 0, 0, 0.2);
  transition: background-color 120ms ease, border-color 120ms ease;
}

button:hover,
.login-card button[type="submit"]:hover,
.login-card button:hover {
  background: var(--brand-hover);
}

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

button.danger:hover {
  background: var(--danger-hover);
}

.draftrow form.inline button {
  padding: 4px 10px;
  min-height: 28px;
  font-size: 12.5px;
  font-weight: 650;
}

.login-wrap {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 3px solid var(--brand);
  border-radius: var(--radius-lg);
  padding: 28px 26px;
  box-shadow: var(--shadow-card);
}

.login-card h1,
.login-card h2 {
  margin-top: 0;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.login-card label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fg);
}

.login-card input {
  font: inherit;
  font-size: max(16px, 1rem); /* Prevents iOS auto-zoom on focus */
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  color: var(--fg-strong);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.login-card input:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
  border-color: transparent;
  background: var(--card);
}

.login-card button,
.login-card button[type="submit"] {
  padding: 10px 14px;
  font-size: 14px;
  margin-top: 2px;
}

.codebox {
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin: 10px 0 16px;
}

.codebox label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.055em;
  margin-bottom: 5px;
}

.codebox code {
  font-family: var(--font-mono);
  font-size: 13.5px;
  color: var(--fg-strong);
  word-break: break-all;
}

.error {
  color: var(--danger);
  background: var(--st-bad-bg);
  border: 1px solid var(--st-bad-border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  margin: 8px 0;
}

/* ==========================================================================
   Responsive / Mobile Breakpoint (<= 720px)
   ========================================================================== */

@media (max-width: 720px) {
  .shell {
    flex-direction: column;
  }

  .sidebar {
    position: static;
    height: auto;
    width: 100%;
    flex: none;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 10px;
    padding: 12px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    border-bottom: 0;
    padding: 2px 4px;
    margin-right: auto;
  }

  .brand br {
    display: none;
  }

  .brand span {
    display: inline;
    margin-top: 0;
    margin-left: 6px;
  }

  .sidebar nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
    width: 100%;
    order: 3;
  }

  .sidebar nav.nav-bottom {
    width: auto;
    order: 2;
    margin-top: 0;
    margin-left: auto;
    padding-top: 0;
    border-top: 0;
  }

  .sidebar nav a,
  .sidebar nav button {
    width: auto;
    padding: 6px 10px;
    font-size: 13px;
  }

  .sidebar nav a.active {
    box-shadow: inset 0 -2px 0 var(--brand);
  }

  .nav-bottom form.inline {
    display: inline;
    width: auto;
  }

  .content {
    padding: 18px 14px 40px;
  }

  h1 {
    font-size: 19px;
    margin-bottom: 14px;
  }

  /* Horizontal scroll for data tables on narrow mobile screens (375px) */
  table.grid:not(.kv) {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table.kv th {
    width: 48%;
  }

  .issuecard {
    padding: 12px 14px;
  }

  .draftrow {
    gap: 6px 8px;
    padding: 10px 0;
  }
}
