.ns-media-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10050;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgb(5 24 48 / 58%);
  backdrop-filter: blur(3px);
}

.ns-media-dialog {
  width: min(720px, 100%);
  max-height: min(820px, calc(100vh - 32px));
  overflow: auto;
  border: 1px solid var(--theme-border, #d4e0ec);
  border-radius: 14px;
  background: var(--theme-surface, #fff);
  color: var(--theme-text, #14243a);
  box-shadow: 0 24px 70px rgb(7 31 59 / 24%);
}

.ns-media-dialog > header {
  display: grid;
  grid-template-columns: 42px 1fr 34px;
  gap: 12px;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--theme-border, #d4e0ec);
}

.ns-media-dialog h2 { margin: 0; font-size: 16px; font-weight: 600; }
.ns-media-dialog header p { margin: 3px 0 0; font-size: 12px; color: var(--theme-text-muted, #64748b); }
.ns-media-heading-icon { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 10px; background: var(--theme-primary-soft, #e9f3fc); color: var(--theme-primary, #1b75ce); }
.ns-media-svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ns-media-close { display: grid; width: 34px; height: 34px; place-items: center; padding: 0; border: 0; border-radius: 8px; background: transparent; color: inherit; }
.ns-media-close:hover { background: var(--theme-primary-soft, #e9f3fc); }

.ns-media-selected-file { display: flex; align-items: center; gap: 12px; margin: 16px 20px 0; padding: 11px 12px; border: 1px solid var(--theme-border, #d4e0ec); border-radius: 9px; background: var(--theme-surface-muted, #f7fafc); }
.ns-media-selected-file > img, .ns-media-file-kind { display: grid; flex: 0 0 44px; width: 44px; height: 44px; place-items: center; border-radius: 8px; object-fit: cover; background: var(--theme-primary-soft, #e9f3fc); color: var(--theme-primary, #1b75ce); }
.ns-media-selected-file > div { display: grid; min-width: 0; gap: 3px; }
.ns-media-selected-file strong { min-width: 0; overflow: hidden; font-size: 12.5px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.ns-media-selected-file span { font-size: 11.5px; color: var(--theme-text-muted, #64748b); }

.ns-media-metadata-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 16px 20px 20px; }
.ns-media-metadata-form label { display: grid; gap: 5px; min-width: 0; }
.ns-media-metadata-form label > span { font-size: 11.5px; font-weight: 500; color: var(--theme-text-muted, #52677e); }
.ns-media-metadata-form input,
.ns-media-metadata-form select,
.ns-media-metadata-form textarea { width: 100%; min-height: 34px; padding: 5px 7px; border: 1px solid var(--theme-border, #cbd9e8); border-radius: 7px; background: var(--theme-surface, #fff); color: inherit; font: 500 12.5px/1.35 inherit; }
.ns-media-metadata-form textarea { min-height: 62px; resize: vertical; }
.ns-media-wide { grid-column: 1 / -1; }
.ns-media-metadata-form footer { display: flex; grid-column: 1 / -1; gap: 8px; justify-content: flex-end; padding-top: 4px; }

input[type="file"][aria-busy="true"] { cursor: progress; opacity: .65; }
.ns-upload-status { display: block; margin-top: 5px; font-size: 11px; font-weight: 500; color: var(--theme-text-muted, #64748b); }
.ns-upload-status[data-state="success"] { color: var(--color-success, #119c62); }
.ns-upload-status[data-state="error"] { color: var(--color-danger, #dc3545); }
.ns-upload-dragover { outline: 2px dashed var(--theme-primary, #1b75ce) !important; outline-offset: 3px; background: var(--theme-primary-soft, #e9f3fc) !important; }

@media (max-width: 640px) {
  .ns-media-backdrop { align-items: end; padding: 0; }
  .ns-media-dialog { width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0; }
  .ns-media-dialog > header { padding: 15px 16px; }
  .ns-media-selected-file { display: grid; margin-inline: 16px; }
  .ns-media-metadata-form { grid-template-columns: 1fr; padding-inline: 16px; }
  .ns-media-wide { grid-column: auto; }
  .ns-media-metadata-form footer { grid-column: auto; }
}

.ns-photo-picker { display: grid; min-width: 0; gap: 12px; container-type: inline-size; }
.ns-photo-picker__preview { display: grid; width: min(280px, 100%); aspect-ratio: 1; place-items: center; justify-self: center; overflow: hidden; border-radius: var(--radius-control, 10px); background: var(--color-primary-soft); color: var(--color-primary); }
.ns-photo-picker__preview img { width: 100%; height: 100%; object-fit: cover; }
.ns-photo-picker__preview > span { font-size: clamp(34px, 5vw, 54px); font-weight: 600; }
.ns-photo-picker__actions { display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 0; }
.ns-photo-picker__control { position: relative; display: inline-flex; width: 34px; min-width: 34px; height: 34px; align-items: center; justify-content: center; gap: 7px; padding: 0; border: 1px solid var(--color-border-strong); border-radius: var(--radius-control, 7px); background: var(--color-surface); color: var(--color-primary); cursor: pointer; }
.ns-photo-picker__control:hover, .ns-photo-picker__control:focus-visible, .ns-photo-picker__control:has(input:focus-visible) { border-color: var(--color-primary); background: var(--color-primary-soft); outline: none; }
.ns-photo-picker__control > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.ns-photo-picker__control input { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }
.ns-photo-picker__icon { width: 17px; height: 17px; flex: 0 0 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ns-photo-picker__control--danger { color: var(--color-danger); }
.ns-photo-picker__control:disabled { color: var(--color-text-muted); cursor: not-allowed; opacity: .5; }
.ns-photo-picker__control::after { position: absolute; z-index: 20; left: 50%; bottom: calc(100% + 7px); max-width: 190px; padding: 5px 7px; border-radius: 5px; background: var(--color-structural-dark); color: var(--color-on-structural-dark, #fff); content: attr(data-tooltip); font-size: 11px; font-weight: 500; line-height: 1.2; opacity: 0; pointer-events: none; transform: translate(-50%, 4px); transition: opacity 120ms ease, transform 120ms ease; white-space: nowrap; }
.ns-photo-picker__control:hover::after, .ns-photo-picker__control:focus-visible::after, .ns-photo-picker__control:has(input:focus-visible)::after { opacity: 1; transform: translate(-50%, 0); }
.ns-photo-picker__help { margin: 0; color: var(--color-text-secondary); font-size: 11.5px; font-weight: 400; line-height: 1.35; text-align: center; }

.ns-media-editor-layer { position: fixed; inset: 0; z-index: 5200; display: grid; place-items: center; padding: 18px; background: var(--modal-overlay); backdrop-filter: blur(3px); }
.ns-media-editor, .ns-camera-capture { width: min(560px, 94vw); overflow: hidden; border: 1px solid var(--color-border-strong); border-radius: 14px; color: var(--color-text-primary); background: var(--modal-bg); box-shadow: 0 28px 80px color-mix(in srgb, var(--color-structural-dark) 34%, transparent); }
.ns-media-editor > header, .ns-camera-capture > header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--color-border); }
.ns-media-editor h2, .ns-camera-capture h2 { margin: 0; font-size: 16px; font-weight: 600; }.ns-media-editor header p, .ns-camera-capture header p { margin: 2px 0 0; color: var(--color-text-secondary); font-size: 11.5px; }
.ns-media-editor header button, .ns-camera-capture header button { display: grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 50%; color: var(--color-text-primary); background: var(--color-primary-soft); font-size: 22px; }
.ns-media-editor-preview { position: relative; width: min(330px, 70vw); aspect-ratio: 1; margin: 18px auto 12px; overflow: hidden; border: 1px solid var(--color-border-strong); border-radius: 14px; background: var(--color-page-bg); cursor: grab; touch-action: none; user-select: none; }
.ns-media-editor-preview:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 3px; }
.ns-media-editor-preview.is-dragging { cursor: grabbing; }
.ns-media-editor-preview img { position: absolute; max-width: none; transform-origin: center; transition: transform 80ms linear, left 80ms linear, top 80ms linear; pointer-events: none; user-select: none; }
.ns-media-editor-preview.is-dragging img { transition: none; }
.ns-media-editor-drag-hint { position: absolute; z-index: 2; left: 50%; bottom: 10px; display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 999px; background: color-mix(in srgb, var(--color-structural-dark) 72%, transparent); color: var(--color-on-structural-dark, #fff); font-size: 11px; font-weight: 500; transform: translateX(-50%); pointer-events: none; white-space: nowrap; }
.ns-media-editor-controls { display: grid; gap: 9px; padding: 0 18px 14px; }.ns-media-editor-controls label { display: grid; grid-template-columns: 82px 1fr; align-items: center; gap: 8px; font-size: 11.5px; }.ns-media-editor-controls input { width: 100%; accent-color: var(--color-primary); }
.ns-media-editor-controls > div { display: flex; justify-content: center; gap: 7px; }.ns-media-editor-controls button { display: inline-flex; min-height: 34px; align-items: center; justify-content: center; gap: 7px; padding: 5px 9px; border: 1px solid var(--color-border-strong); border-radius: 7px; color: var(--color-text-primary); background: var(--color-surface); font-size: 11.5px; line-height: 1.2; }
.ns-media-editor-controls button .ns-media-svg { width: 17px; height: 17px; flex: 0 0 17px; }
.ns-media-editor > footer, .ns-camera-capture > footer { display: flex; justify-content: flex-end; gap: 8px; padding: 11px 16px; border-top: 1px solid var(--color-border); background: var(--modal-footer-bg); }
.ns-camera-capture video { display: block; width: calc(100% - 32px); max-height: 58vh; margin: 16px; border-radius: 10px; background: var(--color-structural-dark); object-fit: cover; transform: scaleX(-1); }
.ns-camera-message { margin: 0 16px 12px; color: var(--color-text-secondary); font-size: 11.5px; text-align: center; }
@media (max-width: 600px) {
  .ns-photo-picker__actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ns-photo-picker__control { width: 100%; min-width: 0; padding: 0 10px; }
  .ns-photo-picker__control > span { position: static; width: auto; height: auto; overflow: visible; clip-path: none; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
  .ns-photo-picker__control::after { display: none; }
  .ns-photo-picker__control--danger:nth-child(3):last-child { grid-column: 1 / -1; }
  .ns-media-editor-layer { padding: 0; }
  .ns-media-editor, .ns-camera-capture { width: 100vw; min-height: 100dvh; border: 0; border-radius: 0; }
  .ns-media-editor-preview { width: min(300px, 78vw); }
  .ns-media-editor-controls label { grid-template-columns: 72px 1fr; }
  .ns-media-editor-controls > div { flex-wrap: wrap; }
}

@media (max-width: 360px) {
  .ns-photo-picker__actions { grid-template-columns: 1fr; }
  .ns-photo-picker__control--danger:last-child { grid-column: auto; }
}
/* A narrow portrait card needs the same protection as a narrow viewport. */
@media (max-width: 600px) {
  @container (max-width: 210px) {
    .ns-photo-picker__actions { grid-template-columns: minmax(0, 1fr); }
  }
}
/* Shared document viewer, also used by enrolment and student profiles. */
.ns-media-document-view .ns-confirm-dialog {width:min(760px,calc(100vw - 32px));max-height:90vh;overflow:auto}
.ns-media-document-view header {display:flex;align-items:center;justify-content:space-between;gap:var(--ui-card-padding)}
.ns-media-document-view :is(img,iframe) {display:block;width:100%;max-height:65vh;object-fit:contain;border:0}
.ns-media-document-view iframe {height:65vh}
