.ms-host {
  width: 100%;
  max-width: 320px;
}

.ms-trigger {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  border: 1px solid #d1d5db;
  background: #e5e7eb center / cover no-repeat;
  color: #6b7280;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: hidden;
}

.ms-trigger-label {
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  padding: 12px;
}

.ms-trigger.has-image .ms-trigger-label {
  display: none;
}

.ms-panel {
  position: absolute;
  inset: 0;
  z-index: 80;
  display: none;
}

.ms-panel.ms-show {
  display: block;
}

.ms-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.55);
}

.ms-card-wrap {
  position: absolute;
  inset: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ms-card {
  width: min(920px, 100%);
  height: min(90%, 100%);
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid #d1d5db;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
}

.ms-head {
  padding: 12px 16px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ms-title {
  font-size: 16px;
  font-weight: 700;
  color: #111827;
}

.ms-close-btn {
  border: 1px solid #e5e7eb;
  background: #ffffff;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
}

.ms-body {
  padding: 12px 16px 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.ms-status {
  color: #6b7280;
  font-size: 13px;
  min-height: 18px;
  margin-bottom: 8px;
}

.ms-grid {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(var(--ms-cols, 1), minmax(0, 1fr));
  gap: 10px;
  align-content: start;
}

.ms-section-title,
.ms-section-empty {
  grid-column: 1 / -1;
}

.ms-section-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #4b5563;
  margin-top: 4px;
}

.ms-section-empty {
  color: #6b7280;
  font-size: 13px;
}

.ms-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  border: 1px solid #dbe3ea;
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.05);
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.ms-item:hover {
  border-color: #c7d2fe;
  box-shadow: 0 10px 22px rgba(59, 130, 246, 0.08);
}

.ms-item.is-selected {
  border-color: #22c55e;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.16), 0 10px 22px rgba(22, 163, 74, 0.08);
}

.ms-item.is-selected .ms-thumb {
  border-color: rgba(34, 197, 94, 0.7);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.14);
}

.ms-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid #d1d5db;
  background: linear-gradient(180deg, #f8fafc 0%, #e5e7eb 100%);
}

.ms-thumb-badges {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.ms-item:hover .ms-thumb-badges {
  opacity: 1;
  transform: translateY(0);
}

.ms-preview-btn {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: zoom-in;
}

.ms-img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: center;
  background: #e5e7eb;
}

.ms-video {
  background: #111827;
}

.ms-thumb-fit-contain .ms-img {
  object-fit: contain;
}

.ms-upload {
  cursor: pointer;
}

.ms-upload .ms-thumb {
  background: linear-gradient(180deg, #f8fafc 0%, #eef2ff 100%);
  border-style: dashed;
}

.ms-action-tile {
  border-style: dashed;
  cursor: pointer;
}

.ms-action-tile .ms-thumb {
  background: linear-gradient(180deg, #eff6ff 0%, #dbeafe 100%);
  border-style: dashed;
}

.ms-action-tile.is-disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.ms-upload-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: #2563eb;
}

.ms-action-tile-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: #1d4ed8;
}

.ms-actions-overlay {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
}

.ms-item:hover .ms-actions-overlay,
.ms-item.is-selected .ms-actions-overlay,
.ms-preview-actions .ms-actions-overlay {
  opacity: 1;
}

.ms-item.is-selected .ms-actions-overlay .ms-action-btn {
  display: none;
}

.ms-item.is-selected .ms-actions-overlay .ms-action-btn[data-action="select"] {
  display: inline-flex;
}

.ms-item.is-selected:hover .ms-actions-overlay .ms-action-btn {
  display: inline-flex;
}

.ms-actions-overlay .ms-action-btn {
  pointer-events: auto;
}

.ms-action-btn {
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.14s ease, background 0.14s ease, opacity 0.14s ease;
}

.ms-action-btn:hover {
  transform: translateY(-1px);
}

.ms-action-round {
  width: 38px;
  height: 38px;
  border-radius: 999px;
}

.ms-action-pill {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
}

.ms-action-tone-neutral {
  background: rgba(17, 24, 39, 0.45);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.ms-action-tone-primary {
  background: rgba(29, 78, 216, 0.8);
  color: #ffffff;
  border: 1px solid rgba(191, 219, 254, 0.45);
}

.ms-action-tone-danger {
  background: rgba(185, 28, 28, 0.82);
  color: #ffffff;
  border: 1px solid rgba(254, 202, 202, 0.45);
}

.ms-action-hover {
  opacity: 0.96;
}

.ms-icon {
  font-size: 16px;
  line-height: 1;
}

.ms-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
}

.ms-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ms-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
  backdrop-filter: blur(6px);
}

.ms-badge-neutral {
  background: #e5e7eb;
  color: #374151;
}

.ms-badge-preset {
  background: rgba(30, 41, 59, 0.76);
  color: #f8fafc;
  border-color: rgba(226, 232, 240, 0.28);
}

.ms-badge-user {
  background: rgba(20, 83, 45, 0.82);
  color: #f0fdf4;
  border-color: rgba(187, 247, 208, 0.34);
}

.ms-name {
  font-size: 13px;
  font-weight: 400;
  color: #4b5563;
  text-align: center;
  line-height: 1.25;
  word-break: break-word;
}

.ms-item.is-selected .ms-action-btn[data-action="select"],
.ms-preview.ms-selected .ms-action-btn[data-action="select"] {
  background: rgba(22, 163, 74, 0.92);
  color: #ffffff;
  border: 1px solid rgba(187, 247, 208, 0.55);
}

.ms-preview {
  position: absolute;
  inset: 0;
  display: none;
  z-index: 4;
}

.ms-preview.ms-show {
  display: block;
}

.ms-preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
}

.ms-preview-card {
  position: absolute;
  inset: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ms-preview-sheet {
  width: min(760px, 100%);
  max-height: 100%;
  background: #111827;
  color: #f9fafb;
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.3);
}

.ms-preview-head {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ms-preview-title {
  font-size: 15px;
  font-weight: 700;
}

.ms-preview-close {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
}

.ms-preview-body {
  padding: 0 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.ms-preview-image-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.06);
}

.ms-preview-media {
  width: 100%;
  height: 100%;
}

.ms-preview-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.ms-preview-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ms-preview-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

@media (hover: none), (pointer: coarse) {
  .ms-actions-overlay {
    opacity: 1;
  }
}

@media (max-width: 640px) {
  .ms-card-wrap {
    inset: 10px;
  }

  .ms-card {
    width: 100%;
    height: 100%;
  }

  .ms-preview-card {
    inset: 12px;
  }
}
