/* ═══════════════════════════════════════════════════════════
   ReplicatorNT — capa móvil (no altera escritorio ≥861px)
   ═══════════════════════════════════════════════════════════ */

#app-menu-btn { display: none !important; }

@media (min-width: 861px) {
  #app-drawer { display: none !important; }
  .m-card-list { display: none !important; }
}

@media (max-width: 860px) {
  :root {
    --control-h: 3rem; /* 48px */
    --page-pad: 1.25rem; /* px-5 */
  }

  html, body {
    overflow-x: clip;
    max-width: 100vw;
  }
  #app {
    max-width: 100vw;
    overflow-x: clip;
  }

  #app-menu-btn:not(.hidden) {
    display: inline-flex !important;
  }
  .only-mobile {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }
  .hide-mobile { display: none !important; }

  /* ── Tipografía ─────────────────────────────────────── */
  .page-head h1,
  .auth-card h2,
  .auth-aside-content h2 {
    font-size: 1.35rem;
    line-height: 1.25;
  }
  .hero h1,
  .hero-copy h1 {
    font-size: clamp(1.55rem, 7.2vw, 2rem) !important;
    line-height: 1.15;
  }
  .landing-title,
  .section-head h2 {
    font-size: 1.35rem;
  }
  .card-head h2,
  .log-title-wrap h2 {
    font-size: 1rem;
  }
  .finance-value,
  .kpi.big strong {
    font-size: 1.25rem;
  }

  /* ── Espaciado / layout ─────────────────────────────── */
  .page {
    padding: calc(0.85rem + env(safe-area-inset-top, 0px)) var(--page-pad) 1.5rem;
    max-width: 100%;
    min-width: 0;
  }
  .card {
    padding: 1rem;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: clip;
  }
  .card-head {
    flex-wrap: wrap;
    min-width: 0;
    gap: 0.45rem;
  }
  .check-row {
    flex-wrap: wrap;
    white-space: normal;
    min-width: 0;
  }
  .container {
    padding-inline: var(--page-pad);
  }
  .landing {
    padding: 0 var(--page-pad) 2.5rem;
  }

  .dash-grid,
  .finance-grid,
  .license-store,
  .landing-steps,
  .landing-features,
  .form-grid,
  .form-grid-2,
  .notify-prefs-grid,
  .field-grid,
  .profile-grid,
  .pub-grid,
  .pub-stats-row,
  .profile-kpis,
  .hero-metrics,
  .hero-inner,
  .auth-page,
  .auth-shell,
  .site-footer-grid,
  .dash-tab,
  .key-field,
  .aff-link-row,
  .inline-form,
  .connect-phase,
  .connect-req-block {
    min-width: 0;
    max-width: 100%;
  }

  .dash-grid,
  .finance-grid,
  .license-store,
  .landing-steps,
  .landing-features,
  .form-grid,
  .form-grid-2,
  .notify-prefs-grid,
  .field-grid,
  .profile-grid,
  .pub-grid,
  .pub-stats-row,
  .profile-kpis,
  .hero-metrics,
  .hero-inner,
  .auth-page,
  .auth-shell,
  .site-footer-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem;
  }
  .dash-grid > *,
  .finance-grid > *,
  .card > * {
    min-width: 0;
    max-width: 100%;
  }
  .span-12, .span-7, .span-5 {
    grid-column: 1 / -1 !important;
  }
  .steps-strip {
    grid-template-columns: 1fr !important;
    gap: 0.75rem;
  }
  #public-channel-list,
  #license-list {
    grid-template-columns: 1fr !important;
  }
  .pub-grid {
    grid-template-columns: 1fr !important;
  }
  .pub-stats-row {
    grid-template-columns: 1fr 1fr !important;
  }

  /* ── Textos largos: jamás empujan el viewport ───────── */
  .hint,
  .hint.tiny,
  p,
  h1, h2, h3, h4,
  .connect-phase-detail,
  .connect-req-block,
  .connect-req-block li,
  .page-head .hint,
  .card-head,
  .pub-name {
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: normal;
    max-width: 100%;
  }
  #api-key-display,
  #ws-url-hint,
  .ws-hint,
  #aff-url,
  .crypto-wallet,
  .license-key,
  code.license-key,
  .pay-id,
  .admin-lic-info code,
  .m-row-v code,
  .m-row-v {
    white-space: normal !important;
    overflow-wrap: anywhere;
    word-break: break-all;
    overflow-x: hidden;
    max-width: 100%;
  }
  #api-key-display,
  .ws-hint,
  #ws-url-hint {
    display: block;
    width: 100%;
    flex: 1 1 100%;
    min-width: 0;
    overflow-x: hidden;
  }

  .aff-link-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.55rem;
  }
  .aff-link-row #aff-url {
    display: block;
    width: 100%;
    padding: 0.75rem;
    background: #18181b;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.5rem;
    font-size: 0.8rem;
    color: var(--key-fg);
    font-family: var(--mono);
  }

  /* ── Header marketing ───────────────────────────────── */
  .site-header-inner {
    height: 56px;
    gap: 0.5rem;
    padding-inline: 0;
  }
  .site-nav,
  .site-header-inner > .row {
    display: none !important;
  }

  /* ── Topbar autenticada ─────────────────────────────── */
  .topbar {
    padding: 0.45rem var(--page-pad);
    padding-top: max(0.45rem, env(safe-area-inset-top, 0px));
    gap: 0.5rem;
    flex-wrap: nowrap;
    min-height: 56px;
  }
  .topbar .brand-name { font-size: 0.95rem; }
  body.is-authed .topbar-actions { display: none !important; }
  .topbar-actions {
    gap: 0.4rem;
  }
  .topbar-actions button {
    min-height: 44px;
    padding: 0 0.85rem;
    font-size: 0.85rem;
  }

  /* Tabs del panel → van al drawer */
  .dash-tabs {
    display: none !important;
  }

  /* ── Hamburguesa ────────────────────────────────────── */
  .hamburger-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    color: var(--text);
    cursor: pointer;
    flex-shrink: 0;
    filter: none;
    box-shadow: none;
  }
  .hamburger-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    filter: none;
  }
  .hamburger-bars {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 16px;
  }
  .hamburger-bars i {
    display: block;
    height: 1.5px;
    width: 100%;
    background: currentColor;
    border-radius: 2px;
    transition: transform 0.22s ease, opacity 0.18s ease;
  }
  .hamburger-btn[aria-expanded="true"] .hamburger-bars i:nth-child(1) {
    transform: translateY(6.5px) rotate(45deg);
  }
  .hamburger-btn[aria-expanded="true"] .hamburger-bars i:nth-child(2) {
    opacity: 0;
  }
  .hamburger-btn[aria-expanded="true"] .hamburger-bars i:nth-child(3) {
    transform: translateY(-6.5px) rotate(-45deg);
  }

  /* ── Drawer unificado ───────────────────────────────── */
  #mkt-drawer,
  #app-drawer {
    position: fixed;
    inset: 0;
    z-index: 80;
  }
  #mkt-drawer.hidden,
  #app-drawer.hidden {
    display: none !important;
  }
  .drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(9, 9, 11, 0.72);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: mobile-fade 0.2s ease;
  }
  .drawer {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    width: min(20.5rem, 88vw);
    background: #0c0c0f;
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    box-shadow: -18px 0 50px rgba(0, 0, 0, 0.45);
    padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
    animation: mobile-drawer-in 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
    min-height: 56px;
  }
  .drawer-head .icon-btn,
  .drawer-head [data-mkt-close],
  .drawer-head [data-app-close] {
    width: 44px;
    height: 44px;
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
  }
  .sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.75rem 0.5rem;
    overflow-y: auto;
    flex: 1;
  }
  .sidebar-nav .nav-item,
  .sidebar-nav button.nav-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    height: 3rem;
    min-height: 3rem;
    max-height: 3rem;
    padding: 0 0.9rem 0 0.85rem;
    border-radius: 0 10px 10px 0;
    border: none;
    border-left: 3px solid transparent;
    background: transparent !important;
    color: rgba(244, 244, 245, 0.78);
    font-size: 0.95rem;
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    filter: none;
    box-shadow: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .sidebar-nav .nav-item:hover,
  .sidebar-nav .nav-item:active {
    background: rgba(255, 255, 255, 0.05) !important;
    filter: none;
  }
  .sidebar-nav .nav-item.active {
    background: transparent !important;
    border-left-color: var(--accent-2);
    color: #fff;
    font-weight: 600;
  }
  .drawer-sep {
    height: 1px;
    background: var(--border);
    margin: 0.55rem 0.35rem;
  }
  .nav-item.danger { color: #fca5a5; }

  /* ── Inputs (equivalente w-full bg-zinc-900 border p-3) ─ */
  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="color"]):not([type="file"]):not([type="range"]),
  select,
  textarea {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    background: #18181b;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.5rem;
    padding: 0.75rem;
    font-size: 0.875rem;
    height: auto;
    min-height: 48px;
    box-sizing: border-box;
  }
  textarea { min-height: 7.5rem; }

  .inline-check {
    display: flex;
    align-items: flex-start;
    white-space: normal;
    width: 100%;
    max-width: 100%;
    min-height: 44px;
    padding: 0.35rem 0;
  }
  .notify-prefs-grid > div {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
  }

  /* ── Botones: texto visible, full-width, sin bloques vacíos */
  button:not(.hamburger-btn):not(.icon-btn):not(.nav-item):not(.help-i):not(.m-row-card-toggle):not(.pub-filter-group button):not(.profile-window-tabs button):not(.admin-tabs button):not(.canales-tabs button):not(.tabs button):not(.pub-share-btn):not(.share-act) {
    height: auto !important;
    min-height: 48px;
    max-width: 100%;
    justify-content: center;
    text-align: center;
    white-space: normal;
    overflow: visible;
    line-height: 1.3;
    padding: 0.75rem 1rem;
    box-sizing: border-box;
    font-size: 0.875rem;
  }
  .help-i {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    max-width: 44px;
    font-size: 0.85rem;
  }

  .hero-actions,
  .key-field,
  .key-field .channel-actions,
  .license-product-actions,
  .channel-actions,
  .inline-form,
  .connect-actions,
  .cfg-actions,
  .profile-cta-row,
  .log-header,
  .pub-card-ctas,
  .pub-card-foot,
  .m-row-card-actions,
  #notification-prefs-body .channel-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
  }
  .hero-actions .btn-mkt,
  .hero-actions .btn-mkt-outline,
  .hero-actions a,
  .key-field .channel-actions button,
  .license-product-actions button,
  .channel-actions button,
  .inline-form button,
  .inline-form input,
  .inline-form select,
  .inline-form label,
  .connect-actions button,
  .cfg-actions button,
  .profile-cta-row button,
  .pub-card-ctas button,
  .pub-card-foot button,
  .m-row-card-actions button,
  #btn-copy-api-key,
  #btn-regen-key,
  #btn-cta-register,
  #btn-copy-aff,
  #btn-request-wd,
  #btn-save-notify-prefs,
  #btn-link-telegram,
  #btn-unlink-telegram,
  #btn-enable-push {
    width: 100%;
    max-width: 100%;
  }

  /* ── Tablas → tarjetas acordeón ─────────────────────── */
  .table-wrap:not(.comparison-table-wrap) > table.admin-table,
  .table-wrap:not(.comparison-table-wrap) > table.journal-table,
  .payments-table-wrap > table.payments-table {
    display: none !important;
  }
  .table-wrap,
  .payments-table-wrap {
    overflow: visible;
    max-width: 100%;
    min-width: 0;
  }
  .comparison-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  .m-card-list {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    width: 100%;
    min-width: 0;
  }
  .m-row-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    overflow: hidden;
    min-width: 0;
  }
  .m-row-card-empty {
    padding: 0.9rem 1rem;
  }
  .m-row-card-toggle {
    display: flex !important;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.65rem;
    width: 100%;
    min-height: 48px;
    height: auto !important;
    padding: 0.85rem 0.9rem;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    filter: none !important;
    color: var(--text);
    text-align: left;
    cursor: pointer;
    border-radius: 0;
  }
  .m-row-card-toggle:active {
    background: rgba(255, 255, 255, 0.05) !important;
  }
  .m-row-card-summary {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    flex: 1;
    min-width: 0;
    padding: 0.85rem 0.9rem;
  }
  .m-row-card-toggle .m-row-card-summary {
    padding: 0;
  }
  .m-chevron {
    flex-shrink: 0;
    width: 1.75rem;
    height: 1.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 0.85rem;
    transition: transform 0.2s ease;
    margin-top: 0.15rem;
  }
  .m-row-card.is-open .m-chevron {
    transform: rotate(180deg);
  }
  .m-row-card-details {
    display: none;
    padding: 0 0.9rem 0.9rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
  }
  .m-row-card.is-open .m-row-card-details {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding-top: 0.75rem;
  }
  .m-row-kv {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    min-width: 0;
  }
  .m-row-k {
    flex-shrink: 0;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding-top: 0.15rem;
  }
  .m-row-v {
    text-align: right;
    font-size: 0.85rem;
    min-width: 0;
    flex: 1;
  }
  .m-row-card-actions {
    margin-top: 0.55rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
  }
  .m-row-card-actions .pay-actions,
  .m-row-card-actions .pay-actions-inner {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 0.45rem;
  }

  /* ── Touch targets / tabs ───────────────────────────── */
  .tabs button {
    min-height: 44px;
    height: auto;
  }
  .admin-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0.35rem;
    padding-bottom: 0.25rem;
  }
  .admin-tabs button {
    min-height: 44px;
    flex: 0 0 auto;
    padding: 0 0.9rem;
    font-size: 0.82rem;
    white-space: nowrap;
    width: auto;
  }
  .canales-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .canales-tabs button {
    min-height: 44px;
    flex: 0 0 auto;
    width: auto;
  }
  .pub-filter-group button,
  .profile-window-tabs button {
    width: auto;
    min-height: 44px;
  }

  /* ── Auth / hero ────────────────────────────────────── */
  .auth-aside { display: none; }
  .auth-main { padding: 1.25rem var(--page-pad) 2rem; }
  .auth-card { width: 100%; max-width: 100%; }
  .terminal-body { min-height: 0; }
  .term-line {
    grid-template-columns: auto 1fr auto;
    white-space: normal;
    font-size: 0.72rem;
  }
  .term-line .ts { display: none; }
  .pub-spark { display: none; }
  .pub-toolbar,
  .finance-toolbar,
  .finance-filters,
  .finance-exports {
    flex-direction: column;
    align-items: stretch;
  }
  .finance-filters label,
  .pub-search,
  .pub-sort-label select {
    min-width: 0;
    width: 100%;
  }
  .btn-finance-export { width: 100%; }
  .log-header > * { width: 100%; }
  .channel-row,
  .subscription-row {
    flex-direction: column;
    align-items: stretch;
  }
  .prod-row {
    grid-template-columns: 1fr auto;
    grid-template-areas: "main price" "status status" "actions actions";
  }
  .prod-actions button { flex: 1; min-height: 44px; }
  .footer {
    flex-direction: column;
    gap: 0.4rem;
    padding: 1.25rem var(--page-pad);
    text-align: center;
  }
}

@keyframes mobile-drawer-in {
  from { transform: translateX(100%); }
  to { transform: none; }
}
@keyframes mobile-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (max-width: 860px) and (prefers-reduced-motion: reduce) {
  .drawer,
  .drawer-backdrop,
  .hamburger-bars i,
  .m-chevron {
    animation: none !important;
    transition: none !important;
  }
}
