/* ==========================================================================
   MEDIA LIBRARY (#/media) — the "Select images" picker laid out as a page.
   Measurements are copied from the picker in product-form.css (.ipk-*): 28px buttons with 8px radius,
   120px+ square tiles with 8px radius and a 1px #E3E3E3 border, #F7F7F7 tile background, dark "badge" pill,
   green (--color-primary) selection ring and tick. Delete uses the same dark red as the picker's "Remove image".
   Scoped to #view-media and the .mdl-pv dialog; nothing else is touched.
   ========================================================================== */
#view-media .mdl {
  position: relative; background: #fff; border: 1px solid #E3E3E3; border-radius: 16px; overflow: hidden;
  color: #303030; font-size: 13px; line-height: 20px; min-height: 320px;
}

/* bucket tabs (same chips as the picker's "All images" tab) */
.mdl-tabs { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 16px 0; }
.mdl-chip { height: 28px; padding: 0 12px; border: 1px solid #E3E3E3; border-radius: 8px; background: #fff; color: #303030; font: inherit; font-size: 13px; line-height: 1; cursor: pointer; }
.mdl-chip:hover:not(:disabled) { background: #F7F7F7; }
.mdl-chip:disabled { opacity: .6; cursor: default; }
.mdl-chip.is-on { background: #E3F4EB; border-color: var(--color-primary-hover); color: var(--color-primary-hover); font-weight: 550; }
@media (max-width: 640px) { .mdl-tabs { padding: 12px 12px 0; } }

/* toolbar */
.mdl-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 56px; padding: 12px 16px; }
.mdl-bar.is-sel { background: var(--color-primary-soft, #E3F4EB); border-bottom: 1px solid var(--color-primary-soft-border, #BFE3CE); }
.mdl-spacer { flex: 1; }
.mdl-meta { font-size: 13px; color: #616161; }
.mdl-count { font-weight: 650; }

.mdl-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; height: 28px; padding: 0 12px;
  border: 1px solid #8A8A8A; border-radius: 8px; background: #fff; color: #303030;
  font: inherit; font-size: 13px; font-weight: 550; line-height: 1; cursor: pointer; white-space: nowrap; box-shadow: none;
}
.mdl-btn svg { flex: none; fill: #4A4A4A; }
.mdl-btn .ai { width: 16px; height: 16px; }
.mdl-btn:hover:not(:disabled) { background: #F7F7F7; }
.mdl-btn:disabled { opacity: .6; cursor: default; }
.mdl-viewbtn { padding: 0 8px; gap: 2px; }
.mdl-danger { color: #8E0B21; border-color: #8E0B21; }
.mdl-danger:hover:not(:disabled) { background: #FDF2F4; }
.mdl-link { border: 0; background: none; padding: 0; font: inherit; font-size: 13px; font-weight: 550; color: var(--color-primary-hover, #0F6E3E); cursor: pointer; }
.mdl-link:hover { text-decoration: underline; }
#view-media button:focus-visible, .mdl-pv button:focus-visible, .mdl-pv a:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 1px; }

/* sort menu */
.mdl-sortwrap { position: relative; }
.mdl-menu { position: absolute; z-index: 5; top: calc(100% + 4px); left: 0; min-width: 160px; padding: 4px; background: #fff; border: 1px solid #E3E3E3; border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .16); }
.mdl-menu[hidden] { display: none; }
.mdl-menu button { display: block; width: 100%; padding: 6px 10px; border: 0; border-radius: 6px; background: transparent; text-align: left; font: inherit; font-size: 13px; color: #303030; cursor: pointer; }
.mdl-menu button:hover { background: #F1F1F1; }
.mdl-menu button.is-on { font-weight: 650; background: #F7F7F7; }

.mdl-notice { margin: 0 16px 8px; padding: 8px 12px; border: 1px solid #F0D9A8; border-radius: 8px; background: #FFF8E6; color: #5C4300; font-size: 13px; }
.mdl-inline-err { margin: 12px 0 0; text-align: center; color: #8E0B21; }

/* body + grid */
.mdl-body { padding: 4px 16px 16px; }
.mdl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.mdl-cell { position: relative; aspect-ratio: 1; border: 1px solid #E3E3E3; border-radius: 8px; background: #F7F7F7; overflow: hidden; }
.mdl-cell:hover { border-color: #8A8A8A; }
.mdl-open { display: block; width: 100%; height: 100%; padding: 0; border: 0; background: transparent; cursor: zoom-in; }
.mdl-cell .mdl-open img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mdl-cell.is-sel, .mdl-row.is-sel { border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary); }
.mdl-badge { position: absolute; left: 6px; bottom: 6px; padding: 0 6px; border-radius: 6px; background: rgba(0, 0, 0, .65); color: #fff; font-size: 11px; line-height: 18px; pointer-events: none; }

/* tick box (top-left) */
.mdl-chk {
  position: absolute; top: 6px; left: 6px; z-index: 1; display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; padding: 0; border: 1.5px solid #8A8A8A; border-radius: 6px; background: #fff; color: #fff;
  cursor: pointer; opacity: 0; transition: opacity .12s ease;
}
.mdl-chk svg { fill: currentColor; }
.mdl-chk.is-on { opacity: 1; border-color: var(--color-primary); background: var(--color-primary); }
.mdl-chk:disabled { cursor: default; }
.mdl-cell:hover .mdl-chk:not(:disabled), .mdl-cell:focus-within .mdl-chk:not(:disabled), .mdl.has-sel .mdl-chk:not(:disabled) { opacity: 1; }
.mdl-bar .mdl-chk { position: static; opacity: 1; flex: none; }
.mdl-dash { width: 10px; height: 2px; border-radius: 1px; background: currentColor; }

/* delete icon (top-right) */
.mdl-trash {
  position: absolute; top: 6px; right: 6px; z-index: 1; display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0; border: 0; border-radius: 8px; background: rgba(255, 255, 255, .94);
  color: #4A4A4A; cursor: pointer; opacity: 0; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: opacity .12s ease;
}
.mdl-trash .ai { width: 16px; height: 16px; }
.mdl-trash:hover { color: #8E0B21; background: #fff; }
.mdl-cell:hover .mdl-trash, .mdl-cell:focus-within .mdl-trash { opacity: 1; }
.mdl.has-sel .mdl-cell .mdl-trash { display: none; }

/* list view */
.mdl-listv { display: flex; flex-direction: column; gap: 8px; }
.mdl-row { position: relative; display: flex; align-items: center; gap: 12px; padding: 8px 12px 8px 40px; border: 1px solid #E3E3E3; border-radius: 8px; background: #fff; }
.mdl-row:hover { background: #F7F7F7; }
.mdl-row .mdl-chk { top: 50%; transform: translateY(-50%); left: 10px; }
.mdl-row:hover .mdl-chk:not(:disabled), .mdl-row:focus-within .mdl-chk:not(:disabled), .mdl.has-sel .mdl-row .mdl-chk:not(:disabled) { opacity: 1; }
.mdl-ropen { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; padding: 0; border: 0; background: transparent; text-align: left; font: inherit; color: inherit; cursor: zoom-in; }
.mdl-rthumb { flex: none; width: 48px; height: 48px; border-radius: 6px; overflow: hidden; background: #F7F7F7; border: 1px solid #E3E3E3; }
.mdl-rthumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mdl-rtxt { display: flex; flex-direction: column; min-width: 0; }
.mdl-rtxt b { font-weight: 550; }
.mdl-rtxt i { font-style: normal; color: #616161; }
.mdl-use { flex: none; max-width: 40%; padding: 0 8px; border-radius: 6px; background: #F1F1F1; color: #4A4A4A; font-size: 12px; line-height: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mdl-row .mdl-trash { position: static; opacity: 1; flex: none; box-shadow: none; border: 1px solid #E3E3E3; }
.mdl.has-sel .mdl-row .mdl-trash { display: none; }

.mdl-more { display: flex; justify-content: center; padding: 16px 0 0; }
.mdl-state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 240px; padding: 24px; text-align: center; }
.mdl-state h3 { margin: 0; font-size: 20px; line-height: 28px; font-weight: 650; color: #303030; }
.mdl-state p { margin: 0 0 8px; font-size: 14px; color: #616161; }

/* drag and drop overlay */
.mdl-dropmsg { display: none; position: absolute; inset: 8px; z-index: 4; align-items: center; justify-content: center; border: 2px dashed var(--color-primary); border-radius: 12px; background: rgba(227, 244, 235, .92); color: var(--color-primary-hover, #0F6E3E); font-size: 15px; font-weight: 650; pointer-events: none; }
.mdl.is-drop .mdl-dropmsg { display: flex; }

/* preview dialog (same shell as the picker dialog) */
.mdl-pv { position: fixed; inset: 0; z-index: 190; display: flex; align-items: center; justify-content: center; padding: 24px; color: #303030; font-size: 13px; line-height: 20px; }
.mdl-pv-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .5); }
.mdl-pv-dialog { position: relative; display: flex; flex-direction: column; width: 100%; max-width: 860px; max-height: 100%; background: #fff; border-radius: 16px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .06), 0 24px 48px rgba(0, 0, 0, .28); overflow: hidden; }
.mdl-pv-head { display: flex; align-items: center; justify-content: space-between; flex: none; height: 52px; padding: 0 16px; background: #F7F7F7; border-bottom: 1px solid #E3E3E3; }
.mdl-pv-head h2 { margin: 0; font-size: 14px; line-height: 20px; font-weight: 650; color: #303030; }
.mdl-x { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: #616161; cursor: pointer; }
.mdl-x:hover { background: #EBEBEB; color: #303030; }
.mdl-pv-body { display: flex; gap: 16px; flex: 1 1 auto; min-height: 0; padding: 16px; overflow-y: auto; }
.mdl-pv-img { flex: 1 1 60%; display: flex; align-items: center; justify-content: center; min-height: 260px; border: 1px solid #E3E3E3; border-radius: 8px; background: #F7F7F7; overflow: hidden; }
.mdl-pv-img img { display: block; max-width: 100%; max-height: min(60vh, 520px); object-fit: contain; }
.mdl-pv-info { flex: 1 1 40%; min-width: 0; }
.mdl-pv-info dl { margin: 0; }
.mdl-pv-info dt { margin: 12px 0 2px; font-size: 12px; color: #616161; }
.mdl-pv-info dt:first-child { margin-top: 0; }
.mdl-pv-info dd { margin: 0; font-weight: 550; word-break: break-word; }
.mdl-mono { font-family: "Paper Mono", ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; font-weight: 400 !important; }
.mdl-uses { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.mdl-uses a { color: var(--color-primary-hover, #0F6E3E); font-weight: 550; text-decoration: none; }
.mdl-uses a:hover { text-decoration: underline; }
.mdl-hint { margin: 8px 0 0; font-size: 12px; font-weight: 400; color: #616161; }
.mdl-pv-foot { display: flex; align-items: center; gap: 8px; flex: none; min-height: 60px; padding: 12px 16px; border-top: 1px solid #E3E3E3; }

@media (hover: none) {
  .mdl-chk:not(:disabled) { opacity: 1; }
  .mdl-cell .mdl-trash { opacity: 1; }
}
@media (max-width: 640px) {
  .mdl-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .mdl-bar { padding: 12px; }
  .mdl-body { padding: 4px 12px 12px; }
  .mdl-meta { display: none; }
  .mdl-use { display: none; }
  .mdl-pv { padding: 0; }
  .mdl-pv-dialog { max-width: none; height: 100%; border-radius: 0; }
  .mdl-pv-body { flex-direction: column; }
  .mdl-pv-img { min-height: 200px; }
}
@media (prefers-reduced-motion: reduce) { .mdl-chk, .mdl-trash { transition: none; } }
