/* ══════════════════════════════════════════════
   Responsive: Tablet (≤768px)
   ══════════════════════════════════════════════ */

@media (max-width: 768px) {
  .dashboard-welcome h1 {
    font-size: 1.5rem;
  }

  .dashboard-welcome p {
    font-size: 0.9375rem;
  }

  .albums-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }

  .photo-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }

  .album-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .editable-header {
    flex-wrap: wrap;
  }

  .site-header {
    padding: 0 var(--space-md);
  }

  .user-name {
    display: none;
  }

  .user-menu-trigger {
    padding: 4px;
  }

  /* Show actions always on touch devices (no hover) */
  .photo-select-checkbox {
    opacity: 1;
  }

  .selection-toolbar {
    position: sticky;
    top: 0;
    gap: var(--space-sm);
    padding: var(--space-sm);
  }

  /* Stack compact settings vertically on narrow screens */
  .settings-form--compact {
    flex-direction: column;
    align-items: stretch;
  }

  .settings-grid {
    grid-template-columns: 1fr 1fr;
  }

  .settings-group--hidden {
    display: none;
  }

  /* Touch-friendly: ensure 44px minimum targets */
  .theme-toggle {
    min-height: 44px;
    min-width: 44px;
  }

  .btn-icon {
    min-width: 44px;
    min-height: 44px;
  }

  .trash-icon-btn {
    min-height: 36px;
    min-width: 36px;
  }

  .error-toast-close {
    min-height: 44px;
    min-width: 44px;
  }

  .view-size-btn {
    min-height: 44px;
    padding: var(--space-sm);
  }

  .remove-page-btn {
    width: 44px;
    height: 44px;
    opacity: 1;
  }

  .crop-btn,
  .move-grip {
    width: 36px;
    height: 36px;
    min-height: unset;
    min-width: unset;
    padding: 0;
    font-size: 18px;
  }

  .slot-delete-btn {
    opacity: 1;
    border-radius: 50%;
    width: 22px;
    height: 22px;
  }

  .preview-slot .crop-btn {
    left: 3px;
  }

  /* Preview grid: single column on mobile regardless of view size */
  .preview-container,
  .preview-container[data-view-size] {
    grid-template-columns: 1fr;
  }

  .preview-header {
    flex-direction: column;
    align-items: flex-start;
  }

  /* Create book row: stack on tablets */
  .create-book-row {
    flex-direction: column;
  }

  .create-book-row input,
  .create-book-row select {
    min-width: 0;
    width: 100%;
  }

  /* Generate actions: stack buttons vertically */
  .generate-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
  }

  .generate-actions .btn,
  .generate-actions .btn-download,
  .generate-actions a {
    width: 100%;
    text-align: center;
  }

  /* Confirm dialog: make it more touch-friendly */
  .confirm-actions {
    flex-direction: column;
  }

  .confirm-actions .confirm-cancel,
  .confirm-actions .confirm-danger {
    width: 100%;
  }

  /* Breadcrumb: truncate on narrow screens */
  .breadcrumb {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 50vw;
  }

  /* Inline preview header: stack */
  .inline-preview-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ══════════════════════════════════════════════
   Responsive: Mobile (≤480px)
   ══════════════════════════════════════════════ */

@media (max-width: 480px) {
  :root {
    --header-height: 48px;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  body {
    padding-top: 52px;
  }

  .site-header {
    height: 48px;
    padding: 0 var(--space-sm);
  }

  .logo {
    font-size: 1.1rem;
  }

  main {
    margin: var(--space-md) auto;
    padding: 0 var(--space-sm);
  }

  .dashboard-welcome {
    padding: var(--space-lg) 0 var(--space-md);
  }

  .dashboard-welcome h1 {
    font-size: 1.375rem;
  }

  .dashboard-welcome p {
    font-size: 0.875rem;
  }

  form {
    flex-direction: column;
  }

  input[type="text"],
  input[type="file"] {
    width: 100%;
  }

  button, .btn-download, .btn {
    width: 100%;
    text-align: center;
  }

  .btn-sm {
    width: auto;
  }

  .albums-grid {
    grid-template-columns: 1fr;
  }

  .photo-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
  }

  .btn-generate {
    width: 100%;
  }

  .upload-dropzone {
    padding: var(--space-xl) var(--space-md);
  }

  .radio-option {
    padding: var(--space-sm) var(--space-md);
  }

  .editable-header {
    width: 100%;
  }

  .editable-title-input {
    width: 100%;
  }

  /* Breadcrumb: tighter on phones */
  .breadcrumb {
    max-width: 35vw;
    font-size: 0.75rem;
  }

  /* View size controls: stack vertically */
  .view-size-controls {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .view-size-buttons {
    width: auto;
  }

  .view-size-btn {
    flex: none;
  }

  /* Preview actions: full-width buttons */
  .preview-actions {
    width: 100%;
    flex-direction: column;
  }

  .preview-actions .btn {
    width: 100%;
  }

  /* Inline preview actions: stack */
  .inline-preview-actions {
    width: 100%;
    flex-direction: column;
  }

  .inline-preview-actions .btn {
    width: 100%;
  }

  /* Unplaced photos: smaller cards */
  .unplaced-photo-card {
    width: 56px;
    height: 56px;
  }

  /* Template picker: allow wrap */
  .template-picker {
    gap: var(--space-xs);
  }

  /* Error toast: full-width */
  .error-toast {
    margin: var(--space-sm);
    flex-wrap: wrap;
  }

  /* Confirm dialog: use more screen width */
  .confirm-dialog {
    width: calc(100% - var(--space-md) * 2);
    padding: var(--space-lg);
  }
}


/* Tablet: hide options that would make pages too narrow (<250px) */
@media (min-width: 769px) and (max-width: 1024px) {
  .view-size-btn[data-size="sm"],
  .view-size-btn[data-size="md"] {
    display: none;
  }
}

/* Touch-friendly: larger resize grip on mobile */
@media (max-width: 768px) {
  .resize-grip {
    width: 28px;
    height: 28px;
  }
  
  .resize-grip svg {
    width: 16px;
    height: 16px;
  }

  .move-grip {
    opacity: 0.8;
    font-size: 18px;
    width: 36px;
    height: 36px;
    min-height: unset;
    min-width: unset;
    padding: 0;
  }

  .crop-btn {
    opacity: 1;
    width: 36px;
    height: 36px;
    min-height: unset;
    min-width: unset;
    padding: 0;
  }

  .crop-btn svg {
    width: 20px;
    height: 20px;
  }

  .slot-delete-btn {
    opacity: 1;
    width: 22px;
    height: 22px;
    min-height: unset;
    min-width: unset;
    padding: 0;
    font-size: 11px;
  }

  .preview-slot .crop-btn {
    left: 3px;
  }
}

/* Responsive */
@media (max-width: 768px) {
  .view-size-buttons { display: none !important; }
  .view-size-label { display: none !important; }

  .preview-container,
  .preview-container[data-view-size] {
    grid-template-columns: 1fr;
  }

  .preview-page-wrapper {
    max-width: 100% !important;
    width: 100% !important;
    align-items: stretch;
  }

  .preview-container[data-view-size] .preview-page,
  .preview-container[data-view-size] .add-page-card {
    max-height: none;
    max-width: none;
  }

  /* Reset viewport breakout on mobile */
  .inline-preview-section {
    width: auto;
    max-width: none;
    margin-left: 0;
    padding-left: 0;
    padding-right: 0;
  }

  .preview-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .remove-page-btn {
    opacity: 1;
  }

  .crop-btn {
    opacity: 1;
  }

  .slot-delete-btn {
    opacity: 1;
  }

  .unplaced-photos-panel {
    position: static;
    border-radius: var(--radius-md);
  }

  .unplaced-photos-panel.panel-floating,
  .unplaced-photos-panel.panel-dragged {
    position: fixed !important;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    z-index: 500;
    max-height: 120px;
    overflow: hidden;
    border-top: 2px solid var(--border-color, var(--border-default));
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -4px 16px var(--overlay-lighter);
    margin: 0;
    width: 100%;
  }

  .unplaced-photos-body {
    overflow: hidden;
    padding: var(--space-xs) var(--space-sm);
  }

  .unplaced-photos-grid {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .unplaced-photo-card {
    width: 60px;
    height: 60px;
    flex-shrink: 0;
  }

  /* Bottom padding so floating panel doesn't cover page content */
  .panel-floating-active .preview-container {
    padding-bottom: max(130px, 15vh);
  }

  .panel-sentinel {
    display: block;
    height: 0;
    pointer-events: none;
  }
}

@media (max-width: 480px) {
  .preview-container,
  .preview-container[data-view-size] {
    grid-template-columns: 1fr;
    gap: var(--space-lg);
  }

  .preview-actions {
    width: 100%;
    flex-direction: column;
  }

  .preview-actions .btn {
    width: 100%;
  }

  .unplaced-photos-body {
    overflow: hidden;
    padding: var(--space-xs) var(--space-sm);
  }

  .unplaced-photo-card {
    width: 55px;
    height: 55px;
  }

  .move-grip {
    padding: 0;
    font-size: 20px;
    width: 40px;
    height: 40px;
    min-height: unset;
    min-width: unset;
  }

  .crop-btn {
    width: 40px;
    height: 40px;
    min-height: unset;
    min-width: unset;
    padding: 0;
  }

  .crop-btn svg {
    width: 22px;
    height: 22px;
  }

  .slot-delete-btn {
    min-height: unset;
    min-width: unset;
    width: 24px;
    height: 24px;
    padding: 0;
    font-size: 12px;
  }

  .resize-grip {
    width: 32px;
    height: 32px;
  }
  
  .resize-grip svg {
    width: 18px;
    height: 18px;
  }
}


@media (max-width: 768px) {
  .export-fab {
    position: static !important;
    bottom: auto;
    right: auto;
    border-radius: var(--radius-md);
    box-shadow: none;
    width: 100%;
    padding: 10px 16px;
    font-size: 0.9rem;
    min-height: 44px;
    justify-content: center;
  }
}
