/* ── Reset & base ─────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #f0f2f5;
  color: #333;
  min-height: 100vh;
}

/* ── Container ───────────────────────────────── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 20px 60px;
}

h1 {
  font-size: 1.8rem;
  margin-bottom: 4px;
}

.subtitle {
  color: #666;
  margin-bottom: 24px;
}

/* ── Toolbar ─────────────────────────────────── */
.toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.upload-btn,
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.2s,
    opacity 0.2s,
    transform 0.1s;
  user-select: none;
}

.upload-btn {
  background: #4f8cff;
  color: #fff;
}
.upload-btn:hover {
  background: #3a6fdb;
}

.btn-danger {
  background: #e74c4c;
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  background: #c73a3a;
}

.btn-save {
  background: #27ae60;
  color: #fff;
  margin-left: auto;
}
.btn-save:hover:not(:disabled) {
  background: #1e8c4c;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ── Grid ────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}

.grid-item {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  cursor: grab;
  transition:
    transform 0.2s,
    box-shadow 0.2s;
  user-select: none;
}

.grid-item:active {
  cursor: grabbing;
}

.grid-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

/* Order badge */
.grid-item .badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 20px;
  pointer-events: none;
}

/* Delete button */
.grid-item .del-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}
.grid-item:hover .del-btn {
  opacity: 1;
}
.grid-item .del-btn:hover {
  background: #e74c4c;
}

/* View button */
.grid-item .view-btn {
  position: absolute;
  top: 6px;
  right: 36px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}
.grid-item:hover .view-btn {
  opacity: 1;
}
.grid-item .view-btn:hover {
  background: #4f8cff;
}

/* File name label */
.grid-item .file-name {
  display: block;
  padding: 6px 8px;
  font-size: 0.75rem;
  color: #555;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: #fafafa;
  border-top: 1px solid #eee;
  cursor: default;
  position: relative;
}

.grid-item .file-name:hover {
  white-space: normal;
  word-break: break-all;
  overflow: visible;
  background: #fff;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  border-radius: 0 0 12px 12px;
}

/* Drag states */
.grid-item.dragging {
  opacity: 0.4;
  transform: scale(0.95);
}

.grid-item.drag-over {
  box-shadow: 0 0 0 3px #4f8cff;
  transform: scale(1.03);
}

/* ── Empty message ───────────────────────────── */
.empty-msg {
  text-align: center;
  color: #999;
  margin-top: 60px;
  font-size: 1.05rem;
}

.empty-msg.hidden {
  display: none;
}

/* ── Responsive ──────────────────────────────── */
@media (max-width: 500px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
  }
}
