/*
 * media.css — styles for the Phase 4 universal media library.
 *
 * Three concerns:
 *   1. The reusable dropzone (`.te-dz`, `.is-dragover`)
 *   2. The library page (chips, grid, list, drawer, bulk bar)
 *   3. The bottom-right upload tray that shows per-file progress
 *
 * Tokens reuse the admin shell's CSS custom properties (--fg, --fg-mute,
 * --glass-border, etc.) — see admin.css. Adding a new variable here
 * means a follow-up `admin.css` mirror; we avoided that for Phase 4.
 */

/* ── Dropzone (shared) ─────────────────────────────────────── */
.te-dz {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  font-family: var(--mono, monospace);
  font-size: 12px;
  color: var(--fg-mute, #888);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  background: transparent;
  border: 1.5px dashed var(--glass-border, rgb(255 255 255 / 12%));
  border-radius: 8px;
  transition:
    background 120ms,
    border-color 120ms,
    color 120ms;
}

.te-dz:hover,
.te-dz:focus-visible {
  /* Light theme: dark ink on a light tint — the old white-on-light (a
     dark-theme remnant) was invisible. */
  color: var(--ink);
  background: var(--surface-2);
  border-color: var(--accent);
  outline: none;
}

.te-dz.is-dragover {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.te-dz-label {
  pointer-events: none;
}

/* Body-level dropzone — invisible until something is being dragged
 * across the window. The overlay sits above the rest of the UI so the
 * user gets unambiguous feedback even when the cursor is over a
 * non-dropzone element. */
body.te-has-body-dropzone {
  /* No persistent visual; the dragover state lights up a single overlay. */
  position: relative;
}

body.te-has-body-dropzone.is-dragover::after {
  position: fixed;
  inset: 16px;
  z-index: var(--z-drawer);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono, monospace);
  font-size: 14px;
  color: var(--fg, #fff);
  pointer-events: none;
  content: "DROP TO UPLOAD";
  background: var(--accent-soft);
  border: 2px dashed var(--accent);
  border-radius: 12px;
}

/* ── Library page ──────────────────────────────────────────── */
#view-media[hidden] {
  display: none;
}

.te-media-head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}

.te-media-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.te-media-chip {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 6px 10px;
  font-family: var(--mono, monospace);
  font-size: 11px;
  color: var(--fg-mute, #aaa);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  background: transparent;
  border: 1px solid var(--glass-border, rgb(255 255 255 / 10%));
  border-radius: 999px;
  transition: all 120ms;
}

.te-media-chip:hover,
.te-media-chip:focus-visible {
  color: var(--fg, #fff);
  background: var(--surface-2);
  border-color: var(--line-strong-www);
  outline: none;
}

.te-media-chip.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.te-media-chip .count {
  padding: 0 5px;
  font-size: 10px;
  color: inherit;
  background: var(--surface-3);
  border-radius: 4px;
}

.te-media-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.te-media-toolbar .te-media-spacer {
  flex: 1;
}

.te-media-toolbar input[type="search"],
.te-media-toolbar select {
  min-height: 36px;
  padding: 6px 10px;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong-www);
  border-radius: var(--radius-sm);
}

.te-media-toolbar .te-view-toggle {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--glass-border, rgb(255 255 255 / 10%));
  border-radius: 6px;
}

.te-media-toolbar .te-view-toggle button {
  padding: 6px 10px;
  font-family: var(--mono, monospace);
  font-size: 11px;
  color: var(--fg-mute, #888);
  cursor: pointer;
  background: transparent;
  border: none;
}

.te-media-toolbar .te-view-toggle button[aria-pressed="true"] {
  color: var(--fg, #fff);
  background: var(--surface-2);
}

/* Usage filter pills (All / In posts / Unused) — segmented control that
   matches the v2 chip vocabulary. The pressed pill uses accent-soft fill
   with AA --accent text (decoration-only --accent-bg is never paired with
   white text here). */
.te-media-used-filter {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line-www, var(--glass-border, rgb(255 255 255 / 10%)));
  border-radius: 999px;
}

.te-media-used-filter button {
  padding: 6px 12px;
  font-family: var(--mono, monospace);
  font-size: 11px;
  color: var(--ink-mute, var(--fg-mute, #888));
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  background: transparent;
  border: none;
  transition:
    background 120ms,
    color 120ms;
}

.te-media-used-filter button + button {
  border-left: 1px solid var(--line-www, var(--glass-border, rgb(255 255 255 / 10%)));
}

.te-media-used-filter button:hover,
.te-media-used-filter button:focus-visible {
  color: var(--ink, var(--fg, #fff));
  background: var(--surface-2, rgb(255 255 255 / 5%));
  outline: none;
}

.te-media-used-filter button[aria-pressed="true"] {
  color: var(--accent);
  background: var(--accent-soft);
}

#media-library-dropzone {
  margin-bottom: 16px;
}

#media-grid {
  display: grid;
  gap: 12px;
  align-items: start;
}

#media-grid.view-grid {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

#media-grid.view-list {
  grid-template-columns: 1fr;
}

#media-grid[aria-busy="true"] {
  opacity: 0.6;
}

.te-media-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line-www);
  border-radius: 8px;
  transition:
    background 120ms,
    border-color 120ms;
}

.te-media-card:hover {
  background: var(--surface-2);
  border-color: var(--line-strong-www);
}

.te-media-card.is-selected {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.te-media-check {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 2;
  padding: 2px;
  background: rgb(0 0 0 / 60%);
  border-radius: 4px;
}

.te-media-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  cursor: pointer;
  background: var(--surface-3);
  border: none;
  border-radius: 8px 8px 0 0;
}

.te-media-thumb:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.te-media-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.te-media-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-mute, #5a72b0);
}

/* "Showing first N of M" note when the library exceeds the 200-item cap. */
.te-media-more {
  grid-column: 1 / -1;
  padding: var(--space-3, 12px) var(--space-2, 8px);
  font-family: var(--font-ui);
  font-size: var(--fs-sm, 13px);
  color: var(--ink-mute, #5a72b0);
  text-align: center;
}
.te-media-glyph svg {
  width: 32px;
  height: 32px;
}

.te-media-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px 10px;
}

.te-media-name {
  overflow: hidden;
  font-family: var(--mono, monospace);
  font-size: 12px;
  color: var(--fg, #fff);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.te-media-sub {
  font-family: var(--mono, monospace);
  font-size: 10px;
  color: var(--fg-mute, #888);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* "Used in" chip on a card — accent-soft fill with AA --accent text
   (never white-on-accent). Truncates to a single line. */
.te-media-post {
  display: inline-block;
  max-width: 100%;
  margin-top: 4px;
  overflow: hidden;
  font-family: var(--mono, monospace);
  font-size: 10px;
  color: var(--accent);
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 1px 6px;
}

#media-grid.view-list .te-media-post {
  margin-top: 0;
}

/* ── Phase 5: per-card conversion status ──────────────────── */
.te-media-status {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 3px 8px;
  font-family: var(--mono, monospace);
  font-size: 10px;
  color: var(--fg, #fff);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  pointer-events: none;
  background: rgb(0 0 0 / 60%);
  border-radius: 999px;
}

.te-media-status.processing {
  color: rgb(180 200 255);
  background: rgb(30 50 100 / 80%);
  animation: te-shimmer 1.4s ease-in-out infinite;
}

.te-media-status.failed {
  color: rgb(255 200 200);
  background: rgb(160 30 30 / 85%);
}

/* Accessibility chip: image has no usable alt text yet. Sits bottom-left
   so it can coexist with a processing/failed chip in the top corner. */
.te-media-status.no-alt {
  top: auto;
  right: auto;
  bottom: 6px;
  left: 6px;
  color: var(--warn, #8c5a0a);
  background: var(--bg-card, #fff);
  border: 1px solid var(--warn, #8c5a0a);
}

.te-media-retry {
  position: absolute;
  right: 6px;
  bottom: 6px;
  z-index: 3;
  padding: 4px 10px;
  font-family: var(--mono, monospace);
  font-size: 10px;
  color: var(--fg, #fff);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  background: rgb(160 30 30 / 85%);
  border: 1px solid rgb(255 100 100 / 50%);
  border-radius: 4px;
}

.te-media-retry:hover,
.te-media-retry:focus-visible {
  background: rgb(200 40 40 / 95%);
  outline: none;
}

.te-media-retry[disabled] {
  cursor: progress;
  opacity: 0.55;
}

.te-media-card.status-processing {
  /* Subtle ring while the worker is grinding. */
  box-shadow: inset 0 0 0 1px rgb(100 140 255 / 35%);
}

.te-media-card.status-failed {
  box-shadow: inset 0 0 0 1px rgb(220 80 80 / 50%);
}

@keyframes te-shimmer {
  0%,
  100% {
    opacity: 0.85;
  }
  50% {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .te-media-status.processing {
    animation: none;
  }
}

/* List view: collapse the card into a single row */
#media-grid.view-list .te-media-card {
  display: grid;
  grid-template-columns: 40px 56px 1fr;
  gap: 12px;
  align-items: center;
  padding: 6px 10px;
}

#media-grid.view-list .te-media-check {
  position: static;
  background: transparent;
}

#media-grid.view-list .te-media-thumb {
  width: 56px;
  height: 42px;
  aspect-ratio: auto;
  border-radius: 4px;
}

#media-grid.view-list .te-media-info {
  flex-direction: row;
  gap: 12px;
  align-items: baseline;
  padding: 0;
}

#media-grid.view-list .te-media-name {
  flex: 1;
}

/* Status chips are absolutely positioned for grid view; in list view the
   left edge holds the check + thumb, so nudge the no-alt chip to the
   row's bottom-right to avoid overlapping them. (Grid view unchanged.) */
#media-grid.view-list .te-media-status.no-alt {
  top: auto;
  right: 6px;
  bottom: 6px;
  left: auto;
}

#media-empty {
  padding: 32px;
  font-family: var(--mono, monospace);
  font-size: 12px;
  color: var(--fg-mute, #888);
  text-align: center;
  background: var(--surface-2);
  border: 1px dashed var(--glass-border, rgb(255 255 255 / 8%));
  border-radius: 8px;
}

/* ── Detail drawer ─────────────────────────────────────────── */
.te-media-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: var(--z-drawer);
  display: flex;
  flex-direction: column;
  width: min(480px, 92vw);
  font-family: var(--mono, monospace);
  background: var(--bg-elev);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px rgb(14 41 96 / 12%);
  transform: translateX(100%);
  transition: transform 200ms;
}

.te-media-drawer.open {
  transform: translateX(0);
}

.te-media-drawer-head {
  display: flex;
  justify-content: space-between;
  padding: 14px 18px;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--line);
}

.te-media-drawer-body {
  flex: 1;
  padding: 16px 18px;
  overflow-y: auto;
}

.te-drawer-preview {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  background: var(--paper-warm);
  border-radius: 8px;
}

.te-drawer-preview.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 160px;
}

.te-drawer-title {
  margin: 14px 0 8px;
  font-size: 14px;
  color: var(--fg, #fff);
  word-break: break-all;
}

.te-drawer-meta {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 6px 14px;
  margin: 0;
  font-size: 11px;
  color: var(--fg-mute, #aaa);
}

.te-drawer-meta dt {
  text-transform: uppercase;
}

.te-drawer-meta dd {
  margin: 0;
  color: var(--fg, #fff);
  word-break: break-all;
}

.te-drawer-usage {
  padding: 0;
  margin: 0;
  list-style: none;
}

.te-drawer-usage li + li {
  margin-top: 4px;
}

.te-drawer-usage.empty {
  color: var(--fg-mute, #888);
}

.te-drawer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 16px;
}

/* Quiet "not used" note sitting next to the Delete button. */
.te-drawer-unused {
  font-family: var(--mono, monospace);
  font-size: 11px;
  font-style: italic;
  color: var(--ink-mute, var(--fg-mute, #888));
}

/* ── Alt text editor (images only) ─────────────────────────── */
.te-drawer-alt {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
}

.te-drawer-alt-label {
  font-family: var(--mono, monospace);
  font-size: 11px;
  color: var(--fg-mute, #888);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.te-drawer-alt-input,
.te-drawer-name-input {
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
  line-height: 1.45;
  color: var(--fg);
  resize: vertical;
  background: var(--bg-card, #fff);
  border: 1px solid var(--line-strong, #b5bab1);
  border-radius: 6px;
}
.te-drawer-name-input {
  resize: none;
}

/* Bulk-edit modal (name + alt for many assets at once) */
.te-media-bulk-card {
  width: min(640px, 92vw);
}
.te-media-bulk-rows {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 60vh;
  overflow-y: auto;
}
/* On phones the modal itself scrolls — drop the inner scroll so the list and
   the dialog don't fight over two nested scroll regions. */
@media (max-width: 560px) {
  .te-media-bulk-rows {
    max-height: none;
    overflow-y: visible;
  }
}
.te-media-bulk-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.te-media-bulk-thumb {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-2, #f0f0f0);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.te-media-bulk-fields {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.te-media-bulk-name,
.te-media-bulk-alt {
  width: 100%;
  padding: 6px 9px;
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  background: var(--bg-card, #fff);
  border: 1px solid var(--line-strong, #b5bab1);
  border-radius: 6px;
}

.te-drawer-alt-input:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent-soft, rgb(4 128 55 / 10%));
}

.te-drawer-alt-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.te-drawer-alt-hint {
  font-family: var(--mono, monospace);
  font-size: 11px;
  color: var(--warn, #8c5a0a);
}

/* ── Upload progress tray ──────────────────────────────────── */
/* Bottom-LEFT so it never overlaps the bottom-right toast stack (they're
   independent fixed elements; sharing a corner meant the tray painted over
   toasts). Width clamps so it doesn't clip on the narrowest phones. */
.te-upload-tray {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: calc(var(--z-toast) + 1);
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(320px, calc(100vw - 32px));
  font-family: var(--mono, monospace);
  pointer-events: none;
}

.te-upload-row {
  display: grid;
  grid-template-columns: 1fr 28px;
  grid-template-rows: auto auto;
  gap: 4px 8px;
  align-items: center;
  padding: 8px 12px;
  font-size: 11px;
  color: var(--ink);
  pointer-events: auto;
  background: var(--surface);
  border: 1px solid var(--line-www);
  border-radius: 8px;
  box-shadow: var(--shadow-pop);
}

.te-upload-meta {
  display: flex;
  justify-content: space-between;
  min-width: 0;
}

.te-upload-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.te-upload-status {
  flex-shrink: 0;
  color: var(--ink-mute);
}

.te-upload-bar {
  grid-column: 1 / 2;
  height: 4px;
  overflow: hidden;
  background: var(--surface-3);
  border-radius: 2px;
}

.te-upload-bar i {
  display: block;
  width: 0%;
  height: 100%;
  background: var(--accent-bg);
  transition: width 120ms;
}

.te-upload-row.done .te-upload-bar i {
  background: var(--ok);
}

.te-upload-row.failed .te-upload-bar i {
  background: var(--danger);
}

.te-upload-x {
  grid-row: 1 / 3;
  grid-column: 2 / 3;
  padding: 0;
  font-size: 14px;
  color: var(--ink-mute);
  cursor: pointer;
  background: transparent;
  border: none;
}

.te-upload-x:hover,
.te-upload-x:focus-visible {
  color: var(--fg, #fff);
  outline: none;
}
.te-upload-x svg {
  width: 13px;
  height: 13px;
}

/* ── Sidebar dropzone (always visible in admin shell) ──────── */
.side-dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 12px;
  font-family: var(--mono, monospace);
  font-size: 10px;
  color: var(--fg-mute, #888);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

@media (prefers-reduced-motion: reduce) {
  .te-media-drawer,
  .te-upload-bar i {
    transition: none;
  }
}
