/* ==========================================================================
   Life OS — mobile & touch layer
   Loaded last. Touch behaviour applies at every size; layout rules apply
   ≤760px (phones). The app is designed phone-first from here.
   ========================================================================== */

/* ---------- Touch behaviour (all sizes) ---------- */
html { -webkit-tap-highlight-color: transparent; }
button, a, .task-main, .hw, .sheet-tile, .action-tile { touch-action: manipulation; }
.task { touch-action: pan-y; background: var(--surface); }
.task-grip { touch-action: none; }
.sheet-grip { display: none; }
.mobile-brand { display: none; }
.brand-mark.sm { width: 32px; height: 32px; border-radius: 10px; }

/* swipe-to-complete / swipe-to-delete */
.task-list { position: relative; }
.swipe-bg {
  position: absolute; left: 0; right: 0; border-radius: 14px; z-index: 0;
  display: flex; align-items: center; justify-content: space-between; padding: 0 18px;
  background: var(--bad); color: #fff; font-weight: 600; font-size: 13px;
}
.swipe-bg.right { background: var(--accent); color: var(--accent-ink); }
.swipe-bg span { display: flex; align-items: center; gap: 8px; opacity: 0.55; transition: opacity 0.15s, transform 0.2s var(--spring); }
.swipe-bg.right .sw-r, .swipe-bg:not(.right) .sw-l { visibility: hidden; }
.swipe-bg.armed span { opacity: 1; transform: scale(1.08); }
.task.swiping { transition: none; z-index: 1; border-radius: 14px; }
.task { transition: background 0.15s, opacity 0.35s var(--ease), transform 0.22s var(--ease); }
.task.lifting { z-index: 5; transition: none; box-shadow: var(--shadow-lg); border-radius: 14px; }
.task.lifting::before { opacity: 0; }

/* press feedback instead of hover on touch screens */
@media (hover: none) {
  .card.interactive:hover, .today-tile:hover, a.kpi:hover, .budget-card:hover { transform: none; box-shadow: var(--shadow-xs); }
  .task:hover { background: var(--surface); }
  .list-row.hoverable:hover { background: transparent; }
  .habit-tap:hover { transform: none; }
}
.today-tile:active, .card.interactive:active, .budget-card:active, a.kpi:active, .sheet-tile:active, .action-tile:active { transform: scale(0.97); }
.list-row.hoverable:active, .task:active:not(.swiping):not(.lifting) { background: var(--surface-hover); }

/* ---------- Sheets (More / Quick add) ---------- */
.sheet-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.sheet-tile {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px 6px 14px;
  border-radius: 20px; background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; font-weight: 550; text-align: center;
  transition: transform 0.15s var(--ease), background 0.15s;
}
.sheet-tile.active { background: var(--accent-soft); border-color: var(--accent-2); }
.sheet-ic { width: 46px; height: 46px; border-radius: 15px; background: var(--surface); border: 1px solid var(--border); display: grid; place-items: center; flex-shrink: 0; }
.sheet-tile.active .sheet-ic { background: var(--accent); border-color: var(--accent-2); color: var(--accent-ink); }
.sheet-rows { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.sheet-row { display: flex; align-items: center; gap: 12px; height: 52px; padding: 0 16px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--border); font-weight: 550; text-align: left; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.action-tile { display: flex; align-items: center; gap: 12px; padding: 12px; min-height: 66px; border-radius: 18px; background: var(--surface-2); border: 1px solid var(--border); font-weight: 550; font-size: 13.5px; line-height: 1.25; text-align: left; transition: transform 0.15s var(--ease); }
.action-tile .sheet-ic { width: 40px; height: 40px; border-radius: 13px; }
.bn-badge {
  position: absolute; top: 5px; left: 50%; margin-left: 5px; min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px;
  font-style: normal; font-size: 10px; font-weight: 700; display: grid; place-items: center; background: #3a3d36; color: #fff;
}
.bn-badge.alert { background: var(--bad); }
.sheet-tile .bn-badge { top: 8px; left: auto; right: 10px; margin: 0; background: var(--ink); color: var(--ink-text); }
.sheet-tile .bn-badge.alert { background: var(--bad); color: #fff; }
.tab-picks { display: flex; gap: 6px; flex-wrap: wrap; }
.tab-picks .select-wrap { width: 128px; }

/* ---------- Phones ---------- */
@media (max-width: 760px) {
  :root { --topbar: 58px; }

  /* top bar: brand + title, search, alerts */
  .topbar { height: calc(var(--topbar) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 10px 0 16px; background: color-mix(in srgb, var(--bg) 90%, transparent); }
  .topbar .mobile-brand.mobile-only { display: flex; align-items: center; gap: 10px; min-width: 0; }
  .mobile-title { font-weight: 650; font-size: 17px; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .top-actions { gap: 2px; }
  .top-actions .btn-icon { width: 42px; height: 42px; background: transparent; border-color: transparent; }
  .bell-dot { top: 10px; right: 11px; border-color: var(--bg); }

  /* page rhythm */
  .page { padding: 0 16px calc(118px + env(safe-area-inset-bottom)); }
  .page-head { margin: 6px 0 14px; gap: 12px; }
  .page-title { font-size: 28px; }
  .page-sub { font-size: 13.5px; margin-top: 4px; }
  .eyebrow { font-size: 12.5px; }
  .page-actions { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 2px; width: calc(100% + 32px); }
  .page-actions::-webkit-scrollbar { display: none; }
  .page-actions .btn { height: 38px; padding: 0 14px; font-size: 13.5px; flex-shrink: 0; }
  .page-actions > .btn.primary:last-child { margin-left: 0; }
  .page-actions:empty { display: none; }

  /* section tabs stay reachable while scrolling */
  .tabs { position: sticky; top: calc(var(--topbar) + env(safe-area-inset-top)); z-index: 20; margin: 0 -16px 12px; padding: 6px 16px 8px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
  .tab { height: 36px; padding: 0 14px; font-size: 13px; }

  /* stat rows become swipeable carousels instead of tall stacks */
  .kpis, .kpis.six, .today-strip {
    display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding-left: 16px; scrollbar-width: none;
    gap: 10px; margin: 0 -16px 12px; padding: 2px 16px 6px;
  }
  .kpis::-webkit-scrollbar, .today-strip::-webkit-scrollbar { display: none; }
  .kpis > .kpi { flex: 0 0 min(47%, 200px); scroll-snap-align: start; }
  .today-strip > .today-tile { flex: 0 0 min(44%, 180px); scroll-snap-align: start; }
  .modal .kpis { margin: 0 -20px 4px; padding: 2px 20px 6px; scroll-padding-left: 20px; }

  /* toolbars: search on its own row, filters in one scrollable row */
  .toolbar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-bottom: 12px; }
  .toolbar .search-input { min-width: 0; }
  .toolbar-filters { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 2px; }
  .toolbar-filters::-webkit-scrollbar { display: none; }
  .toolbar-filters > * { flex-shrink: 0; }
  .toolbar .seg { overflow: visible; max-width: none; }
  .select-sm { height: 38px; }

  /* comfortable touch targets (≥ 36px, most 44px) */
  .btn.sm { height: 36px; }
  .btn-icon.sm { width: 36px; height: 36px; }
  .btn-icon.xs { width: 32px; height: 32px; }
  .check { width: 26px; height: 26px; }
  .check.lg { width: 30px; height: 30px; }
  .seg-btn { height: 34px; }
  .list-row { padding: 13px 4px; }
  .mini-check { width: 20px; height: 20px; }
  .sub { padding: 6px 0; font-size: 14px; }

  /* tasks */
  .task { padding: 14px 6px; }
  .task-grip { display: grid !important; position: static; opacity: 1; order: 9; place-items: center; width: 34px; height: 34px; margin: -5px -4px -5px 0; color: var(--text-3); }
  .task .prio { order: 8; }
  .task .row-actions { order: 10; }
  .task + .task::before { left: 46px; }
  .tasks-head { margin-bottom: 12px; }
  .quick-add { margin-bottom: 4px; }
  .qa-preview { padding-bottom: 6px; }

  /* bottom bar with raised quick-add button */
  .bottom-nav { left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); height: 66px; padding: 0 6px; border-radius: 26px; justify-content: space-between; overflow: visible; }
  .bn-item { flex: 1; height: 56px; position: relative; font-size: 10.5px; border-radius: 18px; color: #8d9286; }
  .bn-item.active { background: transparent; color: var(--accent); }
  .bn-item.active svg { transform: translateY(-1px); }
  .bn-fab {
    width: 62px; height: 62px; border-radius: 50%; flex-shrink: 0; margin: 0 4px;
    display: grid; place-items: center; background: var(--accent); color: var(--accent-ink);
    border: 5px solid var(--bg); transform: translateY(-16px); box-shadow: 0 10px 22px -8px rgba(150, 190, 20, 0.7);
    transition: transform 0.2s var(--spring);
  }
  .bn-fab:active { transform: translateY(-16px) scale(0.92); }

  /* bottom sheets */
  .modal { max-height: 92dvh; }
  .modal::before { display: none; }
  .sheet-grip { display: flex; justify-content: center; align-items: center; height: 24px; margin-bottom: -10px; flex-shrink: 0; touch-action: none; cursor: grab; }
  .sheet-grip::after { content: ''; width: 42px; height: 5px; border-radius: 3px; background: var(--border-2); }
  .modal-head { padding: 12px 20px 4px; touch-action: none; }
  .modal-title { font-size: 19px; }
  .modal-body { padding: 12px 20px 18px; }
  .modal-foot { padding: 12px 20px calc(14px + env(safe-area-inset-bottom)); flex-wrap: nowrap; }
  .modal:not(.confirm) .modal-foot .btn.ghost[data-close] { display: none; }
  .modal-foot .btn.primary { flex: 1; height: 46px; font-size: 15px; }
  .modal-foot .btn { height: 46px; }
  .sheet-more .modal-body, .sheet-actions .modal-body { padding-bottom: calc(22px + env(safe-area-inset-bottom)); }
  .confirm .modal-foot .btn { height: 48px; }

  /* command palette drops from the top so the keyboard never covers results */
  .palette-back { align-items: flex-start; }
  .palette-back .modal.palette { border-radius: 0 0 26px 26px; transform: translateY(-100%); padding-top: env(safe-area-inset-top); }
  .palette-back.open .modal.palette { transform: none; }
  .palette-back.closing .modal.palette { transform: translateY(-100%); }
  .palette .sheet-grip, .pal-foot { display: none; }
  .pal-input { height: 58px; padding: 0 16px; }
  .pal-input kbd { display: none; }
  .pal-list { max-height: 62dvh; }
  .pal-item { padding: 10px 12px; }

  /* context menus become action sheets */
  .menu.sheet {
    left: 8px !important; right: 8px; top: auto !important; bottom: calc(8px + env(safe-area-inset-bottom));
    min-width: 0; max-height: 72dvh; overflow-y: auto; padding: 8px; border-radius: 24px; z-index: 810;
    transform: translateY(24px); transform-origin: bottom center;
  }
  .menu.sheet.open { transform: none; }
  .menu.sheet .menu-item { height: 50px; font-size: 15px; padding: 0 14px; border-radius: 14px; gap: 12px; }
  .menu.sheet .menu-head { padding: 10px 14px 4px; }
  .menu-scrim { position: fixed; inset: 0; z-index: 805; background: rgba(12, 14, 10, 0.38); opacity: 0; transition: opacity 0.2s; }
  .menu-scrim.open { opacity: 1; }

  /* habit tiles: tap target top-right, week row gets the full width */
  .habit { padding: 16px; gap: 14px; }
  .habit-top { padding-right: 64px; }
  .habit-top .btn-icon { top: auto; bottom: 12px; right: 10px; }
  .habit-tap { top: 14px; right: 14px; bottom: auto; }
  .habit-off { top: 22px; bottom: auto; }
  .habit-bottom { padding-right: 38px; }
  .habit-week { gap: 4px; }
  .hw { width: 31px; height: 31px; border-radius: 10px; font-size: 11px; }

  /* misc density */
  .w-prod-score .big { font-size: 40px; }
  .gym-hero .hero-title { font-size: 32px; }
  .date-nav { margin-bottom: 14px; }
  .meal-empty { height: 56px; }
  .settings .card { padding: 16px 18px; }
  .tab-picks { width: 100%; }
  .tab-picks .select-wrap { flex: 1; width: auto; min-width: 0; }
  .toasts { bottom: calc(96px + env(safe-area-inset-bottom)); }
  /* top bar title: wordmark at rest, page name once the big title scrolls away */
  .mobile-title { position: relative; display: grid !important; }
  .mt-brand, .mt-page { grid-area: 1 / 1; transition: opacity 0.2s, transform 0.25s var(--ease); }
  .mt-brand span { color: var(--text-3); font-weight: 450; }
  .mt-page { opacity: 0; transform: translateY(6px); }
  .topbar.titled .mt-brand { opacity: 0; transform: translateY(-6px); }
  .topbar.titled .mt-page { opacity: 1; transform: none; }

  /* the + button owns each page's main action on phones */
  .page-actions .btn.primary { display: none; }
  .page-actions:not(:has(> :not(.primary))) { display: none; }
  .action-tile.featured { grid-column: span 2; background: var(--ink); color: var(--ink-text); border-color: var(--ink); min-height: 70px; font-size: 15px; }
  .action-tile.featured .sheet-ic { background: var(--accent); border-color: var(--accent-2); color: var(--accent-ink); }
  .action-tile.featured > svg:last-child { margin-left: auto; opacity: 0.6; }

  /* side KPI stacks (gym/habits) become the same swipe row */
  .gym-side { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; gap: 10px; margin: 0 -16px; padding: 2px 16px 6px; grid-template-columns: none; }
  .gym-side::-webkit-scrollbar { display: none; }
  .gym-side > .kpi { flex: 0 0 min(47%, 200px); scroll-snap-align: start; }
  .gym-side > .kpi:first-child { grid-column: auto; }

  /* compact heroes */
  .habit-hero { flex-direction: row; align-items: center; gap: 16px; padding: 18px; }
  .habit-hero .ring { width: 84px !important; height: 84px !important; }
  .habit-hero .ring svg { width: 84px; height: 84px; }
  .habit-hero .ring-big { font-size: 18px; }
  .habit-hero .hero-title { font-size: 21px; }
  .habit-hero .eyebrow { font-size: 12px; }
  .habit-hero p { font-size: 12.5px; }
  .toast { padding: 8px 8px 8px 10px; font-size: 13px; border-radius: 16px; }
  .toast-icon { width: 26px; height: 26px; }
  .desktop-only { display: none !important; }
  body.has-modal .toasts { top: calc(10px + env(safe-area-inset-top)); bottom: auto; }
  body.has-modal .toast { animation-name: toast-in-top; }
}
@keyframes toast-in-top { from { opacity: 0; transform: translateY(-12px) scale(0.96); } }



/* very small phones */
@media (max-width: 360px) {
  .page-title { font-size: 25px; }
  .hw { width: 28px; height: 28px; }
  .bn-item span { font-size: 9.5px; }
  .sheet-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
