:root {
  --bg: #f6f3ef;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --text: #1f1a1c;
  --muted: #6f6569;
  --border: #e6dfd8;
  --accent: #8a2846;
  --accent-ink: #ffffff;
  --accent-soft: #f6e8ed;
  --pos: #1f7a4d;
  --pos-soft: #e5f4ec;
  --neg: #b4322b;
  --warn-soft: #fdf2e1;
  --warn-ink: #7a4b0c;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(31 26 28 / 6%), 0 4px 16px rgb(31 26 28 / 5%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171315;
    --surface: #211b1e;
    --surface-2: #1c1719;
    --text: #f1eaec;
    --muted: #a99ca1;
    --border: #3a3034;
    --accent: #e0789a;
    --accent-ink: #1b1013;
    --accent-soft: #3a2029;
    --pos: #5fcf95;
    --pos-soft: #183326;
    --neg: #f07d73;
    --warn-soft: #3a2c15;
    --warn-ink: #f2c77f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 28px; letter-spacing: -0.01em; }
h2 { font-size: 18px; margin-bottom: 4px; }
small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.muted { color: var(--muted); }
.hint { color: var(--muted); margin: 4px 0 14px; }
.footnote { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

/* ---------- Layout ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
.brand span { font-weight: 400; color: var(--muted); }
.topbar-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

main { max-width: 1180px; margin: 0 auto; padding: 24px 24px 64px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
#resultados { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

.hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.eyebrow { margin: 0 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); font-weight: 600; }
.hero .muted { margin: 4px 0 0; }
.hero .notas { margin: 6px 0 0; white-space: pre-line; }
textarea {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
  width: 100%; resize: vertical;
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }

.welcome { max-width: 640px; margin: 48px auto; text-align: center; }
.welcome p { color: var(--muted); }
.row-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }

/* ---------- Controles ---------- */

.btn {
  font: inherit; font-weight: 600; font-size: 14px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.danger { color: var(--neg); background: transparent; }
.btn.add { margin-top: 10px; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); text-decoration: underline; cursor: pointer; }
.icon-btn {
  width: 28px; height: 28px; border-radius: 6px;
  border: 1px solid transparent; background: transparent; color: var(--muted);
  font-size: 18px; line-height: 1; cursor: pointer;
}
.icon-btn:hover { color: var(--neg); border-color: var(--border); }

input, select {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }
input[type="number"] { text-align: right; font-variant-numeric: tabular-nums; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field span { font-weight: 600; font-size: 14px; }
.field input { width: 100%; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }

.inline-tool { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 12px; }
.inline-tool input { width: 80px; }

/* ---------- Asistente de configuración ---------- */

.setup { max-width: 760px; width: 100%; margin: 0 auto; }
.stepper { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 22px; }
.step {
  display: flex; align-items: center; gap: 8px;
  padding: 8px; border-radius: 8px;
  border: 1px solid var(--border); background: transparent; color: var(--muted);
  font: inherit; font-size: 13px; text-align: left; cursor: pointer;
}
.step-n {
  flex: none; display: grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--border); font-weight: 700;
}
.step.active { border-color: var(--accent); color: var(--text); background: var(--accent-soft); }
.step.active .step-n { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.step-body h2 { margin-bottom: 4px; }
.step-nav { display: flex; justify-content: space-between; margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--border); }
.danger-zone { margin-top: 18px; }

.fase-toggles { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.check {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-weight: 600; font-size: 14px; cursor: pointer;
}
.check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.check input { accent-color: var(--accent); margin: 0; }

/* ---------- Pestañas de fase ---------- */

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin: 4px 0 12px; border-bottom: 1px solid var(--border); }
.tab {
  font: inherit; font-weight: 600; font-size: 14px;
  padding: 8px 14px; margin-bottom: -1px;
  background: transparent; color: var(--muted);
  border: 1px solid transparent; border-radius: 8px 8px 0 0; cursor: pointer;
  text-align: left;
}
.tab small { font-weight: 400; }
.tab.active { color: var(--text); border-color: var(--border); border-bottom-color: var(--surface); background: var(--surface); }
.tab.active small { color: var(--accent); }

/* ---------- Tablas ---------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody th { font-weight: 600; }
tfoot th, tfoot td { border-bottom: 0; border-top: 2px solid var(--border); font-weight: 600; }
tfoot tr + tr th, tfoot tr + tr td { border-top: 1px solid var(--border); }
.num { text-align: right; white-space: nowrap; }
.empty-row { color: var(--muted); text-align: center; padding: 18px; }

table.edit input { width: 100%; }
table.edit td.num { width: 170px; }
table.edit .icon-cell { width: 40px; text-align: center; }

table.matrix input { width: 76px; padding: 6px 8px; }
table.matrix thead th small { text-transform: none; letter-spacing: 0; }
table.matrix tbody th { white-space: nowrap; }
table.matrix tr.directa th, table.matrix tr.directa td { background: var(--surface-2); }

table.results .rank { color: var(--muted); width: 32px; }
table.results .total { font-weight: 700; color: var(--accent); font-size: 16px; }
table.results tbody th { white-space: nowrap; }
table.results small.up { color: var(--pos); font-weight: 600; }
.badge {
  display: inline-block; padding: 1px 6px; border-radius: 99px;
  background: var(--pos-soft); color: var(--pos); font-size: 11px; font-weight: 700; white-space: nowrap;
}
.meta-next { font-size: 13px; color: var(--muted); white-space: nowrap; }
.meta-next strong { color: var(--text); }
.meta-next.done { color: var(--pos); font-weight: 600; }
table.sim tbody td strong { font-size: 15px; }

/* ---------- KPIs y cobertura ---------- */

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi {
  display: grid; gap: 2px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px;
}
.kpi-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.kpi strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--muted); }
.kpi.pos strong { color: var(--pos); }
.kpi.neg strong { color: var(--neg); }

.coverage { display: grid; gap: 10px; }
.coverage-head { display: flex; justify-content: space-between; font-weight: 600; }
.bar { height: 10px; border-radius: 99px; background: var(--border); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.3s; }

.banner { padding: 12px 16px; border-radius: 10px; border: 1px solid transparent; }
.banner.warn { background: var(--warn-soft); color: var(--warn-ink); }
.banner.ok { background: var(--pos-soft); color: var(--pos); }
.banner strong { margin-right: 4px; }

/* ---------- Simulación ---------- */

.sim-controls { display: flex; flex-wrap: wrap; gap: 4px 20px; align-items: center; margin-top: 10px; }
.sim-controls .inline-tool { margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 4px 4px 10px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 13px;
}
.chip button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 15px; line-height: 1; padding: 0 4px; }

/* ---------- Vista para compartir (horizontal, para pantallazo en computadora) ---------- */

body.sharing .topbar { display: none; }
body.sharing main { max-width: 1320px; padding: 16px 32px 20px; }

.share-exit {
  position: fixed; top: 8px; right: 8px; z-index: 5;
  width: 28px; height: 28px; border-radius: 50%;
  border: 0; background: transparent; color: var(--muted);
  font-size: 14px; line-height: 1; cursor: pointer;
  opacity: 0.25; transition: opacity 0.15s;
}
.share-exit:hover, .share-exit:focus-visible { opacity: 1; background: var(--surface); }

.share { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }

.sh-head {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 24px;
  padding: 16px 26px;
  border-radius: 16px;
  background: linear-gradient(120deg, #8a2846, #5b1a35);
  color: #fff;
}
.sh-head h1 { font-size: 28px; color: #fff; }
.sh-club { margin: 0 0 6px; font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.8; font-weight: 600; }
.sh-date { margin: 0; text-align: right; font-size: 13px; opacity: 0.85; display: grid; }
.sh-date strong { font-size: 17px; opacity: 1; }

.sh-summary { display: grid; grid-template-columns: repeat(3, minmax(150px, 0.6fr)) minmax(260px, 1.4fr); gap: 12px; }
.sh-stat {
  display: grid; align-content: center; gap: 2px;
  padding: 10px 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border);
}
.sh-stat span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.sh-stat strong { font-size: 24px; font-variant-numeric: tabular-nums; }
.sh-progress { height: 6px; border-radius: 99px; background: var(--border); overflow: hidden; margin-top: 4px; }
.sh-progress span { display: block; height: 100%; border-radius: 99px; background: var(--accent); }

.sh-status { align-self: stretch; display: block; padding: 12px 18px; border-radius: 12px; font-size: 15px; line-height: 1.4; }
.sh-status.warn { background: var(--warn-soft); color: var(--warn-ink); }
.sh-status.ok { background: var(--pos-soft); color: var(--pos); }

.sh-table {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  border-collapse: separate; border-spacing: 0; overflow: hidden;
  font-size: 15px;
}
.sh-table th, .sh-table td { padding: 7px 14px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
.sh-table tbody tr:last-child > * { border-bottom: 0; }
.sh-table .left, .sh-table tbody th { text-align: left; }
.sh-table thead th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.sh-table tr.sh-groups th { width: auto; text-align: left; font-size: 12px; color: var(--text); border-bottom: 0; padding-top: 12px; padding-bottom: 2px; }
.sh-groups .g-sim { color: var(--pos); }
.sh-groups .g-meta { color: var(--accent); }
.sh-table tbody th { font-size: 16px; }
.sh-table td:first-child, .sh-table th:first-child { width: 44px; text-align: center; }
.sh-pos {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; font-weight: 700; color: var(--muted);
}
.sh-table tr.first .sh-pos { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.sh-table tr.first > * { background: var(--accent-soft); }
.sh-total { font-weight: 800; font-size: 17px; color: var(--accent); }
.sh-sc { color: var(--pos); font-weight: 600; }
.sh-table .sep { border-left: 2px solid var(--border); }
.sh-meta { text-align: left !important; font-size: 13px; color: var(--muted); border-left: 2px solid var(--border); }
.sh-meta strong { color: var(--accent); }
.sh-meta.done { color: var(--pos); font-weight: 600; }

.sh-foot { font-size: 14px; color: var(--muted); text-align: center; }
.sh-foot strong { color: var(--text); }

@media (max-width: 900px) {
  body.sharing main { padding: 16px; }
  .sh-summary { grid-template-columns: repeat(3, 1fr); }
  .sh-status { grid-column: 1 / -1; }
  .sh-head { flex-direction: column; align-items: flex-start; }
  .sh-date { text-align: left; }
  .sh-head h1 { font-size: 24px; }
  .sh-stat strong { font-size: 18px; }
}

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Móvil ---------- */

@media (max-width: 640px) {
  .topbar { padding: 10px 16px; }
  main { padding: 16px 16px 64px; }
  h1 { font-size: 22px; }
  .card { padding: 16px; }
  .stepper { grid-template-columns: repeat(5, auto); }
  .step-label { display: none; }
  .step.active .step-label { display: inline; }
  table.edit td.num { width: 120px; }
}

@media print {
  .no-shot, .topbar, .share-exit { display: none !important; }
  body { background: #fff; }
}
