/* ==========================================================================
   coms — capa de app móvil (celular/tablet y app instalada)
   Se carga solo con media="(max-width: 820px), (display-mode: standalone) and (pointer: coarse)".
   Todo va acotado a :root:has(.tabbar) para no tocar la landing ni la web de escritorio.
   ========================================================================== */

/* Transición suave entre pantallas, como en una app */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .18s; }
.tabbar { view-transition-name: tabbar; }


:root:has(.tabbar) {
  --tab-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
:root:has(.tabbar) body { padding-bottom: calc(var(--tab-h) + var(--safe-b) + 8px); -webkit-text-size-adjust: 100%; }
:root:has(.tabbar) input, :root:has(.tabbar) select, :root:has(.tabbar) textarea { font-size: 16px !important; } /* sin zoom en iOS */
:root:has(.tabbar) button, :root:has(.tabbar) .btn, :root:has(.tabbar) .tabbar a { -webkit-user-select: none; user-select: none; touch-action: manipulation; }
:root:has(.tabbar) .btn:active { transform: scale(.97); }

/* ---------------------------------------------------------------- Barra superior compacta */
:root:has(.tabbar) .topbar { background: var(--paper); padding-top: var(--safe-t); }
:root:has(.tabbar) .topbar-in { height: 54px; padding: 0 14px; gap: 10px; }
:root:has(.tabbar) .topbar-nav { display: none; }
:root:has(.tabbar) .acct-email, :root:has(.tabbar) .pop-btn .caret { display: none; }
:root:has(.tabbar) .brand { font-size: 18px; }

/* ---------------------------------------------------------------- Barra inferior de pestañas */
.tabbar[hidden] {
  display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  height: calc(var(--tab-h) + var(--safe-b)); padding: 0 6px var(--safe-b);
  background: rgba(255, 255, 255, .94); -webkit-backdrop-filter: saturate(1.6) blur(16px); backdrop-filter: saturate(1.6) blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--ink-3); text-decoration: none; font-size: 11.5px; font-weight: 700; border-radius: 12px; position: relative;
}
.tabbar a svg { width: 23px; height: 23px; stroke-width: 2; }
.tabbar a[aria-current="page"] { color: var(--sign-deep); }
.tabbar a[aria-current="page"]::before {
  content: ""; position: absolute; top: 6px; width: 46px; height: 30px; border-radius: 999px; background: var(--sign-tint); z-index: -1;
}
.tabbar a[data-new-site] svg { width: 26px; height: 26px; padding: 4px; border-radius: 10px; background: var(--sign); color: #fff; stroke-width: 2.6; }
.tabbar a:active { background: var(--ground); }

/* ---------------------------------------------------------------- Página */
:root:has(.tabbar) .page { padding: 16px 14px 20px; }
:root:has(.tabbar) .page-head { margin-bottom: 16px; }
:root:has(.tabbar) .page-head h1 { font-size: 24px; }
:root:has(.tabbar) .panel { border-radius: 16px; }
:root:has(.tabbar) .app-foot { padding: 6px 16px 14px; justify-content: center; font-size: 12px; }
:root:has(.tabbar) .crumb { font-size: 14px; }

/* ---------------------------------------------------------------- Mis sitios */
:root:has(.tabbar) .ph { margin-bottom: 12px; gap: 10px; }
:root:has(.tabbar) .ph h1 { font-size: 26px; }
:root:has(.tabbar) .ph-usage {
  width: calc(100% + 28px); margin: 0 -14px; padding: 0 14px 2px; flex-wrap: nowrap; overflow-x: auto; scroll-snap-type: x proximity;
  scrollbar-width: none;
}
:root:has(.tabbar) .ph-usage::-webkit-scrollbar { display: none; }
:root:has(.tabbar) .pu, :root:has(.tabbar) .ph-usage .btn { flex: none; scroll-snap-align: start; height: 34px; }

/* Crear sitio: hoja inferior que abre la pestaña «Nuevo» */
:root:has(.tabbar) .newsite {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 90; margin: 0;
  display: flex; flex-direction: column; align-items: stretch; gap: 12px;
  background: var(--paper); border-radius: 22px 22px 0 0; padding: 26px 16px calc(18px + var(--safe-b));
  box-shadow: 0 -20px 60px rgba(32, 38, 26, .25);
  transform: translateY(105%); transition: transform .28s cubic-bezier(.2, .8, .2, 1); visibility: hidden;
}
:root:has(.tabbar) .newsite::before {
  content: ""; position: absolute; top: 9px; left: 50%; width: 40px; height: 5px; margin-left: -20px; border-radius: 9px; background: var(--line);
}
:root.new-open .newsite { transform: none; visibility: visible; }
:root:has(.tabbar) .newsite-k { display: block !important; font-size: 19px; font-weight: 800; }
:root:has(.tabbar) .newsite .kind-seg { order: 0; display: flex; }
:root:has(.tabbar) .newsite .kind-seg button { flex: 1; justify-content: center; height: 40px; }
:root:has(.tabbar) .newsite .create-addr { flex: none; max-width: none; flex-wrap: wrap; }
:root:has(.tabbar) .newsite .create-addr input { flex: 1 1 100%; height: 54px; border-bottom: 1px solid var(--line-2); }
:root:has(.tabbar) .newsite .create-addr select { flex: 1; height: 50px; border-left: 0; }
:root:has(.tabbar) .newsite .create-addr .btn { height: 50px; padding: 0 20px; }
:root:has(.tabbar) .newsite .create-addr .btn span { display: inline !important; }
:root:has(.tabbar) .newsite .drop-tip { display: none; }

/* Lista de sitios */
:root:has(.tabbar) .sl { border-radius: 16px; }
:root:has(.tabbar) .sl-tools {
  position: sticky; top: calc(54px + var(--safe-t)); z-index: 20; background: var(--paper); border-radius: 16px 16px 0 0; padding: 10px;
}
:root:has(.tabbar) .sl-search { height: 44px; flex-basis: 100%; }
:root:has(.tabbar) .sl-search kbd { display: none; }
:root:has(.tabbar) .sl-tools { flex-wrap: wrap; }
:root:has(.tabbar) .sl-sel { height: 38px; flex: 1 1 0; min-width: 0; font-size: 13.5px !important; padding: 0 26px 0 10px; background-position: right 8px center; }
:root:has(.tabbar) .sl-head { display: none; }
:root:has(.tabbar) .sl .row { grid-template-columns: minmax(0, 1fr) auto; padding: 12px 12px 12px 14px; min-height: 64px; column-gap: 8px; cursor: pointer; }
:root:has(.tabbar) .sl .row > .c-num { display: none; }
:root:has(.tabbar) .sl .row:active { background: var(--ground); }
:root:has(.tabbar) .c-sub { display: flex !important; }
:root:has(.tabbar) .m-meta { display: inline-flex; gap: 10px; font-size: 12.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
:root:has(.tabbar) .host { font-size: 16px; }
:root:has(.tabbar) .c-acts { gap: 6px; }
:root:has(.tabbar) .c-acts .d-only { display: none !important; }
:root:has(.tabbar) .c-acts .btn { width: 40px; height: 40px; min-width: 40px; padding: 0; justify-content: center; border-radius: 11px; }
:root:has(.tabbar) .c-acts .btn-up .lbl { display: none; }
:root:has(.tabbar) .sl-foot { padding: 12px 14px; }
:root:has(.tabbar) .sl-foot .btn { height: 40px; }
:root:has(.tabbar) .site.folder .c-site { padding-left: 16px; }

/* ---------------------------------------------------------------- Menús ⋮ como hoja inferior */
:root:has(.tabbar) .pop-menu.open {
  position: fixed !important; left: 8px !important; right: 8px !important; top: auto !important;
  bottom: calc(8px + var(--safe-b)) !important; min-width: 0; z-index: 95; border-radius: 20px; padding: 18px 8px 8px;
  max-height: 72vh; overflow-y: auto; animation: sheetUp .24s cubic-bezier(.2, .8, .2, 1);
  box-shadow: 0 -10px 50px rgba(32, 38, 26, .25);
}
:root:has(.tabbar) .pop-menu.open::before {
  content: ""; position: absolute; top: 7px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 9px; background: var(--line);
}
:root:has(.tabbar) .pop-menu.open a, :root:has(.tabbar) .pop-menu.open button { min-height: 50px; font-size: 16px; padding: 0 14px; border-radius: 12px; }
:root:has(.tabbar) .pop-menu.open svg { width: 19px; height: 19px; }
:root:has(.tabbar) .pop-menu .m-only { display: flex; }
:root:has(.tabbar) .pop-menu hr.m-only { display: block; }
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Fondo de las hojas */
.app-scrim {
  position: fixed; inset: 0; z-index: 85; background: rgba(32, 38, 26, .42); opacity: 0; pointer-events: none; transition: opacity .2s;
}
.app-scrim.on { opacity: 1; pointer-events: auto; }

/* Diálogos (confirmar / escribir) como hoja inferior */
:root:has(.tabbar) .coms-ov { align-items: flex-end !important; padding: 0 !important; }
:root:has(.tabbar) .coms-modal {
  width: 100% !important; max-width: none !important; border-radius: 22px 22px 0 0 !important; padding-bottom: calc(18px + var(--safe-b)) !important;
}
:root:has(.tabbar) .coms-modal button { height: 50px !important; font-size: 16px !important; }
:root:has(.tabbar) .coms-modal input { height: 50px !important; }

/* Avisos encima de la barra inferior */
:root:has(.tabbar) .coms-toasts { bottom: calc(var(--tab-h) + var(--safe-b) + 12px) !important; top: auto !important; left: 12px !important; right: 12px !important; }

/* ---------------------------------------------------------------- Tarjetas de la app (instalar / actualizar) */
.app-card {
  position: fixed; left: 10px; right: 10px; bottom: calc(var(--tab-h) + var(--safe-b) + 10px); z-index: 70;
  display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 14px; border-radius: 16px;
  background: var(--ink); color: #fff; box-shadow: 0 16px 40px rgba(32, 38, 26, .35); animation: sheetUp .3s cubic-bezier(.2, .8, .2, 1);
}
.app-card img { width: 40px; height: 40px; border-radius: 10px; flex: none; }
.app-card .ac-tx { flex: 1; min-width: 0; font-size: 13.5px; line-height: 1.35; color: #E8E0CE; }
.app-card .ac-tx b { display: block; color: #fff; font-size: 14.5px; }
.app-card .ac-go { flex: none; height: 38px; padding: 0 14px; border: 0; border-radius: 10px; background: #fff; color: var(--sign-deep); font: inherit; font-weight: 800; font-size: 14px; }
.app-card .ac-x { flex: none; width: 32px; height: 32px; border: 0; background: transparent; color: #CFC6B2; border-radius: 8px; display: grid; place-items: center; }
.app-card .ac-x svg { width: 16px; height: 16px; }

/* Jalar para actualizar */
.app-ptr {
  position: fixed; left: 50%; top: calc(60px + var(--safe-t)); z-index: 30; width: 38px; height: 38px; margin-left: -19px; border-radius: 50%;
  background: var(--paper); box-shadow: 0 6px 18px rgba(32, 38, 26, .2); display: grid; place-items: center; color: var(--sign);
  transform: translateY(-80px); opacity: 0; transition: opacity .15s;
}
.app-ptr svg { width: 20px; height: 20px; }
.app-ptr.ready svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Sin conexión */
.app-offline {
  position: fixed; left: 0; right: 0; top: 0; z-index: 80; padding: calc(6px + var(--safe-t)) 12px 6px; text-align: center;
  background: var(--stop); color: #fff; font-size: 13px; font-weight: 700;
}

/* ---------------------------------------------------------------- Otras pantallas */
:root:has(.tabbar) .tabs { top: calc(54px + var(--safe-t)) !important; }
:root:has(.tabbar) .site-head h1 { font-size: 21px; }
:root:has(.tabbar) .setting { gap: 10px; }
:root:has(.tabbar) .stats { border-radius: 16px; }

/* App instalada: sin barra de navegador, el contenido llega al borde */
:root.standalone:has(.tabbar) .topbar { border-bottom-color: transparent; box-shadow: 0 1px 0 var(--line); }

@media (prefers-reduced-motion: reduce) {
  :root:has(.tabbar) .newsite, .app-card, :root:has(.tabbar) .pop-menu.open { transition: none; animation: none; }
  @view-transition { navigation: none; }
}
.sheet-t { padding: 4px 14px 10px; font-size: 13.5px; font-weight: 700; color: var(--ink-3); border-bottom: 1px solid var(--line-2); margin-bottom: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
