/*
  RESPONSIVE.CSS - Mobile & Tablet Responsive Styles
  Applies to all app pages (not landing page)
  Breakpoints: 768px (tablet), 480px (mobile)
*/

/* ===========================================
   MOBILE LAYOUT FIXES (max-width: 768px)
   =========================================== */

@media (max-width: 768px) {
  /* ===== BASE LAYOUT ===== */

  /* Allow page to scroll on mobile (desktop uses internal pane scrolling).
     Precedence: simpler.css:130 sets the desktop default (overflow:hidden, height:100vh).
     This mobile block overrides it with !important; mobile.css:934 inherits via the same media query.
     Keep simpler.css as the source of truth for desktop; responsive.css + mobile.css handle viewport <=768px. */
  body {
    height: auto !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
  }

  /* Main content should take full width when sidebar hidden */
  #main-content,
  .main-content {
    width: 100% !important;
    min-width: 0 !important;
    margin-left: 0 !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* App layout adjustments */
  .app-layout {
    flex-direction: column !important;
    height: auto !important;
    min-height: calc(100vh - 120px) !important;
    overflow: visible !important;
  }

  /* Panel full width */
  .panel {
    width: 100% !important;
    min-width: 0 !important;
    border-right: none !important;
  }

  /* Split pane layouts stack vertically */
  .split-pane-layout,
  .split-pane-grid {
    flex-direction: column !important;
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* ===== PAGE HEADERS ===== */

  .page-header {
    padding: 16px !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 12px !important;
  }

  .page-header-actions {
    width: 100% !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .page-title {
    font-size: 20px !important;
  }

  /* ===== CONTAINER PADDING ===== */

  .billing-container,
  .analytics-container,
  .monitoring-container,
  .credentials-container,
  .panel-content,
  .panel-content-lg {
    padding: 16px !important;
  }

  /* Ensure page content clears the fixed 64px bottom navigation bar */
  .billing-container,
  .support-container,
  .support-content,
  .team-container,
  .analytics-container,
  .main-content,
  #main-content,
  .app-container,
  .workflow-layout,
  .tracks-container {
    padding-bottom: 80px !important;
  }

  /* ===== GRID LAYOUTS - STACK VERTICALLY ===== */

  /* 2-column grids */
  .billing-hero,
  .billing-bottom,
  .billing-grid,
  .stat-grid,
  .work-grid,
  .two-column-layout {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
  }

  /* 3-column grids */
  .template-grid,
  .inspection-grid,
  .three-column-layout {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
  }

  /* 4-column grids */
  .stats-row,
  .quick-stats,
  .tactical-board,
  .four-column-layout {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }

  /* Mobile grid collapse — opt-in via class (pages add .responsive-grid-collapse to grids they want single-column on mobile) */
  .responsive-grid-collapse {
    grid-template-columns: 1fr !important;
  }

  /* Board layouts */
  .board-layout {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
    padding: 16px !important;
    height: auto !important;
    overflow-x: visible !important;
  }

  .board-column {
    min-width: 100% !important;
    max-height: 400px !important;
  }

  /* ===== CARDS & COMPONENTS ===== */

  /* Balance card */
  .balance-card {
    padding: 20px !important;
  }

  .balance-amount {
    font-size: 32px !important;
  }

  /* Stats cards */
  .stat-card,
  .quick-stat-card,
  .metric-card {
    padding: 16px !important;
  }

  /* Data cards */
  .data-card {
    padding: 12px !important;
    margin-bottom: 8px !important;
  }

  /* Credit card display */
  .credit-card-display {
    height: auto !important;
    min-height: 180px !important;
    padding: 24px !important;
  }

  .credit-balance {
    font-size: 36px !important;
  }

  /* Template cards */
  .template-card {
    height: auto !important;
    min-height: 240px !important;
  }

  .card-preview {
    height: 120px !important;
  }

  /* ===== TABLES ===== */

  .activity-table,
  .data-table {
    display: block !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .activity-table table,
  .data-table table {
    min-width: 600px !important;
  }

  /* ===== PROCESS TRACKER ===== */

  .process-tracker,
  .pipeline-track {
    padding: 16px !important;
    overflow-x: auto !important;
    gap: 8px !important;
  }

  .step-item,
  .pipeline-step {
    min-width: 80px !important;
    flex-shrink: 0 !important;
  }

  .step-label {
    font-size: 10px !important;
    max-width: 70px !important;
  }

  /* ===== INSPECTION PANELS ===== */

  .inspection-panel {
    height: auto !important;
    min-height: 300px !important;
    max-height: 500px !important;
  }

  .inspection-grid {
    height: auto !important;
    gap: 16px !important;
  }

  /* ===== FORMS & INPUTS ===== */

  .input-tech,
  .btn-tech,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  input[type="tel"],
  input[type="search"],
  input[type="url"],
  textarea,
  select {
    font-size: 16px !important; /* Prevents iOS zoom */
    padding: 12px !important;
    min-height: 48px !important;
  }

  /* Button groups */
  .btn-group,
  .button-group,
  .action-buttons {
    flex-direction: column !important;
    gap: 8px !important;
    width: 100% !important;
  }

  .btn-group > *,
  .button-group > *,
  .action-buttons > * {
    width: 100% !important;
  }

  /* Gate actions */
  .gate-actions {
    flex-direction: column !important;
    gap: 8px !important;
  }

  .btn-gate {
    width: 100% !important;
  }

  /* ===== BILLING PAGE SPECIFIC ===== */

  /* Action link cards (Auto Top-up, Payment Methods) */
  .action-links,
  .billing-actions,
  .quick-actions {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }

  .action-link-card,
  .quick-action-card {
    width: 100% !important;
  }

  /* Balance footer (payment method + button) */
  .balance-footer {
    flex-direction: column !important;
    gap: 12px !important;
    align-items: stretch !important;
  }

  .balance-footer .btn-add-funds,
  .balance-footer button {
    width: 100% !important;
    justify-content: center !important;
  }

  /* Activity table header */
  .activity-header,
  .table-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 12px !important;
  }

  .activity-tabs,
  .tab-group {
    width: 100% !important;
    overflow-x: auto !important;
  }

  /* Usage sidebar on mobile */
  .usage-sidebar,
  .billing-sidebar {
    width: 100% !important;
    margin-top: 16px !important;
  }

  /* ===== CHAT & MESSAGING ===== */

  /* CRM/Chat container - stack panels */
  .crm-container {
    display: flex !important;
    flex-direction: column !important;
    grid-template-columns: unset !important;
    height: auto !important;
    min-height: calc(100vh - 120px) !important;
  }

  /* Hide CRM sidebar on mobile (use main nav) */
  .crm-sidebar {
    display: none !important;
  }

  /* Conversation list takes full width */
  .conversation-list-pane {
    width: 100% !important;
    max-height: 50vh !important;
    border-right: none !important;
    border-bottom: 1px solid var(--border-subtle) !important;
  }

  /* Chat pane takes full width */
  .chat-pane,
  .conversation-detail-pane {
    width: 100% !important;
    flex: 1 !important;
  }

  /* Contact sidebar hidden on mobile */
  .contact-pane,
  .contact-sidebar {
    display: none !important;
  }

  .chat-container,
  .conversation-panel {
    height: calc(100vh - 180px) !important;
  }

  .message-input-container {
    padding: 12px !important;
  }

  /* ===== DESK PAGE ===== */

  /* Desk layout */
  .desk-container,
  .desk-layout {
    flex-direction: column !important;
  }

  /* Insights sidebar */
  .insights-sidebar,
  .attention-panel {
    width: 100% !important;
    max-height: 300px !important;
    overflow-y: auto !important;
  }

  /* Widget grid */
  .widget-grid,
  .desk-widgets {
    grid-template-columns: 1fr !important;
  }

  /* ===== DOCUMENTS PAGE ===== */

  .documents-grid,
  .file-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  .document-card,
  .file-card {
    width: 100% !important;
  }

  /* ===== IMAGE/VIDEO GENERATORS ===== */

  .generator-layout,
  .creator-layout {
    flex-direction: column !important;
  }

  .generator-sidebar,
  .creator-sidebar,
  .settings-panel {
    width: 100% !important;
    max-height: 400px !important;
    border-right: none !important;
    border-bottom: 1px solid var(--border-subtle) !important;
  }

  .preview-area,
  .output-area {
    width: 100% !important;
    min-height: 300px !important;
  }

  /* ===== WHATSAPP INBOX ===== */

  .inbox-layout {
    flex-direction: column !important;
  }

  .inbox-list-panel {
    width: 100% !important;
    max-height: 40vh !important;
  }

  .inbox-detail-panel {
    width: 100% !important;
    flex: 1 !important;
  }

  /* ===== ANALYTICS PAGE ===== */

  .analytics-grid,
  .chart-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  .chart-card {
    width: 100% !important;
    min-height: 250px !important;
  }

  /* ===== MONITORING PAGE ===== */

  .monitoring-layout {
    flex-direction: column !important;
  }

  .log-panel,
  .metrics-panel {
    width: 100% !important;
    max-height: 400px !important;
  }

  /* ===== TEAM PAGE ===== */

  .team-grid,
  .members-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  .member-card {
    width: 100% !important;
  }

  /* Hide header invite button on mobile - empty state card has its own */
  .header-invite-btn {
    display: none !important;
  }

  /* ===== CREDENTIALS PAGE ===== */

  .credentials-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  .credential-card {
    width: 100% !important;
  }

  /* ===== MODALS & OVERLAYS ===== */

  /* Fix modal positioning to prevent buttons being cut off */
  .modal-overlay {
    padding: 16px !important;
    align-items: flex-start !important;
    padding-top: 60px !important;
  }

  .modal,
  .dialog {
    width: 95% !important;
    max-width: none !important;
    margin: 0 !important;
    max-height: calc(100vh - 120px) !important;
    display: flex !important;
    flex-direction: column !important;
  }

  .modal-body,
  .dialog-body {
    flex: 1 !important;
    overflow-y: auto !important;
    min-height: 0 !important;
  }

  .modal-footer,
  .dialog-footer {
    flex-shrink: 0 !important;
  }

  .modal-content,
  .dialog-content {
    padding: 20px !important;
  }

  /* ===== ROI HEADER ===== */

  .roi-header {
    flex-direction: column !important;
    gap: 16px !important;
    padding: 16px !important;
    align-items: flex-start !important;
  }

  .roi-stat {
    width: 100% !important;
    flex-direction: row !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 8px 0 !important;
    border-bottom: 1px solid var(--border-subtle) !important;
  }

  .roi-stat:last-child {
    border-bottom: none !important;
  }

  .roi-value {
    font-size: 18px !important;
  }

  /* ===== TYPOGRAPHY SCALING ===== */

  h1 {
    font-size: 24px !important;
  }

  h2 {
    font-size: 20px !important;
  }

  h3 {
    font-size: 18px !important;
  }

  /* ===== UTILITY OVERRIDES ===== */

  .flex-between {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .gap-4 {
    gap: 12px !important;
  }

  /* Hide desktop-only elements */
  .desktop-only {
    display: none !important;
  }

  /* Show mobile-only elements */
  .mobile-only {
    display: block !important;
  }

  /* ===== SCROLLING ===== */

  .horizontal-scroll {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding-bottom: 8px !important;
  }

  /* Hide scrollbars on mobile for cleaner look */
  .horizontal-scroll::-webkit-scrollbar {
    display: none;
  }

  /* ===== TOUCH TARGET ENFORCEMENT (44px minimum) ===== */

  /* Filter chips, tags, pills */
  .filter-chip,
  .chip,
  .tag,
  .pill,
  .tab-btn,
  .filter-btn {
    min-height: 44px !important;
    min-width: 44px !important;
    padding: 8px 16px !important;
  }

  /* Close/dismiss buttons */
  .close-btn,
  .dismiss-btn,
  .btn-close,
  [aria-label="Close"],
  [aria-label="Dismiss"] {
    min-width: 44px !important;
    min-height: 44px !important;
  }

  /* Icon-only buttons */
  .icon-btn,
  .btn-icon,
  button:has(> svg:only-child) {
    min-width: 44px !important;
    min-height: 44px !important;
  }

  /* Dropdown selects */
  select {
    min-height: 44px !important;
  }

  /* Links in lists/tables */
  .list-item a,
  .activity-row a {
    min-height: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
  }
}

/* ===========================================
   SMALL MOBILE (max-width: 480px)
   =========================================== */

@media (max-width: 480px) {
  /* Even tighter padding */
  .billing-container,
  .analytics-container,
  .monitoring-container,
  .credentials-container,
  .panel-content,
  .panel-content-lg {
    padding: 12px !important;
  }

  /* Smaller typography */
  .balance-amount {
    font-size: 28px !important;
  }

  .credit-balance {
    font-size: 28px !important;
  }

  .page-title {
    font-size: 18px !important;
  }

  /* Stack action rows */
  .balance-footer {
    flex-direction: column !important;
    gap: 12px !important;
    align-items: stretch !important;
  }

  .btn-add-funds,
  .btn-primary {
    width: 100% !important;
    justify-content: center !important;
  }

  /* Cards even more compact */
  .stat-card,
  .quick-stat-card,
  .metric-card {
    padding: 12px !important;
  }

  .data-card {
    padding: 10px !important;
  }

  /* Smaller stat values */
  .stat-value,
  .metric-value,
  .roi-value {
    font-size: 16px !important;
  }

  /* Template cards */
  .template-card {
    min-height: 200px !important;
  }

  .card-preview {
    height: 100px !important;
  }

  .card-title {
    font-size: 14px !important;
  }

  .card-desc {
    font-size: 12px !important;
  }

  /* Process tracker more compact */
  .step-item,
  .pipeline-step {
    min-width: 60px !important;
  }

  .step-circle,
  .step-indicator {
    width: 20px !important;
    height: 20px !important;
    font-size: 9px !important;
  }

  .step-label {
    font-size: 9px !important;
    max-width: 60px !important;
  }
}

/* ===========================================
   TABLET SPECIFIC (481px to 768px)
   =========================================== */

@media (min-width: 481px) and (max-width: 768px) {
  /* 2-column grids can remain 2 columns on tablet */
  .stats-row,
  .quick-stats {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 12px !important;
  }

  /* Template grid 2 columns */
  .template-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 16px !important;
  }

  .template-card {
    height: 260px !important;
  }
}

/* ===========================================
   LANDSCAPE MOBILE
   =========================================== */

@media (max-width: 896px) and (orientation: landscape) {
  /* Reduce header height in landscape */
  .mobile-header {
    height: 48px !important;
  }

  body {
    padding-top: 48px !important;
  }

  /* Chat takes more height */
  .chat-container,
  .conversation-panel {
    height: calc(100vh - 120px) !important;
  }
}

/* ===========================================
   DARK MODE MOBILE ADJUSTMENTS
   =========================================== */

@media (max-width: 768px) {
  [data-theme="dark"] .balance-card,
  [data-theme="dark"] .stat-card,
  [data-theme="dark"] .data-card {
    background: var(--bg-panel) !important;
    border-color: var(--border-subtle) !important;
  }

  [data-theme="dark"] .glass-card {
    background: rgba(37, 35, 28, 0.9) !important;
    backdrop-filter: blur(12px) !important;
    border-color: var(--border-subtle) !important;
  }
}

/* ===========================================
   SAFE AREA HANDLING (iOS Notch)
   =========================================== */

@supports (padding-top: env(safe-area-inset-top)) {
  @media (max-width: 768px) {
    .mobile-header {
      padding-top: env(safe-area-inset-top) !important;
      height: calc(56px + env(safe-area-inset-top)) !important;
    }

    body {
      padding-top: calc(56px + env(safe-area-inset-top)) !important;
    }

    .mobile-tabs {
      padding-bottom: env(safe-area-inset-bottom) !important;
      height: calc(64px + env(safe-area-inset-bottom)) !important;
    }

    body {
      padding-bottom: calc(64px + env(safe-area-inset-bottom)) !important;
    }
  }
}

/* ===========================================
   IMAGE/VIDEO GENERATOR MOBILE FIXES
   =========================================== */

@media (max-width: 768px) {
  /* Generator pages: Override fixed 50vh heights */
  section.chat-pane {
    width: 100% !important;
    height: auto !important;
    min-height: auto !important;
    max-height: none !important;
    flex-shrink: 0 !important;
  }

  section.editor-pane {
    width: 100% !important;
    height: auto !important;
    min-height: auto !important;
    flex-shrink: 0 !important;
    padding-bottom: 80px !important; /* Clear mobile bottom nav (64px + safe margin) */
  }

  /* Main content scrollable */
  .main-content:has(.chat-pane):has(.editor-pane) {
    flex-direction: column !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    height: auto !important;
  }

  /* Chat pane body scrollable with max height */
  .chat-pane-body {
    max-height: 60vh !important;
    overflow-y: auto !important;
  }

  /* Canvas area should fit content */
  .canvas-area,
  .canvas-wrapper {
    min-height: 200px !important;
    height: auto !important;
  }

  /* Download/Export buttons always accessible - sticky at bottom */
  .carousel-actions {
    position: sticky !important;
    bottom: 64px !important;
    background: var(--bg-panel, #fff) !important;
    padding: 12px !important;
    z-index: 10 !important;
    margin: 0 -12px !important;
    border-top: 1px solid var(--border-subtle, #e5e5e5) !important;
  }

  /* Editor header actions (Download button) */
  .editor-header {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .editor-actions {
    width: 100% !important;
    justify-content: center !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  /* Ensure buttons are tappable size (44px min for iOS) */
  .carousel-actions .btn,
  .editor-actions .btn,
  .btn-download,
  .btn-export {
    min-height: 44px !important;
    padding: 12px 16px !important;
    font-size: 14px !important;
  }

  /* Color palette wrap */
  .color-swatches,
  .background-colors {
    flex-wrap: wrap !important;
    justify-content: center !important;
  }

  /* Image generator toolbar - stack vertically on mobile */
  .toolbar-always-visible {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
  }

  .toolbar-always-visible .toolbar-group {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 8px !important;
  }

  .gradient-presets-row {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    justify-content: flex-start !important;
  }

  .gradient-preset-btn {
    width: 36px !important;
    height: 36px !important;
  }

  .toolbar-add-text {
    flex-direction: row !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    width: 100% !important;
  }

  .btn-add-text-pill {
    flex: 1 !important;
    min-width: 120px !important;
    justify-content: center !important;
  }
}

/* ===========================================
   DOCUMENT TRANSLATOR MOBILE FIXES
   =========================================== */

@media (max-width: 768px) {
  /* Upload area full width */
  .upload-zone,
  .drop-zone,
  .upload-area {
    width: 100% !important;
    min-height: 120px !important;
  }

  /* Language selectors stack */
  .language-selectors,
  .translation-controls,
  .lang-row {
    flex-direction: column !important;
    gap: 12px !important;
  }

  /* Results area scrollable */
  .translation-results,
  .document-preview,
  .result-panel {
    max-height: 50vh !important;
    overflow-y: auto !important;
  }

  /* Download button always visible */
  .document-actions,
  .export-actions {
    position: sticky !important;
    bottom: 64px !important;
    background: var(--bg-panel, #fff) !important;
    padding: 12px !important;
    z-index: 10 !important;
  }

  /* Feature tags wrap */
  .feature-tags {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }
}

/* ===========================================
   PRINT STYLES (hide navigation on print)
   =========================================== */

@media print {
  .sidebar,
  .mobile-header,
  .mobile-tabs,
  .mobile-overlay {
    display: none !important;
  }

  body {
    padding: 0 !important;
  }

  .app-layout {
    height: auto !important;
  }

  #main-content {
    width: 100% !important;
  }
}

/* ===========================================
   REUSABLE MOBILE COMPONENTS
   Extracted from video-studio for platform-wide use
   =========================================== */

/* --- Bottom Sheet ---
   Usage: Add .bottom-sheet to a panel element.
   States: .bottom-sheet--peek (260px), .bottom-sheet--full (85dvh)
   Requires a .bottom-sheet__handle child for drag interaction.
*/
@media (max-width: 768px) {
  .bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    background: var(--bg-panel, #1a1a1a);
    border-radius: 16px 16px 0 0;
    border-top: 1px solid var(--border, #333);
    z-index: var(--z-modal);
    transform: translateY(100%);
    transition: transform var(--duration-smooth) var(--ease-spring);
    will-change: transform;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .bottom-sheet--peek {
    transform: translateY(0);
    height: 260px;
  }

  .bottom-sheet--full {
    transform: translateY(0);
    height: 85dvh;
    max-height: 85dvh;
  }

  .bottom-sheet__handle {
    display: flex;
    justify-content: center;
    padding: 8px 0 4px;
    cursor: grab;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
  }

  .bottom-sheet__handle::after {
    content: '';
    width: 36px;
    height: 4px;
    background: var(--border, #333);
    border-radius: 2px;
  }

  .bottom-sheet__content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  @media (prefers-reduced-motion: reduce) {
    .bottom-sheet {
      transition: none;
    }
  }
}

/* --- Mobile Toolbar Strip ---
   Usage: Add .mobile-toolbar-strip to a nav element.
   Extends the .mobile-horizontal-scroll pattern from mobile.css.
   Children should be buttons with min-width: 44px.
*/
@media (max-width: 768px) {
  .mobile-toolbar-strip {
    display: flex;
    align-items: center;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    gap: 0;
    background: var(--bg-panel, #1a1a1a);
    border-top: 1px solid var(--border, #333);
  }

  .mobile-toolbar-strip::-webkit-scrollbar {
    display: none;
  }

  .mobile-toolbar-strip > button {
    scroll-snap-align: start;
    flex-shrink: 0;
    min-width: var(--touch-target-min, 44px);
    -webkit-tap-highlight-color: transparent;
  }
}

/* --- Mobile Header Compact ---
   Usage: Add .mobile-header-compact to compress a header to 44px on mobile.
*/
@media (max-width: 768px) {
  .mobile-header-compact {
    height: 44px !important;
    padding: 0 8px !important;
    gap: 6px !important;
  }
}
