:root {
  --bg: #f0f2f5;
  --ink: #050505;
  --muted: #65676b;
  --card: #fff;
  --line: #dadde1;
  --line-soft: #e4e6eb;
  --accent: #1877f2;
  --accent-hover: #166fe5;
  --accent-tint: #e7f3ff;
  --green: #31a24c;
  --danger: #e41e3f;
  --danger-tint: #ffebe9;
  --amber: #b45309;
  --shadow: 0 1px 2px rgba(0,0,0,.10), 0 0 1px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px 16px 56px;
}

h1, h2, h3, p { margin: 0; letter-spacing: 0; }
h1 { font-size: 28px; font-weight: 800; }
h2 { font-size: 22px; font-weight: 900; }
h3 { font-size: 15px; font-weight: 900; }
p { color: var(--muted); margin-top: 4px; font-size: 15px; }
button, input, textarea { font: inherit; }

.page-head {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--card);
  padding: 6px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 18px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.nav-btn:hover { background: var(--line-soft); color: var(--ink); }
.nav-btn.active { background: var(--accent-tint); color: var(--accent); }

.status-strip {
  display: grid;
  grid-template-columns: 170px 170px minmax(220px, 1fr) minmax(120px, max-content);
  gap: 12px;
  margin: 16px 0;
  align-items: stretch;
}

.status-card,
.save-pill {
  border: none;
  border-radius: 8px;
  background: var(--card);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.status-card {
  text-align: left;
  cursor: pointer;
}

.status-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 6px;
}

.status-card strong {
  display: block;
  color: var(--accent);
  font-size: 28px;
  line-height: 1;
  font-weight: 900;
}

.status-card.active {
  background: var(--accent);
  color: #fff;
  box-shadow: none;
}

.status-card.active span,
.status-card.active strong {
  color: #fff;
}

.save-pill {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  color: var(--accent);
  font-size: 13px;
  font-weight: 900;
}

.save-pill.is-error { color: var(--danger); }

.search-box {
  display: grid;
  gap: 7px;
  min-width: 0;
  border-radius: 8px;
  background: var(--card);
  padding: 9px 11px;
  box-shadow: var(--shadow);
}

.search-box span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.search-box input {
  width: 100%;
  min-width: 0;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 7px 10px;
  outline: none;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  text-overflow: ellipsis;
}

.search-box input::placeholder {
  color: #7b8188;
  opacity: 1;
  font-size: 13px;
  font-weight: 700;
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.clearance-board {
  display: grid;
  gap: 14px;
}

.clearance-group {
  background: var(--card);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
}

.group-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.group-head p {
  font-size: 13px;
  font-weight: 700;
}

.group-count {
  color: var(--accent);
  background: var(--accent-tint);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
}

.search-result-note {
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 800;
}

.empty-search p {
  font-weight: 700;
}

.size-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.size-card {
  display: grid;
  grid-template-columns: 120px 150px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  min-height: 154px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #fafbfc;
  padding: 10px;
  transition: border-color .15s, background .15s;
}

.size-card.is-dragover {
  border-color: var(--accent);
  background: var(--accent-tint);
}

.size-head {
  display: grid;
  gap: 8px;
  align-items: start;
}

.size-head strong {
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
}

.size-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.upload-chip {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 132px;
  border: 2px dashed var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  text-align: center;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 900;
  transition: border-color .15s, background .15s, color .15s;
}

.upload-chip:hover,
.size-card.is-dragover .upload-chip {
  border-color: var(--accent);
  color: var(--accent);
  background: #fff;
}

.upload-chip input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.image-list {
  display: flex;
  gap: 10px;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0 2px 6px;
  scroll-snap-type: x proximity;
  overscroll-behavior-inline: contain;
}

.image-list.is-empty::before {
  content: attr(data-empty-text);
  display: grid;
  place-items: center;
  min-width: 220px;
  width: 100%;
  min-height: 132px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
  font-size: 13px;
  font-weight: 800;
}

.image-card {
  flex: 0 0 178px;
  width: 178px;
  display: grid;
  gap: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
  cursor: grab;
}

.image-card.is-dragging {
  opacity: .45;
  cursor: grabbing;
}

.image-frame {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: #f0f2f5;
}

.image-preview-trigger {
  display: block;
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: zoom-in;
}

.image-frame img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  -webkit-user-drag: none;
  user-select: none;
}

.remove-image {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 30px;
  min-height: 30px;
  border: none;
  border-radius: 50%;
  background: rgba(228, 30, 63, .94);
  color: #fff;
  cursor: pointer;
  font-size: 18px;
  font-weight: 900;
}

.remove-image:hover { background: var(--danger); }

.image-note {
  width: 100%;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #f0f2f5;
  color: var(--ink);
  padding: 9px 10px;
  resize: vertical;
  line-height: 1.4;
  font-size: 13px;
}

.image-note:focus {
  outline: none;
  background: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.image-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  place-items: center;
  padding: 24px;
}

.image-modal.is-open {
  display: grid;
}

.image-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 5, 5, .82);
}

.image-modal-panel {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 10px;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 48px);
  margin: 0;
  overflow: auto;
}

.image-modal-panel img {
  display: block;
  width: auto;
  height: auto;
  max-width: min(1400px, calc(100vw - 48px));
  max-height: calc(100vh - 110px);
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}

.image-modal-panel figcaption {
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  text-align: center;
}

.image-modal-close {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 2;
  width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 28px;
  font-weight: 900;
  line-height: 1;
}

body.is-previewing-image {
  overflow: hidden;
}

@media (max-width: 1100px) {
  .status-strip {
    grid-template-columns: 1fr;
  }

  .save-pill {
    justify-content: flex-start;
  }
}

@media (max-width: 700px) {
  main { padding: 16px 12px 40px; }
  h1 { font-size: 24px; }
  .clearance-group { padding: 12px; }
  .size-card {
    grid-template-columns: 1fr;
  }
  .upload-chip {
    min-height: 62px;
  }
  .image-card {
    flex-basis: 154px;
    width: 154px;
  }
  .image-modal {
    padding: 12px;
  }
  .image-modal-panel,
  .image-modal-panel img {
    max-width: calc(100vw - 24px);
  }
  .image-modal-panel img {
    max-height: calc(100vh - 94px);
  }
  .nav-btn { flex: 1 1 auto; padding: 8px 10px; }
}
