/**
 * SaleSmartly Panel - Mobile Responsive Styles
 * v2 Enhancement: Full mobile-friendly implementation
 */

/* ====================================
   CSS Variables for Mobile
   ==================================== */
:root {
  --sidebar-width: 16rem; /* 256px = w-64 */
  --sidebar-collapsed-width: 0;
  --header-height: 4rem; /* 64px = h-16 */
  --touch-target-min: 44px;
  --mobile-padding: 1rem;
  --transition-speed: 0.3s;
}

/* ====================================
   Mobile Navigation (Hamburger Menu)
   ==================================== */
.mobile-menu-btn {
  display: none;
  width: var(--touch-target-min);
  height: var(--touch-target-min);
  padding: 0.5rem;
  background: transparent;
  border: none;
  cursor: pointer;
  z-index: 1001;
}

.mobile-menu-btn .hamburger-icon {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 24px;
  height: 18px;
}

.mobile-menu-btn .hamburger-icon span {
  display: block;
  width: 100%;
  height: 2px;
  background-color: #374151;
  border-radius: 1px;
  transition: transform var(--transition-speed), opacity var(--transition-speed);
}

/* Hamburger animation when sidebar open */
.sidebar-open .mobile-menu-btn .hamburger-icon span:nth-child(1) {
  transform: translateY(8px) rotate(45deg);
}

.sidebar-open .mobile-menu-btn .hamburger-icon span:nth-child(2) {
  opacity: 0;
}

.sidebar-open .mobile-menu-btn .hamburger-icon span:nth-child(3) {
  transform: translateY(-8px) rotate(-45deg);
}

/* ====================================
   Sidebar Responsive Behavior
   ==================================== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 999;
  opacity: 0;
  transition: opacity var(--transition-speed);
}

.sidebar-open .sidebar-overlay {
  opacity: 1;
}

/* ====================================
   Touch-Friendly Elements
   ==================================== */
/* Minimum touch target size */
.nav-item,
button,
a,
input[type="checkbox"],
select {
  min-height: var(--touch-target-min);
}

/* Larger checkbox on mobile */
.touch-checkbox {
  width: 20px;
  height: 20px;
}

/* ====================================
   Mobile Breakpoint Styles
   ==================================== */
@media (max-width: 768px) {
  /* Show mobile menu button */
  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Mobile header */
  .mobile-header {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: white;
    border-bottom: 1px solid #e5e7eb;
    padding: 0 var(--mobile-padding);
    align-items: center;
    justify-content: space-between;
    z-index: 1000;
  }

  .mobile-header .logo {
    font-size: 1.125rem;
    font-weight: 700;
    color: #2563eb;
  }

  /* Sidebar becomes full-screen overlay */
  aside.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    transition: transform var(--transition-speed) ease-in-out;
    z-index: 1000;
    overflow-y: auto;
  }

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

  .sidebar-open .sidebar-overlay {
    display: block;
  }

  /* Main content adjustments */
  main.main-content {
    margin-top: var(--header-height);
    padding: var(--mobile-padding) !important;
    width: 100%;
    min-height: calc(100vh - var(--header-height));
  }

  /* Stack grids vertically on mobile */
  .grid-cols-3,
  .lg\:grid-cols-3 {
    grid-template-columns: 1fr !important;
  }

  .grid-cols-2 {
    grid-template-columns: 1fr !important;
  }

  /* Reduce gaps on mobile */
  .gap-6 {
    gap: 1rem !important;
  }

  /* Reduce padding on cards */
  .p-6 {
    padding: 1rem !important;
  }

  .p-8 {
    padding: 1rem !important;
  }

  /* Smaller headings on mobile */
  .text-2xl {
    font-size: 1.25rem !important;
  }

  h2.text-2xl {
    font-size: 1.25rem !important;
    line-height: 1.75rem !important;
  }

  /* Full width buttons on mobile */
  .flex.gap-2 button {
    flex: 1;
    min-height: var(--touch-target-min);
  }

  /* Responsive tables - convert to cards */
  .mobile-card-table {
    display: block;
  }

  .mobile-card-table thead {
    display: none;
  }

  .mobile-card-table tbody {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .mobile-card-table tr {
    display: block;
    background: #f9fafb;
    border-radius: 0.5rem;
    padding: 1rem;
    border: 1px solid #e5e7eb;
  }

  .mobile-card-table td {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border: none;
  }

  .mobile-card-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #6b7280;
    margin-right: 1rem;
  }

  /* Hide table columns on mobile */
  .hide-mobile {
    display: none !important;
  }

  /* Smaller icons and badges */
  .text-xs {
    font-size: 0.75rem !important;
  }

  /* Queue lists with max height on mobile */
  .max-h-40 {
    max-height: 8rem !important;
  }

  .max-h-48 {
    max-height: 10rem !important;
  }

  /* Log section responsive */
  .h-48 {
    height: 10rem !important;
  }

  /* Form inputs touch friendly */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  textarea,
  select {
    min-height: var(--touch-target-min);
    font-size: 16px !important; /* Prevent zoom on iOS */
    padding: 0.75rem !important;
  }

  /* Select dropdown */
  select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    padding-right: 2.5rem !important;
  }

  /* Textarea with smaller height on mobile */
  textarea.h-20 {
    height: 4rem !important;
  }

  /* Step details - smaller on mobile */
  .space-y-3 > div {
    padding: 0.5rem !important;
  }

  .space-y-3 .w-8 {
    width: 1.5rem !important;
    height: 1.5rem !important;
    font-size: 0.75rem !important;
  }

  /* Modal responsive */
  .modal-content {
    margin: 0.5rem;
    max-height: calc(100vh - 1rem);
    overflow-y: auto;
  }
}

/* ====================================
   Tablet Breakpoint (768px - 1024px)
   ==================================== */
@media (min-width: 768px) and (max-width: 1024px) {
  /* Two column grids on tablet */
  .lg\:grid-cols-3 {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Slightly reduced padding */
  main.main-content {
    padding: 1.5rem !important;
  }

  /* Sidebar visible but narrower */
  aside.sidebar {
    width: 14rem;
  }
}

/* ====================================
   Desktop Enhancements
   ==================================== */
@media (min-width: 1025px) {
  /* Hide mobile header on desktop */
  .mobile-header {
    display: none;
  }

  /* Ensure sidebar is visible */
  aside.sidebar {
    transform: translateX(0) !important;
    position: relative !important;
  }

  .sidebar-overlay {
    display: none !important;
  }
}

/* ====================================
   Utility Classes
   ==================================== */
.touch-friendly {
  min-height: var(--touch-target-min);
  min-width: var(--touch-target-min);
}

.mobile-full-width {
  width: 100%;
}

/* Safe area insets for notched devices */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .mobile-header {
    padding-top: env(safe-area-inset-top);
    height: calc(var(--header-height) + env(safe-area-inset-top));
  }

  main.main-content {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ====================================
   Additional Mobile Fixes
   ==================================== */
@media (max-width: 768px) {
  /* Profile header - stack buttons */
  .flex.flex-col.sm\:flex-row {
    flex-direction: column;
  }

  /* Table horizontal scroll wrapper */
  .overflow-x-auto {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  /* Larger checkboxes on mobile */
  input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
  }

  /* Action buttons in table */
  table button {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
  }

  /* Code/Log output scrollable */
  .font-mono {
    font-size: 0.75rem;
    overflow-x: auto;
  }

  /* Hide optional columns on very small screens */
  @media (max-width: 480px) {
    .hide-xs {
      display: none !important;
    }
  }
}

/* ====================================
   Animation Classes
   ==================================== */
.slide-in-left {
  animation: slideInLeft 0.3s ease-out;
}

@keyframes slideInLeft {
  from {
    transform: translateX(-100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.fade-in {
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ====================================
   Loading States
   ==================================== */
.loading-overlay {
  backdrop-filter: blur(2px);
}

.btn-loading {
  position: relative;
  pointer-events: none;
}

.btn-loading::after {
  content: '';
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1rem;
  height: 1rem;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to {
    transform: translateY(-50%) rotate(360deg);
  }
}

/* Skeleton loading */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: skeleton 1.5s ease-in-out infinite;
}

@keyframes skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ====================================
   Print Styles - Hide non-essential
   ==================================== */
@media print {
  .mobile-header,
  .sidebar,
  .sidebar-overlay,
  .mobile-menu-btn {
    display: none !important;
  }

  main.main-content {
    margin: 0;
    padding: 1rem;
  }
}
