/* Mobile-specific overrides and optimizations */

@media (max-width: 768px) {
  :root {
    --bottom-nav-h: 68px;
  }

  /* Font sizing for mobile */
  .card-value {
    font-size: 22px;
  }

  /* Summary cards stack */
  .summary-cards {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  /* Tighter spacing */
  .tab-content {
    padding: 12px;
  }

  .section {
    margin-bottom: 18px;
  }

  /* Category chips - fit 2 per row on narrow screens */
  .category-chips {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Make inputs bigger to avoid iOS zoom */
  .text-input,
  .select-input,
  .textarea-input,
  .amount-input {
    font-size: 16px; /* Prevents iOS auto-zoom on input focus */
    padding: 12px;
  }

  /* Touch targets - minimum 44px */
  .btn-primary,
  .btn-secondary,
  .btn-danger,
  .txn-row,
  .account-row,
  .chip,
  .nav-btn {
    min-height: 44px;
  }

  /* Remove tap highlight color */
  button, input, select, a {
    -webkit-tap-highlight-color: transparent;
  }

  /* Bottom sheet adjustments */
  .bottom-sheet {
    max-height: 92vh;
    max-height: 92dvh;
  }

  /* Sheet tabs - prevent overflow */
  .sheet-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .sheet-tabs::-webkit-scrollbar {
    display: none;
  }

  /* Form sections in sheets */
  .sheet-content {
    padding: 12px;
  }

  /* FAB positioning for mobile */
  .desktop-nav-wrap,
  .nav-primary-action {
    display: none !important;
  }

  .fab {
    display: flex;
    bottom: calc(var(--bottom-nav-h) + 12px);
    right: 12px;
    width: 46px;
    height: 46px;
    border-radius: 14px;
    font-size: 22px;
  }

  /* Navigation bar - optimize for mobile */
  .nav-inner {
    padding: 0 12px;
    gap: 0.55rem;
  }

  .nav-logo {
    font-size: 16px;
  }

  .nav-title {
    font-size: 13px;
  }

  /* Toast - full width on mobile */
  .toast-viewport {
    left: 12px;
    right: 12px;
    bottom: calc(var(--bottom-nav-h) + 12px);
  }

  .toast-stack {
    align-items: stretch;
  }

  .toast-card {
    width: 100%;
  }

  /* Budget month navigation */
  .budget-month {
    padding: 10px;
  }

  .btn-nav {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }

  .month-label {
    font-size: 14px;
  }

  /* Prevent horizontal scrolling */
  body, html {
    overflow-x: hidden;
  }

  /* Context menu - clamp to screen */
  .context-menu {
    max-width: calc(100vw - 24px);
  }

  /* Grid layouts */
  .summary-cards {
    grid-template-columns: 1fr;
  }

  .category-chips {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Ultra-small screens */
@media (max-width: 480px) {
  .card-value {
    font-size: 20px;
  }

  .tab-content {
    padding: 10px;
  }

  .section-title {
    font-size: 15px;
  }

  .txn-desc {
    font-size: 13px;
  }

  /* Amount input - make huge for one-handed operation */
  .amount-input {
    font-size: 28px;
    padding: 20px 12px;
    min-height: 60px;
  }

  .sheet-header h2 {
    font-size: 16px;
  }

  .budget-card {
    padding: 12px;
  }

  .category-chips {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .chip {
    padding: 8px 10px;
    font-size: 12px;
  }
}

/* iPhone notch safe area */
@supports (padding: max(0px)) {
  .navbar {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }

  .bottom-nav {
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }

  .fab {
    right: max(12px, env(safe-area-inset-right));
    bottom: calc(var(--bottom-nav-h) + max(12px, env(safe-area-inset-bottom)));
  }

  .toast-viewport {
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    bottom: calc(var(--bottom-nav-h) + max(12px, env(safe-area-inset-bottom)));
  }

  .content-area {
    padding-bottom: calc(var(--bottom-nav-h) + max(0px, env(safe-area-inset-bottom)));
  }
}

/* Landscape mode adjustments */
@media (max-height: 500px) {
  .summary-cards {
    gap: 8px;
    margin-bottom: 12px;
  }

  .card {
    padding: 10px;
    margin-bottom: 8px;
  }

  .card-value {
    font-size: 18px;
    margin-top: 4px;
  }

  .section {
    margin-bottom: 12px;
  }

  .section-title {
    margin-bottom: 8px;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Dark mode forced */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
  }
}

/* Light mode forced */
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
  }
}

/* Swipe/scroll hints for touch devices */
.sheet-tabs {
  position: relative;
}

.sheet-tabs::after {
  content: '→';
  position: absolute;
  right: 8px;
  opacity: 0.3;
  pointer-events: none;
}

/* Transaction row touch feedback */
.txn-row {
  touch-action: manipulation;
  user-select: none;
}

/* Numpad-like buttons */
.numpad-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 12px;
}

.numpad-btn {
  aspect-ratio: 1;
  padding: 0;
  min-height: 50px;
  border-radius: 8px;
  font-size: 20px;
  font-weight: 600;
}

.numpad-btn.del {
  grid-column: 3;
}

.numpad-btn.zero {
  grid-column: 1 / 3;
}

.numpad-btn.submit {
  grid-column: 1 / 4;
  aspect-ratio: auto;
}
