/* ==========================================================================
   MetricMech Admin — analytics dashboard
   Built on the tokens in styles.css. Prefix: .ad-

   Chart palette (validated with the dataviz six-checks against a white
   surface — do not substitute by eye):
     slot 1  #2554BA  blueprint  — pageviews / magnitude bars
     slot 2  #D97706  amber-600  — calculator runs
   Worst adjacent CVD pair ΔE 30.2 (protan), normal-vision 37.1, both
   ≥ 3:1 on white. #F59E0B was rejected at 2.15:1.
   ========================================================================== */

:root {
  --c1: #2554BA;   /* series 1 */
  --c2: #D97706;   /* series 2 */
  --c1-soft: rgba(37, 84, 186, 0.12);
  --grid: #E8EDF4;
}

.ad-wrap { max-width: 1240px; margin: 0 auto; padding: 0 24px 80px; }

/* ------------------------------------------------------------------ head */
.ad-head { padding: 28px 0 18px; border-bottom: 1px solid var(--rule); margin-bottom: 22px; }
.ad-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.ad-head h1 { font-family: var(--display); font-size: clamp(26px, 3.4vw, 34px); font-weight: 700;
  letter-spacing: -0.024em; line-height: 1.08; }
.ad-head h1 em { font-style: normal; color: var(--blueprint); }
.ad-eyebrow { font-family: var(--mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.14em; color: var(--blueprint); font-weight: 700; margin-bottom: 7px; }
.ad-sub { color: var(--mute); font-size: 13.5px; margin-top: 6px; }

/* --------------------------------------------------------------- controls */
.ad-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 24px; }
.ad-seg { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: var(--rad); overflow: hidden; }
.ad-seg button { background: var(--paper); border: 0; border-right: 1px solid var(--rule);
  padding: 9px 15px; font-family: var(--mono); font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.08em; font-weight: 600; color: var(--mute); cursor: pointer; transition: all 0.14s; }
.ad-seg button:last-child { border-right: 0; }
.ad-seg button:hover { background: var(--paper-2); color: var(--ink); }
.ad-seg button.on { background: var(--ink); color: #fff; }
.ad-btn { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; font-weight: 600;
  padding: 9px 15px; border: 1px solid var(--rule-strong); border-radius: var(--rad);
  background: var(--paper); color: var(--ink); cursor: pointer; text-decoration: none; }
.ad-btn:hover { border-color: var(--ink); text-decoration: none; }
.ad-stamp { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--mute); }

/* ------------------------------------------------------------- stat tiles */
.ad-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 26px; }
@media (max-width: 900px) { .ad-kpis { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .ad-kpis { grid-template-columns: 1fr; } }

.ad-tile { background: var(--paper-2); border: 1px solid var(--rule); border-radius: var(--rad-lg); padding: 18px 20px; }
.ad-tile-label { font-family: var(--mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.12em; color: var(--mute); font-weight: 700; margin-bottom: 8px; }
.ad-tile-value { font-family: var(--display); font-size: 34px; font-weight: 700;
  letter-spacing: -0.03em; line-height: 1; color: var(--ink); }
.ad-tile-foot { margin-top: 10px; display: flex; align-items: center; gap: 6px; font-size: 12.5px; }

/* Deltas carry an arrow glyph and the word, so direction never rests on hue alone. */
.ad-delta { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; }
.ad-delta.up   { color: #15803D; }
.ad-delta.down { color: #B91C1C; }
.ad-delta.flat { color: var(--mute); }
.ad-delta-note { color: var(--mute); }

/* ----------------------------------------------------------------- panels */
.ad-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
@media (max-width: 940px) { .ad-grid { grid-template-columns: 1fr; } }
.ad-grid.full { grid-template-columns: 1fr; }

/* min-width:0 is required: a grid item defaults to min-width:auto, which makes
   it grow to its widest content (the pages table) instead of letting the
   .ad-tablewrap scroll inside it. Without this the whole page scrolls sideways
   on a phone. */
.ad-grid > * { min-width: 0; }
.ad-panel { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--rad-lg);
  padding: 20px 22px; min-width: 0; }
.ad-panel-head { display: flex; align-items: baseline; justify-content: space-between;
  gap: 14px; margin-bottom: 4px; }
.ad-panel h2 { font-family: var(--display); font-size: 17px; font-weight: 600; letter-spacing: -0.012em; }
.ad-panel-note { font-size: 12.5px; color: var(--mute); margin-bottom: 16px; line-height: 1.5; }

/* ------------------------------------------------------------------ chart */
.ad-chart { width: 100%; overflow-x: auto; }
.ad-chart svg { display: block; width: 100%; height: auto; }
.ad-axis text { font-family: var(--mono); font-size: 10px; fill: var(--mute); }
.ad-gridline { stroke: var(--grid); stroke-width: 1; }
.ad-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; font-size: 12.5px; color: var(--ink-2); }
.ad-legend span { display: inline-flex; align-items: center; gap: 6px; }
.ad-swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* --------------------------------------------------------- ranked bar rows */
.ad-rank { display: flex; flex-direction: column; gap: 2px; }
.ad-row { display: grid; grid-template-columns: minmax(0, 1fr) 64px; gap: 12px;
  align-items: center; padding: 7px 0; border-bottom: 1px dotted var(--rule); }
.ad-row:last-child { border-bottom: 0; }
.ad-row-label { min-width: 0; }
.ad-row-name { font-size: 13.5px; color: var(--ink); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; display: block; }
.ad-row-name a { color: var(--ink); }
.ad-row-name a:hover { color: var(--blueprint); }
.ad-row-sub { font-family: var(--mono); font-size: 10.5px; color: var(--mute-2); }
.ad-bar-track { height: 8px; background: var(--paper-3); border-radius: 4px; margin-top: 5px; overflow: hidden; }
.ad-bar-fill { height: 100%; background: var(--c1); border-radius: 4px; }
.ad-bar-fill.alt { background: var(--c2); }
.ad-row-value { font-family: var(--mono); font-size: 14px; font-weight: 600;
  color: var(--ink); text-align: right; }
.ad-row-value small { display: block; font-size: 10px; font-weight: 400; color: var(--mute); }

/* ------------------------------------------------------------------ table */
.ad-tablewrap { overflow-x: auto; }
.ad-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.ad-table th { text-align: left; font-family: var(--mono); font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.1em; color: var(--mute); font-weight: 700;
  padding: 8px 10px; border-bottom: 2px solid var(--ink); white-space: nowrap; }
.ad-table th.num, .ad-table td.num { text-align: right; font-family: var(--mono); }
.ad-table td { padding: 9px 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.ad-table tr:hover td { background: var(--paper-2); }
.ad-table .path { color: var(--ink); font-family: var(--mono); font-size: 12px; }
.ad-table .title { display: block; color: var(--mute); font-size: 12px; margin-top: 2px;
  max-width: 460px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ad-table td:first-child { max-width: 60vw; }

/* ------------------------------------------------------------------ misc */
.ad-empty { text-align: center; padding: 34px 20px; color: var(--mute); font-size: 14px; line-height: 1.6; }
.ad-note { background: var(--blueprint-tint); border-left: 3px solid var(--blueprint);
  border-radius: var(--rad); padding: 14px 18px; font-size: 14px; line-height: 1.6;
  color: var(--ink-2); margin-bottom: 20px; }
.ad-note.warn { background: var(--amber-tint); border-left-color: var(--amber); }
.ad-note.error { background: var(--alert-tint); border-left-color: var(--alert); color: #7F1D1D; }
.ad-note code { font-family: var(--mono); font-size: 0.9em; background: rgba(0,0,0,0.05);
  padding: 1px 5px; border-radius: 3px; }
.ad-note ol { margin: 10px 0 0 18px; }
.ad-note li { margin-bottom: 6px; }

.ad-skel { height: 96px; border-radius: var(--rad-lg); margin-bottom: 14px;
  background: linear-gradient(90deg, var(--paper-2) 25%, var(--paper-3) 37%, var(--paper-2) 63%);
  background-size: 400% 100%; animation: adShim 1.3s ease infinite; }
@keyframes adShim { from { background-position: 100% 50%; } to { background-position: 0 50%; } }

.ad-gate { max-width: 460px; margin: 80px auto; text-align: center; }
.ad-gate h1 { font-family: var(--display); font-size: 26px; font-weight: 700;
  letter-spacing: -0.02em; margin-bottom: 10px; }
.ad-gate p { color: var(--ink-2); line-height: 1.6; margin-bottom: 20px; }

/* Tooltip for the trend chart */
.ad-tip { position: fixed; left: 0; top: 0; z-index: 900; pointer-events: none; background: var(--ink);
  color: #fff; border-radius: var(--rad); padding: 9px 12px; font-size: 12.5px;
  line-height: 1.5; box-shadow: 0 8px 22px rgba(15,23,42,0.25); white-space: nowrap; opacity: 0;
  transition: opacity 0.1s; }
.ad-tip.on { opacity: 1; }
.ad-tip b { font-family: var(--mono); font-weight: 600; }
.ad-tip .k { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

@media print {
  .ad-controls, .site-header, .notice-bar, .site-footer, .grid-bg { display: none !important; }
  .ad-panel { break-inside: avoid; }
}
