:root{
  --ml-yellow:#ffe600;
  --ml-blue:#3483fa;
  --ml-blue-2:#2d6ee6;
  --ml-green:#00a650;

  --text:#1f2937;
  --muted:#6b7280;
  --border:rgba(15,23,42,.12);
  --bg:#f6f7fb;
  --card:#ffffff;

  --shadow: 0 10px 30px rgba(2,6,23,.08);
  --shadow2: 0 18px 55px rgba(2,6,23,.14);

  --radius:18px;
  --radius2:22px;
  --max: 1240px;

  --ring: 0 0 0 4px rgba(52,131,250,.18);

  /* capas */
  --z-bg: 0;
  --z-content: 10;
  --z-topbar: 50;
  --z-overlay: 100;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color:var(--text);
  background:var(--bg);
  overflow-x:hidden;
  -webkit-tap-highlight-color: transparent;

  /* stacking context estable (evita “z-index raro”) */
  position: relative;
  isolation: isolate;
}

/* ===== Topbar ===== */
.topbar{
  position:sticky;
  top:0;
  z-index: var(--z-topbar);
  padding: env(safe-area-inset-top) 0 0 0;
  background:var(--ml-yellow);
  border-bottom:1px solid rgba(0,0,0,.10);
  transform: translateZ(0);
}
.topbar-inner{
  max-width:var(--max);
  margin:0 auto;
  padding: 10px 14px;
  display:flex;
  align-items:center;
  gap:12px;
}
.brand{display:flex;align-items:center;gap:10px;min-width:0}
.logo{
  width:38px;height:38px;border-radius:14px;
  background: linear-gradient(135deg, var(--ml-blue), rgba(110,231,255,.95));
  display:grid;place-items:center;
  color:white;
  box-shadow: 0 10px 22px rgba(52,131,250,.20);
  font-weight:950;
  flex:0 0 auto;
}
.brand-text{display:flex;flex-direction:column;gap:2px;min-width:0}
.brand-text .t1{font-size:14px;font-weight:950;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.brand-text .t2{font-size:12px;color: rgba(0,0,0,.60);font-weight:800;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}

.pill{
  margin-left:auto;
  display:inline-flex;
  align-items:center;
  gap:8px;
  font-size:12.5px;
  color: rgba(0,0,0,.86);
  background: rgba(255,255,255,.8);
  padding:8px 10px;
  border-radius:999px;
  border:1px solid rgba(0,0,0,.10);
  user-select:none;
  white-space:nowrap;
  box-shadow: 0 10px 22px rgba(0,0,0,.08);
}
.dot{
  width:9px;height:9px;border-radius:50%;
  background: rgba(239,68,68,.95);
  box-shadow: 0 0 0 3px rgba(239,68,68,.18);
}
.dot.ok{
  background: rgba(0,166,80,.95);
  box-shadow: 0 0 0 3px rgba(0,166,80,.18);
}

/* ===== Layout ===== */
.wrap{
  max-width:var(--max);
  margin: 14px auto 22px auto;
  padding: 0 14px calc(18px + env(safe-area-inset-bottom));
  position: relative;
  z-index: var(--z-content);
}
.layout{
  display:grid;
  grid-template-columns: 1fr;
  gap:14px;
  align-items:start;
}
@media(min-width: 980px){
  .layout{ grid-template-columns: 360px 1fr; gap:16px; }
}

/* ===== Cards ===== */
.card{
  background: var(--card);
  border:1px solid var(--border);
  border-radius: var(--radius2);
  box-shadow: var(--shadow);
  overflow:hidden;
  position: relative;
  z-index: var(--z-content);
}
.card-header{
  padding:16px 16px 10px 16px;
  border-bottom: 1px solid var(--border);
}
.card-title{
  margin:0;
  font-size:15px;
  font-weight:950;
  color: rgba(0,0,0,.88);
}
.card-sub{
  margin:7px 0 0 0;
  color: rgba(0,0,0,.62);
  font-size:13px;
  line-height:1.45;
}
.card-body{ padding: 14px 16px 16px 16px; }
.sticky{ position:sticky; top: 74px; }

/* ===== Forms ===== */
.stack{ display:flex; flex-direction:column; gap:12px; }
.row{ display:flex; gap:10px; align-items:center; }
label{ font-size:12.5px; color: rgba(0,0,0,.62); font-weight:800; }
.field{ position:relative; width:100%; }
.field input{
  width:100%;
  padding:12px 12px;
  border-radius:14px;
  border:1px solid var(--border);
  outline:none;
  font-size:14px;
  background:#fff;
  color: rgba(0,0,0,.88);
}
.field input:focus{
  border-color: rgba(52,131,250,.7);
  box-shadow: var(--ring);
}
.hint{
  font-size:12px;
  color: rgba(0,0,0,.55);
  margin-top:8px;
  line-height:1.35;
}
.muted{
  font-size:12px;
  color: rgba(0,0,0,.56);
  line-height:1.35;
}

/* ===== Buttons ===== */
.btn{
  cursor:pointer;
  border:0;
  border-radius:14px;
  padding:12px 14px;
  font-weight:950;
  font-size:14px;
  transition: transform .12s ease, opacity .12s ease;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:10px;
  user-select:none;
  min-height:44px;
  white-space:nowrap;
}
.btn:active{ transform: scale(.985); }
.btn:disabled{ opacity:.55; cursor:not-allowed; }
.btn-sm{ min-height:36px; padding:9px 12px; font-size:13px; border-radius:12px; }

.btn-primary{
  background: linear-gradient(135deg, var(--ml-blue), rgba(110,231,255,.9));
  color: rgba(255,255,255,.98);
  box-shadow: 0 10px 22px rgba(52,131,250,.14);
}
.btn-ghost{
  background:#fff;
  color: rgba(0,0,0,.86);
  border: 1px solid var(--border);
}
.btn-dark{
  background: linear-gradient(135deg, #0f172a, #334155);
  color:#fff;
  box-shadow: 0 10px 22px rgba(0,0,0,.10);
}

.icon-btn{
  width:44px;height:44px;border-radius:14px;
  display:grid;place-items:center;
  cursor:pointer;
  border:1px solid var(--border);
  background:#fff;
  color: rgba(0,0,0,.86);
  user-select:none;
}
.icon-btn:active{ transform: scale(.985); }

/* ===== Search block (categoría + búsqueda compacta) ===== */
.search-block{
  padding: 12px;
  border-radius: 18px;
  border: 1px solid rgba(52,131,250,.16);
  background: rgba(52,131,250,.06);
}

.btn-chip{
  padding: 10px 12px;
  min-height: 44px;
  border-radius: 16px;
  flex: 1 1 auto;
}
.btn-chip .chip-label{
  display:block;
  max-width: 100%;
  overflow:hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.searchbar{
  width:100%;
  display:flex;
  align-items:center;
  gap:10px;
  padding: 10px;
  border-radius: 18px;
  border: 1px solid rgba(52,131,250,.22);
  background: rgba(255,255,255,.92);
  box-shadow: 0 10px 22px rgba(52,131,250,.10);
}
.search-toggle{
  width:44px;height:44px;
  border-radius: 16px;
  border: 1px solid rgba(52,131,250,.22);
  background: rgba(52,131,250,.10);
  color: rgba(52,131,250,.95);
  cursor:pointer;
  font-weight: 1000;
}
.search-toggle:active{ transform: scale(.985); }

.searchbar input{
  border: 0;
  outline: none;
  width: 100%;
  font-size: 14px;
  background: transparent;
  color: rgba(0,0,0,.90);
}

/* Colapsado: solo botón, input “se abre” para aprovechar espacio */
.searchbar.collapsed{
  padding: 8px;
  justify-content:flex-start;
}
.searchbar.collapsed input{
  width: 0;
  min-width: 0;
  opacity: 0;
  pointer-events: none;
}

.searchbar.expanded input{
  opacity: 1;
  pointer-events: auto;
}

/* ===== Toast ===== */
.toast{
  font-size:12.5px;
  padding:10px 12px;
  border-radius:14px;
  border:1px solid rgba(15,23,42,.10);
  background: rgba(15,23,42,.03);
  color: rgba(15,23,42,.86);
}
.toast.ok{ background: rgba(0,166,80,.10); border-color: rgba(0,166,80,.20); color: rgba(0,166,80,.95); font-weight:900; }
.toast.warn{ background: rgba(245,158,11,.12); border-color: rgba(245,158,11,.22); color: rgba(146,64,14,.95); font-weight:900; }
.toast.error{ background: rgba(239,68,68,.10); border-color: rgba(239,68,68,.22); color: rgba(185,28,28,.95); font-weight:900; }
.toast.show{ display:block; }
.hidden{ display:none !important; }

/* =========================================================
   HEADER PRINCIPAL (TU PROBLEMA)
   - 1ra fila: tabs (Explorar / Suscripciones)
   - 2da fila: context (Top · ...)
   - 3ra fila: controls (Ver todo | Vista)
   ========================================================= */
.main-head{
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-items: start;
}

/* fila tabs */
.tabs{
  display:flex;
  align-items:center;
  gap:14px;
  flex-wrap: nowrap;            /* CLAVE: no se apilan */
  min-width: 0;
}

/* botones */
.tab{
  appearance:none;
  background:transparent;
  border:0;
  padding:10px 2px;
  font-weight:950;
  font-size:14px;
  color: rgba(0,0,0,.70);
  cursor:pointer;
  border-bottom: 3px solid transparent;

  flex: 0 0 auto;               /* CLAVE */
  white-space: nowrap;          /* CLAVE */
}
.tab.on{
  color: rgba(0,0,0,.90);
  border-bottom-color: rgba(52,131,250,.95);
}
.count{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:26px;
  height:20px;
  padding:0 8px;
  border-radius:999px;
  background: rgba(52,131,250,.12);
  color: rgba(52,131,250,.95);
  font-size:12px;
  font-weight:1000;
  margin-left:6px;
  border:1px solid rgba(52,131,250,.18);
}

/* el context DEBE ir abajo (otra recta) */
.context{
  display:inline-flex;
  font-size:12px;
  padding:7px 10px;
  border-radius:999px;
  border:1px solid var(--border);
  background: rgba(2,6,23,.02);
  color: rgba(2,6,23,.70);
  font-weight:900;

  /* CLAVE: lo sacamos del flujo de tabs y lo mandamos a otra fila */
  margin-top: 6px;
}

/* Para lograr “otra recta”, movemos .context a otra línea via grid:
   como HTML no cambia, hacemos que .tabs pueda wrap, PERO:
   1) tabs nunca rompen (nowrap)
   2) context ocupa 100% y va al final
*/
.tabs{ flex-wrap: wrap; }
.tabs .tab{ flex:0 0 auto; }
.tabs .context{
  flex-basis: 100%;
  order: 99;
  margin-top: 4px;
}

/* controles: siempre en la misma recta */
.controls{
  display:flex;
  align-items:center;
  justify-content: space-between; /* CLAVE */
  gap:10px;
  flex-wrap: nowrap;              /* CLAVE */
}
.controls .btn{
  flex: 0 0 auto;
}

/* =========================================================
   NO SWIPE: convertimos panes a normal (y hidden funciona)
   ========================================================= */
.swipe{
  position:relative;
  width:100%;
  overflow: visible;            /* ya no scroll horizontal */
  display:block;                /* ya no flex */
  scroll-snap-type: none;
  -webkit-overflow-scrolling: auto;
}

/* panes en vertical normal */
.pane{
  padding: 14px 16px 16px 16px;
  min-width: auto;
}

/* En tu CSS viejo forzabas esto:
   #paneSubs.hidden{ display:block !important; }
   Eso rompe la lógica de hidden. Lo anulamos:
*/
#paneSubs.hidden{ display:none !important; }

/* ===== Sections ===== */
.section{ margin-bottom: 16px; }
.section-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  flex-wrap:wrap;
  margin-bottom:10px;
}
.section-title{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
}
.pill2{
  font-size:12px;
  padding:7px 10px;
  border-radius:999px;
  background: rgba(52,131,250,.10);
  color: rgba(52,131,250,.95);
  border:1px solid rgba(52,131,250,.18);
  font-weight:1000;
}
.hint-inline{
  font-size:12px;
  color: rgba(2,6,23,.55);
  font-weight:800;
}
.footer-note{
  margin-top: 8px;
  padding: 12px 12px;
  border-top: 1px solid var(--border);
  color: rgba(0,0,0,.56);
  font-size:12px;
  background: rgba(0,0,0,.02);
  border-radius: 14px;
}

/* ===== Results container ===== */
.results{
  display:grid;
  grid-template-columns: 1fr;
  gap:12px;
}
.results.mode-grid{
  grid-template-columns: repeat(2, minmax(0,1fr));
}
@media(min-width: 900px){
  .results.mode-grid{ grid-template-columns: repeat(3, minmax(0,1fr)); }
}
@media(min-width: 1180px){
  .results.mode-grid{ grid-template-columns: repeat(4, minmax(0,1fr)); }
}
.results.mode-list{
  grid-template-columns: 1fr;
}

/* Si mantienes mode-carousel, que sea scroll normal, sin snap (ya no swipe) */
.results.mode-carousel{
  display:flex;
  gap:12px;
  overflow-x:auto;
  scroll-snap-type:none;
  padding-bottom: 4px;
  -webkit-overflow-scrolling:auto;
}
.results.mode-carousel .p-card{ min-width: 84%; }
@media(min-width: 560px){
  .results.mode-carousel .p-card{ min-width: 360px; }
}

/* ===== Product Card ===== */
.p-card{
  border:1px solid var(--border);
  background:#fff;
  border-radius: 18px;
  box-shadow: 0 8px 18px rgba(2,6,23,.05);
  overflow:hidden;
  display:flex;
  flex-direction:column;
}

/* Resultado de búsqueda: background más “ML blue” */
#results.results-search .p-card{
  border-color: rgba(52,131,250,.24);
  background: linear-gradient(180deg, rgba(52,131,250,.10), #fff 55%);
}

/* Top 2 destacados (amarillo oferta) */
.p-card.top-offer{
  border-color: rgba(255,230,0,.70);
  background: linear-gradient(180deg, rgba(255,230,0,.55), #fff 62%);
}

.p-top{
  display:flex;
  gap:12px;
  padding: 12px;
  align-items:flex-start;
}
.p-thumb{
  width: 78px;
  height: 78px;
  border-radius: 16px;
  border:1px solid var(--border);
  background: #fafafa;
  display:grid;
  place-items:center;
  overflow:hidden;
  flex: 0 0 auto;
}
.p-thumb img{
  width:100%;
  height:100%;
  object-fit:contain;
  padding:8px;
  display:block;
}
.p-head{
  min-width:0;
  flex:1 1 auto;
  display:flex;
  flex-direction:column;
  gap:6px;
  padding-top: 2px;
}
.p-title{
  margin:0;
  font-size: 13.8px;
  font-weight: 950;
  line-height: 1.22;
  color: rgba(0,0,0,.90);
  display:-webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow:hidden;
}
.p-price-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}
.p-price{
  font-weight: 1000;
  color: rgba(0,0,0,.92);
  font-size: 15px;
  white-space:nowrap;
}
.p-meta{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  margin-top:2px;
}
.tag{
  font-size:12px;
  padding:6px 10px;
  border-radius:999px;
  background: rgba(2,6,23,.03);
  border:1px solid rgba(2,6,23,.08);
  color: rgba(2,6,23,.70);
  font-weight:900;
}
.tag.green{
  background: rgba(0,166,80,.10);
  border-color: rgba(0,166,80,.20);
  color: rgba(0,166,80,.95);
}
.tag.orange{
  background: rgba(245,158,11,.12);
  border-color: rgba(245,158,11,.20);
  color: rgba(146,64,14,.95);
}
.tag.blue{
  background: rgba(52,131,250,.10);
  border-color: rgba(52,131,250,.18);
  color: rgba(52,131,250,.95);
}
.tag.yellow{
  background: rgba(255,230,0,.45);
  border-color: rgba(255,230,0,.65);
  color: rgba(0,0,0,.86);
}
.suggest{
  margin: 0 12px 10px 12px;
  padding: 10px 10px;
  border-radius: 14px;
  border: 1px dashed rgba(2,6,23,.14);
  background: rgba(2,6,23,.02);
  font-size: 12.2px;
  color: rgba(2,6,23,.66);
  line-height: 1.35;
}

/* ===== Footer actions ===== */
.p-footer{
  display:grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap:10px;
  padding: 10px 12px 12px 12px;
  border-top: 1px solid var(--border);
  background: rgba(2,6,23,.01);
}
.p-footer .a{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height: 38px;
  padding: 9px 10px;
  border-radius: 14px;
  border:1px solid var(--border);
  background:#fff;
  font-weight:1000;
  font-size: 13px;
  color: rgba(0,0,0,.86);
  text-decoration:none;
  cursor:pointer;
  user-select:none;
}
.p-footer .a.primary{
  border-color: rgba(52,131,250,.22);
  background: rgba(52,131,250,.10);
  color: rgba(52,131,250,.95);
}
.p-footer .a.danger{
  border-color: rgba(239,68,68,.22);
  background: rgba(239,68,68,.10);
  color: rgba(185,28,28,.95);
}

/* ===== Modals ===== */
.modal-backdrop,
.dialog-backdrop{
  position:fixed;
  inset:0;
  background: rgba(0,0,0,.46);
  display:none;
  align-items:center;
  justify-content:center;
  padding: 14px;
  z-index: var(--z-overlay);
}
.modal-backdrop.show,
.dialog-backdrop.show{ display:flex; }

.sheet{
  width: min(720px, 100%);
  background: #fff;
  border-radius: 22px;
  box-shadow: var(--shadow2);
  border: 1px solid rgba(0,0,0,.06);
  overflow:hidden;
}
.sheet-head{
  padding: 14px 14px 10px 14px;
  border-bottom: 1px solid var(--border);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}
.sheet-title{ font-weight: 1000; font-size: 14px; }
.sheet-close{
  width: 42px;height: 42px;border-radius: 14px;
  border: 1px solid var(--border);
  background: #fff;
  cursor:pointer;
  display:grid;
  place-items:center;
}
.sheet-body{ padding: 12px 14px 14px 14px; }

.cat-search{ display:flex; gap:10px; align-items:center; margin-bottom: 12px; }
.cat-list{
  max-height: min(60vh, 520px);
  overflow:auto;
  padding-right: 4px;
  display:flex;
  flex-direction:column;
  gap:8px;

  /* diferenciación visual */
  background: rgba(52,131,250,.05);
  border: 1px solid rgba(52,131,250,.14);
  border-radius: 18px;
  padding: 10px;
}
.cat-row{
  display:flex;align-items:center;justify-content:space-between;gap:10px;
  padding: 12px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #fff;
  cursor:pointer;
}
.cat-row:hover{ background: rgba(52,131,250,.04); }
.cat-left{ min-width:0; display:flex; flex-direction:column; gap:4px; }
.cat-name{ font-weight: 950; color: rgba(0,0,0,.88); font-size: 13.6px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.cat-id{ font-size: 12px; color: rgba(0,0,0,.52); font-weight: 800; }
.cat-check{
  width: 22px;height: 22px;border-radius: 999px;
  border: 2px solid rgba(0,0,0,.18);
  display:grid;place-items:center;
  background: transparent;flex:0 0 auto;
}
.cat-check.on{ border-color: rgba(0,166,80,.35); background: rgba(0,166,80,.95); }

.dialog{
  width: min(860px, 100%);
  background:#fff;
  border-radius: 22px;
  border: 1px solid rgba(0,0,0,.08);
  box-shadow: var(--shadow2);
  overflow:hidden;
}
.dialog-head{
  padding: 14px 14px 10px 14px;
  border-bottom: 1px solid var(--border);
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:10px;
}
.dialog-title{ font-weight: 1000; font-size: 14px; color: rgba(0,0,0,.88); }
.dialog-sub{ margin-top:6px; color: rgba(0,0,0,.58); font-size: 12.5px; font-weight: 800; }
.dialog-body{ padding: 12px 14px 14px 14px; }

.spark{
  width: 100%;
  height: 120px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,.02);
  overflow:hidden;
  margin-bottom: 12px;
  display:grid;
  place-items:center;
  position:relative;
}
.spark svg{ width:100%; height:100%; }

.hist-list{
  display:flex;
  flex-direction:column;
  gap:8px;
  max-height: min(45vh, 420px);
  overflow:auto;
  padding-right: 4px;
}
.hist-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding: 10px 10px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background:#fff;
  font-size: 12.8px;
}
.hist-left{ display:flex; flex-direction:column; gap:3px; min-width:0; }
.hist-price{ font-weight: 1000; color: rgba(0,0,0,.88); }
.hist-date{ color: rgba(0,0,0,.56); font-weight: 800; font-size: 12px; }

.dialog-ml{ width:min(1100px, 100%); }
.dialog-ml-body{ padding: 0; }
.ml-frame{
  width:100%;
  height: min(76vh, 820px);
  border:0;
  display:block;
  background:#fff;
}
.ml-guard{ padding: 14px; background: rgba(0,0,0,.03); border-bottom: 1px solid var(--border); }

@media (prefers-reduced-motion: reduce){
  *{transition:none!important; animation:none!important}
}