/**
 * Mobile-First Responsive Design Styles
 * Optimized for touch devices with 44px minimum targets
 */

/* ===================================
   Enhanced Mobile Bottom Navigation
   =================================== */

.mobile-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 70px;
  background: rgba(0, 0, 0, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
  display: none;
  justify-content: space-around;
  align-items: center;
  z-index: 1000;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

@media (max-width: 768px) {
  .mobile-bottom-nav {
    display: flex;
  }
}

.mobile-bottom-nav .nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 56px;
  min-width: 56px;
  text-decoration: none;
  color: rgba(255, 255, 255, 0.6);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  padding: 8px 12px;
  border-radius: 12px;
  margin: 0 4px;
}

.mobile-bottom-nav .nav-item .icon {
  font-size: 24px;
  margin-bottom: 4px;
  transition: transform 0.3s ease;
  display: block;
}

.mobile-bottom-nav .nav-item span {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: all 0.3s ease;
}

.mobile-bottom-nav .nav-item:active {
  transform: scale(0.95);
}

.mobile-bottom-nav .nav-item.active {
  color: rgb(99, 102, 241);
  background: rgba(99, 102, 241, 0.1);
}

.mobile-bottom-nav .nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 3px;
  background: linear-gradient(90deg, rgb(99, 102, 241), rgb(139, 92, 246));
  border-radius: 0 0 3px 3px;
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.mobile-bottom-nav .nav-item.active .icon {
  transform: scale(1.1);
  filter: drop-shadow(0 2px 4px rgba(99, 102, 241, 0.4));
}

.mobile-bottom-nav .nav-item .badge {
  position: absolute;
  top: 4px;
  right: 20%;
  background: #ef4444;
  color: white;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===================================
   Hamburger Menu
   =================================== */

.hamburger-menu {
  display: none;
  flex-direction: column;
  justify-content: space-between;
  width: 32px;
  height: 26px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  z-index: 1001;
  transition: transform 0.3s ease;
}

.hamburger-menu:hover {
  transform: scale(1.1);
}

.hamburger-menu:active {
  transform: scale(0.95);
}

.hamburger-menu .line {
  width: 100%;
  height: 3px;
  background: white;
  border-radius: 3px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: center;
}

.hamburger-menu.active .line:nth-child(1) {
  transform: rotate(45deg) translateY(11px);
}

.hamburger-menu.active .line:nth-child(2) {
  opacity: 0;
  transform: translateX(-20px);
}

.hamburger-menu.active .line:nth-child(3) {
  transform: rotate(-45deg) translateY(-11px);
}

@media (max-width: 768px) {
  .hamburger-menu {
    display: flex;
  }
  
  .nav-links {
    position: fixed;
    top: 60px;
    left: -100%;
    width: 85%;
    max-width: 320px;
    height: calc(100vh - 60px);
    background: rgba(15, 23, 42, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    flex-direction: column;
    padding: 24px 16px;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
  }
  
  .nav-links.active {
    left: 0;
  }

  .nav-links li {
    margin: 0;
    width: 100%;
  }

  .nav-links a {
    display: block;
    padding: 16px 20px;
    border-radius: 12px;
    transition: all 0.3s ease;
    font-size: 16px;
    margin-bottom: 8px;
  }

  .nav-links a:hover,
  .nav-links a.active {
    background: rgba(99, 102, 241, 0.1);
    color: rgb(99, 102, 241);
    transform: translateX(8px);
  }

  body.nav-open {
    overflow: hidden;
  }

  body.nav-open::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    animation: fadeIn 0.3s ease-out;
  }
  
  .dashboard-main {
    padding-bottom: 90px;
  }
}

/* Ripple effect on tap */
.mobile-bottom-nav .nav-item::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(59, 130, 246, 0.3);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.mobile-bottom-nav .nav-item:active::after {
  width: 100px;
  height: 100px;
}

/* ===================================
   Mobile Menu Toggle
   =================================== */

.mobile-menu-toggle {
  display: none;
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 12px;
  margin-right: 12px;
  color: #1e293b;
  transition: all 0.2s ease;
}

@media (max-width: 768px) {
  .mobile-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

.mobile-menu-toggle i {
  font-size: 20px;
}

.mobile-menu-toggle:active {
  transform: scale(0.95);
  background: rgba(0, 0, 0, 0.05);
  border-radius: 8px;
}

/* ===================================
   Mobile Sidebar
   =================================== */

@media (max-width: 768px) {
  .sidebar,
  .side-nav,
  aside {
    position: fixed;
    left: -100%;
    top: 0;
    height: 100vh;
    width: 280px;
    max-width: 80%;
    z-index: 1001;
    transition: left 0.3s ease;
    overflow-y: auto;
  }

  .sidebar.mobile-visible,
  .side-nav.mobile-visible,
  aside.mobile-visible {
    left: 0;
  }
}

.mobile-sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.mobile-sidebar-overlay.active {
  display: block;
  opacity: 1;
}

/* ===================================
   Pull to Refresh
   =================================== */

.pull-to-refresh-indicator {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translate(-50%, -100%);
  z-index: 9999;
  background: white;
  padding: 12px 24px;
  border-radius: 0 0 12px 12px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 12px;
  transition: transform 0.3s ease;
}

.pull-to-refresh-indicator .spinner {
  width: 20px;
  height: 20px;
  border: 2px solid #e2e8f0;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  opacity: 0;
}

.pull-to-refresh-indicator.ready .spinner,
.pull-to-refresh-indicator.refreshing .spinner {
  opacity: 1;
}

.pull-to-refresh-indicator .text {
  font-size: 14px;
  font-weight: 500;
  color: #475569;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ===================================
   Touch-Friendly Elements (44px min)
   =================================== */

@media (max-width: 768px) {
  button,
  a.btn,
  input[type="button"],
  input[type="submit"],
  .clickable {
    min-height: 44px;
    min-width: 44px;
    font-size: 16px; /* Prevent zoom on iOS */
  }

  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  input[type="date"],
  select,
  textarea {
    min-height: 44px;
    font-size: 16px; /* Prevent zoom on iOS */
    padding: 12px;
  }

  input[type="checkbox"],
  input[type="radio"] {
    width: 22px;
    height: 22px;
    cursor: pointer;
  }

  /* Larger click areas for checkboxes and radios */
  input[type="checkbox"]::before,
  input[type="radio"]::before {
    /* Disable oversized invisible hit area to avoid overlap with nearby buttons on mobile */
    content: none;
    pointer-events: none;
  }
}

/* ===================================
   Mobile-Optimized Forms
   =================================== */

@media (max-width: 768px) {
  form {
    padding: 16px;
  }

  .form-group {
    margin-bottom: 20px;
  }

  label {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    display: block;
  }

  .form-row {
    flex-direction: column;
  }

  .form-row .form-group {
    width: 100% !important;
  }
}

/* ===================================
   Mobile Tables
   =================================== */

@media (max-width: 768px) {
  .data-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 100%;
    font-size: 14px;
  }

  th,
  td {
    padding: 12px 8px;
    white-space: nowrap;
  }

  /* Optional: Stack table rows on very small screens when explicitly opted-in */
  @media (max-width: 480px) {
    .table-card-mobile table,
    .table-card-mobile thead,
    .table-card-mobile tbody,
    .table-card-mobile th,
    .table-card-mobile td,
    .table-card-mobile tr {
      display: block;
    }

    .table-card-mobile thead tr {
      position: absolute;
      top: -9999px;
      left: -9999px;
    }

    .table-card-mobile tr {
      border: 1px solid #e2e8f0;
      margin-bottom: 12px;
      border-radius: 8px;
    }

    .table-card-mobile td {
      border: none;
      position: relative;
      padding-left: 50%;
      text-align: right;
    }

    .table-card-mobile td::before {
      content: attr(data-label);
      position: absolute;
      left: 12px;
      font-weight: 600;
      text-align: left;
    }
  }
}

/* ===================================
   Mobile Cards
   =================================== */

@media (max-width: 768px) {
  .card,
  .chart-card {
    margin: 12px;
    border-radius: 12px;
  }

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

/* ===================================
   Mobile Header
   =================================== */

@media (max-width: 768px) {
  header,
  .header,
  .top-nav {
    padding: 12px;
    position: sticky;
    top: 0;
    z-index: 999;
  }

  .header-title {
    font-size: 18px;
  }

  .header-actions {
    gap: 8px;
  }

  .header-actions > * {
    min-width: 44px;
    min-height: 44px;
  }
}

/* ===================================
   Mobile Modals
   =================================== */

@media (max-width: 768px) {
  .modal,
  .dialog {
    max-width: 100%;
    margin: 0;
    border-radius: 16px 16px 0 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    transform: translateY(100%);
    transition: transform 0.3s ease;
  }

  .modal.active,
  .dialog.active {
    transform: translateY(0);
  }

  .modal-header {
    position: relative;
    padding-top: 24px;
  }

  .modal-header::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: #cbd5e1;
    border-radius: 2px;
  }
}

/* ===================================
   Safe Area Insets (iPhone notch)
   =================================== */

@supports (padding: env(safe-area-inset-bottom)) {
  .mobile-bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(70px + env(safe-area-inset-bottom));
  }

  .modal,
  .dialog {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ===================================
   Swipeable Cards
   =================================== */

.swipeable-card {
  position: relative;
  transition: transform 0.3s ease;
}

.swipeable-card.swiping {
  transition: none;
}

.swipeable-card .swipe-actions {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: #ef4444;
}

.swipeable-card .swipe-actions button {
  background: white;
  color: #ef4444;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 600;
  min-height: 44px;
}

/* ===================================
   Mobile Utilities
   =================================== */

@media (max-width: 768px) {
  .hide-mobile {
    display: none !important;
  }

  .show-mobile {
    display: block !important;
  }

  /* Larger text for readability */
  body {
    font-size: 15px;
    line-height: 1.6;
  }

  h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 20px;
  }

  h3 {
    font-size: 18px;
  }

  /* Better spacing */
  .container,
  .content-wrapper {
    padding: 16px;
  }

  /* Stack flex items */
  .flex-row-mobile-stack {
    flex-direction: column;
  }

  /* Full width on mobile */
  .mobile-full-width {
    width: 100% !important;
  }
}

/* ===================================
   Landscape Mode Optimizations
   =================================== */

@media (max-width: 768px) and (orientation: landscape) {
  .mobile-bottom-nav {
    height: 56px;
  }

  .mobile-bottom-nav .nav-item span {
    display: none;
  }

  .modal,
  .dialog {
    max-height: 90vh;
    overflow-y: auto;
  }
}

/* ===================================
   Reduced Motion Support
   =================================== */

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

/* ===================================
   Dark Mode for Mobile
   =================================== */

@media (prefers-color-scheme: dark) {
  .mobile-bottom-nav {
    background: #1e293b;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }

  .mobile-bottom-nav .nav-item {
    color: #94a3b8;
  }

  .mobile-bottom-nav .nav-item.active {
    color: #60a5fa;
  }

  .mobile-menu-toggle {
    color: #f1f5f9;
  }

  .pull-to-refresh-indicator {
    background: #1e293b;
    color: #e2e8f0;
  }
}
