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

:root {
  /* Exact tokens from Mercari's live CSS (alias-color-* design system) */
  --red:        #ff333f;   /* alias-color-background-attention-default */
  --red-dark:   #e32b36;   /* alias-color-background-attention-active  */
  --red-thin:   #fdf1f3;   /* alias-color-background-attentionThin-default */
  --red-border: #ffdcdf;   /* alias-color-background-attentionThin-highlight */
  --logo-red:   #ff0211;   /* literal color on the <svg> logo in their HTML */
  --text:       #333333;   /* alias-color-text-primary-default */
  --text-sub:   #666666;   /* alias-color-text-secondary-default */
  --text-muted: #999999;   /* alias-color-text-placeholder-default */
  --bg:         #f5f5f5;   /* alias-color-background-secondary-default (page bg) */
  --white:      #ffffff;   /* alias-color-background-primary-default (card bg) */
  --border:     #cccccc;   /* alias-color-border-primary-default */
  --border-lt:  #e5e5e5;   /* alias-color-border-primary-highlight */
  --img-bg:     #ffffff;   /* letterbox area — white against gray page, matching Mercari's primary/secondary contrast */
  --radius:     4px;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Mercari's exact dark mode alias-color-* tokens */
    --red:        #da3e50;
    --red-dark:   #ff5266;
    --red-thin:   #401c22;
    --red-border: #531d26;
    --text:       #e5e5e5;
    --text-sub:   #9c9c9c;
    --text-muted: #686868;
    --bg:         #2d2d2d;
    --white:      #222222;
    --border:     #444444;
    --border-lt:  #333333;
    --img-bg:     #383838;   /* lighter than #2d2d2d page bg in dark mode */
  }

  .modal-image,
  .modal-image-placeholder { background: #333333; }

  .item-image-placeholder,
  .admin-item-thumb-placeholder { background: #333333; color: #555; }


  .claimed-tag { background: #032b23; color: #42d87e; }
  .available-tag { background: #333333; }

  .photo-upload-area.has-file { border-color: #42d87e; }

  .login-card { box-shadow: 0 2px 24px rgba(0,0,0,0.6); }

  .filter-chip { background: var(--white); }
  .filter-chip:hover { background: var(--bg); }
  .filter-chip.active { color: var(--red); background: var(--white); }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

/* ── Header ── */
.site-header {
  background: var(--white);
  border-bottom: 1px solid var(--border-lt);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 36px;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 24px;
}

@media (max-width: 959px) {
  .header-inner { padding: 0 8px; gap: 12px; height: 56px; }
}

.logo {
  display: flex;
  align-items: center;
  text-decoration: none;
  flex-shrink: 0;
  color: var(--text);
}

.search-bar {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  height: 36px;
  min-width: 0;
  max-width: 560px;
}

.search-bar input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 15px;
  color: var(--text);
  width: 100%;
  font-family: inherit;
  padding: 0 16px;
  height: 100%;
  min-width: 0;
}

.search-bar input::placeholder { color: var(--text-muted); }

.search-bar-btn {
  flex-shrink: 0;
  width: 36px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-left: 1px solid var(--border);
  cursor: pointer;
  color: var(--text-sub);
  padding: 0;
}

.search-bar-btn:hover { background: var(--border-lt); }

.header-nav {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.header-nav a {
  color: var(--text-sub);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: color 0.15s;
}

.header-nav a:hover { color: var(--text); }

/* ── Main ── */
main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px 16px;
}

/* ── Category tab bar ── */
.category-filters {
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  background: var(--white);
  border-bottom: 1px solid var(--border-lt);
  position: sticky;
  top: 64px;
  z-index: 90;
  margin: 0 -16px;
  padding: 0 20px;
}

@media (max-width: 959px) {
  .category-filters { top: 56px; padding: 0 8px; }
}

.category-filters::-webkit-scrollbar { display: none; }

.filter-chip {
  flex-shrink: 0;
  position: relative;
  height: 44px;
  padding: 0 20px;
  border: none;
  background: var(--white);
  color: var(--text-sub);
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  transition: background 0.1s, color 0.1s;
}

.filter-chip:hover { background: var(--bg); }

.filter-chip.active {
  color: var(--red);
}

.filter-chip.active::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: var(--red);
  border-radius: 2px;
}

.results-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* ── Items grid ── */
.items-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 12px;
}

@media (max-width: 1100px) { .items-grid { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 800px)  { .items-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 520px)  { .items-grid { grid-template-columns: repeat(2, 1fr); gap: 6px; } }

/* ── Item card ── */
.item-card {
  cursor: pointer;
}

.item-image-wrap {
  position: relative;
  aspect-ratio: 1;
  background: var(--img-bg);
  border-radius: var(--radius);
  overflow: hidden;
}

.item-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.item-hover-overlay {
  position: absolute;
  inset: 0;
  background: transparent;
  transition: background 0.25s cubic-bezier(.65,0,.35,1);
  pointer-events: none;
}

.item-card:hover .item-hover-overlay { background: rgba(255,255,255,0.15); }

.item-image-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  color: var(--border);
}

.item-price-overlay {
  position: absolute;
  bottom: 8px;
  left: 0;
  background: rgba(0,0,0,0.4);
  border-radius: 0 20px 20px 0;
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  padding: 2px 12px 2px 8px;
  line-height: 1.4;
  white-space: nowrap;
}

.item-price-overlay .yen { font-size: 14px; font-weight: 600; }

.sold-corner,
.claimed-corner {
  position: absolute;
  top: 0;
  left: 0;
  width: 60px;
  height: 60px;
  overflow: hidden;
  z-index: 1;
}

.sold-corner::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 0; height: 0;
  border-top: 60px solid var(--red);
  border-right: 60px solid transparent;
}

.claimed-corner::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 0; height: 0;
  border-top: 60px solid #e07b00;
  border-right: 60px solid transparent;
}

.sold-corner span,
.claimed-corner span {
  position: absolute;
  top: 13px;
  left: -8px;
  width: 56px;
  text-align: center;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.8px;
  transform: rotate(-45deg);
  z-index: 1;
  pointer-events: none;
}

.item-info { padding: 8px 0 4px; }

.item-title {
  font-size: 14px;
  color: var(--text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.yen { font-size: 11px; font-weight: 600; }

/* ── Empty / loading ── */
.empty-state {
  text-align: center;
  padding: 80px 16px;
  color: var(--text-sub);
  grid-column: 1 / -1;
}

.empty-icon { font-size: 40px; margin-bottom: 12px; }

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 60px auto;
  grid-column: 1 / -1;
}

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

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

@media (min-width: 560px) {
  .modal-overlay { align-items: center; padding: 16px; }
}

.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal-content {
  background: var(--white);
  width: 100%;
  max-width: 480px;
  border-radius: 12px 12px 0 0;
  overflow: hidden;
  transform: translateY(40px);
  transition: transform 0.25s cubic-bezier(.4,0,.2,1);
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 560px) {
  .modal-content {
    border-radius: 12px;
    transform: scale(0.97) translateY(8px);
  }
  .modal-overlay.open .modal-content { transform: scale(1) translateY(0); }
}

.modal-overlay.open .modal-content { transform: translateY(0); }

.modal-drag-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 0;
}

@media (min-width: 560px) { .modal-drag-handle { display: none; } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 15px; font-weight: 600; }

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  font-size: 18px;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.modal-close:hover { background: var(--border); }

.modal-image {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: #f0f0f0;
}

.modal-image-placeholder {
  width: 100%;
  aspect-ratio: 1;
  background: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 64px;
}

.modal-body { padding: 16px; }

.modal-price {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: baseline;
  gap: 2px;
  margin-bottom: 8px;
}

.modal-price .yen { font-size: 16px; font-weight: 600; }

.modal-title { font-size: 16px; font-weight: 500; margin-bottom: 8px; }

.modal-category {
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: 12px;
  display: block;
}

.modal-divider { height: 1px; background: var(--border); margin: 12px 0; }

.modal-description-label {
  font-size: 11px;
  color: var(--text-sub);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.modal-description {
  font-size: 14px;
  color: var(--text);
  line-height: 1.65;
  margin-bottom: 16px;
  white-space: pre-wrap;
}

.sold-info {
  background: var(--red-thin);
  border: 1px solid var(--red-border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--red-dark);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}

.claimed-info {
  background: #fff8ee;
  border: 1px solid #ffd591;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 13px;
  color: #7c4a00;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

@media (prefers-color-scheme: dark) {
  .claimed-info { background: #2a1f00; border-color: #6b4c00; color: #ffd591; }
}

.btn-unclaim {
  margin-left: auto;
  padding: 4px 12px;
  border: 1px solid currentColor;
  border-radius: 12px;
  background: none;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  color: inherit;
  opacity: 0.8;
  transition: opacity 0.15s;
}
.btn-unclaim:hover { opacity: 1; }

/* ── Buttons ── */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 48px;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 24px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover { background: var(--red-dark); }
.btn-primary:disabled { background: #ccc; cursor: not-allowed; }

.btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 48px;
  background: var(--white);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 24px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s;
  margin-top: 10px;
}

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

/* ── Forms ── */
.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
  background: var(--white);
  font-family: inherit;
  -webkit-appearance: none;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus { border-color: var(--text); }

.form-group textarea { resize: vertical; min-height: 80px; line-height: 1.5; }

/* ── Photo upload ── */
.photo-upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px;
  cursor: pointer;
  transition: border-color 0.15s;
  text-align: center;
}

.photo-upload-area:hover { border-color: var(--text); }
.photo-upload-area.has-file { border-color: #4caf50; border-style: solid; }

.upload-icon { font-size: 28px; }
.upload-filename { font-size: 13px; color: var(--text); }
.upload-hint { font-size: 11px; color: var(--text-muted); }

.photo-preview {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-top: 10px;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--text);
  color: #fff;
  padding: 11px 22px;
  border-radius: 24px;
  font-size: 13px;
  z-index: 400;
  transition: transform 0.25s;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { background: #2e7d32; }
.toast.error { background: #c62828; }

/* ── Login ── */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
}

.login-card {
  background: var(--white);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 6px;
  text-decoration: none;
  color: var(--text);
}

.login-subtitle {
  text-align: center;
  color: var(--text-sub);
  font-size: 13px;
  margin-bottom: 24px;
}

/* ── Admin ── */
.admin-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 28px;
  margin-bottom: 16px;
}

.admin-controls h1 { font-size: 18px; font-weight: 700; }
.admin-stats { font-size: 12px; color: var(--text-sub); margin-top: 2px; }

.btn-add {
  padding: 0 20px;
  height: 40px;
  background: var(--red);
  color: var(--white);
  border: none;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
  flex-shrink: 0;
}

.btn-add:hover { background: var(--red-dark); }

.csv-export-wrap { position: relative; flex-shrink: 0; }

.btn-export {
  padding: 0 16px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  background: transparent;
  color: var(--text-sub);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s;
}
.btn-export:hover { border-color: var(--text-sub); color: var(--text); }

.export-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  min-width: 200px;
  z-index: 200;
  padding: 12px;
}
.export-panel-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 10px 0 4px;
}
.export-panel-label:first-child { margin-top: 0; }
.export-link {
  display: block;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  transition: background 0.1s;
}
.export-link:hover { background: var(--bg); }
.export-none { font-size: 13px; color: var(--text-muted); padding: 4px 8px; display: block; }

.admin-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--border-lt);
  border-top: 3px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}
.stat-card--available { border-top-color: #2e7d32; }
.stat-card--claimed   { border-top-color: #e07b00; }
.stat-card--sold      { border-top-color: var(--red); }

.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}
.stat-count {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  margin-bottom: 4px;
}
.stat-value {
  font-size: 13px;
  color: var(--text-sub);
}

@media (max-width: 600px) {
  .admin-stats-grid { grid-template-columns: repeat(2, 1fr); }
}

.admin-items { display: flex; flex-direction: column; gap: 8px; }

.admin-item-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.admin-item-thumb {
  width: 72px;
  height: 72px;
  border-radius: var(--radius);
  object-fit: cover;
  background: #f0f0f0;
  flex-shrink: 0;
}

.admin-item-thumb-placeholder {
  width: 72px;
  height: 72px;
  border-radius: var(--radius);
  background: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  color: #ccc;
}

.admin-item-details { flex: 1; min-width: 0; }
.admin-item-title { font-size: 14px; font-weight: 600; margin-bottom: 3px; }
.admin-item-meta { font-size: 12px; color: var(--text-sub); margin-bottom: 6px; }

.sold-tag {
  display: inline-block;
  font-size: 11px;
  color: var(--red-dark);
  font-weight: 600;
  background: var(--red-thin);
  padding: 2px 8px;
  border-radius: 10px;
}

.claimed-tag {
  display: inline-block;
  font-size: 11px;
  color: #7c4a00;
  font-weight: 600;
  background: #fff0cc;
  padding: 2px 8px;
  border-radius: 10px;
}

.available-tag {
  display: inline-block;
  font-size: 11px;
  color: var(--text-sub);
  background: #f0f0f0;
  padding: 2px 8px;
  border-radius: 10px;
}

.admin-item-actions { display: flex; gap: 6px; flex-shrink: 0; align-self: center; }

.btn-sm {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--white);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  color: var(--text-sub);
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-sm:hover { border-color: var(--text); color: var(--text); }
.btn-sm.danger:hover { border-color: #c62828; color: #c62828; }
.btn-sm.success { border-color: #2e7d32; color: #2e7d32; }
.btn-sm.success:hover { background: #e8f5e9; }

@media (max-width: 480px) {
  .admin-item-card { flex-wrap: wrap; }
  .admin-item-actions { width: 100%; justify-content: flex-end; }
}
