/**
 * @file
 * DAM Media Widget styles.
 */

/* ==========================================================================
   Widget Base
   ========================================================================== */

.dam-widget {
  border: 1px solid var(--gin-border-color, #d4d4d8);
  border-radius: var(--gin-border-radius, 8px);
  padding: 1rem;
  background: var(--gin-bg-layer, #fff);
}

.dam-widget__selected {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.dam-widget__selected:empty {
  display: none;
}

.dam-widget__selected:empty + .dam-widget__actions {
  margin-top: 0;
}

/* Grid-style item preview (similar to DAM grid) */
.dam-widget__item {
  position: relative;
  background: var(--gin-bg-layer, #fff);
  border: 1px solid var(--gin-border-color-layer, #e5e5e5);
  border-radius: var(--gin-border-radius, 8px);
  overflow: hidden;
  transition: all 0.2s ease;
}

.dam-widget__item:hover {
  border-color: var(--gin-color-primary, #003cc5);
  box-shadow: var(--gin-shadow-l, 0 4px 12px rgba(0, 0, 0, 0.1));
}

.dam-widget__thumb-wrapper {
  aspect-ratio: 1;
  background: var(--gin-bg-layer2, #f8f9fa);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.dam-widget__thumbnail {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.dam-widget__icon {
  font-size: 2rem;
  color: var(--gin-color-text-light, #6b7280);
  opacity: 0.5;
}

.dam-widget__info {
  padding: var(--gin-spacing-s, 0.75rem);
  border-top: 1px solid var(--gin-border-color-layer, #e5e5e5);
}

.dam-widget__name {
  display: block;
  font-size: var(--gin-font-size-s, 0.875rem);
  font-weight: var(--gin-font-weight-semibold, 600);
  color: var(--gin-color-text, #222330);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: var(--gin-spacing-xxs, 0.25rem);
}

.dam-widget__meta {
  font-size: var(--gin-font-size-xs, 0.75rem);
  color: var(--gin-color-text-light, #6b7280);
  text-transform: capitalize;
}

.dam-widget__item > button.dam-widget__remove,
.dam-widget .dam-widget__item .dam-widget__remove {
  position: absolute !important;
  top: 0.5rem !important;
  right: 0.5rem !important;
  left: auto !important;
  bottom: auto !important;
  width: 24px !important;
  height: 24px !important;
  min-width: 24px !important;
  min-height: 24px !important;
  padding: 0 !important;
  margin: 0 !important;
  border: none !important;
  background: rgba(0, 0, 0, 0.6) !important;
  cursor: pointer;
  font-size: 1rem !important;
  line-height: 1 !important;
  color: #fff !important;
  border-radius: 50% !important;
  display: flex !important;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 10;
  box-shadow: none !important;
}

.dam-widget__item:hover > button.dam-widget__remove,
.dam-widget .dam-widget__item:hover .dam-widget__remove {
  opacity: 1;
}

.dam-widget__item > button.dam-widget__remove:hover,
.dam-widget .dam-widget__item .dam-widget__remove:hover {
  background: var(--gin-color-danger, #d32f2f) !important;
}

.dam-widget__actions {
  display: flex;
  gap: 0.5rem;
}

.dam-widget__browse {
  cursor: pointer;
}

.dam-widget__clear {
  cursor: pointer;
}

/* ==========================================================================
   Widget Modal
   ========================================================================== */

.dam-widget-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
}

.dam-widget-modal.is-open {
  display: flex;
}

.dam-widget-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.dam-widget-modal__content {
  position: relative;
  width: 90vw;
  max-width: 1200px;
  height: 80vh;
  max-height: 800px;
  background: var(--gin-bg-layer, #fff);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.dam-widget-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--gin-border-color, #d4d4d8);
  flex-shrink: 0;
}

.dam-widget-modal__title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.dam-widget-modal__header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.dam-widget-modal__upload-btn {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.dam-widget-modal__upload-btn:hover {
  background: var(--gin-bg-layer2, #f4f4f5);
}

.dam-widget-modal__close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--gin-color-text-light, #71717a);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dam-widget-modal__close:hover {
  background: var(--gin-bg-layer2, #f4f4f5);
}

/* Modal Body */
.dam-widget-modal__body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.dam-widget-modal__sidebar {
  width: 240px;
  border-right: 1px solid var(--gin-border-color, #d4d4d8);
  overflow-y: auto;
  flex-shrink: 0;
  padding: 1rem;
}

.dam-widget-modal__filters {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.dam-widget-modal__search {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gin-border-color, #d4d4d8);
  border-radius: 4px;
  font-size: 0.875rem;
}

.dam-widget-modal__type-filter {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gin-border-color, #d4d4d8);
  border-radius: 4px;
  font-size: 0.875rem;
  background: var(--gin-bg-layer, #fff);
}

.dam-widget-modal__folders-header,
.dam-widget-modal__collections-header {
  margin-bottom: 0.5rem;
}

.dam-widget-modal__folders-header h4,
.dam-widget-modal__collections-header h4 {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gin-color-text-light, #71717a);
}

.dam-widget-modal__collections-header {
  margin-top: 1.5rem;
}

.dam-widget-modal__folders,
.dam-widget-modal__collections {
  list-style: none;
  margin: 0;
  padding: 0;
}

.dam-widget-modal__folder,
.dam-widget-modal__collection {
  margin: 0;
}

.dam-widget-modal__folder button,
.dam-widget-modal__collection button {
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.75rem;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 0.875rem;
  border-radius: 4px;
  color: var(--gin-color-text, #18181b);
}

.dam-widget-modal__folder button:hover,
.dam-widget-modal__collection button:hover {
  background: var(--gin-bg-layer2, #f4f4f5);
}

.dam-widget-modal__folder--active button,
.dam-widget-modal__collection--active button {
  background: var(--gin-color-primary-light, rgba(0, 60, 197, 0.1));
  color: var(--gin-color-primary, #003cc5);
  font-weight: 500;
}

.dam-widget-modal__empty {
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--gin-color-text-light, #71717a);
  font-style: italic;
}

/* Modal Main / Grid */
.dam-widget-modal__main {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  position: relative;
  transition: background-color 0.2s ease;
}

.dam-widget-modal__main.is-dragover {
  background-color: var(--gin-color-primary-light, rgba(0, 60, 197, 0.05));
}

.dam-widget-modal__main.is-dragover::after {
  content: 'Drop files here to upload';
  position: absolute;
  inset: 1rem;
  border: 2px dashed var(--gin-color-primary, #003cc5);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--gin-color-primary, #003cc5);
  background: rgba(255, 255, 255, 0.9);
  pointer-events: none;
  z-index: 10;
}

.dam-widget-modal__grid {
  min-height: 200px;
}

.dam-widget-modal__loading,
.dam-widget-modal__upload-progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--gin-color-text-light, #71717a);
}

.dam-widget-modal__upload-progress {
  padding: 1.5rem;
  background: var(--gin-bg-layer2, #f4f4f5);
  border-radius: 8px;
  margin-bottom: 1rem;
}

.dam-widget-modal__spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--gin-border-color, #d4d4d8);
  border-top-color: var(--gin-color-primary, #003cc5);
  border-radius: 50%;
  animation: dam-widget-spin 0.8s linear infinite;
  margin-bottom: 1rem;
}

@keyframes dam-widget-spin {
  to { transform: rotate(360deg); }
}

.dam-widget-modal__items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
}

.dam-widget-modal__item {
  position: relative;
  aspect-ratio: 1;
  border: 2px solid var(--gin-border-color, #d4d4d8);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  background: var(--gin-bg-layer2, #f4f4f5);
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.dam-widget-modal__item:hover {
  border-color: var(--gin-color-primary-light, #99b3e6);
}

.dam-widget-modal__item.is-selected {
  border-color: var(--gin-color-primary, #003cc5);
  box-shadow: 0 0 0 2px var(--gin-color-primary-light, rgba(0, 60, 197, 0.2));
}

.dam-widget-modal__thumb {
  width: 100%;
  height: 100%;
  object-fit: contain;
  position: absolute;
  inset: 0;
}

.dam-widget-modal__item .dam-widget-modal__icon {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
}

.dam-widget-modal__item .dam-widget-modal__name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.5rem;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
  color: #fff;
  font-size: 0.75rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dam-widget-modal__check {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid var(--gin-border-color, #d4d4d8);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.dam-widget-modal__item.is-selected .dam-widget-modal__check {
  background: var(--gin-color-primary, #003cc5);
  border-color: var(--gin-color-primary, #003cc5);
}

.dam-widget-modal__item.is-selected .dam-widget-modal__check::after {
  content: '';
  width: 10px;
  height: 6px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translateY(-1px);
}

.dam-widget-modal__error {
  text-align: center;
  padding: 2rem;
  color: var(--gin-color-danger, #d32f2f);
}

/* Modal Footer */
.dam-widget-modal__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--gin-border-color, #d4d4d8);
  flex-shrink: 0;
}

.dam-widget-modal__selection-info {
  font-size: 0.875rem;
  color: var(--gin-color-text-light, #71717a);
}

.dam-widget-modal__footer-actions {
  display: flex;
  gap: 0.5rem;
}

.dam-widget-modal__cancel {
  cursor: pointer;
}

.dam-widget-modal__confirm {
  cursor: pointer;
}

.dam-widget-modal__confirm:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
