/* ============ GALLERY DIALOG ============ */

/* Gallery section labels */
.gallery-section-label {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--color-text-secondary, #64748B);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 8px 24px 0;
}

/* Native <dialog> reset */
.widget-gallery {
  border: none;
  padding: 0;
  background: transparent;
  max-width: none;
  max-height: none;
}

.widget-gallery::backdrop {
  background: rgba(0, 0, 0, 0.5);
  /* backdrop-filter removed — jank on low-end mobile (PERF-011) */
}

/* Inner container — the visible card */
.widget-gallery-inner {
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 85vh;
}

/* Scrollable body: gallery-current, divider, sections scroll together */
.gallery-scroll-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,0.15) transparent;
}
.gallery-scroll-body::-webkit-scrollbar { width: 6px; }
.gallery-scroll-body::-webkit-scrollbar-track { background: transparent; }
.gallery-scroll-body::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.15);
  border-radius: 3px;
}
.gallery-scroll-body::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.25); }

/* Header + footer stay pinned (flex-shrink:0 is default, but be explicit) */
.gallery-header { flex-shrink: 0; }
.gallery-footer { flex-shrink: 0; }

/* ── Desktop (≥1280px) — centered modal ── */
@media (min-width: 1280px) {
  .widget-gallery {
    max-width: 560px;
    width: 90vw;
    margin: auto;
    border-radius: 16px;
  }

  .widget-gallery[open] .widget-gallery-inner {
    animation: galleryScaleIn 250ms ease-out;
  }
}

/* ── Tablet (<1280px) — bottom sheet ── */
@media (max-width: 1279px) {
  .widget-gallery {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
    width: 100%;
    max-width: 100%;
  }

  .widget-gallery-inner {
    border-radius: 16px 16px 0 0;
  }

  .widget-gallery[open] .widget-gallery-inner {
    animation: gallerySlideUp 400ms cubic-bezier(0.32, 0.72, 0, 1);
  }
}

/* ── Mobile ≤767px — full-screen sheet ── */
@media (max-width: 767px) {
  .widget-gallery-inner {
    max-height: 100dvh;
    border-radius: 0;
  }
}

/* ============ GALLERY INTERNAL LAYOUT ============ */

/* Header row */
.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.gallery-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text-primary, #0F172A);
  margin: 0;
}

/* Close button */
.gallery-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  color: var(--color-text-secondary, #64748B);
  transition: background 150ms ease, color 150ms ease;
  padding: 0;
  flex-shrink: 0;
}

.gallery-close-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--color-text-primary, #0F172A);
}

.gallery-close-btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Current widgets section */
.gallery-current {
  padding: 16px 24px;
  background: #f8f9fa;
}

.gallery-current-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-secondary, #64748B);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 8px;
}

.gallery-current-empty {
  font-size: 0.8125rem;
  color: var(--color-text-secondary, #64748B);
  padding: 8px 0;
}

/* Pill list */
.gallery-pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

/* Divider */
.gallery-divider {
  height: 1px;
  background: rgba(0, 0, 0, 0.08);
  border: none;
  margin: 0;
}

/* Widget card grid — single column, compact rows */
.gallery-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 24px;
}

/* Footer */
.gallery-footer {
  padding: 12px 24px;
  text-align: center;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

/* ============ GALLERY PILLS ============ */

.gallery-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text-primary, #0F172A);
  transition: border-color 200ms ease, background 200ms ease;
  user-select: none;
}

.gallery-pill:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Drag handle */
.gallery-pill-handle {
  color: var(--color-text-secondary, #64748B);
  cursor: grab;
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
}

.gallery-pill-handle:active {
  cursor: grabbing;
}

/* Remove X button — hidden by default, visible on hover/focus */
.gallery-pill-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  color: var(--color-text-secondary, #64748B);
  font-size: 12px;
  padding: 0;
  opacity: 0;
  transition: opacity 150ms ease, background 150ms ease, color 150ms ease;
  flex-shrink: 0;
}

.gallery-pill:hover .gallery-pill-remove,
.gallery-pill:focus-within .gallery-pill-remove {
  opacity: 1;
}

.gallery-pill-remove:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.gallery-pill-remove:focus-visible {
  opacity: 1;
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Touch devices: always show remove button (BUG-020) */
@media (hover: none) {
  .gallery-pill-remove { opacity: 1; }
}

/* BUG-018: Touch-friendly move buttons for pill reorder */
.gallery-pill-move-btns {
  display: none; /* Hidden on mouse devices — use drag instead */
  gap: 2px;
  margin-left: auto;
}
.gallery-pill-move {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.06);
  color: #64748B;
  cursor: pointer;
  padding: 0;
}
.gallery-pill-move:active {
  background: rgba(0, 0, 0, 0.12);
}
@media (hover: none) {
  .gallery-pill-move-btns { display: inline-flex; }
  .gallery-pill-handle { display: none; } /* Hide drag handle on touch — can't drag */
}

/* Dragging state */
.gallery-pill.dragging {
  opacity: 0.5;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

/* Drag over state */
.gallery-pill.drag-over {
  border-color: var(--color-primary);
  background: rgba(var(--color-primary-rgb), 0.06);
}

/* ============ GALLERY CARDS ============ */

.gallery-card {
  background: #f8f9fa;
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.gallery-card-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(var(--color-primary-rgb), 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.gallery-card-icon svg {
  width: 18px;
  height: 18px;
  color: var(--color-primary);
}

.gallery-card-info {
  flex: 1;
  min-width: 0;
}

.gallery-card-label {
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--color-text-primary, #0F172A);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery-card-desc {
  font-size: 0.6875rem;
  color: var(--color-text-secondary, #64748B);
  margin: 2px 0 0;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Toggle button — compact, right-aligned */
.gallery-card-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 0;
  border-radius: 8px;
  padding: 6px 12px;
  border: none;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font-family);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease, transform 100ms ease;
  min-height: 32px;
  white-space: nowrap;
  touch-action: manipulation;
}

.gallery-card-toggle:active {
  transform: scale(0.98);
}

.gallery-card-toggle:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Inactive — "+ Tilføj" */
.gallery-card-toggle[aria-pressed="false"] {
  background: var(--color-primary);
  color: #fff;
}

.gallery-card-toggle[aria-pressed="false"]:hover {
  background: var(--color-primary-hover);
}

/* Active — "✓ Tilføjet" */
.gallery-card-toggle[aria-pressed="true"] {
  background: #e2e8f0;
  color: #64748B;
}

.gallery-card-toggle[aria-pressed="true"]:hover {
  background: #cbd5e1;
}

/* Disabled card (sidebar-hidden tool) */
.gallery-card--disabled {
  opacity: 0.5;
}

.gallery-card--disabled .gallery-card-toggle {
  pointer-events: none;
}

/* Reset link */
.gallery-reset {
  display: inline;
  background: none;
  border: none;
  padding: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text-secondary, #64748B);
  cursor: pointer;
  font-family: var(--font-family);
  transition: color 150ms ease;
  text-decoration: none;
}

.gallery-reset:hover {
  text-decoration: underline;
  color: var(--color-text-primary, #0F172A);
}

.gallery-reset:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Gallery animations (used by gallery responsive rules above) */
@keyframes galleryScaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes gallerySlideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* ============ DARK MODE — Widget Gallery ============ */

[data-theme="dark"] .widget-gallery-inner {
  background: #2b2a27;
}

[data-theme="dark"] .gallery-header {
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .gallery-header h2 {
  color: var(--color-text-primary, #F1F5F9);
}

[data-theme="dark"] .gallery-close-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #e8e6e1;
}

[data-theme="dark"] .gallery-current {
  background: #232220;
}

[data-theme="dark"] .gallery-current-label {
  color: #a3a19b;
}

[data-theme="dark"] .gallery-current-empty {
  color: #a3a19b;
}

[data-theme="dark"] .gallery-pill {
  background: #33322f;
  border-color: rgba(255, 255, 255, 0.1);
  color: #e8e6e1;
}

[data-theme="dark"] .gallery-pill-handle {
  color: #a3a19b;
}

[data-theme="dark"] .gallery-pill-remove {
  color: #a3a19b;
}

[data-theme="dark"] .gallery-pill-remove:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

[data-theme="dark"] .gallery-pill-move {
  background: rgba(255, 255, 255, 0.08);
  color: #a3a19b;
}
[data-theme="dark"] .gallery-pill-move:active {
  background: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .gallery-pill.dragging {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .gallery-pill.drag-over {
  border-color: var(--color-primary);
  background: rgba(var(--color-primary-rgb), 0.1);
}

[data-theme="dark"] .gallery-divider {
  background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .gallery-card {
  background: #232220;
}

[data-theme="dark"] .gallery-card-label {
  color: #e8e6e1;
}

[data-theme="dark"] .gallery-card-desc {
  color: #a3a19b;
}

[data-theme="dark"] .gallery-card-toggle[aria-pressed="true"] {
  background: #3a3936;
  color: #a3a19b;
}

[data-theme="dark"] .gallery-card-toggle[aria-pressed="true"]:hover {
  background: #46443f;
}

/* Keep primary colors for active/add button in dark mode */
[data-theme="dark"] .gallery-card-toggle[aria-pressed="false"] {
  background: var(--color-primary);
  color: #fff;
}

[data-theme="dark"] .gallery-scroll-body {
  scrollbar-color: rgba(255,255,255,0.12) transparent;
}
[data-theme="dark"] .gallery-scroll-body::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.12);
}
[data-theme="dark"] .gallery-scroll-body::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.2);
}

[data-theme="dark"] .gallery-footer {
  border-top-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .gallery-reset {
  color: #a3a19b;
}

[data-theme="dark"] .gallery-reset:hover {
  color: #e8e6e1;
}

/* Dark mode — Gallery section label */
[data-theme="dark"] .gallery-section-label {
  color: #a3a19b;
}
