* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #09b1ba;
  --primary-dark: #078a91;
  --danger: #e74c3c;
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #2d3436;
  --text-light: #636e72;
  --border: #dfe6e9;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }
.error { color: var(--danger); font-size: 0.875rem; margin-top: 0.5rem; }

/* Login */
.login-box {
  max-width: 360px;
  margin: 20vh auto;
  background: var(--card);
  padding: 2.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}
.login-box h1 { margin-bottom: 1.5rem; color: var(--primary); }
.login-box input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  margin-bottom: 1rem;
}
.login-box button {
  width: 100%;
  padding: 0.75rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
}
.login-box button:hover { background: var(--primary-dark); }

/* Nav */
nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}
nav h2 { color: var(--primary); font-size: 1.25rem; }
.nav-links { display: flex; gap: 0.25rem; }
.nav-links a {
  padding: 0.5rem 1rem;
  text-decoration: none;
  color: var(--text-light);
  border-radius: var(--radius);
  font-weight: 500;
}
.nav-links a.active { background: var(--primary); color: white; }
.nav-links a:hover:not(.active) { background: var(--bg); }
#logout-btn {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  background: white;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-light);
}
#logout-btn:hover { background: var(--bg); }

/* Pages */
.page { padding: 1.5rem; max-width: 1200px; margin: 0 auto; }

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem;
  text-align: center;
  color: var(--text-light);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 1.5rem;
}
.upload-zone.dragover { border-color: var(--primary); background: rgba(9,177,186,0.05); }
.file-label { color: var(--primary); cursor: pointer; text-decoration: underline; }

/* Progress */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin-bottom: 0.5rem;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s;
  width: 0%;
}
#upload-progress { margin-bottom: 1.5rem; }
#progress-text { font-size: 0.875rem; color: var(--text-light); }

/* Section header */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

/* Gallery grid */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
}
.gallery-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  border: 3px solid transparent;
  transition: border-color 0.2s;
  content-visibility: auto;
  contain-intrinsic-size: 140px 140px;
}
.gallery-item.selected { border-color: var(--primary); }
.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.gallery-item .check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  background: rgba(0,0,0,0.4);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.2s;
}
.gallery-item.selected .check { opacity: 1; background: var(--primary); }
.gallery-item:hover .check { opacity: 1; }
.gallery-item .delete-btn {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 24px;
  height: 24px;
  background: rgba(231,76,60,0.85);
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 14px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.gallery-item:hover .delete-btn { opacity: 1; }

/* Buttons */
.btn-primary {
  padding: 0.6rem 1.25rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary {
  padding: 0.6rem 1.25rem;
  background: white;
  color: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
}
.btn-secondary:hover { background: rgba(9,177,186,0.05); }
.btn-danger {
  padding: 0.6rem 1.25rem;
  background: white;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
}
.btn-danger:hover { background: rgba(231,76,60,0.05); }
.btn-back {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.95rem;
  margin-bottom: 1rem;
  padding: 0;
}

/* Status tabs */
.status-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.status-tabs button {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  background: white;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-light);
}
.status-tabs button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Items grid */
.items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}
.item-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s;
}
.item-card:hover { transform: translateY(-2px); }
.item-card-image {
  aspect-ratio: 1;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  font-size: 0.875rem;
  position: relative;
}
.item-card-image img { width: 100%; height: 100%; object-fit: cover; }
.item-card-image .img-count {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0,0,0,0.6);
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
}
.item-card-info { padding: 0.75rem; }
.item-card-info h4 {
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-card-info .item-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
}
.item-card-info .item-price { font-weight: 600; color: var(--primary); }
.status-badge {
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}
.status-draft { background: #ffeaa7; color: #d35400; }
.status-ready { background: #81ecec; color: #00695c; }
.status-listed { background: #a29bfe; color: #2d1b69; }
.status-sold { background: #55efc4; color: #006c3e; }
.status-archived { background: #b2bec3; color: #2d3436; }

/* Item detail */
.item-detail {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}
@media (max-width: 768px) {
  .item-detail { grid-template-columns: 1fr; }
}
.item-images-section h3 { margin-bottom: 1rem; }
#image-count { font-weight: 400; color: var(--text-light); font-size: 0.875rem; }
.item-images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.item-img-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  cursor: grab;
  border: 2px solid transparent;
}
.item-img-thumb.sortable-chosen { border-color: var(--primary); opacity: 0.8; }
.item-img-thumb img { width: 100%; height: 100%; object-fit: cover; }
.item-img-thumb .position-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(0,0,0,0.6);
  color: white;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
}
.item-img-thumb .remove-img {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  background: rgba(231,76,60,0.85);
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.item-img-thumb:hover .remove-img { opacity: 1; }
.add-images-section { margin-bottom: 1rem; }

/* Form */
.item-form-section {
  background: var(--card);
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text-light);
}
.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(9,177,186,0.15);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-actions { display: flex; gap: 0.75rem; margin-top: 1.5rem; }
#save-feedback {
  margin-top: 0.75rem;
  font-size: 0.875rem;
  color: var(--primary);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal-content {
  background: var(--card);
  border-radius: var(--radius);
  width: 90%;
  max-width: 700px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 1.5rem;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-light);
}
.modal-footer {
  margin-top: 1rem;
  display: flex;
  justify-content: flex-end;
}

/* Crop modal */
.crop-modal-content {
  max-width: 90vw;
  max-height: 90vh;
  width: 800px;
}
.crop-container {
  max-height: 60vh;
  overflow: hidden;
}
.crop-container img {
  display: block;
  max-width: 100%;
}
.crop-footer {
  gap: 0.75rem;
}
.item-img-thumb .crop-btn {
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  background: rgba(9,177,186,0.85);
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.item-img-thumb:hover .crop-btn { opacity: 1; }
.item-img-thumb.is-cropped { border-color: var(--primary); border-style: dashed; }

/* Empty states */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-light);
}
