/* ============================================================================
   ATLAS REDESIGN — Reports & Analytics screen styles  ·  Phase 2
   Branch: atlas-redesign-2026-06-29

   Prefix: .rd-reports. Tokens only (--r-*) so Calm (almanac) + Operator themes
   both work automatically. No hardcoded hex. Theme-specific selectors
   (html[data-rtheme="operator"] …) only where a token can't express the tweak.
   ========================================================================== */

.rd-reports {
  font-family: var(--r-font-body);
  color: var(--r-body);
  padding: var(--r-gutter);
  max-width: var(--r-page-max);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---- page header --------------------------------------------------------- */
.rd-rep-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.rd-rep-head-l {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.rd-rep-head-r {
  flex: none;
  padding-top: 2px;
}
.rd-rep-print {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 15px;
  border-radius: var(--r-radius-control);
  border: 1px solid var(--r-border);
  background: var(--r-surface);
  color: var(--r-body);
  font: 600 12.5px var(--r-font-body);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--r-dur) var(--r-ease),
              border-color var(--r-dur) var(--r-ease),
              transform var(--r-dur) var(--r-ease);
}
.rd-rep-print i { font-size: 15px; }
.rd-rep-print:hover { background: var(--r-well); border-color: var(--r-hairline-2); }
.rd-rep-print:active { transform: translateY(.5px); }
.rd-rep-print:focus-visible { outline: var(--r-focus); outline-offset: 2px; }
.rd-rep-eyebrow {
  font-family: var(--r-font-mono);
  font-size: var(--r-fs-eyebrow);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--r-clay);
}
.rd-rep-h1 {
  font-family: var(--r-font-display);
  font-size: var(--r-fs-h1);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -.01em;
  color: var(--r-ink);
  margin: 0;
}
.rd-rep-sub-lead {
  margin: 4px 0 0;
  font-size: var(--r-fs-body);
  line-height: 1.5;
  color: var(--r-muted);
  max-width: 640px;
}

/* ---- KPI strip (4-up, joined card) --------------------------------------- */
.rd-rep-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--r-surface);
  border: 1px solid var(--r-border);
  border-radius: var(--r-radius-card);
  box-shadow: var(--r-shadow-card);
  overflow: hidden;
}
.rd-rep-kpi {
  padding: 15px 18px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  border-right: 1px solid var(--r-hairline);
}
.rd-rep-kpi:last-child { border-right: none; }
.rd-rep-kpi-label {
  font-family: var(--r-font-mono);
  font-size: var(--r-fs-eyebrow);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--r-faint);
}
.rd-rep-kpi-value {
  font-family: var(--r-font-display);
  font-size: 25px;
  font-weight: 600;
  line-height: 1;
  color: var(--r-ink);
}
.rd-rep-kpi-foot {
  font-size: var(--r-fs-meta);
  font-weight: 600;
  color: var(--r-muted);
}
.rd-rep-kpi-foot[data-tone="good"] { color: var(--r-good); }
.rd-rep-kpi-foot[data-tone="clay"] { color: var(--r-clay-2); }

/* ---- two-column grid (production | geography) ---------------------------- */
.rd-rep-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 20px;
  align-items: start;
  min-height: 0;
}

/* shared card chrome */
.rd-rep-tile {
  background: var(--r-surface);
  border: 1px solid var(--r-border);
  border-radius: var(--r-radius-card);
  box-shadow: var(--r-shadow-card);
  padding: 20px 22px;
  transition: box-shadow var(--r-dur) var(--r-ease),
              transform var(--r-dur) var(--r-ease);
}
.rd-rep-tile:hover {
  box-shadow: var(--r-shadow-hover);
  transform: translateY(-2px);
}
.rd-rep-tile-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.rd-rep-kicker {
  display: block;
  font-family: var(--r-font-mono);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--r-faint);
  margin-bottom: 2px;
}
.rd-rep-tile-title {
  margin: 0;
  font-family: var(--r-font-display);
  font-size: var(--r-fs-h2);
  font-weight: 600;
  color: var(--r-ink);
}
.rd-rep-tile-note {
  font-size: var(--r-fs-meta);
  color: var(--r-muted);
}

/* ---- monthly GCI bar chart ----------------------------------------------- */
.rd-rep-chart {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  height: 150px;
  margin-top: 18px;
  padding-bottom: 4px;
}
.rd-rep-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  min-width: 0;
  height: 100%;
  justify-content: flex-end;
}
.rd-rep-bar {
  width: 100%;
  min-height: 4px;
  border-radius: 6px 6px 0 0;
  background: var(--r-mint-surface);
  transition: filter var(--r-dur) var(--r-ease),
              transform var(--r-dur) var(--r-ease);
}
.rd-rep-bar.is-on {
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--r-primary) 78%, var(--r-surface)),
    var(--r-primary));
}
.rd-rep-bar:hover,
.rd-rep-bar:focus-visible { filter: brightness(1.05); }
.rd-rep-bar:focus-visible { outline: var(--r-focus); outline-offset: 2px; }
.rd-rep-bar-x {
  font-family: var(--r-font-mono);
  font-size: 12px;
  color: var(--r-faint);
  white-space: nowrap;
}
/* peak marker — the tallest REAL bar in the series, derived not fabricated */
.rd-rep-bar-col[data-peak="1"] .rd-rep-bar-x { color: var(--r-primary-2); font-weight: 700; }
.rd-rep-bar-col[data-peak="1"]::before {
  content: "";
  display: block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--r-primary-2);
  margin-bottom: 3px;
}

/* ---- sub-section (attribution / brackets) -------------------------------- */
.rd-rep-sub {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--r-hairline);
}
.rd-rep-sub-label {
  font-family: var(--r-font-mono);
  font-size: 9.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--r-faint);
  margin-bottom: 10px;
}
.rd-rep-bars {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

/* one horizontal bar row — keyboard-focusable, carries the CSS tooltip below */
.rd-rep-barrow {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 6px;
}
.rd-rep-barrow:focus-visible {
  outline: var(--r-focus);
  outline-offset: 3px;
}
.rd-rep-barrow-label {
  flex: 0 0 96px;
  font-size: 12px;
  color: var(--r-body);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rd-rep-track {
  flex: 1 1 auto;
  height: 8px;
  border-radius: 5px;
  background: var(--r-well);
  overflow: hidden;
  min-width: 0;
}
.rd-rep-fill {
  height: 100%;
  border-radius: 5px;
  background: var(--r-primary);
  transition: width var(--r-dur) var(--r-ease);
}
.rd-rep-fill[data-tone="clay"] { background: var(--r-clay); }
/* honest "no value" track — faint dashed marker, no filled bar */
.rd-rep-track-empty {
  display: block;
  height: 100%;
  border-top: 1px dashed var(--r-border);
  margin-top: 3px;
  opacity: .7;
}
.rd-rep-barrow-val {
  flex: 0 0 38px;
  text-align: right;
  font-family: var(--r-font-mono);
  font-size: 12px;
  color: var(--r-muted);
}
.rd-rep-barrow-val[data-tone="clay"] { color: var(--r-clay-2); }

/* ---- top zip ranked list ------------------------------------------------- */
.rd-rep-ziplist {
  margin-top: 8px;
}
.rd-rep-zip {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 0;
  border-top: 1px solid var(--r-hairline);
}
.rd-rep-zip:first-child { border-top: none; }
.rd-rep-zip-rank {
  flex: 0 0 18px;
  font-family: var(--r-font-mono);
  font-size: 12px;
  color: var(--r-faint);
}
.rd-rep-zip-id {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.rd-rep-zip-head {
  font-size: 13px;
  font-weight: 600;
  color: var(--r-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rd-rep-zip-sub {
  font-size: 12px;
  color: var(--r-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rd-rep-zip-share {
  flex: 0 0 auto;
  font-family: var(--r-font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--r-good);
}

/* ---- honest empty state -------------------------------------------------- */
.rd-rep-empty {
  font-family: var(--r-font-mono);
  font-size: var(--r-fs-meta);
  letter-spacing: .02em;
  line-height: 1.5;
  color: var(--r-faint);
  text-align: center;
  padding: 20px 12px;
  border: 1px dashed var(--r-border);
  border-radius: var(--r-radius-control);
  margin-top: 14px;
}
.rd-rep-tile-head + .rd-rep-empty,
.rd-rep-chart + .rd-rep-sub .rd-rep-empty { margin-top: 14px; }

/* honest "couldn't load" ERROR state (safe()-caught fetch exception) — distinct
   from the plain "not connected" empty state above. var(--r-alert) family. */
.rd-rep-empty[data-tone="alert"] {
  color: var(--r-alert);
  border-color: color-mix(in srgb, var(--r-alert) 38%, var(--r-border));
}
.rd-rep-empty[data-tone="alert"] i {
  margin-right: 6px;
  color: var(--r-alert);
}

/* ---- focus visibility (keyboard) ----------------------------------------- */
.rd-reports a:focus-visible,
.rd-reports button:focus-visible,
.rd-reports [tabindex]:focus-visible {
  outline: var(--r-focus);
  outline-offset: 2px;
}

/* ---- lightweight CSS tooltip (bar chart + attribution/bracket rows) ------
   No library — a data-tip attribute + a ::after bubble. --r-ink/--r-canvas
   are inverse-contrasting in BOTH themes (dark-on-light in Calm, light-on-dark
   in Operator), so the same two tokens read correctly either way. */
.rd-reports [data-tip] { position: relative; }
.rd-reports [data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%) translateY(4px);
  background: var(--r-ink);
  color: var(--r-canvas);
  font-family: var(--r-font-mono);
  font-size: 11px;
  line-height: 1.3;
  white-space: nowrap;
  padding: 5px 9px;
  border-radius: 7px;
  box-shadow: var(--r-shadow-hover);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--r-dur) var(--r-ease), transform var(--r-dur) var(--r-ease);
  z-index: 5;
}
.rd-reports [data-tip]:hover::after,
.rd-reports [data-tip]:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.rd-rep-barrow[data-tip]::after { bottom: calc(100% + 6px); }

/* ---- entrance motion (one-shot; off under reduced motion) ---------------- */
.rd-rep-kpis, .rd-rep-tile {
  animation: rdRepIn .38s var(--r-ease) both;
}
.rd-rep-grid .rd-rep-tile:nth-child(2) { animation-delay: .05s; }
@keyframes rdRepIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .rd-rep-kpis, .rd-rep-tile { animation: none; }
  .rd-rep-tile:hover { transform: none; }
  .rd-reports [data-tip]::after { transition: none; }
}

/* ---- responsive ---------------------------------------------------------- */
@media (max-width: 980px) {
  .rd-rep-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .rd-rep-head { flex-direction: column; align-items: stretch; }
  .rd-rep-head-r { padding-top: 0; }
  .rd-rep-print { width: 100%; justify-content: center; }
  .rd-rep-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* restore right border on the 1st-of-row, drop on 2nd-of-row, add a bottom rule */
  .rd-rep-kpi { border-right: 1px solid var(--r-hairline); }
  .rd-rep-kpi:nth-child(2n) { border-right: none; }
  .rd-rep-kpi:nth-child(1),
  .rd-rep-kpi:nth-child(2) { border-bottom: 1px solid var(--r-hairline); }
  .rd-rep-barrow-label { flex-basis: 76px; }
}

/* ---- print stylesheet — clean report handout ------------------------------
   Hides the app chrome (rail / top command bar / launch banner — stable ids
   from index.html, referenced read-only) and the Print button itself, forces
   a printable light palette regardless of the active theme (Operator is dark
   on-screen but must not waste ink), and keeps each card intact across a
   page break. */
@media print {
  #rail, #statusbar, #launch-banner { display: none !important; }
  html, body, #main-content, .canvas { background: #fff !important; }
  .rd-reports {
    color: #111;
    max-width: 100%;
    padding: 0;
  }
  .rd-rep-print, .rd-rep-head-r { display: none !important; }
  .rd-rep-eyebrow, .rd-rep-kicker, .rd-rep-sub-label, .rd-rep-bar-x,
  .rd-rep-tile-note, .rd-rep-zip-sub, .rd-rep-zip-rank { color: #555 !important; }
  .rd-rep-h1, .rd-rep-tile-title, .rd-rep-kpi-value, .rd-rep-zip-head { color: #111 !important; }
  .rd-rep-kpis, .rd-rep-tile {
    background: #fff !important;
    border: 1px solid #ccc !important;
    box-shadow: none !important;
    animation: none !important;
  }
  .rd-rep-tile:hover { transform: none !important; box-shadow: none !important; }
  .rd-rep-grid { display: block; }
  .rd-rep-grid .rd-rep-tile { break-inside: avoid; page-break-inside: avoid; margin-bottom: 16px; }
  .rd-rep-bar.is-on, .rd-rep-fill {
    background: #2F5D50 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .rd-rep-fill[data-tone="clay"] { background: #B0614A !important; }
  .rd-reports [data-tip]::after { display: none; }
}
