/* ═══════════════════════════════════════════════════
   COMPRA BONIFICADA — v3 calm redesign
   Mobile-first store cards · desktop mail-style two-pane
   ═══════════════════════════════════════════════════ */

:root {
  /* Neutrals */
  --bg-page: #EDEEF1;
  --bg-app: #F4F5F7;
  --bg-pane: #FAFBFC;
  --bg-card: #FFFFFF;
  --bg-inset: #F3F4F6;

  --border: #E5E7EB;
  --border-soft: #EEF0F3;
  --border-softer: #F1F2F4;

  --text: #0F172A;
  --text-muted: #4B5563;
  --text-soft: #6B7280;
  --text-faint: #9CA3AF;
  --text-ghost: #D1D5DB;

  /* Accents */
  --accent-ink: #0F172A;
  --accent-blue: #2A5CE8;
  --accent-amber: #F59E0B;

  --shadow-card: 0 1px 2px rgba(15,23,42,0.04);
  --shadow-pop: 0 6px 18px rgba(15,23,42,0.08);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji";

  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 10px;
  --r-xl: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg-app);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Loading ──────────────────────────────────── */
.app-loading {
  position: fixed; inset: 0; z-index: 10000;
  background: var(--bg-app);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; gap: 12px;
}
.loading-state { color: var(--text-muted); font-size: 13px; font-weight: 500; }
.loading-ring {
  position: relative; width: 80px; height: 80px;
}
.loading-ring svg { display: block; }
.loading-ring .loading-percent {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: var(--text);
  font-variant-numeric: tabular-nums;
}
#loading-ring-fg { transition: stroke-dashoffset 0.3s ease; }

/* ── Login ────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; background: radial-gradient(circle at 50% 30%, #F3F4F7, #E5E7EB);
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--r-xl);
  padding: 32px 28px; box-shadow: var(--shadow-pop);
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-overline {
  font-size: 10px; letter-spacing: 1.6px; font-weight: 600; color: var(--text-faint);
  text-transform: uppercase;
}
.login-title { margin: 4px 0 0; font-size: 22px; font-weight: 800; letter-spacing: -0.3px; color: var(--text); }
.login-rule { width: 48px; height: 3px; background: var(--accent-blue); border-radius: 2px; margin: 8px auto 0; }
.login-form { display: flex; flex-direction: column; }
.login-label {
  font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 4px;
}
.login-input {
  font-family: var(--font); font-size: 14px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--r-md); background: var(--bg-card);
  color: var(--text);
}
.login-input:focus { outline: none; border-color: var(--accent-blue); box-shadow: 0 0 0 3px rgba(42,92,232,0.12); }
.login-btn { margin-top: 16px; }
.login-message { font-size: 12px; margin-top: 10px; text-align: center; min-height: 18px; }
.login-message--error { color: #B91C1C; }
.login-message--success { color: #047857; }
.login-toggle {
  display: block; margin: 10px auto 0; background: transparent; border: none;
  color: var(--text-muted); font-size: 12px; cursor: pointer; text-decoration: underline;
}

/* ── Buttons ──────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: var(--r-md); font-family: var(--font);
  font-size: 12px; font-weight: 700; letter-spacing: 0.4px; cursor: pointer;
  padding: 10px 14px; text-decoration: none; transition: background 0.15s, transform 0.05s;
}
.btn-primary { background: var(--accent-ink); color: #fff; }
.btn-primary:hover { background: #1F2937; }
.btn-primary:active { transform: translateY(1px); }
.btn-ghost {
  background: var(--bg-card); color: var(--text-muted); border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-inset); }

/* ── Top bar ──────────────────────────────────── */
.top-bar {
  background: var(--bg-card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.top-bar-inner {
  max-width: 1440px; margin: 0 auto;
  padding: 12px 16px;
  display: flex; align-items: center; gap: 14px;
}
.top-bar-brand { display: flex; flex-direction: column; flex-shrink: 0; }
.top-bar-overline {
  font-size: 9px; font-weight: 600; color: var(--text-faint);
  letter-spacing: 1.6px; text-transform: uppercase;
}
.top-bar-title {
  font-size: 16px; font-weight: 800; letter-spacing: -0.3px; color: var(--text); margin-top: 1px;
}
.top-bar-search {
  flex: 1; max-width: 360px;
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-inset); border-radius: var(--r-md);
  padding: 8px 12px;
}
.top-bar-search-icon { color: var(--text-faint); font-size: 13px; }
.top-bar-search input {
  flex: 1; border: none; background: transparent; outline: none;
  font-family: var(--font); font-size: 13px; color: var(--text);
  min-width: 0;
}
.top-bar-search input::placeholder { color: var(--text-faint); }
.top-bar-spacer { flex: 1; }
.top-bar-btn {
  background: var(--bg-card); color: var(--text-muted);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 7px 12px; font-size: 11px; font-weight: 700; letter-spacing: 0.6px;
  text-transform: uppercase; cursor: pointer; text-decoration: none;
  font-family: var(--font); white-space: nowrap;
}
.top-bar-btn:hover { background: var(--bg-inset); }
.top-bar-btn.admin-btn { color: var(--text-muted); }
#btn-export {
  background: var(--accent-ink); color: #fff; border-color: var(--accent-ink);
}
#btn-export:hover { background: #1F2937; }
.top-bar-user {
  display: inline-flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-soft);
}
.user-email { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-logout {
  background: transparent; border: none; color: var(--text-faint);
  font-size: 11px; cursor: pointer; text-decoration: underline; font-family: var(--font);
  padding: 0;
}
.btn-logout:hover { color: var(--text-muted); }

/* ── Filter bar ───────────────────────────────── */
.filter-bar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.filter-bar-inner {
  max-width: 1440px; margin: 0 auto;
  padding: 10px 16px;
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
}
.filter-chips-row {
  display: inline-flex; gap: 6px; align-items: center;
  flex-wrap: nowrap; overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.filter-chips-row::-webkit-scrollbar { display: none; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  padding: 10px 12px; min-height: 44px; border-radius: 999px;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 12px; font-weight: 600;
  cursor: pointer; white-space: nowrap; font-family: var(--font);
}
.filter-chip:hover { background: var(--bg-inset); }
.filter-chip.active { background: var(--accent-ink); color: #fff; border-color: var(--accent-ink); }
.filter-chip-count {
  background: var(--bg-inset); color: #374151;
  padding: 0 7px; border-radius: 999px; font-size: 10px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.filter-chip.active .filter-chip-count {
  background: rgba(255,255,255,0.2); color: #fff;
}

#filter-categoria {
  font-family: var(--font); font-size: 12px;
  padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--bg-card); color: var(--text);
}
.filter-count {
  font-size: 11px; color: var(--text-muted); margin-left: auto;
  white-space: nowrap;
}
.filter-count strong { color: var(--text-muted); font-weight: 700; font-variant-numeric: tabular-nums; }

/* ── Main body ────────────────────────────────── */
#app-body { max-width: 1440px; margin: 0 auto; }

/* ── Store cards (mobile-first) ───────────────── */
.store-list {
  padding: 10px 12px 24px;
  display: flex; flex-direction: column; gap: 10px;
}
.store-card {
  background: var(--bg-card);
  border-radius: var(--r-xl); border: 1px solid var(--border);
  overflow: hidden; transition: border-color 0.15s;
}
.store-card.expanded { border-color: var(--text-ghost); box-shadow: var(--shadow-card); }
.store-card-head {
  padding: 12px 14px; display: flex; align-items: center; gap: 12px; cursor: pointer;
}
.store-logo {
  width: 44px; height: 44px; border-radius: var(--r-lg); flex-shrink: 0;
  background: var(--bg-card); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.store-logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.store-logo-initials {
  font-weight: 800; color: var(--text-soft); letter-spacing: 0.3px;
}
.store-head-main { flex: 1; min-width: 0; }
.store-head-title {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  font-size: 14px; font-weight: 700; color: var(--text);
}
.store-head-sub {
  font-size: 10px; color: var(--text-soft); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.store-head-rating-row { margin-top: 6px; display: flex; align-items: center; gap: 6px; }
.store-head-best {
  text-align: right; flex-shrink: 0;
}
.store-head-best-value {
  font-size: 18px; font-weight: 800; letter-spacing: -0.3px;
}
.store-head-best-program {
  font-size: 9px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; margin-top: 1px;
}

/* ── Store detail (expanded) — mobile vertical row list ── */
.store-detail {
  border-top: 1px dashed var(--border);
  background: var(--bg-pane);
}
.m-offer-list {
  padding: 6px 12px 12px;
  display: flex; flex-direction: column; gap: 0;
}
.m-offer-row {
  border: 1px solid var(--border-soft); border-left: 3px solid transparent;
  background: var(--bg-card); border-radius: var(--r-md);
  padding: 10px 12px; margin-top: 8px;
  cursor: pointer;
}
.m-offer-row.selected {
  border-color: transparent;
}
.m-offer-main {
  display: flex; align-items: center; gap: 8px;
}
.m-offer-crown { display: inline-flex; width: 11px; height: 11px; }
/* Program label + inline markers (Novo dot, promo flame) live in a flex
   group so the dot and flame render outside the truncation scope of the
   program label itself — otherwise overflow:hidden + text-overflow:ellipsis
   on .m-offer-program clipped the 6px inline-block dot on narrow viewports. */
.m-offer-program-group {
  display: flex; align-items: center; gap: 6px;
  flex: 1; min-width: 0;
}
.m-offer-program {
  font-size: 13px; font-weight: 800; letter-spacing: -0.1px; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.m-offer-value {
  font-size: 16px; font-weight: 800; letter-spacing: -0.3px; white-space: nowrap;
}
.m-offer-comment {
  margin-top: 4px; font-size: 11px; color: var(--text-soft); line-height: 1.4;
}
.m-offer-inline {
  background: var(--bg-pane);
  padding: 12px 14px 14px;
  border-top: 1px dashed var(--border);
  margin: 0 0 -1px 0; /* visually continuous with the row above */
}
.m-offer-hint {
  text-align: center; color: var(--text-soft);
  font-size: 11px; padding: 10px 8px; font-style: italic;
}

.detail-section { padding: 10px 14px; }
.detail-section-label {
  font-size: 9px; font-weight: 700; color: var(--text-faint);
  letter-spacing: 0.8px; text-transform: uppercase; margin-bottom: 6px;
  display: flex; justify-content: space-between; align-items: center;
}
.detail-section-hint { color: var(--text-ghost); font-weight: 500; letter-spacing: 0; font-size: 9px; }
.detail-card {
  background: var(--bg-card); border: 1px solid var(--border-soft); border-radius: var(--r-md);
  padding: 10px 12px; font-size: 11px; color: var(--text-muted); line-height: 1.5;
}
.detail-termos-text { font-size: 10.5px; color: var(--text-soft); }

.detail-cta-row {
  padding: 4px 14px 14px; display: flex; gap: 8px;
}
.detail-cta-primary {
  flex: 1; color: #fff; border: none;
  padding: 12px 0; min-height: 44px; border-radius: var(--r-lg);
  font-size: 12px; font-weight: 800; letter-spacing: 0.4px;
  cursor: pointer; text-align: center; font-family: var(--font); text-decoration: none;
}

/* ── Chart ────────────────────────────────────── */
.chart-wrap {
  border: 1px solid var(--border-soft); border-radius: var(--r-md);
  background: var(--bg-card);
  max-width: 100%;
  overflow: hidden;
}
/* chart-frame holds both the scrollable data SVG and the sticky Y-axis
   overlay. Positioned so the overlay can live absolute-layered on top. */
.chart-frame { position: relative; }
.chart-scroll {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg-card);
  max-width: 100%;
}
.chart-yaxis {
  position: absolute; left: 0; top: 0; z-index: 2;
  pointer-events: none; /* clicks pass through to the dots behind */
}
.chart-unavailable {
  padding: 30px 12px; text-align: center; font-size: 11px; color: var(--text-faint);
}

/* Floating tooltip that appears when a user clicks a data point. Auto-
   dismisses on next click or after ~3 s. position:fixed so it's anchored
   to the viewport — no scroll-offset math needed. */
.chart-tooltip {
  position: fixed; z-index: 1000;
  background: var(--accent-ink); color: #fff; border-radius: 6px;
  padding: 6px 10px; font-size: 11px; font-weight: 600; letter-spacing: 0.2px;
  display: flex; flex-direction: column; gap: 1px; align-items: center;
  box-shadow: 0 4px 12px rgba(15,23,42,0.18);
  pointer-events: none; white-space: nowrap;
}
.chart-tooltip strong { font-size: 13px; font-weight: 800; }
.chart-tooltip span { opacity: 0.75; font-size: 10px; letter-spacing: 0.4px; text-transform: uppercase; }
.chart-tooltip::after {
  content: ""; position: absolute; bottom: -5px; left: 50%; margin-left: -5px;
  border-left: 5px solid transparent; border-right: 5px solid transparent;
  border-top: 5px solid var(--accent-ink);
}

/* ── Inline markers (new dot + promo flame) ──── */
/* Amber dot next to a name/program to flag a new offer. Lives outside
   any media query so it renders on mobile AND desktop. */
.new-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent-amber); flex-shrink: 0;
  display: inline-block;
}
/* Inline flame next to a name/program to flag an active promo. No
   background — reads as part of the label, not as a separate badge. */
.flame {
  display: inline-block;
  font-size: 0.9em;
  vertical-align: baseline;
  line-height: 1;
}

.rating-pill {
  display: inline-flex; align-items: center; border-radius: 999px;
  font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase;
  font-size: 9px; padding: 2px 6px;
}
.rating-pill--excelente { background: #E5EDFC; color: #1844B8; }
.rating-pill--boa { background: #E3F5EB; color: #0A7A47; }
.rating-pill--regular { background: #F1F2F4; color: #4A5160; }

.crown-icon { width: 10px; height: 10px; display: inline-block; }

/* Program name as plain coloured text (no pill background). Shared by mobile
   rows and desktop offer list. */
.pane-offer-program {
  font-size: 12px; font-weight: 800; letter-spacing: -0.1px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}

/* ── Desktop two-pane ─────────────────────────── */
@media (min-width: 900px) {
  body { background: var(--bg-card); }
  .store-list { display: none; } /* mobile list hidden on desktop */

  .desktop-pane {
    max-width: 1440px; margin: 0 auto;
    display: grid; grid-template-columns: 380px 1fr;
    min-height: calc(100vh - 200px); /* fill below the top bar */
    background: var(--bg-card);
  }
  .pane-left {
    border-right: 1px solid var(--border); overflow-y: auto; background: var(--bg-card);
    max-height: calc(100vh - 140px);
  }
  .pane-right {
    overflow-y: auto; background: var(--bg-pane);
    max-height: calc(100vh - 140px);
  }
  .pane-row {
    padding: 12px 16px; border-bottom: 1px solid var(--border-softer);
    border-left: 3px solid transparent;
    display: flex; gap: 12px; align-items: center; cursor: pointer;
  }
  .pane-row:hover { background: #F9FAFB; }
  .pane-row.selected { background: #F7F9FC; }
  .pane-row-main { flex: 1; min-width: 0; }
  .pane-row-title {
    font-size: 13px; font-weight: 700; color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    display: flex; align-items: center; gap: 6px;
  }
  .pane-row-sub {
    font-size: 10px; color: var(--text-faint); margin-top: 2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .pane-row-best {
    text-align: right; flex-shrink: 0;
    display: flex; flex-direction: column; align-items: flex-end; gap: 3px;
  }
  .pane-row-best-value {
    font-size: 14px; font-weight: 800; color: var(--text); letter-spacing: -0.3px;
  }
  .pane-row-best-program {
    font-size: 9px; font-weight: 600; color: var(--text-faint);
    letter-spacing: 0.4px; text-transform: uppercase; margin-top: 1px;
  }
  .pane-right-header {
    padding: 20px 28px; background: var(--bg-card); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 16px;
  }
  .pane-right-header .store-logo { width: 56px; height: 56px; }
  .pane-right-title {
    margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -0.4px; color: var(--text);
    display: flex; align-items: center; gap: 8px;
  }
  .pane-right-sub { font-size: 12px; color: var(--text-soft); margin-top: 2px; }

  .pane-offers-label { padding: 16px 28px 8px; }
  .pane-offers {
    /* No margin here — the parent .pane-section already applies 28px padding,
       which matches the header + termos boxes above/below for clean alignment. */
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--r-md);
    overflow: hidden;
  }
  .pane-offer-row {
    display: grid; grid-template-columns: 20px 140px 1fr 88px 64px;
    gap: 14px; align-items: center;
    padding: 10px 14px; border-bottom: 1px solid var(--border-softer);
    border-left: 3px solid transparent; cursor: pointer;
    background: var(--bg-card); transition: background 0.1s;
  }
  .pane-offer-row:last-child { border-bottom: none; }
  .pane-offer-row:hover { background: var(--bg-pane); }
  .pane-offer-row.selected { border-left-width: 3px; }
  .pane-offer-comment {
    font-size: 11px; color: var(--text-soft);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .pane-offer-empty { color: var(--text-ghost); }
  .pane-offer-rating {
    display: inline-flex; justify-content: flex-start;
  }
  .pane-offer-rating .rating-pill { font-size: 10px; padding: 3px 8px; }
  .pane-offer-value {
    font-size: 16px; font-weight: 800; letter-spacing: -0.3px;
    min-width: 50px; text-align: right;
  }

  /* Inline chart + termos that sit directly beneath the selected program row,
     still inside the rounded `.pane-offers` container. */
  .pane-offer-inline {
    background: var(--bg-pane); border-top: 1px solid var(--border-softer);
    border-bottom: 1px solid var(--border-softer);
    padding: 14px 16px; display: flex; flex-direction: column; gap: 12px;
  }
  .pane-offer-inline:last-child { border-bottom: none; }
  .pane-offer-inline .pane-section-label { margin-bottom: 6px; }
  .pane-offer-inline .pane-card { font-size: 11px; }

  .pane-section { padding: 16px 28px 8px; }
  .pane-section:last-child { padding-bottom: 24px; }
  .pane-section-label {
    font-size: 10px; font-weight: 700; color: var(--text-faint);
    letter-spacing: 0.8px; text-transform: uppercase; margin-bottom: 8px;
  }
  .pane-card {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--r-md);
    padding: 14px 16px; font-size: 11.5px; color: var(--text-muted); line-height: 1.55;
  }
  .pane-cta-primary {
    color: #fff; border: none; padding: 10px 18px; min-height: 44px; border-radius: var(--r-sm);
    font-size: 12px; font-weight: 800; letter-spacing: 0.4px;
    cursor: pointer; font-family: var(--font); text-decoration: none;
    white-space: nowrap; display: inline-flex; align-items: center;
  }

  /* Desktop filter chip row has more breathing room */
  .filter-bar-inner { padding: 10px 24px; }
  .top-bar-inner { padding: 14px 24px; }
  .top-bar-title { font-size: 18px; }
}

@media (max-width: 899px) {
  .desktop-pane { display: none; }
  .top-bar-user { display: none; }
  .top-bar-btn.admin-btn, #btn-export { display: none; }
  .top-bar-spacer { display: none; }
  .top-bar-search { order: 3; flex-basis: 100%; margin-top: 8px; max-width: none; }
  .top-bar-inner { flex-wrap: wrap; }
}

/* ── Version tag (top-right) ──────────────────── */
.top-bar-version {
  font-size: 10px; color: var(--text-faint);
  font-variant-numeric: tabular-nums; letter-spacing: 0.4px;
  margin-left: 8px; white-space: nowrap;
}

.empty-state {
  padding: 60px 20px; text-align: center;
  font-size: 13px; color: var(--text-soft);
}
.empty-state code {
  background: var(--bg-inset); padding: 2px 6px; border-radius: 4px;
  font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 12px;
}

/* ── Accessibility ─────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent-ink);
  outline-offset: 2px;
  border-radius: inherit;
}
.filter-chip:focus-visible,
.pane-row:focus-visible,
.m-offer-row:focus-visible,
.pane-offer-row:focus-visible { outline-offset: -2px; }

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent-ink); color: #fff;
  padding: 10px 16px; font-weight: 700; font-size: 13px;
  text-decoration: none; z-index: 9999;
  border-radius: 0 0 var(--r-md) 0;
}
.skip-link:focus { left: 0; }

.app-toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--accent-ink); color: #fff;
  padding: 10px 16px; border-radius: var(--r-md); font-size: 12px; font-weight: 600;
  box-shadow: var(--shadow-pop); z-index: 9000;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}
