/* ==========================================================================
   Responsive Design & Mobile Layouts
   ========================================================================== */

/* Mobile Navigation Bar for View Switching (hidden on desktop) */
.mobile-view-tabs {
  display: none;
}

/* Tablet & Mobile Breakpoint (<= 768px) */
@media (max-width: 768px) {
  :root {
    --header-height: 44px;
    --tab-height: 34px;
  }

  .app-header {
    padding: 0 10px;
    gap: 8px;
  }

  .brand-title {
    font-size: 13px;
  }

  .brand-icon {
    width: 20px;
    height: 20px;
  }

  .btn-run kbd {
    display: none;
  }

  .btn {
    height: 28px;
    padding: 0 8px;
    font-size: 11px;
  }

  .toggle-label {
    display: none;
  }

  .toolbar-actions {
    gap: 4px;
  }

  /* Show mobile view tabs */
  .mobile-view-tabs {
    display: flex;
    align-items: center;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    padding: 0 6px;
    height: var(--tab-height);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 0;
    gap: 2px;
  }

  .mobile-tab-btn {
    display: inline-flex;
    align-items: center;
    height: 100%;
    padding: 0 10px;
    font-size: 11px;
    font-family: var(--font-mono);
    font-weight: 400;
    color: var(--text-muted);
    background: transparent;
    white-space: nowrap;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    cursor: pointer;
    transition: color 0.12s ease;
  }

  .mobile-tab-btn.is-active {
    color: var(--text-primary);
    background: transparent;
    border-bottom-color: var(--accent-run);
  }

  /* Hide desktop editor tab bar in mobile mode */
  .editor-header {
    display: none;
  }

  .preview-header {
    display: flex;
  }

  .btn-mobile-edit {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 24px;
    padding: 0 7px;
    font-size: 11px;
    margin-right: 4px;
    background-color: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xs);
  }

  .btn-mobile-edit:hover {
    color: var(--text-primary);
    background-color: var(--bg-hover);
  }

  /* Workspace container on mobile */
  .workspace {
    position: relative;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  .resizer {
    display: none;
  }

  /* Pane sizing on mobile */
  .editor-pane,
  .preview-pane {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    min-width: 100%;
    min-height: 100%;
    border-right: none;
    transition: opacity 0.12s ease;
  }

  /* Mobile view switching preserving iframe state */
  .workspace[data-mobile-view="editor"] .editor-pane {
    position: relative;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    z-index: 2;
  }
  .workspace[data-mobile-view="editor"] .preview-pane {
    position: absolute;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: 1;
  }

  .workspace[data-mobile-view="preview"] .editor-pane {
    position: absolute;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: 1;
  }
  .workspace[data-mobile-view="preview"] .preview-pane {
    position: relative;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    z-index: 2;
  }
}

/* Small Phones (<= 480px and 360px / 320px) */
@media (max-width: 480px) {
  .app-header {
    padding: 0 8px;
  }

  .btn {
    padding: 0 6px;
    font-size: 11px;
  }

  .btn-text-responsive {
    display: none;
  }

  .toolbar-divider {
    display: none;
  }

  .mobile-tab-btn {
    padding: 0 8px;
    font-size: 11px;
  }

  .modal-card {
    padding: 14px;
    margin: 12px;
  }
}

/* Extremely compact phones (<= 340px) */
@media (max-width: 340px) {
  .brand-title {
    display: none;
  }

  .btn {
    padding: 0 5px;
  }
}
