/* =====================================================
   Better Call Saul - Mobile Optimization Styles
   Split-screen editing layout for H5 mobile experience
   ===================================================== */

/* Mobile detection - only apply on screens <= 768px */
@media (max-width: 768px) {
  /* ===== Phase 1: Core Layout ===== */

  /* Reset body padding for mobile split-screen */
  body {
    padding: 0;
    overflow-x: hidden;
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile browsers */
  }

  /* Container adjustments */
  .container {
    width: 100%;
    max-width: 100%;
    padding: 0;
    margin: 0;
    border-radius: 0;
    display: block;
  }

  /* Header - hidden on mobile to maximize canvas space */
  header {
    display: none;
  }

  /* Main content grid becomes vertical stack */
  .content {
    display: block;
    width: 100%;
    max-width: 100%;
    padding-top: 38vh; /* Space for fixed canvas */
    margin: 0;
  }

  /* ===== Canvas Section - Fixed at top ===== */
  .canvas-section {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: #f4a209;
    padding: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    height: 38vh;
    overflow: hidden;
  }

  /* Canvas container with aspect ratio preservation */
  #businessCard {
    width: calc(100% - 16px);
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    border-width: 2px;
    touch-action: manipulation;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  }

  /* Hide download panel inside canvas-section on mobile */
  .canvas-section .download-panel {
    display: none;
  }

  /* ===== Mobile Toolbar ===== */
  .mobile-toolbar {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    margin-bottom: 12px;
    background: white;
    border-radius: 12px;
    border: 1px solid #e0e0e0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  }

  .mobile-toolbar-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .mobile-toolbar-buttons .btn-download,
  .mobile-toolbar-buttons .btn-reset {
    padding: 12px 16px;
    font-size: 14px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
  }

  .mobile-toolbar-scale {
    display: flex;
    gap: 8px;
    justify-content: center;
  }

  .mobile-toolbar-scale .scale-btn {
    flex: 1;
    padding: 10px;
    font-size: 14px;
    border-radius: 8px;
  }

  /* Canvas zoom indicator */
  .canvas-zoom-indicator {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    pointer-events: none;
    z-index: 60;
  }

  .canvas-zoom-indicator.visible {
    display: block;
    animation: fadeInOut 1.5s ease forwards;
  }

  @keyframes fadeInOut {
    0% { opacity: 0; }
    20% { opacity: 1; }
    80% { opacity: 1; }
    100% { opacity: 0; }
  }

  /* ===== Floating Toolbar - Inside fixed canvas-section ===== */
  .download-panel {
    width: calc(100% - 16px);
    margin: 6px 0 0 0;
    padding: 8px 10px;
    border-radius: 8px;
    border: none;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: nowrap;
    flex-shrink: 0;
  }

  .download-panel .scale-options {
    flex: 1;
    min-width: 0;
  }

  .download-panel .scale-options__header {
    display: none; /* Hide label on mobile to save space */
  }

  .download-panel .scale-grid {
    display: flex;
    gap: 6px;
  }

  .download-panel .scale-btn {
    padding: 8px 12px;
    font-size: 13px;
    border-radius: 8px;
    min-width: 40px;
  }

  .download-panel .download-buttons {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
  }

  .download-panel .btn-download,
  .download-panel .btn-reset {
    padding: 10px 16px;
    font-size: 14px;
    border-radius: 8px;
    min-height: 44px; /* Touch-friendly */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
  }

  .download-panel .btn-download span,
  .download-panel .btn-reset span {
    display: none; /* Hide text, show only icons */
  }

  .download-panel .btn-download i,
  .download-panel .btn-reset i {
    font-size: 18px;
  }

  /* ===== Controls Section - Scrollable ===== */
  .controls {
    width: 100%;
    max-width: 100%;
    max-height: none !important;
    overflow-y: visible !important;
    overflow-x: hidden;
    padding: 12px 12px 80px 12px; /* Bottom space for nav */
    margin: 0 auto;
    border-radius: 0;
    border: none;
    background: #f8f9fa;
    box-sizing: border-box;
  }

  /* ===== Phase 2: Collapsible Sections ===== */
  .section {
    margin-bottom: 12px;
    padding: 0;
    border-radius: 12px;
    border: 1px solid #e0e0e0;
    overflow: hidden;
    background: white;
  }

  /* Section header - acts as toggle */
  .section h3 {
    margin: 0;
    padding: 16px;
    font-size: 1em;
    border-bottom: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: white;
    transition: background-color 0.2s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  .section h3::after {
    content: '';
    width: 10px;
    height: 10px;
    border-right: 2px solid #667eea;
    border-bottom: 2px solid #667eea;
    transform: rotate(45deg);
    transition: transform 0.3s ease;
    flex-shrink: 0;
    margin-left: 12px;
  }

  .section.collapsed h3::after {
    transform: rotate(-45deg);
  }

  .section h3:active {
    background: #f5f5f5;
  }

  /* Section content wrapper */
  .section-content {
    padding: 0 16px 16px;
    max-height: 2000px; /* Large enough for any content */
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
    opacity: 1;
  }

  .section.collapsed .section-content {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
  }

  /* ===== Phase 3: Touch Optimization ===== */

  /* Enhanced slider track for touch */
  input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 24px; /* Larger touch area */
    background: transparent;
    cursor: pointer;
    touch-action: manipulation;
  }

  input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    border: none;
  }

  input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: #667eea;
    border-radius: 50%;
    border: 3px solid white;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    margin-top: -8px; /* Center on track */
    cursor: pointer;
  }

  input[type="range"]::-moz-range-track {
    width: 100%;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    border: none;
  }

  input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: #667eea;
    border-radius: 50%;
    border: 3px solid white;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    cursor: pointer;
  }

  input[type="range"]:active::-webkit-slider-thumb {
    transform: scale(1.1);
    background: #5568d3;
  }

  input[type="range"]:active::-moz-range-thumb {
    transform: scale(1.1);
    background: #5568d3;
  }

  /* Prevent iOS zoom on input focus */
  input[type="text"],
  input[type="tel"],
  input[type="number"],
  textarea,
  select {
    font-size: 16px !important; /* Prevents iOS zoom */
    padding: 12px;
    border-radius: 8px;
    min-height: 44px; /* Touch-friendly */
  }

  /* Touch-friendly buttons */
  button,
  .btn-download,
  .btn-reset,
  .scale-btn,
  .lang-btn {
    min-height: 44px;
    min-width: 44px;
  }

  /* Form group spacing for touch */
  .form-group {
    margin-bottom: 16px;
  }

  .form-group-inline {
    gap: 12px;
  }

  /* Label with better touch spacing */
  label {
    font-size: 13px;
    margin-bottom: 8px;
    padding: 4px 0;
  }

  /* ===== Phase 4: Quick Navigation Bar ===== */
  .mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    padding: 8px 4px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    display: flex;
    justify-content: space-around;
    align-items: center;
  }

  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 8px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
    min-width: 44px;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-nav-item:active {
    background: rgba(102, 126, 234, 0.1);
    transform: scale(0.95);
  }

  .mobile-nav-item.active {
    background: rgba(102, 126, 234, 0.15);
  }

  .mobile-nav-item.active .mobile-nav-icon {
    transform: scale(1.1);
  }

  .mobile-nav-icon {
    font-size: 20px;
    line-height: 1;
    transition: transform 0.2s ease;
  }

  .mobile-nav-label {
    font-size: 9px;
    color: #666;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 40px;
  }

  /* ===== SEO Section - Mobile Optimized ===== */
  .seo-section {
    margin: 20px 16px;
    padding: 20px;
    border-radius: 12px;
  }

  .seo-section--footer {
    margin-top: 30px;
    margin-bottom: 20px;
  }

  .seo-heading {
    font-size: 1.3em;
    margin-bottom: 12px;
  }

  .seo-description {
    font-size: 0.95em;
    line-height: 1.5;
  }

  .seo-list {
    margin-left: 16px;
  }

  .seo-list li {
    font-size: 0.9em;
    line-height: 1.5;
    margin-bottom: 6px;
  }

  /* ===== FAQ Section - Mobile Optimized ===== */
  .faq-section {
    margin: 20px 16px;
    padding: 24px 16px;
    border-radius: 12px;
  }

  .faq-title {
    font-size: 1.4em;
    margin-bottom: 20px;
  }

  .faq-list {
    gap: 12px;
  }

  .faq-item {
    border-radius: 10px;
  }

  .faq-question {
    padding: 14px 16px;
    font-size: 15px;
  }

  .faq-question::after {
    font-size: 22px;
    margin-left: 12px;
  }

  .faq-answer {
    padding: 0 16px 14px;
    font-size: 14px;
    line-height: 1.6;
  }

  /* ===== Footer - Mobile Optimized ===== */
  .site-footer {
    margin-top: 30px;
    margin-bottom: 70px; /* Space for bottom nav */
    padding: 24px 16px;
  }

  .footer-content {
    padding: 0;
  }

  .language-switcher {
    gap: 8px;
    margin-bottom: 16px;
  }

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

  .flag {
    font-size: 14px;
  }

  .footer-text {
    font-size: 13px;
  }

  .footer-links {
    margin-top: 12px;
  }

  .footer-link {
    padding: 10px 16px;
    font-size: 13px;
  }

  .footer-disclaimer {
    font-size: 10px;
    margin: 16px auto;
    line-height: 1.5;
  }

  .legal-links {
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 12px;
    font-size: 11px;
  }

  /* ===== Parameters Panel (Debug) - Mobile ===== */
  .parameters-panel {
    margin: 16px !important;
    width: calc(100% - 32px) !important;
  }

  .parameters-panel textarea {
    height: 150px !important;
    font-size: 10px !important;
  }

  /* ===== Toast - Above bottom nav ===== */
  .toast {
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }

  /* ===== Utility Classes ===== */
  .mobile-only {
    display: block !important;
  }

  .desktop-only {
    display: none !important;
  }

  /* Hide scrollbars but keep scrolling */
  .controls::-webkit-scrollbar {
    display: none;
  }

  .controls {
    -ms-overflow-style: none;
    scrollbar-width: none;
  }
}

/* ===== Landscape Mobile Adjustments ===== */
@media (max-width: 768px) and (orientation: landscape) {
  .canvas-section {
    position: relative; /* Not sticky in landscape */
  }

  #businessCard {
    max-height: 50vh;
  }

  .download-panel {
    position: relative;
    top: auto;
  }

  .mobile-nav {
    padding: 6px 4px;
  }

  .mobile-nav-label {
    display: none;
  }

  .mobile-nav-item {
    padding: 8px 12px;
  }
}

/* ===== Small phones (< 375px) ===== */
@media (max-width: 374px) {
  header h1 {
    font-size: 1em;
  }

  header .subtitle {
    font-size: 0.75em;
  }

  .download-panel .scale-btn {
    padding: 6px 8px;
    font-size: 12px;
    min-width: 32px;
  }

  .mobile-nav-item {
    padding: 4px 6px;
    min-width: 36px;
  }

  .mobile-nav-icon {
    font-size: 18px;
  }

  .mobile-nav-label {
    display: none;
  }

  .section h3 {
    font-size: 0.9em;
    padding: 14px;
  }
}

/* ===== Desktop - Hide mobile-only elements ===== */
@media (min-width: 769px) {
  .mobile-nav {
    display: none !important;
  }

  .mobile-only {
    display: none !important;
  }

  .desktop-only {
    display: block !important;
  }
}
