/* PersonalOS 17 Phase 3 — responsive layout safeguards.
   These rules address intrinsic sizing and local overflow without rewriting module layouts. */
#mainContent,
#mainContent > *,
#mainContent :where(.page-header,.page-actions,.surface-card,.surface-card-header,.surface-card-body,
  .system-card,.dashboard-grid,.widget-grid,.grid-2,.grid-3,.grid-4,.p2-list-surface,
  .p2-toolbar,.p2-filter-bar,.q-filter-bar,.p5-toolbar,.p5-content) {
  min-width: 0;
  max-width: 100%;
}
#mainContent :where(.surface-card-header,.page-header,.page-actions,.p2-toolbar,.p2-filter-bar,.q-filter-bar) {
  flex-wrap: wrap;
}
#mainContent :where(.surface-card-body,.modal-body,.modal-card,.modal-layer,.p12-modal) {
  min-width: 0;
  overflow-wrap: anywhere;
}
#mainContent :where(.p2-table-wrap,.table-wrap,.data-table-wrap,.q-table-wrap,.p5-table-wrap) {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}
#mainContent :where(.p2-table,.data-table,.q-table,.p5-table) {
  max-width: 100%;
}
#mainContent :where(.subnav,.p6-subnav,.p12-subnav) {
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}
#mainContent :where(img,canvas,video,svg) { max-width: 100%; }
#mainContent :where(pre,code,.url-value,.file-name,.long-value) { overflow-wrap: anywhere; }
.modal-layer,
.modal-card,
.pl-editor-overlay,
.pl-editor-dialog { max-width: 100vw; }
.modal-card,
.pl-editor-dialog { max-height: min(92dvh, 900px); }
.pl-thumb-placeholder { position:absolute; inset:0; display:grid; place-items:center; color:var(--muted); background:var(--surface-2); font-size:26px; }
.pl-photo-thumb { position:relative; }
.pl-photo-thumb img[data-photo-thumb],
.pl-album-cover img[data-photo-thumb] { position:absolute; inset:0; width:100%; height:100%; object-fit:cover; opacity:0; transition:opacity .14s ease; }
.pl-photo-thumb img[data-thumb-state="loaded"],
.pl-album-cover img[data-thumb-state="loaded"] { opacity:1; }
.pl-thumb-retry { position:absolute; z-index:4; left:7px; bottom:7px; width:28px; height:28px; border:1px solid rgba(255,255,255,.6); border-radius:50%; background:rgba(15,23,42,.78); color:#fff; cursor:pointer; }
.pl-thumb-retry[hidden] { display:none !important; }
.pl-album-cover-wrap { position:relative; min-width:0; }
.pl-album-cover-wrap .pl-album-cover { width:100%; }
.pl-viewer-loading { display:grid; gap:8px; justify-items:center; max-width:min(90vw,480px); padding:24px; text-align:center; color:#e5eaf2; }
.pl-viewer-loading p { color:#cbd5e1; overflow-wrap:anywhere; }
.pl-upload-progress-row { display:flex; align-items:center; justify-content:space-between; gap:10px; flex-wrap:wrap; }
.pl-upload-progress-row .ghost-button { min-height:30px; padding:5px 9px; color:var(--text); }
@media (max-width: 820px) {
  #mainContent :where(.page-actions,.surface-card-header,.p2-toolbar,.p2-filter-bar,.q-filter-bar) { gap:8px; }
  #mainContent :where(.surface-card,.system-card) { max-width:100%; }
  .pl-photo-grid { content-visibility:auto; contain-intrinsic-size: 1px 700px; }
  .pl-viewer-overlay { grid-template-columns:minmax(0,1fr); }
}
@media (max-width: 560px) {
  #mainContent :where(.surface-card-header,.page-actions,.p2-toolbar,.q-filter-bar) { align-items:stretch; }
  #mainContent :where(.surface-card-header > *, .page-actions > *) { min-width:0; max-width:100%; }
  .pl-upload-progress-row { align-items:flex-start; }
}
@media (prefers-reduced-motion: reduce) {
  .pl-photo-thumb img[data-photo-thumb], .pl-album-cover img[data-photo-thumb] { transition:none; }
}

/* Phase 3: gallery placeholder, thumbnail status, and retry controls. */
.pl-photo-visual { position: relative; }
.pl-photo-thumb { position: relative; overflow: hidden; }
.pl-photo-thumb .pl-thumb-placeholder,
.pl-album-cover .pl-thumb-placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); background: var(--surface-2); font-size: 26px; pointer-events: none; }
.pl-photo-thumb img[data-photo-thumb],
.pl-album-cover img[data-photo-thumb] { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; object-fit: cover; opacity: 0; transition: opacity .14s ease; }
.pl-photo-thumb img[data-thumb-state="loaded"],
.pl-album-cover img[data-thumb-state="loaded"] { opacity: 1; }
.pl-thumb-retry { position: absolute; z-index: 5; right: 7px; bottom: 7px; display: grid; place-items: center; width: 30px; height: 30px; border: 1px solid rgba(255,255,255,.65); border-radius: 50%; background: rgba(15,23,42,.82); color: #fff; cursor: pointer; }
.pl-thumb-retry[hidden] { display: none !important; }
.pl-album-cover-wrap { position: relative; min-width: 0; }
.pl-album-cover-wrap .pl-thumb-retry { right: 12px; bottom: 12px; }
.pl-viewer-loading { display: grid; gap: 8px; justify-items: center; max-width: min(90vw, 480px); padding: 24px; text-align: center; color: #e5eaf2; }
.pl-viewer-loading p { color: #cbd5e1; overflow-wrap: anywhere; }
.pl-upload-progress-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.pl-upload-progress-row .ghost-button { min-height: 30px; padding: 5px 9px; color: var(--text); }
@media (prefers-reduced-motion: reduce) {
  .pl-photo-thumb img[data-photo-thumb], .pl-album-cover img[data-photo-thumb] { transition: none; }
}
