/* Temas: rosa (predeterminado), oscuro y neutro. Se eligen en Configuración.
   --logo-*: colores del logo (fondo, etiqueta y símbolo %) en cada tema. */
:root { --radius: 14px; }

:root[data-theme="oscuro"] {
  --bg: #0e1513;
  --surface: #17211e;
  --text: #e8efed;
  --muted: #9aaba6;
  --border: #2b3a36;
  --accent: #2dd4bf;
  --accent-text: #062a25;
  --accent-soft: #123a34;
  --warn: #f5b84d;
  --warn-soft: #3a2c12;
  --manual: #c4a5ff;
  --manual-soft: #2c2142;
  --danger: #ff8a7a;
  --gain: #4ade80;
  --backdrop: rgba(0, 0, 0, 0.6);
  --logo-bg: #2dd4bf;
  --logo-tag: #13201a;
  --logo-sym: #ffffff;
  color-scheme: dark;
}

:root,
:root[data-theme="rosa"] {
  --bg: #fdf3f8;
  --surface: #ffffff;
  --text: #2d0f24;
  --muted: #775a6b;
  --border: #f3d2e4;
  --accent: #e91e8f;
  --accent-text: #ffffff;
  --accent-soft: #fde3f1;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --manual: #6d3fc0;
  --manual-soft: #efe8fb;
  --danger: #b42318;
  --gain: #0f7a45;
  --backdrop: rgba(45, 15, 36, 0.45);
  --logo-bg: #e91e8f;
  --logo-tag: #13201a;
  --logo-sym: #ffffff;
  color-scheme: light;
}

:root[data-theme="neutro"] {
  --bg: #f4f4f5;
  --surface: #ffffff;
  --text: #18181b;
  --muted: #61616a;
  --border: #dcdce0;
  --accent: #27272a;
  --accent-text: #ffffff;
  --accent-soft: #e9e9ec;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --manual: #6d3fc0;
  --manual-soft: #efe8fb;
  --danger: #b42318;
  --gain: #0f7a45;
  --backdrop: rgba(24, 24, 27, 0.45);
  --logo-bg: #27272a;
  --logo-tag: #f4f4f5;
  --logo-sym: #27272a;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Poppins", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.4;
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(6px + env(safe-area-inset-top)) 8px 0 16px;
}
.topbar h1 { margin: 0; font-size: 1.15rem; display: flex; align-items: center; gap: 8px; }
.logo {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  --mm-fondo: var(--logo-bg);
  --mm-etiqueta: var(--logo-tag);
  --mm-simbolo: var(--logo-sym);
}

.icon-btn {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:active { background: var(--accent-soft); }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 4px 16px 32px;
  display: grid;
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.card h2 { margin: 0 0 10px; font-size: 1rem; color: var(--muted); }

.label { display: block; font-size: 0.95rem; font-weight: 500; color: var(--muted); margin-bottom: 6px; }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* Campos */
.field {
  display: flex;
  align-items: center;
  min-height: 56px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  padding: 0 12px;
  gap: 6px;
  flex: 1;
  min-width: 0;
}
.field:focus-within { border-color: var(--accent); }
.field[data-invalid] { border-color: var(--danger); }
.field input {
  flex: 1;
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
  padding: 12px 0;
}
.field input::placeholder { color: var(--muted); opacity: 0.7; }
.affix { color: var(--muted); font-weight: 500; font-size: 1.05rem; }

.field-big { min-height: 72px; padding-right: 6px; }
.field-big input { font-size: 2.2rem; font-weight: 700; }
.field-big .affix { font-size: 1.3rem; }

/* Botones */
.btn, .btn-clear {
  min-height: 52px;
  border-radius: 12px;
  border: 0;
  font: inherit;
  font-weight: 700;
  padding: 0 16px;
  cursor: pointer;
  touch-action: manipulation;
}
.btn { background: var(--accent); color: var(--accent-text); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-clear { background: var(--accent-soft); color: var(--accent); min-height: 58px; }
.btn:active, .btn-clear:active { transform: scale(0.97); }

.summary {
  margin-top: 10px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.88rem;
  padding: 4px 2px;
}
.tag-offline {
  flex: 0 0 auto;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--warn);
  background: var(--warn-soft);
  border-radius: 999px;
  padding: 2px 8px;
}

/* Resultado */
.result { border-color: var(--accent); border-width: 2px; }
.real-cost {
  font-size: clamp(2.6rem, 12vw, 3.4rem);
  font-weight: 700;
  line-height: 1.1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.hint {
  display: block;
  margin: 6px 0 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  text-align: left;
  color: var(--warn);
  font-weight: 500;
  cursor: pointer;
}
.hint[hidden] { display: none; }

.breakdown-box { margin-top: 8px; }
.breakdown-box summary {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 6px 0;
  cursor: pointer;
  list-style-position: inside;
}
.breakdown { margin: 6px 0 0; display: grid; gap: 6px; font-size: 0.95rem; }
.breakdown div { display: flex; justify-content: space-between; gap: 12px; }
.breakdown dt { color: var(--muted); }
.breakdown dd { margin: 0; font-weight: 500; font-variant-numeric: tabular-nums; text-align: right; }
.breakdown .total { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 2px; }
.breakdown .total dt, .breakdown .total dd { color: var(--text); font-weight: 700; }

/* Precios sugeridos */
.suggest { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.suggest li {
  display: grid;
  /* Dos columnas grandes: precio de venta | ganancia */
  grid-template-columns: 1fr 1fr;
  grid-template-areas: "pct glabel" "price profit";
  align-items: end;
  column-gap: 12px;
  row-gap: 2px;
  padding: 10px 14px 12px;
  border-radius: 12px;
  background: var(--bg);
}
.pct {
  min-width: 58px;
  text-align: center;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 4px 6px;
}
.pct { grid-area: pct; justify-self: start; }
.gain-label { grid-area: glabel; font-size: 0.95rem; font-weight: 500; color: var(--muted); }
.sale-price {
  grid-area: price;
  font-size: clamp(1.45rem, 7.2vw, 1.85rem);
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.sale-profit {
  grid-area: profit;
  font-size: clamp(1.15rem, 5.6vw, 1.4rem);
  font-weight: 700;
  line-height: 1.2;
  color: var(--gain);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Margen libre con barra deslizable */
.custom { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.custom .label { margin-bottom: 8px; }
.custom-result {
  display: grid;
  /* Dos columnas grandes: precio de venta | ganancia */
  grid-template-columns: 1fr 1fr;
  grid-template-areas: "pct glabel" "price profit";
  align-items: end;
  column-gap: 12px;
  row-gap: 2px;
  padding: 10px 14px 12px;
  border-radius: 12px;
  border: 2px solid var(--accent);
}
.slider-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.step-btn {
  flex: 0 0 48px;
  height: 48px;
  border-radius: 12px;
  border: 0;
  background: var(--accent-soft);
  color: var(--accent);
  font: inherit;
  font-size: 1.5rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.step-btn:active { transform: scale(0.94); }

.range {
  flex: 1;
  min-width: 0;
  height: 48px;
  margin: 0;
  background: transparent;
  accent-color: var(--accent);
  -webkit-appearance: none;
  appearance: none;
  touch-action: pan-y;
}
.range::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) var(--fill, 0%), var(--border) var(--fill, 0%));
}
.range::-moz-range-track { height: 8px; border-radius: 999px; background: var(--border); }
.range::-moz-range-progress { height: 8px; border-radius: 999px; background: var(--accent); }
.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 32px;
  height: 32px;
  margin-top: -12px;
  border-radius: 50%;
  background: var(--accent);
  border: 4px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
.range::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  border: 4px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
.range:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* Selector de tema */
.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.theme-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 72px;
  padding: 10px 6px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.theme-opt[aria-checked="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
/* Mini vista del tema: fondo, tarjeta, renglón de texto y renglón de color. */
.swatch {
  width: 100%;
  max-width: 76px;
  height: 46px;
  padding: 6px;
  border-radius: 9px;
  background: var(--sw-bg);
  border: 1px solid rgba(127, 127, 127, 0.35);
}
.sw-card {
  display: grid;
  align-content: center;
  gap: 5px;
  height: 100%;
  padding: 0 6px;
  border-radius: 5px;
  background: var(--sw-surface);
}
.sw-line { height: 4px; width: 55%; border-radius: 999px; background: var(--sw-muted); }
.sw-accent { height: 8px; width: 85%; border-radius: 999px; background: var(--sw-accent); }

/* Modal de configuración (hoja inferior) */
.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  color: var(--text);
  overflow-y: auto;
}
.sheet::backdrop { background: var(--backdrop); }
@media (min-width: 600px) {
  .sheet { margin: auto; border-radius: 20px; }
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.sheet-head h2 { margin: 0; font-size: 1.15rem; }

.sheet-title { margin: 4px 0 4px; font-size: 1.3rem; }
.intro { margin: 0 0 14px; color: var(--muted); }

.keep-summary { margin: 0; display: grid; gap: 2px; background: var(--bg); border-radius: 12px; padding: 6px 14px; }
.keep-summary div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 8px 0; }
.keep-summary div + div { border-top: 1px solid var(--border); }
.keep-summary dt { color: var(--muted); white-space: nowrap; }
.keep-summary dd { margin: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.keep-summary small { display: block; font-weight: 500; color: var(--muted); white-space: nowrap; }

.keep-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; margin-top: 16px; }
.keep-actions button { min-height: 58px; font-size: 1.05rem; }
.btn-secondary {
  border-radius: 12px;
  border: 2px solid var(--border);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.btn-secondary:active { transform: scale(0.97); }

.setting + .setting, .status + .setting { margin-top: 16px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.rate-row { display: flex; gap: 8px; align-items: stretch; }
.rate-row .btn { min-height: 56px; }
.rate-row .field[data-empty] { border-color: var(--warn); }

.margins { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.margins .field { padding: 0 8px; gap: 2px; }
.margins input { font-size: 1.1rem; text-align: right; }

.status { margin: 6px 0 0; font-size: 0.88rem; color: var(--muted); }
.status.warn { color: var(--warn); font-weight: 500; }
.note {
  margin: 8px 0 0;
  font-size: 0.85rem;
  color: var(--warn);
  background: var(--warn-soft);
  border-radius: 8px;
  padding: 6px 10px;
}

.badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: 999px;
  padding: 3px 10px;
  margin-bottom: 6px;
  background: var(--accent-soft);
  color: var(--accent);
}
.badge.manual { background: var(--manual-soft); color: var(--manual); }

/* ---------- Licencia ---------- */
[hidden] { display: none !important; }

/* Mientras se verifica el pase no se muestra nada; en la puerta, la calculadora se oculta. */
body[data-vista="cargando"] main,
body[data-vista="cargando"] .topbar,
body[data-vista="puerta"] main,
body[data-vista="puerta"] .topbar { display: none; }
.puerta { display: none; }
body[data-vista="puerta"] .puerta { display: flex; }

.puerta {
  flex-direction: column;
  justify-content: center;
  max-width: 440px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(32px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
}
.puerta-logo { display: flex; justify-content: center; margin-bottom: 20px; }
.puerta-logo .logo { width: 88px; height: 88px; }
.puerta-vista { display: grid; gap: 12px; }
.puerta-titulo { margin: 0; font-size: 1.6rem; line-height: 1.25; text-align: center; }
.puerta-texto { margin: 0 0 8px; color: var(--muted); font-size: 1.05rem; text-align: center; }
.puerta-msg {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--warn-soft);
  color: var(--warn);
  font-weight: 500;
}
.puerta-link { padding: 12px; color: var(--accent); font-weight: 500; text-align: center; }

.btn-grande { width: 100%; min-height: 58px; font-size: 1.1rem; }
a.btn, a.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  text-align: center;
  text-decoration: none;
}
.btn:disabled, .btn-secondary:disabled { opacity: 0.6; cursor: progress; }

.field-codigo .affix { font-size: 1.3rem; }
.field-codigo input { font-size: 1.5rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }

/* Avisos dentro de la calculadora */
.avisos { display: grid; gap: 8px; }
.avisos:empty { display: none; }
.aviso {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}
.aviso p { flex: 1; margin: 0; font-weight: 500; }
.aviso-urgente { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }
.aviso-accion {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}
.aviso-cerrar {
  flex: 0 0 44px;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
}

.keep-actions a { min-height: 58px; font-size: 1.05rem; }

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
