/* ── Horizon Mobile Enhancements (shared) ─────────────────────────────── */

/* Touch-friendly minimum tap targets on mobile */
@media (max-width: 768px) {
  .month-nav-btn,
  .btn-calendar-nav,
  .btn-heatmap-toggle,
  .btn-timeframe,
  .btn-view-toggle,
  .sankey-crumb-back,
  .goal-action-btn,
  .mobile-header-user,
  .mobile-more-nav-item,
  .txn-swipe-action {
    min-width: 44px;
    min-height: 44px;
  }

  .month-nav-btn {
    width: 44px;
    height: 44px;
  }

  /* Hover-only controls visible on touch devices */
  @media (hover: none) {
    .goal-card-actions {
      opacity: 1;
    }
  }
}

/* ── Mobile sticky dashboard summary ─────────────────────────────────── */
.mobile-sticky-summary {
  display: none;
}

@media (max-width: 768px) {
  .mobile-sticky-summary {
    display: none;
    position: fixed;
    top: 3.25rem;
    left: 0;
    right: 0;
    z-index: 850;
    background: var(--surface, #fff);
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem 0.875rem;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
    transform: translateY(-110%);
    transition: transform 0.2s ease;
  }

  .mobile-sticky-summary.visible {
    display: flex;
    transform: translateY(0);
  }

  .mobile-sticky-summary-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
  }

  .mobile-sticky-stat {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
    flex: 1;
  }

  .mobile-sticky-label {
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
  }

  .mobile-sticky-value {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-sticky-value.positive { color: var(--success-color, #22c55e); }
  .mobile-sticky-value.negative { color: var(--danger-color, #ef4444); }

  [data-theme="dark"] .mobile-sticky-summary {
    background: var(--surface);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  }
}

/* ── Hero mobile: 2×2 grid + collapsible secondary tiles ─────────────── */
@media (max-width: 768px) {
  .dashboard-hero .hero-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.4rem;
  }

  .dashboard-hero .hero-grid--primary {
    margin-bottom: 0;
  }

  .hero-more-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    width: 100%;
    margin-top: 0.4rem;
    padding: 0.45rem 0.75rem;
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
  }

  .hero-more-toggle i {
    transition: transform 0.2s ease;
  }

  .hero-more-toggle[aria-expanded="true"] i {
    transform: rotate(180deg);
  }

  .hero-grid--secondary {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    margin-top: 0;
    transition: max-height 0.25s ease, opacity 0.2s ease, margin-top 0.2s ease;
  }

  .hero-grid--secondary.expanded {
    max-height: 400px;
    opacity: 1;
    margin-top: 0.4rem;
  }

  /* Compact sparkline on mobile */
  .hero-sparkline-wrap {
    display: block !important;
    width: 72px;
    height: 36px;
    flex-shrink: 0;
  }

  .hero-sparkline-wrap canvas {
    width: 72px !important;
    height: 36px !important;
  }

  .hero-networth-body {
    flex-wrap: nowrap;
    align-items: center;
  }
}

@media (min-width: 769px) {
  .hero-more-toggle,
  .hero-grid--secondary {
    display: none;
  }
}

/* ── Mobile More sheet (bottom nav overflow) ─────────────────────────── */
.mobile-more-sheet {
  display: none;
}

@media (max-width: 768px) {
  .mobile-more-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1090;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .mobile-more-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-more-sheet {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1100;
    background: var(--surface, #fff);
    border-radius: 1rem 1rem 0 0;
    padding: 0.75rem 0 calc(1rem + env(safe-area-inset-bottom));
    box-shadow: 0 -8px 32px rgba(15, 23, 42, 0.15);
    transform: translateY(100%);
    transition: transform 0.25s ease;
  }

  .mobile-more-sheet.open {
    transform: translateY(0);
  }

  .mobile-more-sheet-handle {
    width: 2.5rem;
    height: 4px;
    background: var(--border-color);
    border-radius: 999px;
    margin: 0 auto 0.75rem;
  }

  .mobile-more-sheet-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    padding: 0 1rem 0.5rem;
  }

  .mobile-more-nav-item {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0.875rem 1rem;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 1rem;
    font-weight: 500;
    border-bottom: 1px solid var(--border-color);
    min-height: 52px;
  }

  .mobile-more-nav-item:last-child {
    border-bottom: none;
  }

  .mobile-more-nav-item.active {
    color: var(--primary-color);
    background: rgba(59, 130, 246, 0.06);
  }

  .mobile-more-nav-item i {
    font-size: 1.25rem;
    width: 1.5rem;
    text-align: center;
  }

  .mobile-nav-item--more {
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: inherit;
  }

  [data-theme="dark"] .mobile-more-sheet {
    background: var(--surface);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.45);
  }
}

/* ── Pull-to-refresh indicator ───────────────────────────────────────── */
.ptr-indicator {
  display: none;
  position: fixed;
  top: 3.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(-100%);
  z-index: 900;
  background: var(--surface, #fff);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  padding: 0.4rem 0.875rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.1);
  transition: transform 0.15s ease, opacity 0.15s ease;
  pointer-events: none;
}

.ptr-indicator.visible {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transform: translateX(-50%) translateY(0.5rem);
}

.ptr-indicator.refreshing i {
  animation: ptr-spin 0.8s linear infinite;
}

@keyframes ptr-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ── Transaction swipe actions ───────────────────────────────────────── */
@media (max-width: 767px) {
  .txn-row-group {
    position: relative;
    overflow: hidden;
  }

  .txn-swipe-actions {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: stretch;
    transform: translateX(100%);
    transition: transform 0.2s ease;
    z-index: 1;
  }

  .txn-row-group.swipe-open .txn-swipe-actions {
    transform: translateX(0);
  }

  .txn-row-group.swipe-open .transaction-item {
    transform: translateX(-156px);
    transition: transform 0.2s ease;
  }

  .txn-swipe-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    width: 52px;
    border: none;
    cursor: pointer;
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: #fff;
    padding: 0.25rem;
  }

  .txn-swipe-action i {
    font-size: 1.1rem;
  }

  .txn-swipe-action--category { background: #3b82f6; }
  .txn-swipe-action--hide { background: #64748b; }
  .txn-swipe-action--note { background: #8b5cf6; }

  .filter-chips-row {
    display: flex !important;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0.375rem;
    padding: 0.5rem 0.875rem;
    scrollbar-width: none;
  }

  .filter-chips-row::-webkit-scrollbar {
    display: none;
  }

  .filter-chip {
    flex-shrink: 0;
    min-height: 36px;
  }
}
