/* Responsive Mobile-Only UI System & Quality Assurance - Dark Fintech SaaS Theme */

/* Accessibility Keyboard & Touch Focus Styles */
:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Touch Action Optimization for Fast Response without 300ms Click Delay */
a, button, input, select, textarea, .btn, .nav-item, .card {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Base Body Containment to Eliminate Unwanted Horizontal Page Scrolling */
html, body {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

/* Mobile-Only Responsive Rules (Screen Width <= 768px) */
@media (max-width: 768px) {

  /* ------------------------------------------------------------
   * PART 1 — DASHBOARD DUPLICATE ACTION BUTTONS (MOBILE FIX)
   * Hide ONLY the header-level "+ Add Income" and "+ Add Expense" buttons in top-navbar.
   * Keep filter-level buttons below "This Month" visible on mobile.
   * ------------------------------------------------------------ */
  /* Hide header action buttons on mobile, but keep Theme Toggle & Notifications */
  #nav-btn-add-income,
  #nav-btn-add-expense,
  .top-navbar .btn-bubble,
  .top-navbar .btn-glow {
    display: none !important;
  }

  /* Theme Toggle icon-only mode on mobile screens */
  #btn-theme-toggle .desktop-only-text {
    display: none !important;
  }

  /* Main Content Spacing for Mobile Navigation */
  .main-content {
    padding: var(--space-4) var(--space-3) 90px var(--space-3);
  }

  /* Main Wrapper Zero Margin on Mobile */
  .main-wrapper {
    margin-left: 0;
    width: 100%;
    max-width: 100vw;
  }

  /* Top Navbar Fixed Single Line on Mobile */
  .top-navbar {
    height: 60px;
    min-height: 60px;
    max-height: 60px;
    padding: 0 12px;
    flex-wrap: nowrap;
    justify-content: space-between;
  }

  .top-navbar h2 {
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
  }

  /* Mobile Header Icon Button Mathematical Centering (Hamburger, Notification Bell & Theme Toggle) */
  #btn-mobile-sidebar-toggle,
  #btn-nav-notifications,
  #btn-theme-toggle {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
    width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
    min-width: 44px !important;
    box-sizing: border-box !important;
    line-height: 1 !important;
  }

  #btn-mobile-sidebar-toggle .ti,
  #btn-nav-notifications .ti,
  #btn-theme-toggle .ti {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    line-height: 1 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Form & Button Touch Targets (44px Minimum) */
  .btn {
    min-height: 44px;
    padding: 10px 16px;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .btn-sm {
    min-height: 44px;
    padding: 8px 14px;
    font-size: 13px;
  }

  .form-control {
    min-height: 44px;
    font-size: 16px !important; /* Prevents auto-zoom on Android/iOS keyboard focus */
    padding: 10px 14px;
    border-radius: 10px;
  }

  /* Mobile Responsive Date Input */
  input[type="date"].form-control {
    min-height: 44px;
    font-size: 16px !important;
    appearance: none;
    -webkit-appearance: none;
    background-color: var(--color-form-bg);
    color: var(--color-text);
  }

  /* Sidebar Mobile Drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 285px;
    z-index: 1050;
    transform: translateX(-100%);
    transition: transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    background: var(--color-sidebar-bg, var(--color-surface));
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  /* Backdrop for Mobile Sidebar */
  .sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(8, 10, 20, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1040;
    opacity: 0;
    visibility: hidden;
    transition: all 250ms ease;
  }

  .sidebar-backdrop.active {
    opacity: 1;
    visibility: visible;
  }

  /* Page Headers Stacking on Mobile */
  .page-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 16px;
    width: 100%;
  }

  .page-header h1 {
    font-size: 1.35rem;
  }

  .page-header select,
  .page-header input {
    width: 100%;
  }

  /* Budget Header Controls Mobile Responsive Overflow Fix */
  .budget-header-controls {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 8px !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .budget-header-controls select,
  .budget-header-controls button {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* Metric & Layout Grids */
  .metrics-grid {
    grid-template-columns: 1fr;
    gap: 12px;
    width: 100%;
  }

  .dashboard-grid {
    grid-template-columns: 1fr !important;
    gap: 16px;
    width: 100% !important;
    max-width: 100% !important;
  }

  .dashboard-grid > div {
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .card {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
    padding: 16px 14px !important;
  }

  /* Modals on Mobile (Centered Mobile Card View with Consistent 18px Rounded Corners) */
  .modal-backdrop {
    padding: 12px;
    align-items: center !important;
    justify-content: center !important;
  }

  .modal {
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
    max-height: 85vh;
    border-radius: 18px !important;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
    overscroll-behavior: contain;
    animation: modalFadeCenter 250ms ease-out;
  }

  .modal form {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  @keyframes modalFadeCenter {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
  }

  .modal-body {
    padding: var(--space-4);
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior-y: contain !important;
    flex: 1;
    min-height: 0;
  }

  .modal-footer {
    flex-shrink: 0;
  }

  .modal-header, .modal-footer {
    padding: var(--space-3) var(--space-4);
  }

  /* Mobile App Bottom Navigation Bar */
  .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--color-sidebar-bg, var(--color-surface));
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 990;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.2);
  }

  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 11px;
    gap: 3px;
    padding: 6px 10px;
    border-radius: 10px;
    transition: all 200ms ease;
    min-width: 52px;
    min-height: 44px;
  }

  .mobile-nav-item.active {
    color: #EC4899;
    background: rgba(124, 58, 237, 0.18);
  }

  .mobile-nav-item span:first-child {
    font-size: 18px;
  }

  /* Floating Quick Action Button for Mobile */
  .mobile-fab-add {
    position: fixed;
    bottom: 76px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7C3AED, #EC4899);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    font-weight: 700;
    box-shadow: 0 10px 30px rgba(124, 58, 237, 0.5);
    z-index: 991;
    border: 2px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
    transition: transform 200ms ease;
  }

  .mobile-fab-add:active {
    transform: scale(0.92);
  }

  .mobile-fab-add.active {
    transform: rotate(45deg);
  }

  /* Mobile Speed-Dial Floating Action Menu */
  .mobile-fab-menu {
    position: fixed;
    bottom: 142px;
    right: 20px;
    z-index: 992;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    transition: opacity 200ms ease, transform 200ms ease, visibility 200ms ease;
  }

  .mobile-fab-menu.hidden {
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px) scale(0.95);
    pointer-events: none;
  }

  .mobile-fab-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 30px;
    border: 1px solid var(--color-border);
    background: var(--color-surface-elevated, var(--color-surface));
    color: var(--color-text);
    font-size: 14px;
    font-weight: 600;
    box-shadow: var(--shadow-md);
    cursor: pointer;
    white-space: nowrap;
    transition: transform 150ms ease, background-color 150ms ease;
  }

  .mobile-fab-option:active {
    transform: scale(0.95);
  }

  .fab-option-expense {
    border-left: 4px solid #EF4444;
  }

  .fab-option-income {
    border-left: 4px solid #22C55E;
  }

  /* State-based: Hide mobile bottom navigation bar, floating FAB button, and speed-dial menu when any modal form is open */
  body.modal-open .mobile-bottom-nav,
  body.modal-open .mobile-fab-add,
  body.modal-open .mobile-fab-menu {
    display: none !important;
  }

  /* Mobile-Only Native App Launch Splash Screen */
  .mobile-splash-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    background: #080A14;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: env(safe-area-inset-top, 20px) 20px env(safe-area-inset-bottom, 20px) 20px;
    box-sizing: border-box;
    overflow: hidden;
    transition: opacity 400ms cubic-bezier(0.4, 0, 0.2, 1), visibility 400ms ease;
  }

  .mobile-splash-container.fade-out {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  .mobile-splash-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 18px;
  }

  .mobile-splash-logo-wrapper {
    width: 90px;
    height: 90px;
    border-radius: 22px;
    overflow: hidden;
    box-shadow: 0 0 35px rgba(124, 58, 237, 0.45);
    animation: splashLogoScale 700ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards, splashGlowGlow 2s ease-in-out infinite alternate;
  }

  .mobile-splash-logo {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .mobile-splash-title {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 700;
    color: #F8FAFC;
    letter-spacing: -0.02em;
    margin: 0;
    opacity: 0;
    animation: splashTitleFade 600ms ease-out 350ms forwards;
  }

  @keyframes splashLogoScale {
    0% {
      opacity: 0;
      transform: scale(0.65);
    }
    100% {
      opacity: 1;
      transform: scale(1);
    }
  }

  @keyframes splashGlowGlow {
    0% {
      box-shadow: 0 0 25px rgba(124, 58, 237, 0.35);
    }
    100% {
      box-shadow: 0 0 45px rgba(236, 72, 153, 0.55);
    }
  }

  @keyframes splashTitleFade {
    0% {
      opacity: 0;
      transform: translateY(10px);
    }
    100% {
      opacity: 1;
      transform: translateY(0);
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .mobile-splash-logo-wrapper,
    .mobile-splash-title {
      animation: none !important;
      opacity: 1 !important;
      transform: none !important;
    }
    .mobile-splash-container {
      transition: opacity 200ms ease !important;
    }
  }
}

/* Compact Smartphones (Screen Width <= 375px: e.g. 320px, 360px, 375px) */
@media (max-width: 375px) {
  .main-content {
    padding: var(--space-3) var(--space-2) 90px var(--space-2);
  }

  .card {
    padding: var(--space-4) var(--space-3);
    border-radius: 14px;
  }

  .metric-value {
    font-size: 1.5rem;
  }

  .page-header h1 {
    font-size: 1.25rem;
  }

  .mobile-nav-item {
    font-size: 10px;
    padding: 4px 6px;
    min-width: 44px;
  }

  .btn {
    padding: 8px 12px;
    font-size: 13px;
  }

  .auth-card {
    padding: 20px 14px;
    border-radius: 16px;
    width: 100%;
  }

  /* Mobile Notification Header Actions (Top-Right Compact Controls) */
  .page-header.notif-page-header {
    display: flex !important;
    flex-direction: row !important;
    align-items: flex-start !important;
    justify-content: space-between !important;
    gap: 8px !important;
    margin-bottom: 16px !important;
  }

  .notif-page-header .page-title-group {
    flex: 1;
    min-width: 0;
  }

  .notif-page-header .page-title-group h1 {
    font-size: 1.25rem !important;
    margin-bottom: 2px !important;
  }

  .notif-page-header .page-title-group p {
    font-size: 0.8rem !important;
  }

  .notif-header-actions {
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    flex-shrink: 0 !important;
    margin-top: 2px !important;
  }

  .notif-header-actions .btn {
    min-height: 36px !important;
    height: 36px !important;
    padding: 4px 10px !important;
    font-size: 12px !important;
    border-radius: 8px !important;
    white-space: nowrap !important;
    line-height: 1 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .notif-header-actions .btn .ti {
    font-size: 1rem !important;
  }

  @media (max-width: 380px) {
    .notif-header-actions .btn .notif-btn-label {
      display: none !important;
    }
    .notif-header-actions .btn {
      width: 36px !important;
      min-width: 36px !important;
      height: 36px !important;
      min-height: 36px !important;
      padding: 0 !important;
    }
    .notif-header-actions .btn .ti {
      margin-right: 0 !important;
      font-size: 1.15rem !important;
    }
  }
}

/* Desktop & Laptop Screens (> 768px) - Preserves Existing Desktop UI 100% Unchanged */
@media (min-width: 769px) {
  .mobile-fab-add,
  .mobile-bottom-nav,
  .sidebar-backdrop,
  .mobile-splash-container {
    display: none !important;
  }

  .page-header.notif-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
  }

  .notif-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
  }
}
