#mobile-tab-bar,
.mobile-selection-shell {
  display: none;
}

#mobile-notes-edit,
#mobile-items-expand,
#mobile-notes-save {
  display: none;
}

@media (max-width: 900px) {
  :root {
    --mobile-tab-bar-height: calc(72px + env(safe-area-inset-bottom));
    --mobile-card-gap: 4%;
    --mobile-selection-bar-gap: 12px;
  }

  html, body {
    height: 100vh;
    min-height: 100vh;
    overflow: hidden;
    overflow-x: hidden;
    overscroll-behavior: none;
  }

  body {
    background: #f6f5f6;
    padding-bottom: calc(var(--mobile-tab-bar-height) + 8px + var(--mobile-selection-bar-gap));
  }

  .container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: calc(100vh - 0px);
    min-height: 100vh;
    padding: 12px 12px calc(12px + var(--mobile-tab-bar-height));
    overflow: hidden;
  }

  .panel {
    min-height: 0;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
    flex: 1;
    display: flex;
    flex-direction: column;
  }

  .panel-body {
    overflow: hidden;
    flex: 1;
  }

  /* Contained scrolling zones (no page scroll chaining) */
  .cards,
  .picked-cards,
  #detail-content,
  #detail-items-wrapper,
  #detail-notes-wrapper {
    overscroll-behavior: contain;
  }

  .cards {
    flex: 1;
    padding: 12px;
    gap: var(--mobile-card-gap);
    row-gap: 14px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
  }

  .cards .card,
  .cards .pipeline-card {
    flex: 0 0 calc((100% - var(--mobile-card-gap)) / 2);
    max-width: calc((100% - var(--mobile-card-gap)) / 2);
    margin-bottom: 6px;
  }

  .fulfillment .sub-section .cards {
    gap: var(--mobile-card-gap);
    row-gap: 14px;
    justify-content: space-between;
  }

  .fulfillment .sub-section .cards .card {
    flex: 0 0 calc((100% - var(--mobile-card-gap)) / 2);
    max-width: calc((100% - var(--mobile-card-gap)) / 2);
    aspect-ratio: auto;
  }

  .panel.fulfillment {
    gap: 12px;
  }

  .panel.fulfillment .sub-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .panel.fulfillment .sub-section .cards {
    flex: 1;
  }

  .panel.pipeline,
  .panel.create,
  .panel.fulfillment {
    display: none;
  }

  body[data-active-tab="pipeline"] .panel.pipeline {
    display: flex;
  }

  body[data-active-tab="blanksCart"] .panel.create {
    display: flex;
  }

  body[data-active-tab="blanksOrdered"] .panel.fulfillment {
    display: flex;
  }

  body[data-active-tab="readyToPrint"] .panel.fulfillment {
    display: flex;
  }

  body[data-active-tab="blanksOrdered"] #print-section {
    display: none !important;
  }

  body[data-active-tab="readyToPrint"] #blanks-section {
    display: none !important;
  }

  .panel.create .create-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  .drag-area {
    margin: 0;
    padding: 16px;
    min-height: 120px;
    border-radius: 18px;
  }

  .picked-cards {
    margin: 0;
    padding: 12px 0;
    max-height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .summary {
    width: 100%;
    margin: 0;
  }

  .panel.fulfillment {
    gap: 12px;
    overflow: hidden;
  }

  .panel.fulfillment .sub-section + .sub-section {
    margin-top: 12px;
  }

  #mobile-tab-bar {
    display: grid;
  }

  .mobile-tab-bar {
    position: fixed;
    bottom: 0px;
    left: 0;
    right: 0;
    margin-left: 8%;
    margin-right: 8%;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid #dfe3eb;
    border-radius: 16px 16px calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-bottom));
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 1200;
  }

  .mobile-selection-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--mobile-tab-bar-height) + var(--mobile-selection-bar-gap));
    display: none;
    gap: 10px;
    padding: 10px 16px;
    z-index: 1250;
  }

  body.mobile-selection-mode .mobile-selection-actions {
    display: flex;
  }

  .mobile-primary,
  .mobile-secondary {
    border: none;
    border-radius: 12px;
    padding: 14px 12px;
    font-size: 1rem;
    font-weight: 700;
    min-height: 48px;
  }

  .mobile-primary {
    flex: 1.25;
    background: #1a73e8;
    color: #fff;
    box-shadow: 0 4px 10px rgba(26, 115, 232, 0.35);
  }

  .mobile-primary:disabled,
  .mobile-primary[aria-disabled="true"] {
    background: #9dbaf0;
    color: #f1f4fb;
    box-shadow: none;
  }

  .mobile-secondary {
    flex: 1;
    background: #e5eaf2;
    color: #334155;
    border: 1px solid #cbd5e1;
  }

  .mobile-select-toggle {
    display: none;
  }

  body.mobile-mode .mobile-select-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid #cbd5e1;
    background: #f1f5f9;
    font-size: 0.9rem;
    font-weight: 600;
    color: #1a73e8;
  }

  .mobile-select-toggle[aria-pressed="true"] {
    background: #e8f1ff;
    border-color: #1a73e8;
    color: #0f55b4;
  }

  body.mobile-detail-open {
    overflow: hidden;
  }

  #detail-overlay.mobile-bottomsheet {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    padding: 0;
  }

  #detail-overlay.mobile-bottomsheet #detail-card {
    width: 100%;
    max-width: 100%;
    border-radius: 18px 18px 0 0;
    max-height: calc(92vh - env(safe-area-inset-bottom));
    overflow: hidden;
    transform: translateY(100%);
    transition: transform 0.25s ease;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.18);
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    position: relative;
    display: flex;
    flex-direction: column;
  }

  body.mobile-detail-open #detail-overlay.mobile-bottomsheet #detail-card {
    transform: translateY(0);
  }

  #detail-overlay.mobile-bottomsheet #detail-content {
    min-height: 0;
  }

  #detail-overlay.mobile-bottomsheet #detail-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    display: grid;
    place-items: center;
    font-size: 1.2rem;
  }

  #detail-card {
    background: #f7f9fc;
  }

  #detail-content {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 12px;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    min-height: 0;
  }

  #detail-main-column {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
    overflow: visible;
  }

  #detail-main-stack {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
    width: 100%;
  }

  #detail-main-stack {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
  }

  #detail-header {
    text-align: center;
    margin-top: 4px;
  }

  #detail-header h2 {
    font-size: 1.25rem;
  }

  #detail-header time {
    display: block;
    margin-top: 4px;
    color: #667085;
    font-size: 0.95rem;
  }

  #detail-mockups-strip {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 14px;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
  }

  #detail-mockups-track {
    display: flex;
    gap: 12px;
    width: 100%;
    justify-content: center;
  }

  #detail-mockups-track img {
    max-width: 44%;
    border-radius: 12px;
    background: #f1f5f9;
    padding: 8px;
  }

  #detail-name-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
    padding: 12px 14px;
    border-radius: 12px;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
  }

  #detail-name-row h3 {
    font-size: 1rem;
    margin: 0;
    color: #0f172a;
  }

  #detail-name-row::before {
    content: "Customer:";
    font-weight: 600;
    color: #475569;
    margin-right: 8px;
  }

  #detail-edit-name-btn {
    font-size: 0.9rem;
  }

  .detail-notes-actions {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
    margin-left: auto;
  }

  #detail-view-notes-btn,
  #detail-edit-notes-btn {
    display: none;
  }

  #mobile-notes-edit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid #d8dee9;
    background: #e9eef6;
    color: #1a73e8;
    font-size: 1rem;
    position: absolute;
    top: 6px;
    left: 6px;
  }

  #detail-notes-wrapper {
    position: relative;
    background: #fff;
    padding: 14px 14px 18px;
    border-radius: 12px;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
    min-height: 90px;
  }

  #detail-notes {
    margin: 0;
    color: #1f2937;
    white-space: pre-wrap;
  }

  #detail-notes-input {
    width: 100%;
    min-height: 80px;
    border-radius: 10px;
    border: 1px solid #d0d7e2;
    padding: 10px;
    font-size: 0.95rem;
    resize: vertical;
  }

  #mobile-notes-save {
    margin-top: 10px;
    padding: 10px 12px;
    border: none;
    border-radius: 10px;
    background: #1a73e8;
    color: #fff;
    font-weight: 700;
    width: 120px;
    float: right;
  }

  #ready-controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    align-items: center;
    background: #fff;
    padding: 12px;
    border-radius: 12px;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
  }

  #ready-controls label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
    font-size: 0.9rem;
    color: #334155;
    padding: 10px 6px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
  }

  #ready-controls input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: #1a73e8;
  }

  #ready-apply {
    grid-column: 1 / -1;
  }

  #progress-section {
    background: #fff;
    padding: 12px;
    border-radius: 12px;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  #progress-text {
    font-weight: 600;
    color: #111827;
  }

  #progress-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  #progress-bar-container {
    height: 18px;
    border-radius: 999px;
    overflow: hidden;
    background: linear-gradient(90deg, #e2e8f0 0%, #f1f5f9 100%);
  }

  #progress-bar {
    border-radius: 999px;
    background: linear-gradient(90deg, #6aa5ff 0%, #1a73e8 100%);
    height: 100%;
  }

  #progress-row button {
    width: 100%;
    border-radius: 12px;
    padding: 12px 10px;
  }

  #progress-row button + button {
    margin-left: 0;
  }

  #detail-items-wrapper {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
    overflow: hidden;
    max-height: 260px;
    position: relative;
    display: block;
  }

  #detail-items-wrapper.mobile-expanded {
    max-height: none;
  }

  #detail-items {
    width: 100%;
    display: table;
  }

  .mobile-items-footer {
    display: flex;
    justify-content: flex-end;
    padding: 8px 10px;
    background: linear-gradient(180deg, transparent 0%, #f8fafc 90%);
    position: sticky;
    bottom: 0;
  }

  #mobile-items-expand {
    display: inline-block;
    border: 1px solid #d0d7e2;
    background: #e8f1ff;
    color: #0f55b4;
    border-radius: 10px;
    padding: 8px 12px;
    font-weight: 700;
  }

  #detail-summary {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
    margin-top: -4px;
  }

  #detail-summary td {
    padding: 10px 12px;
  }

  #detail-summary tr:last-child td {
    font-size: 1.05rem;
  }

  #detail-design-panel {
    background: #f7f9fc;
    border: none;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
    padding: 0;
    width: 100%;
    max-width: none;
    order: 99;
  }

  .design-panel-body {
    display: grid;
    gap: 10px;
    padding: 0;
  }

  .design-group {
    background: #fff;
    border-radius: 12px;
    padding: 10px;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
  }

  .design-group-title {
    font-weight: 700;
    margin-bottom: 6px;
  }

  .design-tiles {
    gap: 8px;
  }

  body.mobile-selection-mode #pipeline-selection-shell {
    display: flex;
  }

  .mobile-selection-shell {
    display: none;
  }

  .mobile-selectable {
    cursor: pointer;
  }

  .mobile-selected {
    outline: 2px solid #1a73e8;
    box-shadow: 0 0 0 4px rgba(26, 115, 232, 0.15);
    background: linear-gradient(180deg, #f6f9ff 0%, #eef3ff 100%);
  }

  .mobile-tab {
    border: none;
    background: transparent;
    border-radius: 12px;
    padding: 10px 8px;
    font-size: 0.95rem;
    font-weight: 700;
    color: #445063;
  }

  .mobile-tab:focus-visible {
    outline: 2px solid #1a73e8;
    outline-offset: 2px;
  }

  body[data-active-tab="pipeline"] .mobile-tab[data-tab="pipeline"],
  body[data-active-tab="blanksCart"] .mobile-tab[data-tab="blanksCart"],
  body[data-active-tab="blanksOrdered"] .mobile-tab[data-tab="blanksOrdered"],
  body[data-active-tab="readyToPrint"] .mobile-tab[data-tab="readyToPrint"] {
    background: #1a73e8;
    color: #ffffff;
  }

  .mobile-selection-shell {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 12px;
    background: #f3f5f8;
    color: #5c6677;
    font-size: 0.9rem;
    border-bottom: 1px dashed #d7dce3;
  }

  .selection-toolbar-placeholder {
    text-align: center;
    width: 100%;
  }
}
