/* SVG Decor Library — global admin panel (/tableLayoutV2). Toolbar + dense gallery.
   Scoped under .tlv2-lib (inside .tlv2-home → inherits --bg/--accent/--border/--shadow tokens).
   Admin surface → modern CSS is fine (no POS-Chrome-85 constraint; that's runtime only). */

.tlv2-lib { display: flex; flex-direction: column; min-height: 100vh; background: var(--bg-body); }
.tlv2-lib-visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── Sticky toolbar ──────────────────────────────────────────────────────── */
.tlv2-lib-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  padding: 16px 32px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.tlv2-lib-title { margin: 0; font-size: 20px; font-weight: 800; color: var(--text-primary); letter-spacing: -0.01em; }
.tlv2-lib-subtitle { margin: 2px 0 0; font-size: 13px; color: var(--text-secondary); }
.tlv2-lib-subtitle strong { color: var(--text-primary); font-weight: 700; }
.tlv2-lib-toolbar-actions { display: flex; align-items: center; gap: 12px; }

/* Search */
.tlv2-lib-search {
  position: relative;
  display: flex;
  align-items: center;
  width: 280px;
  max-width: 42vw;
}
.tlv2-lib-search-icon {
  position: absolute; left: 12px; display: flex; align-items: center; color: var(--text-muted); pointer-events: none;
}
.tlv2-lib-search-input {
  width: 100%;
  height: 40px;
  padding: 0 32px 0 32px;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.tlv2-lib-search-input::-webkit-search-cancel-button { display: none; }
.tlv2-lib-search-input:focus { border-color: var(--accent); background: var(--bg-surface); box-shadow: 0 0 0 3px var(--accent-light); }
.tlv2-lib-search-clear {
  position: absolute; right: 8px;
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; line-height: 1; color: var(--text-muted);
  background: transparent; border: 0; border-radius: 999px; cursor: pointer;
}
.tlv2-lib-search-clear:hover { background: var(--border); color: var(--text-primary); }

/* Buttons */
.tlv2-lib-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 40px;
  min-height: 40px;
  padding: 0 18px;
  font-size: 14px;
  font-weight: 700;
  border-radius: 9px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
}
.tlv2-lib-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-light); }
.tlv2-lib-btn:active { transform: scale(0.985); }
.tlv2-lib-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.tlv2-lib-btn-icon { flex-shrink: 0; }
.tlv2-lib-btn-primary { background: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(65,133,244,0.35); }
.tlv2-lib-btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.tlv2-lib-btn-ghost { background: var(--bg-surface); color: var(--text-secondary); border-color: var(--border-strong); }
.tlv2-lib-btn-ghost:hover { background: var(--bg-input); }
.tlv2-lib-btn-danger { background: var(--danger, #E74C3C); color: #fff; box-shadow: 0 1px 2px rgba(231,76,60,0.35); }
.tlv2-lib-btn-danger:hover:not(:disabled) { background: var(--danger-dark, #C0392B); }

/* ── Body ────────────────────────────────────────────────────────────────── */
.tlv2-lib-body { flex: 1; max-width: 1320px; width: 100%; margin: 0 auto; padding: 28px 32px 56px; }

/* Group header */
.tlv2-lib-group { margin-bottom: 32px; }
/* Sticky sub-header under the toolbar (top≈toolbar height) so the active category stays visible while scrolling. */
.tlv2-lib-group-head {
  position: sticky;
  top: 65px;
  z-index: 4;
  display: flex; align-items: center; gap: 10px;
  margin: 0 0 14px;
  padding: 8px 2px;
  background: var(--bg-body);
}
.tlv2-lib-group-title { margin: 0; font-size: 15px; font-weight: 800; color: var(--text-primary); letter-spacing: -0.01em; }
.tlv2-lib-group-rule { flex: 1; height: 1px; background: var(--border); margin-left: 2px; }
.tlv2-lib-group-count {
  min-width: 22px; height: 20px; padding: 0 7px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--accent);
  background: var(--accent-light); border-radius: 999px;
}

/* Gallery grid */
.tlv2-lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
}

/* Tile */
.tlv2-lib-card {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s, border-color .15s, transform .12s;
}
.tlv2-lib-card:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); transform: translateY(-2px); }
.tlv2-lib-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  background:
    linear-gradient(45deg, #eceef2 25%, transparent 25%) -8px 0/16px 16px,
    linear-gradient(-45deg, #eceef2 25%, transparent 25%) -8px 0/16px 16px,
    linear-gradient(45deg, transparent 75%, #eceef2 75%) -8px 0/16px 16px,
    linear-gradient(-45deg, transparent 75%, #eceef2 75%) -8px 0/16px 16px,
    var(--bg-input);
}
.tlv2-lib-thumb-img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* Hover action cluster — top-right of the thumb; does NOT cover the SVG (kept visible). */
.tlv2-lib-actions {
  position: absolute;
  top: 8px; right: 8px;
  display: flex; gap: 6px;
  opacity: 0; transform: translateY(-4px);
  transition: opacity .15s, transform .15s;
}
.tlv2-lib-card:hover .tlv2-lib-actions,
.tlv2-lib-card:focus-within .tlv2-lib-actions { opacity: 1; transform: none; }
.tlv2-lib-hbtn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--border); border-radius: 9px; cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background .12s, color .12s, border-color .12s, transform .05s;
}
.tlv2-lib-hbtn:hover { background: #fff; color: var(--accent); border-color: var(--accent); }
.tlv2-lib-hbtn:active { transform: scale(0.92); }
.tlv2-lib-hbtn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-light), var(--shadow-sm); }
.tlv2-lib-hbtn-danger:hover { color: var(--danger, #E74C3C); border-color: var(--danger, #E74C3C); }
.tlv2-lib-card-name {
  padding: 10px 12px;
  font-size: 13px; font-weight: 700; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── Placeholders (empty / error / no-results) ──────────────────────────── */
.tlv2-lib-placeholder {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 8px; padding: 72px 24px;
}
.tlv2-lib-placeholder-icon {
  width: 64px; height: 64px; margin-bottom: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow-sm);
}
.tlv2-lib-placeholder-icon-danger { color: var(--danger, #E74C3C); }
.tlv2-lib-placeholder-title { margin: 0; font-size: 17px; font-weight: 800; color: var(--text-primary); }
.tlv2-lib-placeholder-text { margin: 0 0 10px; font-size: 14px; color: var(--text-muted); max-width: 360px; }

/* ── Loading skeleton ───────────────────────────────────────────────────── */
.tlv2-lib-skel-head { margin-bottom: 14px; }
.tlv2-lib-skel-pill { width: 120px; height: 18px; border-radius: 999px; background: var(--border); display: inline-block; }
.tlv2-lib-card-skel { pointer-events: none; }
.tlv2-lib-skel-line { height: 13px; margin: 12px; border-radius: 6px; background: var(--border); }
.tlv2-lib-skel-shimmer {
  position: relative; overflow: hidden;
}
.tlv2-lib-skel-shimmer::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6), transparent);
  transform: translateX(-100%);
  animation: tlv2LibShimmer 1.3s infinite;
}
@keyframes tlv2LibShimmer { 100% { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) {
  .tlv2-lib-skel-shimmer::after { animation: none; }
  .tlv2-lib-actions { transform: none; transition: opacity .15s; }
}

/* ── Modals ─────────────────────────────────────────────────────────────── */
/* $modal teleports the modal to <body>, OUTSIDE .tlv2-home where the design tokens live — so re-declare the
   tokens (VALUES ONLY, no layout) on the modal window class, else every var(--…) below resolves to nothing
   and the modal renders with no background / no input borders and the page bleeds through. Mirrors .tlv2-home
   (home.css); loaded app-wide so it fixes all TLV2 $modal dialogs (decor + floor-list). */
.tlv2-modal-window {
  --bg-body: #F1F2F5;
  --bg-surface: #FFFFFF;
  --bg-input: #F7F8FA;
  --border: #E7EAEE;
  --border-strong: #DEE2E7;
  --text-primary: #373C44;
  --text-secondary: #6A6F77;
  --text-muted: #6A737E;
  --text-faint: #BABFC8;
  --accent: #4185F4;
  --accent-dark: #2C6BD9;
  --accent-light: rgba(65, 133, 244, 0.08);
  --danger: #FF6F92;
  --danger-bg: rgba(255, 111, 146, 0.08);
  --shadow-sm: 0 1px 2px rgba(20, 28, 44, 0.04), 0 1px 3px rgba(20, 28, 44, 0.04);
  --shadow-md: 0 4px 12px rgba(20, 28, 44, 0.06), 0 2px 4px rgba(20, 28, 44, 0.04);
}

.tlv2-lib-modal { width: 440px; max-width: 92vw; background: var(--bg-surface); border-radius: 16px; overflow: hidden; }
.tlv2-lib-modal-head { display: flex; align-items: center; gap: 12px; padding: 20px 24px 0; }
.tlv2-lib-modal-icon {
  width: 40px; height: 40px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 11px;
  color: var(--danger, #E74C3C);
  background: var(--danger-bg, #FDECEA);
}
.tlv2-lib-modal-title { margin: 0; font-size: 18px; font-weight: 800; color: var(--text-primary); }
.tlv2-lib-modal-body { padding: 18px 24px; display: flex; flex-direction: column; gap: 16px; }
.tlv2-lib-modal-text { margin: 0; font-size: 14px; color: var(--text-secondary); line-height: 1.55; }
.tlv2-lib-modal-preview-img { max-width: 100%; max-height: 100%; object-fit: contain; }
.tlv2-lib-modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 24px 22px; border-top: 1px solid var(--border);
}

/* Field */
.tlv2-lib-field { display: flex; flex-direction: column; gap: 6px; }
.tlv2-lib-label { font-size: 11.5px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); }
.tlv2-lib-input {
  height: 40px; padding: 0 12px; font-size: 14px; color: var(--text-primary);
  background: var(--bg-input); border: 1px solid var(--border-strong);
  border-radius: 9px; outline: none; transition: border-color .15s, box-shadow .15s, background .15s;
}
.tlv2-lib-input:focus { border-color: var(--accent); background: var(--bg-surface); box-shadow: 0 0 0 3px var(--accent-light); }

/* Dropzone / picker */
.tlv2-lib-dropzone {
  position: relative;
  width: 100%;
  min-height: 150px;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: var(--bg-input);
  border: 1.5px dashed var(--border-strong);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.tlv2-lib-dropzone:hover { border-color: var(--accent); background: var(--accent-light); }
.tlv2-lib-dropzone.is-set { border-style: solid; }
.tlv2-lib-dropzone-cta { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.tlv2-lib-dropzone-icon { display: flex; color: var(--accent); }
.tlv2-lib-dropzone-text { font-size: 14px; color: var(--text-secondary); }
.tlv2-lib-dropzone-hint { font-size: 12px; color: var(--text-muted); }
.tlv2-lib-dropzone-preview { width: 100%; height: 130px; display: flex; align-items: center; justify-content: center; }
.tlv2-lib-dropzone-overlay {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 7px; font-size: 12px; font-weight: 700; text-align: center;
  color: #fff; background: rgba(31,41,55,0.55);
  opacity: 0; transition: opacity .15s;
}
.tlv2-lib-dropzone:hover .tlv2-lib-dropzone-overlay { opacity: 1; }
.tlv2-lib-filename { margin: -6px 0 0; font-size: 12.5px; color: var(--text-muted); }
.tlv2-lib-linkbtn { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 700; cursor: pointer; font-size: 12.5px; }

/* Inline error inside modals */
.tlv2-lib-inline-error {
  display: flex; align-items: center; gap: 7px;
  padding: 9px 12px; font-size: 13px; font-weight: 600;
  color: #B0212F; background: var(--danger-bg);
  border: 1px solid rgba(255,111,146,0.4); border-radius: 9px;
}
.tlv2-lib-inline-error svg { flex-shrink: 0; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .tlv2-lib-body { padding: 22px 20px 48px; }
  .tlv2-lib-toolbar { padding: 14px 20px; }
}
@media (max-width: 768px) {
  .tlv2-lib-toolbar { gap: 12px; }
  .tlv2-lib-search { width: 100%; max-width: none; order: 3; }
  .tlv2-lib-toolbar-actions { flex-wrap: wrap; width: 100%; }
  .tlv2-lib-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
}
