/* =====================================================================
   PRE-EXPORT CONFIRM MODAL
   Modal that opens BEFORE the AI PPTX job starts. Shows price preview,
   format toggle (PPTX / PDF), bullet checklist, balance hint.
   Built on existing live tokens (style.css :root + [data-theme="dark"])
   to stay consistent with neighbour mobile/* sheets.
   ===================================================================== */

.m-confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 9700;                /* cascade: FAB 9000 < mini-pill 9100 < sidebar 9500 < brand-picker 9600 < confirm 9700 < recent-toast 9750 < stale-toast 9800 */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 16, 20, 0.55);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  backdrop-filter: blur(20px) saturate(140%);
  opacity: 0;
  animation: m-confirm-fade-in 240ms cubic-bezier(0.32, 0.72, 0.36, 1) forwards;
  letter-spacing: -0.01em;
  font-feature-settings: "cv11", "ss01", "ss03";
  font-family: var(--font-body);
}

[data-theme="dark"] .m-confirm-overlay {
  background: rgba(0, 0, 0, 0.62);
}

.m-confirm-overlay.is-closing {
  animation: m-confirm-fade-out 220ms cubic-bezier(0.32, 0.72, 0.36, 1) forwards;
}

@keyframes m-confirm-fade-in  { to { opacity: 1; } }
@keyframes m-confirm-fade-out { to { opacity: 0; } }

/* ────────── Card ────────── */

.m-confirm-card {
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-solid);
  color: var(--text-1);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px 24px 20px;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.06),
    0 12px 32px rgba(0, 0, 0, 0.10),
    0 20px 60px -20px rgba(0, 0, 0, 0.50);
  transform: translateY(8px) scale(0.96);
  opacity: 0;
  animation: m-confirm-card-in 280ms cubic-bezier(0.32, 0.72, 0.36, 1) 40ms forwards;
}

[data-theme="dark"] .m-confirm-card {
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.30),
    0 16px 40px rgba(0, 0, 0, 0.50),
    0 28px 80px -20px rgba(0, 0, 0, 0.60);
}

.m-confirm-overlay.is-closing .m-confirm-card {
  animation: m-confirm-card-out 220ms cubic-bezier(0.32, 0.72, 0.36, 1) forwards;
}

@keyframes m-confirm-card-in {
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes m-confirm-card-out {
  to { opacity: 0; transform: translateY(4px) scale(0.98); }
}

/* ────────── Header ────────── */

.m-confirm-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.m-confirm-title {
  margin: 0;
  font-size: 19px;
  line-height: 1.25;
  font-weight: 600;
  color: var(--text-0, var(--text-1));
  letter-spacing: -0.015em;
  font-family: inherit;
}

.m-confirm-close {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text-2);
  cursor: pointer;
  margin: -6px -6px 0 0;       /* pull into card padding optical */
  transition:
    background 160ms var(--ease, ease),
    border-color 160ms var(--ease, ease),
    color 160ms var(--ease, ease),
    transform 120ms var(--ease, ease);
}

.m-confirm-close:hover {
  background: var(--bg-input);
  color: var(--text-1);
  border-color: var(--border);
}

.m-confirm-close:active { transform: scale(0.94); }

.m-confirm-close:focus-visible {
  outline: 2px solid var(--accent-blue, var(--accent));
  outline-offset: 2px;
}

.m-confirm-close svg {
  width: 16px;
  height: 16px;
  stroke-width: 1.8;
}

/* ────────── Format toggle (segmented control, iOS style) ────────── */

.m-confirm-format {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px;
  margin-bottom: 22px;
  isolation: isolate;          /* keep the slide pill below the buttons */
}

/* Sliding active pill — animated between the two slots */
.m-confirm-format-pill {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: calc(50% - 4px);
  border-radius: 11px;
  background: var(--bg-solid);
  border: 1px solid var(--border);
  box-shadow:
    0 1px 1px rgba(0, 0, 0, 0.04),
    0 2px 6px -2px rgba(0, 0, 0, 0.08);
  transition: transform 320ms cubic-bezier(0.32, 0.72, 0.36, 1);
  z-index: 0;
  will-change: transform;
}

[data-theme="dark"] .m-confirm-format-pill {
  background: var(--bg-input-hover);
  border-color: var(--border-hover);
  box-shadow:
    0 1px 1px rgba(0, 0, 0, 0.20),
    0 2px 6px -2px rgba(0, 0, 0, 0.30);
}

.m-confirm-format[data-active="pdf"] .m-confirm-format-pill {
  transform: translateX(100%);
}

.m-confirm-format-btn {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 10px 14px;
  min-height: 52px;
  background: transparent;
  border: 0;
  border-radius: 11px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text-2);
  text-align: left;
  transition: color 220ms cubic-bezier(0.32, 0.72, 0.36, 1);
}

.m-confirm-format-btn[aria-checked="true"] {
  color: var(--text-1);
}

.m-confirm-format-btn:focus { outline: none; }

.m-confirm-format-btn:focus-visible {
  outline: 2px solid var(--accent-blue, var(--accent));
  outline-offset: 2px;
}

.m-confirm-format-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.m-confirm-format-icon svg { width: 22px; height: 22px; display: block; }

.m-confirm-format-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.15;
}

.m-confirm-format-label {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.012em;
  color: inherit;
}

.m-confirm-format-sublabel {
  font-size: 11.5px;
  font-weight: 400;
  color: var(--text-3);
  letter-spacing: -0.005em;
}

/* ────────── Body sections (price card / pdf body) ────────── */

.m-confirm-body { display: block; }

.m-confirm-body[hidden] { display: none; }

/* ────────── Price card (PPTX) ────────── */

.m-confirm-price {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: color-mix(in srgb, var(--bg-input) 55%, transparent);
  padding: 14px 16px 12px;
  margin-bottom: 16px;
}

.m-confirm-price-header {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 500;
  margin-bottom: 10px;
}

.m-confirm-price-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

.m-confirm-price-row:first-of-type { border-top: 0; padding-top: 4px; }

.m-confirm-price-label {
  font-size: 13.5px;
  line-height: 1.35;
  color: var(--text-1);
  letter-spacing: -0.005em;
}

.m-confirm-price-label-sub {
  display: block;
  font-size: 11.5px;
  color: var(--text-3);
  margin-top: 1px;
  letter-spacing: -0.002em;
}

.m-confirm-price-value {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-1);
  letter-spacing: -0.002em;
  white-space: nowrap;
}

.m-confirm-price-footnote {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--text-3);
  letter-spacing: -0.002em;
}

/* Static-card fallback note — sits below the legacy generic price card when
   the live estimate API is unavailable. Italic, single line, never alarms. */
.m-confirm-price-fallback-note {
  margin-top: 8px;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--text-3);
  letter-spacing: -0.002em;
  font-style: italic;
}

/* ════════════════════════════════════════════════════════════════════════════
   ESTIMATE PANEL — реальная оценка vs баланс (v r6 — balance-check 5 states)
   Same physical slot as .m-confirm-price (replaces it when estimate available).
   States: .is-loading | .is-fetch-error | (default = sufficient) |
           .is-borderline | .is-insufficient
   Apple/Linear-tier: soft borders, tabular-nums, no alarm colours, no halos.
   ══════════════════════════════════════════════════════════════════════════ */

.m-confirm-estimate {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: color-mix(in srgb, var(--bg-input) 55%, transparent);
  padding: 14px 16px 12px;
  margin-bottom: 16px;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
  /* state cross-fade — applied to inner content when state changes */
  transition: border-color 220ms cubic-bezier(0.32, 0.72, 0.36, 1);
}

/* Borderline — barely-visible cool-grey hint via low accent-blue mix.
   Never alarm. */
.m-confirm-estimate.is-borderline {
  border-color: color-mix(in srgb, var(--accent-blue) 28%, var(--border));
}

/* Insufficient — slightly stronger border to match the "this is a gate"
   semantic without screaming. NO background fill. */
.m-confirm-estimate.is-insufficient {
  border-color: var(--border-hover);
}

/* ── Eyebrow row — uppercase tracking + slide count chip on the right ── */

.m-confirm-estimate-eyebrow {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.m-confirm-estimate-eyebrow-label {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 500;
}

.m-confirm-estimate-slidecount {
  font-size: 11.5px;
  color: var(--text-2);
  letter-spacing: -0.002em;
  font-weight: 500;
  white-space: nowrap;
}

/* ── Two-row reveal: Стоимость / Баланс ── */

.m-confirm-estimate-rows {
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.m-confirm-estimate-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.m-confirm-estimate-row dt {
  font-size: 13px;
  color: var(--text-2);
  letter-spacing: -0.005em;
  margin: 0;
}

.m-confirm-estimate-num {
  font-size: 14px;
  color: var(--text-1);
  font-weight: 500;
  letter-spacing: -0.005em;
  margin: 0;
  white-space: nowrap;
}

/* ── Divider before hero (only insufficient/borderline; sufficient hides hero) ── */

.m-confirm-estimate-divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}

/* Sufficient state hides divider + hero (no delta to show) */
.m-confirm-estimate:not(.is-insufficient):not(.is-borderline) .m-confirm-estimate-divider,
.m-confirm-estimate:not(.is-insufficient):not(.is-borderline) .m-confirm-estimate-hero {
  display: none;
}

/* ── Hero row — delta label + delta value (insufficient) or italic hint (borderline) ── */

.m-confirm-estimate-hero {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.m-confirm-estimate-hero-label {
  font-size: 13px;
  color: var(--text-2);
  letter-spacing: -0.005em;
}

.m-confirm-estimate-hero-value {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-0, var(--text-1));
  letter-spacing: -0.012em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  /* DELIBERATELY plain — same colour as title, not red. The size + weight
     is enough hierarchy. Apple Wallet "Insufficient balance" pattern. */
}

/* Borderline: hero is a soft inline hint, not a gate */
.m-confirm-estimate.is-borderline .m-confirm-estimate-hero-label,
.m-confirm-estimate.is-borderline .m-confirm-estimate-hero-value {
  font-style: italic;
  font-weight: 400;
  font-size: 12.5px;
  color: var(--text-2);
}

/* ── Explainer + footnote ── */

.m-confirm-estimate-explainer {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-2);
  letter-spacing: -0.002em;
}

.m-confirm-estimate-footnote {
  margin: 6px 0 0;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--text-3);
  letter-spacing: -0.002em;
}

/* Sufficient state hides explainer (no delta to explain).
   Fetch-error also wants explainer visible (it carries the «Не удалось
   рассчитать сейчас» soft fallback line), so we exempt it here. */
.m-confirm-estimate:not(.is-insufficient):not(.is-borderline):not(.is-fetch-error) .m-confirm-estimate-explainer {
  display: none;
}

/* ── Loading skeleton (shimmer) — same physical size as real estimate ── */

.m-confirm-estimate.is-loading {
  pointer-events: none;
}

.m-confirm-estimate-skeleton {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.m-confirm-estimate-skeleton-row {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(
    90deg,
    var(--bg-input) 0%,
    var(--bg-input-hover) 50%,
    var(--bg-input) 100%
  );
  background-size: 200% 100%;
  animation: m-confirm-estimate-shimmer 1400ms linear infinite;
}

.m-confirm-estimate-skeleton-row:nth-child(1) { width: 70%; }
.m-confirm-estimate-skeleton-row:nth-child(2) { width: 45%; }
.m-confirm-estimate-skeleton-row:nth-child(3) { width: 60%; }

@keyframes m-confirm-estimate-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ════════════════════════════════════════════════════════════════════════════
   FOOTER — secondary explainer line below the action row.
   Used for:
     - insufficient state: muted disabled-link explanation «Создать PPTX (нужно ещё Δ ₽)»
     - borderline state:   inline text-link «Пополнить баланс» wrapped in a sentence
   Sits BELOW the .m-confirm-footer button row, never wedged between buttons.
   ══════════════════════════════════════════════════════════════════════════ */

.m-confirm-footer-explainer {
  margin: 10px 0 0;
  text-align: center;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--text-3);
  letter-spacing: -0.002em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

.m-confirm-footer-explainer[hidden] { display: none; }

/* Inline text-button used in borderline footer-explainer — NOT a real button
   visually, just a tappable underline. Keyboard-focusable. */
.m-confirm-footer-link {
  appearance: none;
  background: transparent;
  border: 0;
  font-family: inherit;
  font-size: inherit;
  font-weight: 500;
  color: var(--text-1);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-decoration-color: var(--border-hover);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition:
    color 160ms var(--ease, ease),
    text-decoration-color 160ms var(--ease, ease);
}

.m-confirm-footer-link:hover {
  color: var(--text-0, var(--text-1));
  text-decoration-color: currentColor;
}

.m-confirm-footer-link:focus { outline: none; }
.m-confirm-footer-link:focus-visible {
  outline: 2px solid var(--accent-blue, var(--accent));
  outline-offset: 3px;
  border-radius: 2px;
}

/* ════════════════════════════════════════════════════════════════════════════
   PRIMARY CTA — when state = insufficient, primary becomes "Пополнить баланс"
   Visually IDENTICAL to existing .m-confirm-btn-confirm — same accent, same
   shadow. Apple/Linear pattern: don't make the rescue action look scary.
   .is-topup is just an explicit class hook for state machine (no extra paint).
   ══════════════════════════════════════════════════════════════════════════ */

.m-confirm-btn-confirm.is-topup {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--bg-solid);
}

/* ────────── Bullet checklist ────────── */

.m-confirm-bullets {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.m-confirm-bullet {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-2);
  letter-spacing: -0.005em;
}

.m-confirm-bullet-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
  color: var(--text-3);
}

.m-confirm-bullet.is-positive .m-confirm-bullet-icon { color: var(--accent); }
.m-confirm-bullet.is-time     .m-confirm-bullet-icon { color: var(--text-2); }

.m-confirm-bullet-icon svg { width: 14px; height: 14px; }

/* ────────── PDF body (compact) ────────── */

.m-confirm-pdf-text {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-1);
  margin: 0 0 14px;
  letter-spacing: -0.005em;
}

/* ────────── Balance row ────────── */

.m-confirm-balance {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: transparent;
  margin-bottom: 16px;
  font-size: 12.5px;
  color: var(--text-2);
  letter-spacing: -0.002em;
}

.m-confirm-balance-value {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
  font-weight: 500;
  color: var(--text-1);
  letter-spacing: -0.002em;
}

/* ────────── Footer / actions ────────── */

.m-confirm-footer {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.m-confirm-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 500;
  letter-spacing: -0.005em;
  cursor: pointer;
  transition:
    background 180ms var(--ease, ease),
    border-color 180ms var(--ease, ease),
    color 180ms var(--ease, ease),
    transform 120ms var(--ease, ease),
    box-shadow 180ms var(--ease, ease);
  white-space: nowrap;
}

.m-confirm-btn:focus { outline: none; }

.m-confirm-btn:focus-visible {
  outline: 2px solid var(--accent-blue, var(--accent));
  outline-offset: 2px;
}

.m-confirm-btn:active { transform: scale(0.98); }

.m-confirm-btn-cancel {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
}

.m-confirm-btn-cancel:hover {
  background: var(--bg-input);
  border-color: var(--border-hover);
  color: var(--text-1);
}

.m-confirm-btn-confirm {
  flex: 1 1 auto;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--bg-solid);
  box-shadow:
    0 1px 1px rgba(0, 0, 0, 0.04),
    0 4px 12px -4px var(--accent-glow);
}

.m-confirm-btn-confirm:hover {
  background: var(--accent-hover, var(--accent));
  border-color: var(--accent-hover, var(--accent));
  box-shadow:
    0 1px 1px rgba(0, 0, 0, 0.06),
    0 6px 16px -4px var(--accent-glow);
}

/* PPTX confirm gets a subtle warm halo via accent-blue (close to ember) when
   theme-light, white-on-dark in dark mode — matches existing usage of
   accent-glow vs accent-blue across other CTAs. */
.m-confirm-btn-confirm.is-pptx {
  border-color: var(--accent);
  background: var(--accent);
}

.m-confirm-btn[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* ────────── Responsive (small phones) ────────── */

@media (max-width: 480px) {
  .m-confirm-overlay { padding: 16px; }
  .m-confirm-card { padding: 20px 18px 18px; border-radius: 16px; }
  .m-confirm-format-btn { min-height: 50px; padding: 8px 12px; gap: 8px; }
  .m-confirm-format-label { font-size: 13.5px; }
  .m-confirm-format-sublabel { font-size: 11px; }
  .m-confirm-price,
  .m-confirm-estimate { padding: 12px 14px 10px; }
  .m-confirm-estimate-eyebrow-label { font-size: 10.5px; }
  .m-confirm-footer { flex-direction: column-reverse; gap: 8px; }
  .m-confirm-btn-cancel,
  .m-confirm-btn-confirm { width: 100%; flex: 1 1 auto; }
}

/* ────────── Reduced motion ────────── */

@media (prefers-reduced-motion: reduce) {
  .m-confirm-overlay,
  .m-confirm-card,
  .m-confirm-format-pill,
  .m-confirm-format-btn,
  .m-confirm-btn { animation: none !important; transition: none !important; }

  /* Estimate panel shimmer also gets killed — perceived "loading" still
     conveyed via the placeholder rows themselves. */
  .m-confirm-estimate-skeleton-row { animation: none !important; }
  .m-confirm-estimate { transition: none !important; }

  /* Without animation, the keyframe `forwards` end-state never lands —
     overlay/card would otherwise stick at base opacity:0 / offset transform
     and the modal would render fully invisible (a11y blocker). Pin the
     visible state explicitly here so the modal still appears. */
  .m-confirm-overlay { opacity: 1 !important; }
  .m-confirm-card    { opacity: 1 !important; transform: none !important; }

  /* Closing state still hides — match the fade-out target so cancel/ESC
     visually unmount instantly instead of leaving a stale overlay. */
  .m-confirm-overlay.is-closing,
  .m-confirm-overlay.is-closing .m-confirm-card { opacity: 0 !important; }
}
