/* ==========================================================================
   Personal OS · capa móvil y app instalada (PWA)
   Barra superior, pestañas inferiores, subpestañas de Finanzas, botón ⚡,
   hojas inferiores, transiciones y ajustes táctiles. Solo actúa ≤ 760 px,
   salvo lo que mejora también el escritorio (feedback táctil, aviso de versión).
   ========================================================================== */

.m-top, .m-sub, .m-tabs, .m-fab { display: none; }

:root {
  --m-top: 48px;
  --m-tabs: 62px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --kb: 0px;
  --m-spring: cubic-bezier(.32, 1.25, .4, 1);
  --m-ease: cubic-bezier(.32, .72, 0, 1);
}

/* Aviso de nueva versión (escritorio y móvil) */
.m-update {
  position: fixed; left: 50%; bottom: 24px; z-index: 70; transform: translate(-50%, 140%);
  display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 16px; border-radius: 999px;
  background: #1d1d23; border: 1px solid var(--line-strong); box-shadow: 0 14px 40px rgba(0,0,0,.55);
  font-size: 13px; font-weight: 500; white-space: nowrap; transition: transform .5s var(--m-ease);
}
.m-update.show { transform: translate(-50%, 0); }
.m-update .btn { height: 32px; }

/* Ajustes (hoja) */
.m-set h2 { display: flex; align-items: center; gap: 10px; }
.m-set h2 img { width: 30px; height: 30px; filter: drop-shadow(0 0 6px rgba(139,124,246,.4)); }
.m-set-group { background: rgba(255,255,255,.035); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; margin-bottom: 14px; }
.m-set-group > p.m-set-label { margin: 0; padding: 12px 16px 4px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.m-set-row {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 10px 16px;
  background: none; border: 0; border-top: 1px solid var(--line); color: var(--text); text-align: left; font-size: 15px; font-weight: 500;
}
.m-set-group > .m-set-row:first-child, .m-set-label + .m-set-row { border-top: 0; }
.m-set-row svg { width: 20px; height: 20px; flex: none; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.m-set-row small { display: block; color: var(--text-3); font-size: 12px; font-weight: 400; margin-top: 1px; }
.m-set-row .m-chev { margin-left: auto; color: var(--text-3); }
.m-set-row.danger { color: var(--red); } .m-set-row.danger svg { stroke: var(--red); }
.m-set-row:active { background: rgba(255,255,255,.05); }
.m-set-foot { text-align: center; color: var(--text-3); font-size: 12px; margin: 6px 0 0; }
.m-ios-steps { margin: 0; padding: 4px 16px 14px 36px; color: var(--text-2); font-size: 14px; line-height: 1.6; }
.m-ios-steps b { color: var(--text); }
.m-ios-steps svg { width: 16px; height: 16px; vertical-align: -3px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Tarjeta de tarea levantada con pulsación larga */
.tk-card { -webkit-touch-callout: none; }
.tk-card.tk-lift { transform: scale(1.035); border-color: rgba(139,124,246,.6); box-shadow: 0 18px 40px rgba(0,0,0,.5), 0 0 0 1px rgba(139,124,246,.35); transition: transform .3s var(--m-spring), box-shadow .3s; }

/* Feedback al pulsar, en cualquier pantalla táctil */
@media (hover: none) {
  .acc-card .tools, .tk-col-actions, .tk-cover-btn, .tk-doc-tools, .tk-comment p .icon-btn, .tk-opt-more { opacity: 1 !important; }
  .btn:hover, .nav a:hover { filter: none; }
  .card[data-act], .acc-card, .tk-card, .hoy-habit, .hb-habit, .rep, .tx-list li, .qr-c, .hb-sq, .hoy-task {
    transition: transform .22s var(--m-spring), background .2s, border-color .2s, opacity .2s;
  }
  .acc-card:active, .tk-card:active, .rep:active { transform: scale(.975); }
  .hoy-habit:active, .hb-habit:active { transform: scale(.95); }
  .icon-btn:active { transform: scale(.88); background: rgba(255,255,255,.08); }
}

/* ======================================================================== */
@media (max-width: 760px) {
  html, body { overflow-x: clip; }
  html { -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; scroll-padding-top: calc(var(--m-top) + var(--sat) + 12px); }
  body { overscroll-behavior-y: none; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; font-size: 15px; }
  body:has(#modal-root .backdrop), body:has(#tk-root > *:not(:empty)) { overflow: hidden; }
  .app { min-height: 100dvh; display: block; }
  .sidebar { display: none !important; }
  .main-wrap { max-width: none; }
  button, a, [data-act], [data-hb], label { touch-action: manipulation; }
  .btn, .m-tabs a, .m-sub a, .nav a, .icon-btn, .hoy-habit, .hb-habit { -webkit-user-select: none; user-select: none; }

  /* Sin zoom de iOS al escribir: los campos a 16 px */
  input:not([type=checkbox]):not([type=radio]):not([type=range]):not(.big), select, textarea { font-size: 16px !important; }

  /* ---------- Barra superior ---------- */
  .m-top {
    display: flex; align-items: center; gap: 10px;
    position: fixed; top: 0; left: 0; right: 0; z-index: 45;
    height: calc(var(--m-top) + var(--sat)); padding: var(--sat) 10px 0 16px;
    border-bottom: .5px solid transparent;
    transition: background .3s, border-color .3s, -webkit-backdrop-filter .3s, backdrop-filter .3s;
    view-transition-name: m-top;
  }
  body.m-scrolled .m-top {
    background: rgba(11, 11, 14, .72);
    -webkit-backdrop-filter: saturate(180%) blur(22px); backdrop-filter: saturate(180%) blur(22px);
    border-bottom-color: var(--line-strong);
  }
  .m-top-logo { width: 26px; height: 26px; flex: none; filter: drop-shadow(0 0 6px rgba(139,124,246,.4)); transition: transform .4s var(--m-spring); }
  .m-top-title {
    flex: 1; min-width: 0; font-size: 16px; font-weight: 650; letter-spacing: -.01em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    opacity: 0; transform: translateY(8px); transition: opacity .22s, transform .35s var(--m-ease);
  }
  body.m-title .m-top-title { opacity: 1; transform: none; }
  .m-top-btn {
    width: 40px; height: 40px; border-radius: 50%; border: 0; display: grid; place-items: center; flex: none;
    background: rgba(255,255,255,.06); color: var(--text-2); transition: transform .25s var(--m-spring), background .2s;
  }
  .m-top-btn:active { transform: scale(.88); background: rgba(255,255,255,.12); }
  .m-top-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

  /* ---------- Contenido ---------- */
  .main, body[data-page] .main { padding: calc(var(--m-top) + var(--sat) + 10px) 16px calc(var(--m-tabs) + var(--sab) + 96px); }
  #mascot { top: calc(var(--m-top) + var(--sat) - 2px); }
  .page-head { margin-bottom: 22px; gap: 14px; padding-right: 84px; }
  .page-head h1 { font-size: 30px; letter-spacing: -.028em; }
  .page-head .sub { font-size: 14px; }
  .page-head .actions { gap: 8px; }
  .card { padding: 20px 18px; border-radius: 20px; }
  .card h3 { margin-bottom: 18px; }
  .btn { height: 40px; padding: 0 16px; font-size: 14px; }
  .btn svg { width: 16px; height: 16px; }
  .icon-btn { width: 40px; height: 40px; border-radius: 12px; }
  .icon-btn svg { width: 18px; height: 18px; }
  kbd, .qc-trigger { display: none !important; }
  .month-picker { height: 40px; }
  .month-picker button { width: 34px; height: 34px; }

  /* KPIs: 2 columnas que nunca se salen */
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 16px 14px; }
  .kpi .label { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .kpi .value { font-size: 21px; margin-top: 8px; }
  .kpi .hint { font-size: 11.5px; }
  .grid2, .grid2.even { gap: 12px; margin-bottom: 12px; }
  .hero { padding: 24px 20px; margin-bottom: 14px; }
  .hero .value { font-size: 36px; }
  .acc-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .acc-card { padding: 16px 14px; }
  .acc-card .bal { font-size: 19px; margin-top: 8px; }
  .acc-card .tools { top: 6px; right: 6px; }
  .acc-card .tools .icon-btn { width: 34px; height: 34px; }
  .acc-card.add { min-height: 140px; }
  .mood { padding: 16px; gap: 14px; }
  .note-banner { padding: 14px 16px; margin-bottom: 18px; }

  /* Filtros */
  .filters { gap: 8px; margin-bottom: 14px; }
  .filters input[type=search], .filters input { flex: 1 1 100%; max-width: none; min-width: 0; height: 44px; border-radius: 12px; }
  .filters select { flex: 1 1 calc(50% - 4px); min-width: 0; height: 40px; border-radius: 12px; }

  /* Tablas → filas tipo lista (Movimientos, Recurrentes) */
  .table-card { padding: 4px 16px; overflow: visible; }
  .table-card table, .table-card tbody, .table-card tr, .table-card td { display: block; }
  .table-card thead { display: none; }
  .table-card tr { display: flex; flex-wrap: wrap; align-items: center; column-gap: 6px; row-gap: 2px; padding: 13px 0; border-bottom: 1px solid var(--line); }
  .table-card tr:last-child { border-bottom: 0; }
  .table-card td { padding: 0; border: 0; white-space: nowrap; order: 3; font-size: 12.5px; color: var(--text-3); background: none !important; }
  .table-card td.note { order: 1; flex: 1 0 55%; min-width: 0; font-size: 15px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .table-card td.r { order: 2; font-size: 15px; color: var(--text); }
  .table-card td.r.pos { color: var(--blue); }
  .table-card td:has(> .pill) { display: none; }
  .table-card td.date { color: var(--text-3); }
  .table-card td:not(.note):not(.r):not(.acts):not(:first-child)::before { content: '·'; margin-right: 6px; color: var(--text-3); }
  .table-card td.date:first-child::before { content: none; }
  .table-card td .cat { color: var(--text-3); }
  .table-card td .dot { width: 7px; height: 7px; margin-right: 5px; }
  /* Desliza una fila a la izquierda para ver Editar / Eliminar; tocarla la edita */
  .table-card { overflow: hidden; }
  .table-card tr { position: relative; transition: transform .42s var(--m-spring); touch-action: pan-y; cursor: pointer; }
  .table-card tr.m-dragging { transition: none; }
  .table-card td.acts { position: absolute; left: 100%; top: 0; bottom: 0; order: 9; width: auto; padding: 0 0 0 10px; display: flex; align-items: center; gap: 6px; }
  .table-card td.acts .icon-btn { width: 44px; height: 44px; border-radius: 14px; background: rgba(255,255,255,.07); color: var(--text); }
  .table-card td.acts .icon-btn.del { background: var(--alert-soft); color: var(--alert); }
  .table-card tr:active:not(.m-dragging) { background: transparent; }
  .table-card td.note .badge { margin-left: 4px; }
  .table-foot { padding: 14px 0; }

  /* Informes */
  .rep { grid-template-columns: 1fr 1fr; gap: 12px 14px; padding: 18px; }
  .rep .title { grid-column: 1 / -1; }
  .rep .btn { grid-column: 1 / -1; justify-content: center; }

  /* Toast por encima de las pestañas */
  .toast { bottom: calc(var(--m-tabs) + var(--sab) + 18px); max-width: calc(100vw - 40px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .m-update { bottom: calc(var(--m-tabs) + var(--sab) + 18px); }

  /* ---------- Subpestañas de Finanzas ---------- */
  .m-sub {
    display: none; position: sticky; top: calc(var(--m-top) + var(--sat)); z-index: 30;
    margin-top: calc(var(--m-top) + var(--sat)); padding: 4px 0 10px;
    background: linear-gradient(var(--bg) 70%, rgba(9,9,11,0));
    view-transition-name: m-sub;
  }
  body.m-scrolled .m-sub { background: rgba(11, 11, 14, .72); -webkit-backdrop-filter: saturate(180%) blur(22px); backdrop-filter: saturate(180%) blur(22px); border-bottom: .5px solid var(--line-strong); }
  body.m-fin .m-sub { display: block; }
  body.m-fin.m-scrolled .m-top { background: rgba(11, 11, 14, .72); border-bottom-color: transparent; }
  body.m-fin .main, body.m-fin[data-page] .main { padding-top: 6px; }
  body.m-fin #mascot { top: calc(var(--m-top) + var(--sat) + 2px); }
  .m-sub-track {
    position: relative; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
    padding: 0 16px; scroll-padding: 0 16px; -webkit-overflow-scrolling: touch;
  }
  .m-sub-track::-webkit-scrollbar { display: none; }
  .m-sub a {
    position: relative; z-index: 1; flex: none; height: 36px; padding: 0 15px; border-radius: 999px;
    display: grid; place-items: center; color: var(--text-2); text-decoration: none; font-size: 14px; font-weight: 600;
    transition: color .25s;
  }
  .m-sub a.on { color: #0b0b10; }
  .m-sub-ink {
    position: absolute; left: 0; top: 0; height: 36px; width: var(--w, 0); border-radius: 999px; background: var(--accent);
    transform: translateX(var(--x, 0)); transition: transform .45s var(--m-spring), width .45s var(--m-spring);
    box-shadow: 0 6px 18px rgba(139,124,246,.35);
  }
  .m-sub.no-anim .m-sub-ink { transition: none; }

  /* ---------- Pestañas inferiores ---------- */
  .m-tabs {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 46;
    padding: 6px 8px calc(6px + var(--sab));
    background: rgba(13, 13, 17, .92);
    -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px);
    border-top: .5px solid var(--line-strong);
    view-transition-name: m-tabs;
  }
  .m-tabs a {
    position: relative; z-index: 1; height: 50px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: var(--text-3); text-decoration: none; font-size: 10.5px; font-weight: 600; letter-spacing: .01em;
    transition: color .25s;
  }
  .m-tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; transition: transform .45s var(--m-spring), stroke .25s; }
  .m-tabs a.on { color: var(--text); }
  .m-tabs a.on svg { stroke: var(--accent); transform: translateY(-1px) scale(1.08); }
  .m-tabs a:active svg { transform: scale(.82); transition-duration: .12s; }
  .m-tabs-ink {
    position: absolute; top: 6px; left: 8px; height: 50px; width: calc((100% - 16px) / 5);
    border-radius: 16px; background: rgba(139, 124, 246, .14);
    transform: translateX(calc(var(--i, 0) * 100%)); transition: transform .5s var(--m-spring);
  }
  .m-tabs.no-anim .m-tabs-ink { transition: none; }

  /* ---------- Botón ⚡ Apuntar ---------- */
  .m-fab {
    display: grid; place-items: center; position: fixed; z-index: 44;
    right: 16px; bottom: calc(var(--m-tabs) + var(--sab) + 16px); width: 56px; height: 56px;
    border: 0; border-radius: 19px; background: var(--accent); color: #0b0b10;
    box-shadow: 0 10px 28px rgba(139,124,246,.45), 0 2px 6px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.35);
    transition: transform .45s var(--m-spring), opacity .25s;
    view-transition-name: m-fab;
  }
  .m-fab svg { width: 24px; height: 24px; fill: currentColor; stroke: currentColor; stroke-width: 1.2; stroke-linejoin: round; }
  .m-fab:active { transform: scale(.88); }
  body.m-fab-hide .m-fab { transform: translateY(calc(100% + var(--m-tabs) + 20px)) scale(.6); opacity: 0; }
  body[data-page="tareas"] .m-fab { display: none; }

  /* ---------- Hojas inferiores (todas las ventanas) ---------- */
  .backdrop { place-items: end stretch; padding: calc(var(--sat) + 12px) 0 var(--kb); animation: m-fade .3s ease-out; transition: padding-bottom .25s var(--m-ease); }
  .backdrop > .modal {
    position: relative; width: 100%; max-width: none !important; margin: 0;
    max-height: calc(100dvh - var(--sat) - 12px - var(--kb)); overflow-y: auto; overscroll-behavior: contain;
    border-radius: 28px 28px 0 0; border-bottom: 0;
    padding: 30px 20px calc(18px + var(--sab));
    box-shadow: 0 -18px 60px rgba(0,0,0,.55);
    animation: m-sheet-in .46s var(--m-ease);
  }
  .backdrop > .modal::before {
    content: ''; position: absolute; top: 9px; left: 50%; width: 38px; height: 5px; margin-left: -19px;
    border-radius: 3px; background: rgba(255,255,255,.22);
  }
  .backdrop > .modal.qc-modal { padding: 18px 0 var(--sab); }
  .backdrop > .modal.qc-modal::before { top: 7px; }
  .m-qc-save { display: flex; gap: 10px; padding: 12px 16px 6px; }
  .m-qc-save .btn { flex: 1; height: 50px; justify-content: center; border-radius: 15px; font-size: 15px; }
  .qc-foot { display: none; }
  .backdrop:has(.qc-modal) { place-items: end stretch; padding-top: calc(var(--sat) + 12px); }
  .modal h2 { font-size: 21px; margin-bottom: 16px; }
  .modal-actions { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 10px; margin-top: 18px; }
  .modal-actions .btn { height: 50px; justify-content: center; border-radius: 15px; font-size: 15px; }
  .form-row { margin-bottom: 12px; }
  .form-row label { font-size: 13px; }
  .form-row input, .form-row select { height: 48px; border-radius: 13px; padding: 0 14px; }
  .form-row input.big { height: 64px; font-size: 32px; }
  .segmented { border-radius: 12px; padding: 3px; }
  .segmented button { height: 38px; border-radius: 10px; font-size: 14px; transition: background .25s, color .25s; }
  .colors button { width: 34px; height: 34px; }

  /* Ficha de tarea: entra desde abajo como hoja a pantalla completa */
  .tk-sheet, .tk-sheet.full { animation: m-sheet-in .46s var(--m-ease); padding-top: var(--sat); }
  .tk-backdrop { animation: m-fade .3s ease-out; }

  /* Hoja que se va (copia animada que deja la capa móvil) */
  .m-leaving { position: fixed; inset: 0; z-index: 49; pointer-events: none; animation: m-fade-out .32s ease-in forwards; }
  .m-leaving > .modal, .m-leaving > .tk-sheet { animation: m-sheet-out .32s cubic-bezier(.4, 0, 1, 1) forwards !important; }

  /* Tareas: una columna por pantalla con imán */
  .tk-board { grid-auto-columns: calc(100vw - 48px); gap: 12px; margin: 0 -16px; padding: 2px 16px 24px; scroll-padding: 0 16px; scroll-snap-type: x mandatory; scrollbar-width: none; }
  .tk-board::-webkit-scrollbar { display: none; }
  .tk-col { scroll-snap-align: start; scroll-snap-stop: always; }

  /* Hoy */
  .hoy-habit { min-height: 48px; }
}

@keyframes m-fade { from { opacity: 0; } }
@keyframes m-fade-out { to { opacity: 0; } }
@keyframes m-sheet-in { from { transform: translateY(100%); } }
@keyframes m-sheet-out { from { transform: translateY(var(--from, 0)); } to { transform: translateY(100%); } }

/* ---------- Transiciones entre páginas ---------- */
::view-transition-old(root) { animation: m-vt-out .2s cubic-bezier(.4, 0, 1, 1) both; }
::view-transition-new(root) { animation: m-vt-in .34s cubic-bezier(.2, .8, .2, 1) both; }
html.vt-fwd::view-transition-old(root) { animation-name: m-vt-out-l; }
html.vt-fwd::view-transition-new(root) { animation-name: m-vt-in-r; }
html.vt-back::view-transition-old(root) { animation-name: m-vt-out-r; }
html.vt-back::view-transition-new(root) { animation-name: m-vt-in-l; }
::view-transition-group(m-tabs), ::view-transition-group(m-top), ::view-transition-group(m-fab), ::view-transition-group(mascot), ::view-transition-group(m-sub) { animation-duration: .3s; }
@keyframes m-vt-out { to { opacity: 0; } }
@keyframes m-vt-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes m-vt-out-l { to { opacity: 0; transform: translateX(-24px); } }
@keyframes m-vt-in-r { from { opacity: 0; transform: translateX(32px); } }
@keyframes m-vt-out-r { to { opacity: 0; transform: translateX(24px); } }
@keyframes m-vt-in-l { from { opacity: 0; transform: translateX(-32px); } }
@media (max-width: 760px) { #mascot { view-transition-name: mascot; } }

/* App instalada: sin selección accidental de texto en la interfaz */
@media (display-mode: standalone) {
  body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
  input, textarea, [contenteditable], .tk-doc, .note, .tx-main { -webkit-user-select: text; user-select: text; }
}

@media (prefers-reduced-motion: reduce) {
  .m-tabs-ink, .m-sub-ink, .m-fab, .m-top-title, .m-tabs svg, .m-update { transition: none !important; }
  .backdrop > .modal, .tk-sheet, .m-leaving, .m-leaving > * { animation: none !important; }
  ::view-transition-old(root), ::view-transition-new(root) { animation: none !important; }
}
