/* Queries page (v2) — per-statement cache management.
   Spec: new-workflow/docs/specs/2026-04-29-traffic-page.md
   Linear: AIR-1044

   Reuses .kpi-grid / .chart-grid / .chart-card / .kpi-tile from
   dashboard.css. Only traffic-specific styles live here. */

/* ===== Loading + empty states ===== */

.traffic-loading {
  display: flex;
  align-items: center;
  gap: var(--s-12);
  padding: var(--s-24);
  color: var(--muted);
  justify-content: center;
}

.traffic-empty {
  display: flex;
  align-items: center;
  gap: var(--s-16);
  padding: var(--s-24);
  color: var(--text);
}
.traffic-empty i { color: var(--accent); font-size: 24px; }
.traffic-empty p { margin: 4px 0 0; color: var(--muted); }

/* ===== List view scaffolding ===== */

.traffic-list {
  display: flex;
  flex-direction: column;
  gap: var(--s-16);
}

/* ===== Year nav + month breadcrumb ===== */

.traffic-yearnav,
.traffic-monthbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-8);
}

.year-pill,
.month-pill {
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.year-pill:hover,
.month-pill:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.year-pill--active,
.month-pill--active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.month-pill--empty {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Mini-calendar pop-over — tap a month pill to open the day picker.
   Hover reveal was removed: mobile has no hover, and a tap-toggle behaves
   the same on both. Keyboard focus still reveals it via :focus-within. */

.month-pill-wrap {
  position: relative;
  display: inline-block;
}

.mini-calendar {
  position: absolute;
  top: 100%;
  left: 0;
  padding-top: var(--s-8);
  z-index: 100;
  display: none;
  min-width: 240px;
}

/* Last few months hug the right edge so the pop-over doesn't overflow. */
.month-pill-wrap:nth-last-child(-n+3) .mini-calendar {
  left: auto;
  right: 0;
}

.month-pill-wrap[data-open] .mini-calendar,
.month-pill-wrap:focus-within .mini-calendar {
  display: block;
}

.mini-calendar-inner {
  background: var(--card-bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--s-12);
  box-shadow: 0 8px 24px var(--shadow-strong);
  padding: var(--s-12);
}

.calendar-header {
  text-align: center;
  font-weight: 600;
  margin-bottom: var(--s-8);
  font-size: 13px;
  color: var(--text);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--s-4);
}

.calendar-day-header {
  text-align: center;
  font-size: 10px;
  color: var(--muted);
  font-weight: 600;
  padding: var(--s-4);
}

.calendar-day {
  text-align: center;
  padding: 6px 0;
  font-size: 11px;
  border-radius: var(--s-4);
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-family: inherit;
}

/* Days outside the month occupy a slot but render nothing. */
.calendar-day--blank {
  visibility: hidden;
}

/* Days in the month with no traffic — visible but inert. */
.calendar-day--empty {
  opacity: 0.35;
  cursor: default;
}

/* Days with traffic — clickable, accent-colored. */
.calendar-day--has-data {
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.calendar-day--has-data:hover,
.calendar-day--has-data:focus-visible {
  background: rgba(253, 108, 29, 0.1);
  border-color: var(--accent);
  outline: none;
}

.calendar-day--today {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ===== View slider (Year / Month / Day granularity) ===== */

.traffic-view-slider {
  display: flex;
  align-items: center;
  gap: var(--s-12);
}

/* Prev/next chevrons flanking the slider step through the current
   granularity (years, months-with-data, days-with-data). 44x44 clears
   the WCAG 2.5.5 / Apple HIG touch target on phones, which is where this
   nav matters most (no keyboard, no hover). */
.period-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
  font-size: 14px;
}
.period-nav-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
.period-nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.view-slider-track {
  display: inline-flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 14px 8px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px var(--shadow);
}

.view-slider-input {
  width: 192px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.view-slider-labels {
  display: flex;
  justify-content: space-between;
  width: 192px;
}

.view-slider-label {
  background: transparent;
  border: 0;
  padding: 0;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  transition: color 0.15s ease;
}

.view-slider-label:hover { color: var(--accent); }
.view-slider-label--active { color: var(--accent); }

/* ===== Table card + filters ===== */

.traffic-table-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--s-24);
  box-shadow: 0 2px 8px var(--shadow);
  display: flex;
  flex-direction: column;
  gap: var(--s-16);
}

.traffic-filters {
  display: flex;
  gap: var(--s-12);
  align-items: center;
  flex-wrap: wrap;
}

.traffic-filters .input {
  flex: 1;
  min-width: 220px;
}

.traffic-filter-checks {
  display: flex;
  gap: var(--s-8);
  flex-wrap: wrap;
}

.traffic-filter-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  background: var(--card-bg);
  transition: all 0.15s ease;
}
.traffic-filter-check input { display: none; }
.traffic-filter-check:hover { border-color: var(--accent); }
.traffic-filter-check--off { opacity: 0.5; text-decoration: line-through; }
.traffic-filter-check .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* ===== Statements table ===== */

.traffic-table-heading {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-strong);
}

.traffic-table-wrap { overflow-x: auto; }

.traffic-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.traffic-table th {
  text-align: left;
  padding: var(--s-12);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  color: var(--text-strong);
}

.traffic-table td {
  padding: var(--s-12);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.traffic-table tr:hover td {
  background: rgba(253, 108, 29, 0.03);
}

.traffic-th-num { text-align: right; }
.traffic-th-sort { cursor: pointer; user-select: none; }
.traffic-th-sort:hover { color: var(--accent); }

.traffic-cell-time {
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.traffic-cell-stmt {
  max-width: 480px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
}

.traffic-statement-link {
  color: var(--accent);
  text-decoration: none;
  word-break: break-word;
}
.traffic-statement-link:hover { text-decoration: underline; }

.rule-link {
  color: var(--accent);
  text-decoration: none;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
}
.rule-link:hover { text-decoration: underline; }

.traffic-empty-row {
  text-align: center;
  padding: var(--s-32) var(--s-12) !important;
  color: var(--muted);
}
.traffic-empty-row i { display: block; font-size: 24px; margin-bottom: var(--s-8); color: var(--muted); }

.http-2xx { color: #10b981; }
.http-4xx { color: #f59e0b; }
.http-5xx { color: #ef4444; }

/* ===== Outcome badges ===== */

.outcome-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--card-bg);
  white-space: nowrap;
}
.outcome-badge .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* ===== Statement drawer (AIR-1240). Drawer chrome is in style.css; this
   section styles the body content rendered into .app-drawer-body. ===== */

.traffic-detail {
  display: flex;
  flex-direction: column;
  gap: var(--s-16);
}

.detail-status {
  display: flex;
  align-items: flex-start;
  gap: var(--s-16);
  padding: var(--s-24);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--card-bg);
}
.detail-status i {
  font-size: 28px;
  color: var(--muted);
  width: 48px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: var(--radius);
  flex-shrink: 0;
}
.detail-status-title { font-size: 18px; font-weight: 600; color: var(--text-strong); }
.detail-status-sub { font-size: 14px; color: var(--muted); margin-top: 4px; }

.detail-status--hit i { color: #10b981; background: rgba(16, 185, 129, 0.1); }
.detail-status--miss-no-rule i { color: #94a3b8; background: rgba(148, 163, 184, 0.1); }
.detail-status--miss-invalidated i { color: #8b5cf6; background: rgba(139, 92, 246, 0.1); }

.detail-block {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--s-24);
}

.detail-block--cta {
  display: flex;
  flex-direction: column;
  gap: var(--s-12);
  align-items: flex-start;
}
.detail-block--cta p { margin: 0; color: var(--muted); }

.detail-block-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--s-12);
}
.detail-block-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-strong);
}
.detail-block-subhead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: var(--s-16) 0 var(--s-8);
}
.detail-block-subtitle {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-16);
}

.detail-dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: var(--s-16);
  row-gap: var(--s-8);
  margin: 0;
  font-size: 13px;
}
.detail-dl dt { color: var(--muted); }
.detail-dl dd { margin: 0; color: var(--text); font-variant-numeric: tabular-nums; }

.sql-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s-12);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow-y: auto;
  margin: 0;
}

/* ===== Cache history (drawer summary + modal) =====
   Drawer keeps a lifespan timeline + a "N versions" trigger button.
   Clicking the trigger opens a full modal where each version exposes
   its operation stepper and an Invalidate (active) / Restore (past)
   action. */

.cache-history .detail-block-head {
  align-items: center;
}
.cache-history .detail-block-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.cache-history-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
/* Full-width CTA below the timeline — the timeline is informational, this
   button is the obvious affordance to drill in. Accent-styled by default
   so it reads as the primary affordance in the cache-history block,
   without competing with destructive actions further down. */
.cache-history-trigger {
  width: 100%;
  margin-top: var(--s-12);
  justify-content: center;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--card-bg);
  border-color: var(--accent);
  color: var(--accent);
}
.cache-history-trigger:hover,
.cache-history-trigger:focus-visible {
  background: rgba(253, 108, 29, 0.08);
  border-color: var(--accent);
  color: var(--accent);
}
.cache-history-trigger > i:last-child {
  margin-left: auto;
  transition: transform 0.15s ease;
}
.cache-history-trigger:hover > i:last-child {
  transform: translateX(2px);
}

.cache-history-timeline {
  margin: var(--s-12) 0 0;
}
.cache-history-rows {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 28px;
}
.cache-history-row {
  position: relative;
  height: 14px;
}
.cache-history-bar {
  position: absolute;
  top: 1px;
  bottom: 1px;
  background: linear-gradient(90deg, rgba(148, 163, 184, 0.55), rgba(148, 163, 184, 0.25));
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  font-size: 9px;
  transition: filter 0.15s ease;
}
.cache-history-row:hover .cache-history-bar {
  filter: brightness(1.15);
}
.cache-history-row--active .cache-history-bar {
  background: linear-gradient(90deg, rgba(253, 108, 29, 0.95), rgba(253, 108, 29, 0.55));
  color: #fff;
  box-shadow: 0 0 0 1px rgba(253, 108, 29, 0.4);
}
.cache-history-now {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--text-strong);
  opacity: 0.35;
  pointer-events: none;
}
.cache-history-now::before {
  content: '';
  position: absolute;
  top: -3px;
  left: -3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-strong);
}
.cache-history-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ----- Modal ----- */
/* Sits above the drawer (.app-drawer z-index 130). */
.cache-history-modal-overlay { z-index: 200; }
.cache-history-modal {
  max-width: 720px;
  width: 100%;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 48px);
}
.cache-history-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-12);
}
.cache-history-modal-head i { margin-right: 6px; }
.cache-history-modal-head .app-util-icon {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  border-color: transparent;
}
.cache-history-modal-head .app-util-icon:hover {
  background: rgba(255, 255, 255, 0.3);
}
.cache-history-modal-body {
  overflow-y: auto;
  flex: 1;
}

.cache-history-versions {
  display: flex;
  flex-direction: column;
  gap: var(--s-16);
}
.cache-version {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s-16);
  display: flex;
  flex-direction: column;
  gap: var(--s-12);
}
.cache-version--active {
  border-color: rgba(253, 108, 29, 0.5);
  box-shadow: 0 0 0 1px rgba(253, 108, 29, 0.15);
}
/* Active-but-not-live: keep an outline so it still reads as "current"
   but drop the accent so users don't think it's serving requests. */
.cache-version--active.cache-version--stale {
  border-color: var(--border);
  box-shadow: none;
}
.cache-version-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-12);
  flex-wrap: wrap;
}
.cache-version-id {
  display: flex;
  align-items: center;
  gap: var(--s-12);
}
.cache-version-when-main {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
}
.cache-version-when-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.cache-version-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.cache-version-badge i { font-size: 10px; }
.cache-version-badge--active {
  background: rgba(253, 108, 29, 0.12);
  color: #fd6c1d;
}
.cache-version-badge--past {
  background: rgba(148, 163, 184, 0.15);
  color: var(--muted);
}
.cache-version-fields { font-size: 12px; }
.cache-version-action .btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

/* ----- Operations stepper ----- */
.cache-ops-stepper-wrap { margin-top: 4px; }
.cache-ops-stepper-wrap .detail-block-subtitle { margin-bottom: 8px; }
.cache-ops-stepper {
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--s-8);
}
/* Connector line down the left rail. */
.cache-ops-stepper::before {
  content: '';
  position: absolute;
  left: 13px;
  top: 14px;
  bottom: 14px;
  width: 2px;
  background: var(--border);
  border-radius: 1px;
}
.cache-ops-step {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: var(--s-12);
  align-items: start;
  position: relative;
}
.cache-ops-step-node {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid currentColor;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}
.cache-ops-step-body {
  padding-top: 4px;
  min-width: 0;
}
.cache-ops-step-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-12);
  flex-wrap: wrap;
}
.cache-ops-step-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-strong);
}
.cache-ops-step-meta {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}
.cache-ops-step-when,
.cache-ops-step-gap {
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  font-size: 10px;
  white-space: nowrap;
}
/* Gap-from-previous reads as supporting data, not the headline timestamp. */
.cache-ops-step-gap {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  padding-left: 0;
  padding-right: 0;
}
.cache-ops-step-suffix {
  margin-left: 6px;
  font-weight: 500;
  color: var(--muted);
  font-size: 11px;
}
.cache-ops-step-warn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.cache-ops-step-warn i { font-size: 9px; }

@media (max-width: 640px) {
  .cache-version-head { flex-direction: column; }
  .cache-version-action { width: 100%; }
  .cache-version-action .btn-sm { width: 100%; }
  .cache-history-modal { max-height: 100vh; border-radius: 0; }
}

.inline-code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9em;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
}

.detail-actions {
  display: flex;
  flex-direction: column;
  gap: var(--s-8);
  align-items: flex-start;
}

.detail-error {
  color: #ef4444;
  font-size: 13px;
  margin: 0;
}

.detail-other-markers {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s-12) var(--s-16);
  font-size: 13px;
}
.detail-other-markers summary { cursor: pointer; color: var(--muted); }
.detail-other-markers ul { margin: var(--s-8) 0 0; padding-left: var(--s-16); }
.detail-other-markers li { color: var(--muted); margin-bottom: 4px; }

/* ===== Responsive ===== */

@media (max-width: 1024px) {
  .detail-grid { grid-template-columns: 1fr; }
  .traffic-cell-stmt { max-width: 320px; }
}

@media (max-width: 768px) {
  .traffic-filters { flex-direction: column; align-items: stretch; }
  .traffic-filters .input { width: 100%; }
  .traffic-cell-stmt { max-width: 220px; }
  .detail-status { flex-direction: column; }
}
