* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #fafafa;
  color: #262626;
}

#widget {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

#toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid #dbdbdb;
  background: #fff;
  flex: 0 0 auto;
}

#tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.tab {
  border: none;
  background: transparent;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  color: #8e8e8e;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.tab.active {
  background: #262626;
  color: #fff;
}

#refreshBtn {
  border: none;
  background: transparent;
  cursor: pointer;
  color: #262626;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  margin-left: 8px;
}

#refreshBtn:hover {
  background: #f0f0f0;
}

#refreshBtn.spinning svg {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

#grid {
  flex: 1 1 auto;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  row-gap: 2px;
  column-gap: 2px;
  padding: 0;
}

.tile {
  position: relative;
  overflow: hidden;
  background: #eee;
  cursor: pointer;
  padding-top: 133.333%;
}

.tile::before {
  content: "";
  display: block;
  padding-top: 133.333%; /* 3:4 portrait ratio, independent of grid row sizing */
}

.tile img,
.tile video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.tile .icon-overlay {
  position: absolute;
  top: 6px;
  right: 6px;
  color: #fff;
  filter: drop-shadow(0 0 2px rgba(0,0,0,0.6));
}

.tile.dragging {
  opacity: 0.4;
}

.tile.drag-over {
  outline: 2px solid #4a90d9;
  outline-offset: -2px;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 20px;
  color: #8e8e8e;
}

/* Modal */
#modalOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

#modalOverlay.hidden {
  display: none;
}

#modal {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#modalSlides {
  position: relative;
  width: min(90vw, 90vh);
  height: min(90vw, 90vh);
  overflow: hidden;
}

.slide {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: #000;
}

.slide.active {
  display: flex;
}

.slide img,
.slide video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.slide .playBtn {
  position: absolute;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

#modalClose {
  position: absolute;
  top: 16px;
  right: 16px;
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  z-index: 2;
}

.modalNav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.4);
  border: none;
  color: #fff;
  font-size: 20px;
  padding: 10px 14px;
  cursor: pointer;
  z-index: 2;
}

#modalPrev { left: 8px; }
#modalNext { right: 8px; }

.modalNav.hidden {
  display: none;
}

#modalDots {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  z-index: 2;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.4);
}

.dot.active {
  background: #fff;
}
