/**
 * Mobile Styles - Advanced Responsive Design
 * Mobile-first approach with progressive enhancement
 */

/* ========================================
   HAMBURGER MENU
   ======================================== */

/* Hamburger positioned in header/topbar on mobile */
.hamburger {
  display: none; /* Hidden on desktop by default */
  position: static; /* Lives inside header actions */
  width: 40px;
  height: 40px;
  background: var(--color-primary);
  border: none;
  border-radius: 8px;
  box-shadow: none;
  cursor: pointer;
  z-index: 100; /* Above header content if needed */
  transition: all 0.2s ease;
  align-items: center;
  justify-content: center;
}

.hamburger:hover {
  filter: brightness(1.05);
}

.hamburger:active {
  transform: scale(0.98);
}

.hamburger-icon {
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
}

.hamburger-icon span {
  display: block;
  width: 24px;
  height: 3px;
  background: white;
  border-radius: 2px;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Animated X when open */
.hamburger.open .hamburger-icon span:nth-child(1) {
  transform: rotate(45deg) translate(7px, 7px);
}

.hamburger.open .hamburger-icon span:nth-child(2) {
  opacity: 0;
  transform: translateX(-10px);
}

.hamburger.open .hamburger-icon span:nth-child(3) {
  transform: rotate(-45deg) translate(7px, -7px);
}

/* Sidebar Overlay (not used for dropdown variant on mobile) */
.sidebar-overlay { display: none; }

/* ========================================
   MOBILE BREAKPOINTS
   ======================================== */

/* Small Mobile (< 375px) */
@media (max-width: 374px) {
  :root {
    --font-size-base: 13px;
    --space-16: 12px;
  }
  
  .btn-icon {
    font-size: 10px;
    padding: 6px 8px;
  }
}

/* Mobile (< 768px) */
@media (max-width: 767px) {
  /* Show hamburger in header on mobile */
  .header-actions .hamburger {
    display: inline-flex;
    margin-left: 8px;
  }
  
  /* Header adjustments */
  .header {
    position: sticky;
    top: 0;
    z-index: 100;
  }
  
  .header-content {
    flex-direction: column;
    gap: 12px;
    padding: 12px 16px;
  }
  
  .logo-section {
    width: 100%;
    text-align: center;
  }
  
  .logo {
    font-size: 20px;
  }
  
  .subtitle {
    font-size: 11px;
    line-height: 1.3;
  }
  
  .badge {
    font-size: 9px;
    padding: 3px 8px;
  }
  
  .header-actions {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .btn-icon {
    font-size: 11px;
    padding: 8px 12px;
    flex: 0 1 auto;
  }
  
  /* Sidebar as dropdown below header */
  .sidebar {
    position: static;
    width: 100%;
    max-height: 0;
    overflow: hidden;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border, rgba(255,255,255,0.08));
    box-shadow: none;
    transition: max-height 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1000;
  }

  .sidebar.open {
    max-height: 70vh; /* Expand vertically below topbar */
  }
  
  .sidebar-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 12px;
  }
  
  .sidebar-tabs::-webkit-scrollbar {
    display: none;
  }
  
  .sidebar-tab {
    flex-shrink: 0;
    font-size: 12px;
    padding: 10px 14px;
    white-space: nowrap;
  }
  
  .sidebar-content {
    max-height: 62vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .sidebar-item {
    font-size: 13px;
    padding: 14px 16px;
  }
  
  /* Container adjustments */
  .container {
    flex-direction: column;
    padding: 0;
  }
  
  .main-content {
    width: 100%;
    padding: 16px;
    min-height: calc(100vh - 140px);
  }
  
  /* Section headers */
  .section-header {
    margin-bottom: 20px;
  }
  
  .section-title {
    font-size: 20px;
    line-height: 1.3;
  }
  
  .section-description {
    font-size: 13px;
    line-height: 1.4;
  }
  
  /* Forms */
  .form-grid {
    grid-template-columns: 1fr !important;
    gap: 14px;
  }
  
  .form-group {
    margin-bottom: 14px;
  }
  
  .form-label {
    font-size: 13px;
    margin-bottom: 6px;
  }
  
  .form-control,
  .form-control select,
  .form-control input {
    font-size: 16px; /* Prevent iOS zoom */
    padding: 12px 14px;
    min-height: 44px; /* Touch target */
  }
  
  /* Buttons */
  .btn {
    width: 100%;
    padding: 14px 20px;
    font-size: 15px;
    min-height: 48px;
  }
  
  .btn-primary,
  .btn-secondary {
    margin-bottom: 12px;
  }
  
  /* Cards */
  .card {
    padding: 16px;
    margin-bottom: 16px;
    border-radius: 12px;
  }
  
  .card-title {
    font-size: 16px;
    margin-bottom: 12px;
  }
  
  /* Tabs */
  .tabs-container {
    margin: 0 -16px;
  }
  
  .tabs-nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0 16px;
    margin-bottom: 16px;
  }
  
  .tabs-nav::-webkit-scrollbar {
    display: none;
  }
  
  .tab-btn {
    flex-shrink: 0;
    font-size: 13px;
    padding: 10px 16px;
    min-width: 100px;
    white-space: nowrap;
  }
  
  .tab-content {
    padding: 0 16px;
  }
  
  /* Tables */
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -16px;
    padding: 0 16px;
  }
  
  table {
    font-size: 12px;
    min-width: 600px;
  }
  
  th, td {
    padding: 10px 8px;
  }
  
  /* Modals */
  .modal {
    padding: 10px;
  }
  
  .modal-content {
    width: 100%;
    max-width: 100%;
    max-height: 90vh;
    margin: 0;
    border-radius: 16px;
  }
  
  .modal-header {
    padding: 16px;
  }
  
  .modal-header h2 {
    font-size: 18px;
  }
  
  .modal-body {
    padding: 16px;
    max-height: calc(90vh - 140px);
  }
  
  .modal-help-content {
    width: 100%;
    max-height: 90vh;
    border-radius: 16px;
  }
  
  .modal-help-body {
    padding: 16px;
  }
  
  /* Result boxes */
  .result-box {
    padding: 16px;
    margin-bottom: 16px;
    font-size: 14px;
  }
  
  /* Help button */
  .btn-help {
    width: 48px;
    height: 48px;
    font-size: 22px;
    bottom: 90px; /* Above hamburger */
  }
  
  /* Footer */
  .footer {
    padding: 16px;
    font-size: 11px;
    text-align: center;
  }
}

/* Tablet (768px - 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
  .hamburger {
    display: none;
  }
  
  .sidebar {
    position: static;
    width: 240px;
  }
  
  .sidebar-overlay {
    display: none !important;
  }
  
  .form-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  .btn {
    width: auto;
  }
  
  .main-content {
    padding: 24px;
  }
}

/* Desktop (1024px+) */
@media (min-width: 1024px) {
  .hamburger,
  .sidebar-overlay {
    display: none !important;
  }
  
  .sidebar {
    position: static;
    width: 300px;
  }
}

/* Slide-out animation when closing after item click (mobile only) */
@media (max-width: 767px) {
  .sidebar.closing-left {
    animation: slideOutLeft 0.25s ease forwards;
  }
}

@keyframes slideOutLeft {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(-12px); opacity: 0; }
}

/* ========================================
   TOUCH OPTIMIZATIONS
   ======================================== */

@media (hover: none) and (pointer: coarse) {
  /* Increase all touch targets */
  .btn,
  .btn-icon,
  .sidebar-item,
  .tab-btn,
  button,
  a {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* Remove hover effects */
  .btn:hover,
  .sidebar-item:hover,
  .card:hover {
    transform: none;
  }
  
  /* Add active states */
  .btn:active {
    transform: scale(0.98);
    opacity: 0.9;
  }
  
  .sidebar-item:active {
    background: var(--color-secondary-active);
  }
  
  /* Larger tap areas for checkboxes/radios */
  input[type="checkbox"],
  input[type="radio"] {
    width: 20px;
    height: 20px;
  }
}

/* ========================================
   LANDSCAPE MOBILE
   ======================================== */

@media (max-width: 767px) and (orientation: landscape) {
  .sidebar {
    width: 100%;
    max-width: none;
  }
  
  .main-content {
    padding: 12px;
  }
  
  .form-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* ========================================
   SAFE AREAS (iPhone notch, etc)
   ======================================== */

@supports (padding: max(0px)) {
  .header {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  
  /* Hamburger lives in header; no fixed position adjustments needed */
  
  .sidebar {
    padding-left: max(0px, env(safe-area-inset-left));
  }
}
