/* ========================================
   Base / Reset
   ======================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f6f6f7;
  color: #1a1a1a;
  font-size: 14px;
}

/* ========================================
   Header
   ======================================== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid #e1e3e5;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 600;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.editable-title {
  cursor: text;
  padding: 4px 8px;
  border-radius: 4px;
  outline: none;
}

.editable-title:hover {
  background: #f0f0f0;
}

.editable-title:focus {
  background: #fff;
  box-shadow: 0 0 0 2px #5c6ac4;
}

/* ========================================
   Buttons
   ======================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  border: 1px solid #c4cdd5;
  border-radius: 6px;
  background: #fff;
  color: #1a1a1a;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn:hover {
  background: #f4f6f8;
}

.btn-primary {
  background: #5c6ac4;
  color: #fff;
  border-color: #5c6ac4;
}

.btn-primary:hover {
  background: #4959bd;
}

.btn-secondary {
  background: #f4f6f8;
}

.btn-danger {
  color: #d72c0d;
  border-color: #d72c0d;
}

.btn-danger:hover {
  background: #fef1f1;
}

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

.btn-back {
  text-decoration: none;
  color: #5c6ac4;
  border: none;
  padding: 4px;
}

/* ========================================
   Sync Status
   ======================================== */
.sync-status {
  margin: 12px 20px;
  padding: 10px 16px;
  background: #eaf5ea;
  border: 1px solid #a4d4a4;
  border-radius: 6px;
  color: #1a7f37;
}

.sync-status.error {
  background: #fef1f1;
  border-color: #e8b4b4;
  color: #d72c0d;
}

/* ========================================
   Catalog List (index page)
   ======================================== */
.catalog-list {
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.catalog-card {
  background: #fff;
  border: 1px solid #e1e3e5;
  border-radius: 8px;
  padding: 20px;
  transition: box-shadow 0.15s;
}

.catalog-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.catalog-card h2 {
  font-size: 16px;
  margin-bottom: 8px;
}

.catalog-card .meta {
  color: #6d7175;
  font-size: 13px;
  margin-bottom: 16px;
}

.catalog-card .card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.loading {
  text-align: center;
  color: #6d7175;
  padding: 40px;
}

/* ========================================
   Editor Layout (3 columns)
   ======================================== */
.editor-layout {
  display: grid;
  grid-template-columns: 260px 1fr 200px;
  height: calc(100vh - 57px);
  overflow: hidden;
}

.editor-sidebar {
  background: #fff;
  border-right: 1px solid #e1e3e5;
  overflow-y: auto;
  padding: 16px;
}

.right-panel {
  border-right: none;
  border-left: 1px solid #e1e3e5;
}

.panel-section {
  margin-bottom: 20px;
}

.panel-section h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.hint {
  font-size: 11px;
  color: #8c9196;
  margin-bottom: 8px;
}

/* ========================================
   Form Elements
   ======================================== */
.input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid #c4cdd5;
  border-radius: 4px;
  font-size: 13px;
  margin-bottom: 8px;
}

.input:focus {
  outline: none;
  border-color: #5c6ac4;
  box-shadow: 0 0 0 1px #5c6ac4;
}

label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: #6d7175;
  margin-bottom: 4px;
}

/* ========================================
   Product Pool (left panel)
   ======================================== */
.product-pool {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid #e1e3e5;
  border-radius: 4px;
}

.pool-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  cursor: pointer;
  border-bottom: 1px solid #f1f1f1;
  font-size: 12px;
}

.pool-item:hover {
  background: #f4f6f8;
}

.pool-item img {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 3px;
}

.pool-item .pool-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ========================================
   Catalog Preview (center)
   ======================================== */
.editor-main {
  overflow-y: auto;
  padding: 16px;
  background: #ebeced;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.preview-nav {
  display: flex;
  gap: 4px;
}

#page-indicator {
  font-weight: 600;
  color: #5c6ac4;
}

.catalog-preview {
  background: #fff;
  border: 1px solid #d2d5d8;
  border-radius: 4px;
  padding: 20px;
  min-height: 600px;
  aspect-ratio: 210 / 297; /* A4比率 */
  max-width: 700px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.preview-header-bar {
  text-align: center;
  padding: 8px;
  font-weight: 600;
  font-size: 16px;
  background: #333;
  color: #fff;
  margin-bottom: 12px;
}

.preview-footer-bar {
  margin-top: auto;
  padding: 6px;
  font-size: 10px;
  color: #888;
  border-top: 1px solid #e1e3e5;
  text-align: center;
}

/* ========================================
   Product Grid (4×5)
   ======================================== */
.product-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 8px;
  flex: 1;
}

.product-card {
  border: 1px solid #e8e8e8;
  border-radius: 4px;
  padding: 4px;
  text-align: center;
  cursor: grab;
  transition: box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.product-card:hover {
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

.product-card.dragging {
  opacity: 0.5;
}

.product-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 2px;
}

.product-card .product-name {
  font-size: 9px;
  line-height: 1.2;
  margin-top: 4px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.product-card .product-price {
  font-size: 10px;
  font-weight: 600;
  color: #1a1a1a;
  margin-top: 2px;
}

.product-card .color-swatches {
  display: flex;
  justify-content: center;
  gap: 2px;
  margin-top: 3px;
}

.color-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  border: 1px solid #ccc;
}

.product-card-empty {
  border: 1px dashed #d2d5d8;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #aaa;
  font-size: 11px;
}

/* ========================================
   Page List (right panel)
   ======================================== */
.page-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.page-thumb {
  border: 2px solid #e1e3e5;
  border-radius: 4px;
  padding: 6px;
  cursor: pointer;
  text-align: center;
  font-size: 11px;
  background: #fff;
  transition: border-color 0.15s;
}

.page-thumb:hover {
  border-color: #5c6ac4;
}

.page-thumb.active {
  border-color: #5c6ac4;
  background: #f4f5fd;
}

.page-thumb .thumb-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 1px;
  margin-bottom: 4px;
  aspect-ratio: 5/4;
}

.thumb-cell {
  background: #e8e8e8;
  border-radius: 1px;
}

.thumb-cell.filled {
  background: #5c6ac4;
}

.page-thumb-label {
  font-size: 10px;
  color: #6d7175;
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 900px) {
  .editor-layout {
    grid-template-columns: 1fr;
  }
  .editor-sidebar {
    display: none;
  }
}
