:root {
  --bg: #fafaf7;
  --surface: #ffffff;
  --border: #ebe7df;
  --text: #2a2a2a;
  --text-soft: #6b6b6b;
  --accent: #2f6f4e;
  --accent-soft: #e7f0ea;
  --warn: #b8651b;
  --danger: #b13b3b;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

a {
  color: var(--accent);
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 18px;
}

.brand h1 {
  margin: 0 0 4px;
  font-size: 26px;
  letter-spacing: 0.5px;
}

.brand p {
  margin: 0;
  color: var(--text-soft);
  font-size: 14px;
  white-space: pre-wrap;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  flex-wrap: wrap;
}

.user-bar .greeting {
  color: var(--text-soft);
}

.user-bar .name {
  color: var(--text);
  font-weight: 500;
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  transition: all 0.15s;
}

.btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn.primary:hover {
  background: #245d40;
  border-color: #245d40;
  color: #fff;
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-soft);
  padding: 6px 10px;
}

.btn.ghost:hover {
  color: var(--accent);
}

.btn.danger {
  border-color: var(--danger);
  color: var(--danger);
}

.btn.danger:hover {
  background: var(--danger);
  color: #fff;
}

.btn.sm {
  padding: 5px 10px;
  font-size: 12px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-soft);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.12s;
}

.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 24px;
}

.toolbar-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 200px;
  padding: 8px 12px 8px 32px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b6b6b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat 10px center;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  background-color: var(--surface);
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-soft);
  cursor: pointer;
  transition: all 0.12s;
}

.chip:hover {
  color: var(--text);
}

.chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-soft);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.toggle input {
  margin: 0;
}

.sort-select {
  padding: 7px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.result-count {
  font-size: 12px;
  color: var(--text-soft);
}

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: all 0.18s;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
  border-color: #d8d4cb;
}

.card.sold {
  opacity: 0.62;
}

.card-img {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #f0ede7;
  overflow: hidden;
}

.card-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.badge {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 3px 9px;
  font-size: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  backdrop-filter: blur(4px);
}

.badge.reserved {
  background: var(--warn);
  color: #fff;
}

.badge.available {
  background: var(--accent);
  color: #fff;
}

.badge.sold {
  background: var(--danger);
  color: #fff;
}

.badge.heart {
  top: 10px;
  left: auto;
  right: 10px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--accent);
  font-weight: 500;
}

.badge.count {
  bottom: 10px;
  top: auto;
  left: auto;
  right: 10px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 11px;
}

.badge.gift {
  top: auto;
  bottom: 10px;
  left: 10px;
  background: #fff6d7;
  color: #7a5200;
  font-weight: 500;
}

.card-body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.card-name {
  font-size: 15px;
  font-weight: 500;
  margin: 0;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-price {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.card-price .now {
  color: var(--accent);
  font-weight: 600;
  font-size: 18px;
}

.card-price .orig {
  color: var(--text-soft);
  font-size: 12px;
  text-decoration: line-through;
}

.card-meta {
  font-size: 12px;
  color: var(--text-soft);
  display: flex;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 6px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 20, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
}

.modal-body {
  padding: 22px 24px 24px;
}

.modal-body h2 {
  margin: 0 0 8px;
  font-size: 22px;
}

.modal-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.modal-row:last-of-type {
  border-bottom: none;
}

.modal-row .label {
  color: var(--text-soft);
}

.modal-note {
  background: #faf7ee;
  border: 1px solid #f0e9d6;
  border-radius: 8px;
  padding: 10px 12px;
  margin: 14px 0;
  font-size: 14px;
  color: #6b5d36;
  white-space: pre-wrap;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.modal-actions .btn {
  flex: 1;
  min-width: 120px;
}

.reserved-list {
  margin: 14px 0 0;
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
}

.reserved-list strong {
  color: var(--accent);
}

.reserved-list ul {
  margin: 6px 0 0;
  padding-left: 18px;
  color: var(--text);
}

.reserved-list li {
  margin: 2px 0;
}

input[type='text'],
input[type='password'],
input[type='number'],
input[type='date'],
textarea,
select {
  width: 100%;
  padding: 9px 11px;
  font-family: inherit;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.12s;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
}

textarea {
  resize: vertical;
  min-height: 60px;
}

.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 13px;
  color: var(--text-soft);
  margin-bottom: 4px;
}

.field-hint {
  min-height: 18px;
  margin-top: 5px;
  color: var(--warn);
  font-size: 12px;
}

.field-row {
  display: flex;
  gap: 10px;
}

.field-row .field {
  flex: 1;
}

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-soft);
}

.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: #2a2a2a;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
}

/* Wishlist */
.wishlist-modal {
  max-width: 480px;
}

.wish-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.wish-item:last-child {
  border-bottom: none;
}

.wish-item img {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  object-fit: cover;
  background: #f0ede7;
}

.wish-item .info {
  flex: 1;
  min-width: 0;
}

.wish-item .info h4 {
  margin: 0 0 4px;
  font-size: 14px;
}

.wish-item .info p {
  margin: 0;
  font-size: 12px;
  color: var(--text-soft);
}

/* Carousel in modal */
.carousel {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #f0ede7;
  overflow: hidden;
}

.carousel-track {
  display: flex;
  width: 100%;
  height: 100%;
  transition: transform 0.25s ease;
}

.carousel-slide {
  flex: 0 0 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-in;
}

.carousel-slide img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.carousel-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}

.carousel-arrow:hover {
  background: rgba(0, 0, 0, 0.7);
}

.carousel-arrow.prev {
  left: 10px;
}

.carousel-arrow.next {
  right: 10px;
}

.carousel-dots {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  background: rgba(0, 0, 0, 0.35);
  padding: 4px 8px;
  border-radius: 999px;
}

.carousel-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  border: none;
  padding: 0;
  cursor: pointer;
}

.carousel-dot.active {
  background: #fff;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: 18px;
  right: 18px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
}

.lightbox-counter {
  position: absolute;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 14px;
  background: rgba(0, 0, 0, 0.4);
  padding: 4px 12px;
  border-radius: 12px;
}

.lightbox-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 24px;
  cursor: pointer;
}

.lightbox-arrow.prev {
  left: 20px;
}
.lightbox-arrow.next {
  right: 20px;
}

/* Admin */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 13px;
}

.admin-table th,
.admin-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.admin-table th {
  background: #f5f2eb;
  font-weight: 500;
  color: var(--text-soft);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.admin-table tr:last-child td {
  border-bottom: none;
}

.admin-table .thumb {
  width: 50px;
  height: 50px;
  border-radius: 6px;
  object-fit: cover;
}

.admin-table .price-input {
  width: 80px;
}

.admin-table .status-cell {
  min-width: 110px;
}

.admin-table .item-summary {
  min-width: 280px;
  max-width: 420px;
}

.admin-table .item-summary strong {
  display: block;
  font-size: 14px;
  color: var(--text);
}

.admin-table .summary-meta,
.admin-table .summary-note,
.price-summary span {
  display: block;
  color: var(--text-soft);
  font-size: 12px;
}

.admin-table .summary-note {
  margin-top: 4px;
  max-width: 420px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-table .price-summary {
  min-width: 88px;
}

.admin-table .price-summary strong {
  color: var(--accent);
}

.admin-table .flag-cell {
  text-align: center;
  min-width: 56px;
}

.admin-table .flag-cell input {
  width: auto;
}

.admin-table .row-actions {
  min-width: 118px;
  white-space: nowrap;
}

.admin-table .row-actions .btn + .btn {
  margin-left: 6px;
}

.bid-inline {
  margin-top: 4px;
  color: var(--text-soft);
  font-size: 12px;
  white-space: nowrap;
}

.bid-modal {
  max-width: 560px;
}

.bid-list {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.bid-row {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.bid-row:last-child {
  border-bottom: none;
}

.bid-rank {
  color: var(--text-soft);
  font-size: 12px;
  text-align: center;
}

.bid-person strong,
.bid-person span {
  display: block;
}

.bid-person span {
  color: var(--text-soft);
  font-size: 12px;
  margin-top: 2px;
}

.bid-price {
  min-width: 96px;
  text-align: right;
  color: var(--accent);
  font-weight: 600;
}

.bid-price small {
  font-weight: 400;
}

.item-form-modal {
  max-width: 680px;
}

.item-form-modal .large-note {
  min-height: 180px;
  line-height: 1.6;
}

.form-toggle {
  flex: 1;
  min-width: 160px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

.section-title {
  font-size: 18px;
  margin: 32px 0 14px;
}

.tab-row {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
  overflow-x: auto;
}

.tab-row .tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-soft);
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

.tab-row .tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Stats grid on admin */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.stat-box .label {
  font-size: 12px;
  color: var(--text-soft);
  margin-bottom: 4px;
}

.stat-box .value {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
}

.stat-box .sub {
  font-size: 11px;
  color: var(--text-soft);
  margin-top: 2px;
}

/* Image manager (admin) — large preview + thumb strip */
.img-mgr-modal .modal {
  max-width: 760px;
}

.img-preview-wrap {
  position: relative;
  width: 100%;
  background: #1a1a1a;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  margin-bottom: 12px;
}

.img-preview-wrap img {
  max-width: 100%;
  max-height: 60vh;
  object-fit: contain;
  display: block;
}

.img-preview-wrap .empty-state {
  color: rgba(255, 255, 255, 0.55);
  font-size: 14px;
}

.img-preview-wrap .preview-cover-flag {
  position: absolute;
  top: 10px;
  left: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
}

.img-preview-wrap .preview-counter {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 12px;
}

.img-action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.img-action-bar .btn {
  flex: 1;
  min-width: 90px;
}

.img-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 8px;
  scrollbar-width: thin;
}

.img-strip .thumb {
  flex: 0 0 auto;
  width: 76px;
  height: 76px;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  border: 2px solid transparent;
  background: #f0ede7;
}

.img-strip .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.img-strip .thumb.active {
  border-color: var(--accent);
}

.img-strip .thumb .order-no {
  position: absolute;
  top: 2px;
  left: 2px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
}

.img-strip .add-thumb {
  flex: 0 0 auto;
  width: 76px;
  height: 76px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text-soft);
  font-size: 28px;
  cursor: pointer;
}

.img-strip .add-thumb:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Crop modal */
.crop-modal .modal-body {
  padding: 18px 20px 20px;
}

.crop-canvas-wrap {
  position: relative;
  background: #1a1a1a;
  border-radius: 8px;
  overflow: hidden;
  margin: 10px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  user-select: none;
}

.crop-canvas-wrap canvas {
  max-width: 100%;
  max-height: 60vh;
  display: block;
}

.crop-overlay {
  position: absolute;
  border: 2px solid #fff;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
  cursor: move;
}

.crop-overlay .handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 50%;
  border: 2px solid var(--accent);
}

.crop-overlay .handle.tl {
  top: -7px;
  left: -7px;
  cursor: nwse-resize;
}
.crop-overlay .handle.tr {
  top: -7px;
  right: -7px;
  cursor: nesw-resize;
}
.crop-overlay .handle.bl {
  bottom: -7px;
  left: -7px;
  cursor: nesw-resize;
}
.crop-overlay .handle.br {
  bottom: -7px;
  right: -7px;
  cursor: nwse-resize;
}

.crop-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 4px;
}

@media (max-width: 600px) {
  .wrap {
    padding: 16px 12px 60px;
  }
  .brand h1 {
    font-size: 22px;
  }
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
  }
  .card-name {
    font-size: 14px;
  }
  .card-price .now {
    font-size: 16px;
  }
  .toolbar {
    padding: 12px;
  }
  .modal-body {
    padding: 18px 18px 22px;
  }
  .admin-table {
    font-size: 12px;
  }
  .admin-table th,
  .admin-table td {
    padding: 8px 8px;
  }
  .img-mgr .thumb-box,
  .img-mgr .add-btn {
    width: 60px;
    height: 60px;
  }
}
