:root {
  --bg: #070a0f;
  --surface: #101820;
  --surface-2: #182230;
  --surface-3: #1f2d3f;
  --border: rgba(255, 255, 255, 0.09);
  --text: #f2f6fa;
  --muted: #94a3b8;
  --gold: #f0c94a;
  --gold-dim: #c9a020;
  --mint: #42e8a0;
  --red: #ff7070;
  --blue: #6eb4ff;
  --radius: 18px;
  --radius-sm: 12px;
  --font: "Montserrat", system-ui, -apple-system, sans-serif;
  --display: "Montserrat", system-ui, -apple-system, sans-serif;
  --wrap: min(1100px, calc(100% - 4rem));
  --section-gap: 2.75rem;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.7;
  font-weight: 400;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.wrap { width: var(--wrap); margin-inline: auto; }

.noise {
  position: fixed; inset: 0; opacity: 0.04; pointer-events: none; z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.glow { position: fixed; border-radius: 50%; filter: blur(120px); pointer-events: none; z-index: 0; }
.glow-a { width: 600px; height: 600px; top: -250px; left: 10%; background: rgba(110, 180, 255, 0.1); }
.glow-b { width: 500px; height: 500px; bottom: 0; right: 5%; background: rgba(240, 201, 74, 0.07); }

/* ── Header ── */
.header {
  position: sticky; top: 0; z-index: 50;
  border-bottom: 1px solid var(--border);
  background: rgba(7, 10, 15, 0.88);
  backdrop-filter: blur(20px);
}

.header-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.125rem 0;
}

.brand { display: flex; align-items: center; gap: 1rem; }

.brand-mark {
  width: 48px; height: 48px; border-radius: 12px;
  background: linear-gradient(145deg, var(--gold), var(--gold-dim));
  color: #070a0f; font-family: var(--display); font-weight: 800; font-size: 1.5rem;
  display: grid; place-items: center;
  box-shadow: 0 8px 28px rgba(240, 201, 74, 0.3);
}

.brand h1 {
  font-family: var(--display);
  font-size: 1.375rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.2;
}
.brand p { font-size: 0.875rem; font-weight: 500; color: var(--muted); margin-top: 0.2rem; line-height: 1.4; }

.status-pill {
  display: flex; align-items: center; gap: 0.625rem;
  padding: 0.5rem 1rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 0.8125rem; font-weight: 600;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.status-pill.live .status-dot { background: var(--mint); box-shadow: 0 0 10px var(--mint); }
.status-pill.demo .status-dot { background: var(--gold); }
.status-pill.error .status-dot { background: var(--red); }

/* ── Main ── */
.main {
  position: relative; z-index: 1;
  padding: 4rem 0 5rem;
  display: flex; flex-direction: column; gap: var(--section-gap);
}

/* ── Hero ── */
.hero {
  text-align: center;
  padding: 2rem 1rem 2.5rem;
  max-width: 760px;
  margin-inline: auto;
}

.eyebrow {
  font-size: 0.8125rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--gold); margin-bottom: 1.25rem;
}

.hero-title {
  font-family: var(--display);
  font-size: clamp(2.25rem, 5vw, 3.25rem);
  font-weight: 800;
  line-height: 1.28;
  letter-spacing: 0;
  margin-bottom: 1.5rem;
}

.hero-title em {
  font-style: normal;
  background: linear-gradient(100deg, var(--gold) 0%, #fff0b0 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}

.hero-lead {
  font-size: clamp(1rem, 2.2vw, 1.125rem);
  font-weight: 400;
  color: var(--muted);
  line-height: 1.75;
  max-width: 560px;
  margin-inline: auto;
}

/* ── Panels ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.25rem 2.5rem;
  box-shadow: 0 8px 48px rgba(0, 0, 0, 0.28);
}

/* ── Config strip ── */
.config-strip {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 2.5rem;
  align-items: end;
}

.config-item label {
  display: block; font-size: 0.8125rem; font-weight: 700;
  color: var(--muted); margin-bottom: 0.625rem; text-transform: uppercase; letter-spacing: 0.04em;
}

.config-item select {
  width: 100%; min-width: 200px;
  padding: 0.875rem 1rem;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-family: inherit; font-size: 1rem; cursor: pointer;
  transition: border-color 0.2s;
}
.config-item select:focus { outline: none; border-color: var(--gold); }

.config-label {
  display: block; font-size: 0.8125rem; font-weight: 700;
  color: var(--muted); margin-bottom: 0.625rem; text-transform: uppercase; letter-spacing: 0.04em;
}

.seg-control { display: flex; gap: 0.625rem; }

.seg-control label { cursor: pointer; flex: 1; }
.seg-control input { position: absolute; opacity: 0; pointer-events: none; }

.seg-control span {
  display: block; text-align: center;
  padding: 0.875rem 1.25rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2);
  font-size: 0.9375rem; font-weight: 500; transition: all 0.2s;
}

.seg-control input:checked + span {
  border-color: var(--gold); background: rgba(240, 201, 74, 0.12); color: var(--gold);
}

.config-hint { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; padding-bottom: 0.875rem; }

.hint-chip {
  font-size: 0.8125rem; font-weight: 600; padding: 0.45rem 0.875rem;
  border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}

/* ── Cards panel ── */
.panel-top {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1.5rem; margin-bottom: 1.75rem;
}

.panel-actions { display: flex; flex-wrap: wrap; gap: 0.625rem; justify-content: flex-end; align-items: center; }

.import-csv-label { cursor: pointer; margin: 0; }

.file-input-offscreen {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.import-status {
  font-size: 0.875rem; font-weight: 600; color: var(--mint);
  margin: -0.75rem 0 1.25rem;
}
.import-status.error { color: var(--red); }

.history-panel { margin-bottom: var(--section-gap); }

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.history-empty {
  font-size: 0.9375rem;
  color: var(--muted);
  padding: 0.5rem 0;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.2s;
}

.history-item:hover { border-color: rgba(240, 201, 74, 0.35); }

.history-item-main {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.history-item-label {
  font-weight: 700;
  font-size: 0.9375rem;
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-meta {
  font-size: 0.8125rem;
  color: var(--muted);
}

.history-item-total {
  font-weight: 800;
  font-size: 1.125rem;
  color: var(--gold);
  white-space: nowrap;
}

.history-item-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-history {
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.45rem 0.875rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.btn-history:hover { border-color: var(--gold); color: var(--gold); }

.btn-history.danger:hover { border-color: var(--red); color: var(--red); }

.saved-banner {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--mint);
  margin-bottom: 1rem;
}

.panel-heading {
  font-family: var(--display);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0;
  margin-bottom: 0.5rem;
}
.panel-sub { font-size: 0.9375rem; font-weight: 400; color: var(--muted); line-height: 1.5; }
.panel-sub code {
  font-family: var(--font); font-weight: 600; font-size: 0.875rem;
  color: var(--gold); background: var(--surface-2); padding: 0.15rem 0.45rem; border-radius: 4px;
}

.cards-list { display: flex; flex-direction: column; gap: 1.125rem; margin-bottom: 2.25rem; }

.card-item {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.875rem;
  padding: 1.375rem 1.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.card-item:focus-within {
  border-color: rgba(240, 201, 74, 0.4);
  box-shadow: 0 0 0 3px rgba(240, 201, 74, 0.08);
}

.card-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-num {
  font-family: var(--display);
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.btn-icon {
  background: none; border: none; color: var(--muted); font-size: 1.375rem;
  cursor: pointer; padding: 0.25rem 0.5rem; border-radius: 8px; line-height: 1;
  transition: color 0.15s, background 0.15s;
}
.btn-icon:hover { color: var(--red); background: rgba(255, 112, 112, 0.1); }

.card-item input[type="text"] {
  width: 100%;
  min-height: 52px;
  padding: 0.9375rem 1.125rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9375rem;
  font-weight: 500;
  letter-spacing: 0;
  transition: border-color 0.2s;
}
.card-item input:focus { outline: none; border-color: var(--gold); }
.card-item input::placeholder { color: var(--muted); opacity: 0.55; }

.foil-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  font-size: 0.875rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid transparent;
  transition: border-color 0.2s, background 0.2s;
  width: fit-content;
}

.foil-toggle:has(input:checked) {
  border-color: rgba(240, 201, 74, 0.25);
  background: rgba(240, 201, 74, 0.06);
  color: var(--text);
}

.foil-toggle input { width: 17px; height: 17px; accent-color: var(--gold); cursor: pointer; }

.foil-toggle.foil-locked {
  opacity: 0.85;
  pointer-events: none;
}

.foil-toggle.foil-locked input { cursor: default; }

@media (min-width: 720px) {
  .card-item {
    grid-template-columns: 7rem 1fr auto auto;
    grid-template-rows: auto;
    align-items: center;
    gap: 1rem 1.25rem;
    padding: 1.125rem 1.5rem;
  }

  .card-item-header {
    grid-column: 1;
    justify-content: flex-start;
  }

  .card-item-header .btn-icon { display: none; }

  .card-item .card-url {
    grid-column: 2;
  }

  .card-item .foil-toggle {
    grid-column: 3;
    white-space: nowrap;
  }

  .card-item .btn-remove-desktop {
    grid-column: 4;
    display: none;
  }

  .card-item-header .btn-remove { display: none; }
  .card-item .btn-remove-desktop { display: block; }
}

/* ── Buttons ── */
.cta-row { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; padding-top: 0.5rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.625rem;
  padding: 0.875rem 1.5rem; border-radius: var(--radius-sm);
  font-family: inherit; font-size: 1rem; font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer; border: none; transition: transform 0.12s, box-shadow 0.2s, opacity 0.15s;
}

.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-xl { padding: 1.125rem 2.25rem; font-size: 1.0625rem; min-width: 220px; }

.btn-primary {
  background: linear-gradient(145deg, var(--gold), var(--gold-dim));
  color: #070a0f; box-shadow: 0 6px 32px rgba(240, 201, 74, 0.28);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 8px 40px rgba(240, 201, 74, 0.4); }

.btn-secondary {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); padding: 1.125rem 1.75rem;
}
.btn-secondary:hover { border-color: var(--muted); }

.btn-outline {
  background: transparent; color: var(--text); border: 1px solid var(--border);
  font-size: 0.875rem; padding: 0.625rem 1.125rem; white-space: nowrap;
}
.btn-outline:hover { border-color: var(--gold); color: var(--gold); }

.btn-spinner {
  width: 1.125rem; height: 1.125rem;
  border: 2px solid rgba(7, 10, 15, 0.25); border-top-color: #070a0f;
  border-radius: 50%; animation: spin 0.7s linear infinite;
}

/* ── Loading ── */
.state-panel { animation: fadeUp 0.4s ease both; }

.state-box {
  text-align: center; padding: 2.5rem 2rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}

.state-box h3 {
  font-family: var(--display);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 0.625rem;
}
.state-box > p { color: var(--muted); font-size: 1rem; font-weight: 500; margin-bottom: 1.75rem; line-height: 1.5; }

.progress-wrap { margin-bottom: 1.75rem; text-align: left; }

.progress-track {
  height: 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold), var(--mint));
  border-radius: 999px;
  transition: width 0.35s ease;
  box-shadow: 0 0 16px rgba(240, 201, 74, 0.35);
}

.progress-meta {
  display: flex; flex-wrap: wrap; gap: 0.75rem 1.25rem;
  margin-top: 0.75rem;
  font-family: var(--font); font-size: 0.8125rem; font-weight: 600; color: var(--muted);
}

#progress-pct { color: var(--gold); font-weight: 500; min-width: 3rem; }
#progress-eta { margin-left: auto; color: var(--blue); }

.log-panel-wrap {
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  overflow: hidden;
}

.log-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem; font-weight: 700;
  letter-spacing: 0.03em; color: var(--muted);
}

.btn-log-clear {
  background: none; border: none; color: var(--muted);
  font-family: inherit; font-size: 0.8125rem; font-weight: 600; cursor: pointer;
  padding: 0.25rem 0.5rem; border-radius: 6px;
}
.btn-log-clear:hover { color: var(--text); background: rgba(255,255,255,0.05); }

.log-panel {
  max-height: 220px; overflow-y: auto;
  padding: 0.75rem 1rem;
  font-family: var(--font); font-size: 0.8125rem; font-weight: 500; line-height: 1.65;
}

.log-line {
  display: flex; gap: 0.625rem; padding: 0.2rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.log-line:last-child { border-bottom: none; }

.log-time { color: var(--muted); flex-shrink: 0; opacity: 0.7; }
.log-msg { word-break: break-word; }

.log-line.info .log-msg { color: var(--text); }
.log-line.success .log-msg { color: var(--mint); }
.log-line.warn .log-msg { color: var(--gold); }
.log-line.error .log-msg { color: var(--red); }

.log-panel:empty::after {
  content: "Esperando eventos…";
  color: var(--muted); opacity: 0.6;
}

/* ── Results ── */
.results { display: flex; flex-direction: column; gap: 1.75rem; animation: fadeUp 0.5s ease both; }

.total-banner {
  text-align: center; padding: 3rem 2rem;
  background: linear-gradient(160deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 48px rgba(0, 0, 0, 0.3);
}

.total-label {
  display: block; font-size: 0.875rem; font-weight: 700;
  letter-spacing: 0.04em; color: var(--muted); margin-bottom: 0.875rem;
}

.total-amount {
  display: block;
  font-family: var(--display);
  font-size: clamp(2.75rem, 8vw, 4.25rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: 0;
  color: var(--mint);
  text-shadow: 0 0 60px rgba(66, 232, 160, 0.25);
}

.total-savings { margin-top: 1rem; font-size: 1rem; font-weight: 600; color: var(--gold); line-height: 1.5; }

.metrics {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem;
}

.metric {
  padding: 1.375rem 1rem; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
}

.metric-k {
  font-size: 0.75rem; font-weight: 700;
  letter-spacing: 0.03em; color: var(--muted); margin-bottom: 0.5rem;
}
.metric-v { font-family: var(--display); font-size: 1.625rem; font-weight: 800; line-height: 1.2; }

.section-label {
  font-family: var(--display); font-size: 0.9375rem; font-weight: 700;
  letter-spacing: 0.02em; color: var(--muted);
}

.seller-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem;
}

.seller-card {
  padding: 1.5rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  border-left: 4px solid var(--gold);
}

.seller-name { font-size: 1.125rem; font-weight: 700; line-height: 1.35; display: flex; align-items: center; gap: 0.625rem; margin-bottom: 0.625rem; flex-wrap: wrap; }
.seller-meta { font-size: 0.9375rem; font-weight: 500; color: var(--muted); line-height: 1.65; }
.seller-actions { margin-top: 0.5rem; }
.seller-total { margin-top: 0.75rem; font-family: var(--display); font-size: 1.25rem; font-weight: 800; color: var(--mint); }

.table-panel { padding: 0; overflow: hidden; }
.table-scroll { overflow-x: auto; padding: 0.5rem 1.5rem 1.5rem; }

table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; min-width: 520px; }

th, td { text-align: left; padding: 1rem 0.75rem; border-bottom: 1px solid var(--border); line-height: 1.45; }
th {
  font-size: 0.75rem; font-weight: 700;
  letter-spacing: 0.03em; color: var(--muted);
  padding-top: 1.25rem;
}
td.price { font-family: var(--display); font-weight: 800; color: var(--mint); font-size: 1.0625rem; }
td.row-link { width: 2.5rem; text-align: center; }

.cm-link {
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid rgba(240, 201, 74, 0.35);
  transition: color 0.15s, border-color 0.15s;
}
.cm-link:hover {
  color: var(--gold);
  border-bottom-color: var(--gold);
}
.cm-link-sm {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--gold);
  border-bottom: none;
}
.cm-link-sm:hover { text-decoration: underline; }

.tag {
  display: inline-block; font-size: 0.75rem; font-weight: 700;
  padding: 0.25rem 0.55rem; border-radius: 6px;
  background: rgba(110, 180, 255, 0.15); color: var(--blue);
  letter-spacing: 0.02em;
}
.tag.foil { background: rgba(240, 201, 74, 0.15); color: var(--gold); }

.footnote { text-align: center; font-size: 0.875rem; font-weight: 500; color: var(--muted); line-height: 1.5; }

.error-box {
  padding: 1.25rem 1.5rem;
  background: rgba(255, 112, 112, 0.08); border: 1px solid rgba(255, 112, 112, 0.35);
  border-radius: var(--radius-sm);
}
.error-box strong { color: var(--red); display: block; margin-bottom: 0.375rem; font-size: 1rem; font-weight: 700; }
.error-box p { color: #ffc0c0; font-size: 0.9375rem; font-weight: 500; line-height: 1.65; white-space: pre-line; }

.footer { position: relative; z-index: 1; text-align: center; padding: 2rem 0 2.5rem; font-size: 0.875rem; font-weight: 500; color: var(--muted); }
.footer a { color: var(--gold); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

.hidden { display: none !important; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  :root { --wrap: calc(100% - 2rem); --section-gap: 2rem; }
  .config-strip { grid-template-columns: 1fr; gap: 1.75rem; }
  .config-hint { padding-bottom: 0; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .panel { padding: 1.75rem; }
  .main { padding: 2.5rem 0 3.5rem; }
  .hero { padding: 1rem 0 1.5rem; }
}

@media (max-width: 540px) {
  .panel-top { flex-direction: column; }
  .cta-row { flex-direction: column; align-items: stretch; }
  .btn-xl { width: 100%; min-width: unset; }
  .metrics { grid-template-columns: 1fr 1fr; }
}
