/* =============================================================================
 * styles/modules/cost-meter.css — Phase 0c: Always-present cost meter
 *
 * Loaded non-blocking via media="print" onload="this.media='all'" in the
 * <head> of the main page template.
 *
 * Token compliance: all colors/spacing from --guide-* tokens.
 * Z-index: uses --guide-z-sticky (200) for the bar, --guide-z-popover (1100)
 * for the breakdown/limits popover — per styles/CONVENTIONS.md rules.
 * ============================================================================= */

/* ─── Bar ─────────────────────────────────────────────────────────────────── */

.guide-cost-meter {
  position: sticky;
  top: 0;
  z-index: var(--guide-z-sticky);
  display: flex;
  align-items: center;
  gap: var(--guide-sp-3, 12px);
  padding: 0 var(--guide-sp-4, 16px);
  height: 32px;
  font-size: var(--guide-fs-xs);
  font-family: var(--guide-font-mono);
  background: var(--guide-color-surface, #fff);
  border-bottom: 1px solid var(--guide-color-border-default, rgba(0, 0, 0, 0.10));
  transition: background var(--guide-dur-fast, 120ms) var(--guide-ease-out, ease-out);
  /* Shift content down by bar height so it's not covered */
  view-transition-name: cost-meter;
}

/* Color states */
.guide-cost-meter--ok {
  background: var(--guide-color-status-ok-bg, #f0fdf4);
  border-bottom-color: var(--guide-color-status-ok-border, #bbf7d0);
}

.guide-cost-meter--warn {
  background: var(--guide-color-status-warn-bg, #fefce8);
  border-bottom-color: var(--guide-color-status-warn-border, #fef08a);
}

.guide-cost-meter--danger {
  background: var(--guide-color-status-danger-bg, #fef2f2);
  border-bottom-color: var(--guide-color-status-danger-border, #fecaca);
}

.guide-cost-meter--cta {
  /* action + its PAIRED foreground, not action + white. Lake is light in the
     dark theme, so a fill that hard-codes white text on it dies there — the
     banner measured 2.13:1 after --guide-color-mt-blue was re-pointed onto
     the action role. --guide-color-on-action is the half of the pair that
     flips with it (7.07:1 in dark). Same fill-vs-text split as the brand red. */
  background: var(--guide-color-action);
  color: var(--guide-color-on-action);
  border-bottom-color: transparent;
}

/* Hide when dismissed */
.guide-cost-meter[hidden] {
  display: none;
}

/* ─── Bar children ───────────────────────────────────────────────────────── */

.guide-cost-session,
.guide-cost-month,
.guide-cost-tier {
  white-space: nowrap;
  color: inherit;
  opacity: 0.85;
}

.guide-cost-session strong,
.guide-cost-month strong {
  font-weight: 700;
  opacity: 1;
}

/* Stays on ink-4 deliberately. This is the separator glyph between meter
   segments — user-select:none, no reading value — and ink-4 is the tier for
   exactly that: hairlines, dividers and washes, held to the non-text 3:1 bar.
   The other five ink-4 text consumers moved to ink-3; this one is not text. */
.guide-cost-sep {
  color: var(--guide-color-ink-4, rgba(0,0,0,.4));
  user-select: none;
}

/* Push actions to the right */
.guide-cost-action,
.guide-cost-dismiss {
  margin-left: auto;
  padding: 2px 8px;
  border: 1px solid currentColor;
  border-radius: var(--guide-radius-sm, 4px);
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: var(--guide-fs-xs);
  cursor: pointer;
  opacity: 0.7;
  transition: opacity var(--guide-dur-fast, 120ms);
}

.guide-cost-action:first-of-type {
  margin-left: auto; /* first action pushes everything left */
}

.guide-cost-action + .guide-cost-action,
.guide-cost-action + .guide-cost-dismiss {
  margin-left: var(--guide-sp-4, 4px); /* subsequent actions don't auto-margin */
}

.guide-cost-action:hover,
.guide-cost-dismiss:hover {
  opacity: 1;
}

.guide-cost-action:focus-visible,
.guide-cost-dismiss:focus-visible {
  outline: 2px solid var(--guide-color-action);
  outline-offset: 2px;
}

/* CTA variant */
.guide-cost-meter--cta .guide-cost-cta-msg {
  flex: 1;
  font-family: var(--guide-font-sans, system-ui, sans-serif);
}

.guide-cost-cta-btn {
  padding: 2px 12px;
  /* follows the banner's own foreground rather than assuming it is white */
  background: color-mix(in srgb, currentcolor 12%, transparent);
  border: 1px solid color-mix(in srgb, currentcolor 32%, transparent);
  border-radius: var(--guide-radius-sm, 4px);
  color: inherit;
  font: inherit;
  font-size: var(--guide-fs-xs);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--guide-dur-fast, 120ms);
}

.guide-cost-cta-btn:hover {
  background: color-mix(in srgb, currentcolor 22%, transparent);
}

/* ─── Popover ────────────────────────────────────────────────────────────── */

.guide-cost-popover {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: var(--guide-z-popover, 1100);
  min-width: 280px;
  max-width: 360px;
  /* A raised sheet with the elevation shadow, like every popover. */
  background: var(--guide-color-raised);
  border: 1px solid var(--guide-color-border-default, rgba(0, 0, 0, 0.10));
  border-radius: var(--guide-radius-md, 8px);
  box-shadow: var(--guide-shadow-overlay);
  padding: var(--guide-sp-4, 16px);
  font-family: var(--guide-font-sans, system-ui, sans-serif);
  font-size: var(--guide-fs-sm);
  color: var(--guide-color-ink, #1a1a1f);
  animation: guideScaleIn var(--guide-dur-base, 180ms) var(--guide-ease-out, ease-out) both;
}

@media (prefers-reduced-motion: reduce) {
  .guide-cost-popover { animation: none; }
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .guide-cost-popover { background: var(--guide-color-surface, #fff); }
}

.guide-pop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--guide-sp-3, 12px);
  font-size: var(--guide-fs-md);
}

.guide-pop-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
  color: var(--guide-color-ink-3, rgba(0,0,0,.55));
  font-size: var(--guide-fs-md);
  border-radius: var(--guide-radius-sm, 4px);
}

.guide-pop-close:hover {
  background: var(--guide-color-surface-2, rgba(0,0,0,.06));
}

.guide-pop-close:focus-visible {
  outline: 2px solid var(--guide-color-mt-blue, #3B5A7A);
  outline-offset: 2px;
}

.guide-pop-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: var(--guide-sp-3, 12px);
}

.guide-pop-table td {
  padding: 4px 0;
  vertical-align: top;
}

.guide-pop-table .guide-pop-label {
  color: var(--guide-color-ink-3, rgba(0,0,0,.55));
}

.guide-pop-table .guide-pop-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.guide-pop-total {
  border-top: 1px solid var(--guide-color-border-default, rgba(0, 0, 0, 0.10));
  font-weight: 700;
}

.guide-pop-total td {
  padding-top: 8px;
}

.guide-pop-note {
  font-size: var(--guide-fs-xs);
  color: var(--guide-color-ink-3, rgba(0,0,0,.55));
  margin: 0;
  line-height: 1.4;
}

.guide-pop-note a {
  color: var(--guide-color-mt-blue, #3B5A7A);
  text-decoration: underline;
}

/* Limits popover extras */
.guide-cost-popover--limits .guide-pop-cap-row {
  display: flex;
  align-items: center;
  gap: var(--guide-sp-4, 4px);
  margin: var(--guide-sp-8, 8px) 0 var(--guide-sp-3, 12px);
}

.guide-pop-cap-input {
  width: 80px;
  padding: 4px 8px;
  border: 1px solid var(--guide-color-border-default, rgba(0, 0, 0, 0.10));
  border-radius: var(--guide-radius-sm, 4px);
  font: inherit;
  font-size: var(--guide-fs-md);
  text-align: right;
}

.guide-pop-cap-input:focus {
  outline: 2px solid var(--guide-color-mt-blue, #3B5A7A);
  outline-offset: 1px;
}

.guide-pop-dollar,
.guide-pop-month {
  color: var(--guide-color-ink-3, rgba(0,0,0,.55));
}

.guide-pop-actions {
  display: flex;
  gap: var(--guide-sp-8, 8px);
  justify-content: flex-end;
  margin-top: var(--guide-sp-8, 8px);
}

.guide-pop-save {
  padding: 4px 16px;
  background: var(--guide-color-mt-blue, #3B5A7A);
  color: var(--guide-color-white, #fff);
  border: none;
  border-radius: var(--guide-radius-sm, 4px);
  font: inherit;
  font-size: var(--guide-fs-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--guide-dur-fast, 120ms);
}

.guide-pop-save:hover {
  background: var(--guide-color-mt-slate-deep, #2A4361);
}

.guide-pop-close-btn {
  padding: 4px 12px;
  background: none;
  border: 1px solid var(--guide-color-border-default, rgba(0, 0, 0, 0.10));
  border-radius: var(--guide-radius-sm, 4px);
  font: inherit;
  font-size: var(--guide-fs-sm);
  cursor: pointer;
  color: var(--guide-color-ink-2, rgba(0,0,0,.7));
}

.guide-pop-close-btn:hover {
  background: var(--guide-color-surface-2, rgba(0,0,0,.05));
}

/* ─── Pre-action cost preview bar ───────────────────────────────────────── */

.guide-cost-preview-bar {
  display: flex;
  align-items: center;
  gap: var(--guide-sp-3, 12px);
  padding: var(--guide-sp-8, 8px) var(--guide-sp-4, 16px);
  background: var(--guide-color-status-warn-bg, #fefce8);
  border: 1px solid var(--guide-color-status-warn-border, #fef08a);
  border-radius: var(--guide-radius-md, 8px);
  margin-bottom: var(--guide-sp-8, 8px);
  font-size: var(--guide-fs-sm);
  font-family: var(--guide-font-sans, system-ui, sans-serif);
}

.guide-cost-preview-msg {
  flex: 1;
}

.guide-cost-preview-confirm-btn,
.guide-cost-preview-cancel-btn {
  padding: 4px 14px;
  border-radius: var(--guide-radius-sm, 4px);
  font: inherit;
  font-size: var(--guide-fs-sm);
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
}

.guide-cost-preview-confirm-btn {
  background: var(--guide-color-mt-blue, #3B5A7A);
  color: var(--guide-color-text-on-accent, #fff);
  font-weight: 600;
}

.guide-cost-preview-cancel-btn {
  background: none;
  border-color: var(--guide-color-border-default, rgba(0, 0, 0, 0.10));
  color: var(--guide-color-ink-2, rgba(0,0,0,.7));
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .guide-cost-tier,
  .guide-cost-sep:last-of-type {
    display: none;
  }

  .guide-cost-meter {
    gap: var(--guide-sp-8, 8px);
    padding: 0 var(--guide-sp-8, 8px);
  }
}

/* ─── Print ──────────────────────────────────────────────────────────────── */

@media print {
  .guide-cost-meter,
  .guide-cost-popover,
  .guide-cost-preview-bar {
    display: none !important;
  }
}
