/* ===================================================
   Manila S.A. — Product Sheet Generator Styles
   =================================================== */

/* ─── RESET & BASE ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --carbon: #2F2C2B;
  --green: #40543B;
  --blue: #365A6E;
  --orange: #C94707;
  --cream: #EEE1B7;
  --accent: var(--green);
  --accent-light: #e8efe7;
  --gray-100: #f7f7f7;
  --gray-200: #e9e9e9;
  --gray-300: #d4d4d4;
  --gray-500: #888;
  --gray-700: #444;
  --radius: 6px;
  --sidebar-w: 280px;
}

html { font-size: 16px; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--carbon);
  background: var(--gray-100);
  display: flex;
  min-height: 100vh;
}

/* ─── SIDEBAR ─── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--gray-200);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  height: 100vh;
  position: sticky;
  top: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--gray-200);
}
.sidebar-logo { height: 32px; width: auto; }
.sidebar-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-700);
  letter-spacing: 0.02em;
}

.editor-section { display: flex; flex-direction: column; gap: 6px; }
.editor-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gray-500);
}

/* Select */
#product-select {
  padding: 8px 10px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13px;
  background: #fff;
  cursor: pointer;
}
#product-select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Brand switcher */
.brand-switcher { display: flex; flex-direction: column; gap: 4px; }
.brand-option { cursor: pointer; display: flex; align-items: center; }
.brand-option input { display: none; }
.brand-chip {
  display: block;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  transition: all 0.15s;
}
.brand-option input:checked + .brand-chip[data-brand="manila"] {
  background: var(--carbon);
  color: #fff;
  border-color: var(--carbon);
}
.brand-option input:checked + .brand-chip[data-brand="patagonia"] {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}
.brand-option input:checked + .brand-chip[data-brand="andes"] {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

/* Quality switcher */
.quality-switcher { display: flex; gap: 4px; }
.quality-option { flex: 1; cursor: pointer; display: flex; }
.quality-option input { display: none; }
.quality-chip {
  display: block;
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  transition: all 0.15s;
}
.quality-chip small { font-weight: 400; color: var(--gray-500); display: block; font-size: 10px; }
.quality-option input:checked + .quality-chip {
  background: var(--carbon);
  color: #fff;
  border-color: var(--carbon);
}
.quality-option input:checked + .quality-chip small { color: rgba(255,255,255,0.6); }

/* Photo picker grid */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}
.photo-thumb {
  aspect-ratio: 4/3;
  border-radius: 4px;
  object-fit: cover;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s;
  width: 100%;
}
.photo-thumb:hover { border-color: var(--gray-300); }
.photo-thumb.active { border-color: var(--accent); }

/* Buttons */
.btn {
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { opacity: 0.85; }
.btn-secondary {
  background: transparent;
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}
.btn-secondary:hover:not(:disabled) { background: var(--gray-100); }
.editor-actions { display: flex; flex-direction: column; gap: 6px; margin-top: auto; }
.sidebar-hint {
  font-size: 11px;
  color: var(--gray-500);
  text-align: center;
  line-height: 1.4;
}

/* ─── SHEET AREA ─── */
#sheet-area {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 30px;
  overflow-y: auto;
}

/* ─── A4 SHEET ─── */
.sheet.a4 {
  width: 210mm;
  min-height: 297mm;
  background: #fff;
  box-shadow: 0 2px 20px rgba(0,0,0,0.10);
  border-radius: 2px;
  position: relative;
  overflow: hidden;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 297mm;
  color: var(--gray-500);
  text-align: center;
  gap: 8px;
}
.empty-icon { font-size: 48px; }
.empty-title { font-size: 18px; font-weight: 600; color: var(--gray-700); }
.empty-sub { font-size: 13px; }

/* ─── SHEET CONTENT ─── */
.sheet-content {
  padding: 6mm 12mm 6mm;
  display: flex;
  flex-direction: column;
  height: 297mm;
  overflow: hidden;
}

/* Editable hover */
[contenteditable="true"] {
  outline: none;
  border-radius: 2px;
  transition: box-shadow 0.15s;
}
[contenteditable="true"]:hover {
  box-shadow: 0 0 0 1px var(--gray-300);
}
[contenteditable="true"]:focus {
  box-shadow: 0 0 0 2px var(--accent);
}

/* 1. HEADER — PROMINENT LOGOS */
.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  padding: 0 0 6px;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}
.brand-logo {
  max-height: 140px;
  width: auto;
  max-width: 60%;
}
.manila-logo-small {
  height: 80px;
  width: auto;
  opacity: 1;
}
/* When Manila is the brand, hide the small Manila logo to avoid duplication */
.sheet-header.brand-manila .manila-logo-small {
  display: none;
}

/* 2. HERO IMAGE — fills available space */
.hero-image-wrap {
  width: 100%;
  flex: 1 1 auto;
  min-height: 60mm;
  max-height: 120mm;
  overflow: hidden;
  border-radius: 6px;
  margin-bottom: 8px;
  background: #fff;
  position: relative;
  cursor: grab;
}
.hero-image-wrap.dragging {
  cursor: grabbing;
}
.hero-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: center center;
  pointer-events: none;
  user-select: none;
}
/* Pan/zoom controls overlay */
.hero-controls {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: none;
  gap: 2px;
  background: rgba(0,0,0,0.45);
  border-radius: 6px;
  padding: 3px 4px;
}
.hero-image-wrap.has-image .hero-controls {
  display: flex;
}
.hero-ctrl-btn {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 15px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  opacity: 0.85;
  line-height: 1;
}
.hero-ctrl-btn:hover {
  opacity: 1;
  background: rgba(255,255,255,0.18);
}
@media print {
  .hero-controls { display: none !important; }
}

/* 3. TITLE */
.product-title-block {
  margin-bottom: 4px;
  border-bottom: 2px solid var(--accent);
  padding-bottom: 4px;
  flex-shrink: 0;
}
.product-name {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 24px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--carbon);
}
.product-subtitle {
  font-size: 12.5px;
  color: var(--gray-500);
  margin-top: 2px;
  font-weight: 500;
}

/* 4. ORIGIN STORY */
.origin-section {
  margin-bottom: 6px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  flex-shrink: 0;
}
.origin-story {
  font-size: 10.5px;
  line-height: 1.55;
  color: var(--gray-700);
  flex: 1;
  font-style: italic;
}
.origin-badge {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-light);
  color: var(--accent);
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}
.origin-pin { font-style: normal; }

/* 5. SPECS GRID */
.specs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 6px;
  flex-shrink: 0;
}
.spec-heading {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: 5px;
  padding-bottom: 3px;
  border-bottom: 1px solid var(--accent);
}
.spec-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
}
.spec-table tr { border-bottom: 1px solid var(--gray-200); }
.spec-table td { padding: 3px 2px; vertical-align: top; }
.spec-label {
  font-weight: 600;
  color: var(--gray-700);
  width: 35%;
  white-space: nowrap;
}
.spec-table td:last-child { color: var(--carbon); }

/* Sizes sub-table */
.sizes-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.size-row {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
}
.size-label { font-weight: 500; }
.size-lbs { color: var(--gray-500); font-size: 9px; }

/* 6. NO BADGES — CLEAN MONOCHROME */
.no-badges-section {
  margin-bottom: 6px;
  text-align: center;
  flex-shrink: 0;
}
.no-badges-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gray-500);
  margin-bottom: 6px;
}
.no-badges-row {
  display: flex;
  justify-content: center;
  gap: 16px;
}
.no-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.no-badge-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--carbon);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.no-badge-icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--carbon);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform: scaleX(-1);
}
/* Diagonal strike-through line */
.no-badge-icon::after {
  content: '';
  position: absolute;
  width: 42px;
  height: 2.5px;
  background: var(--carbon);
  transform: rotate(-45deg);
  border-radius: 1px;
}
.no-badge-label {
  font-size: 8px;
  font-weight: 600;
  color: var(--gray-700);
  text-align: center;
  line-height: 1.2;
  max-width: 75px;
}

/* 7. CERTS + NUTRITION */
.certs-nutrition-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 6px;
  flex-shrink: 0;
}
.cert-logos {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.cert-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  background: var(--gray-100);
  border-radius: var(--radius);
  font-size: 9px;
  font-weight: 600;
  color: var(--gray-700);
}
.cert-item img {
  height: 22px;
  width: auto;
}
.cert-text-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  min-width: 22px;
  padding: 0 4px;
  background: var(--accent);
  color: #fff;
  border-radius: 3px;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

/* Nutrition table */
.nutrition-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 9.5px;
}
.nutrition-table tr { border-bottom: 1px solid var(--gray-200); }
.nutrition-table td { padding: 2px 3px; }
.nutrition-table td:last-child { text-align: right; font-weight: 600; }
.nt-header td {
  font-weight: 700;
  font-size: 10px;
  padding-bottom: 3px;
  border-bottom: 2px solid var(--carbon);
}
.nt-indent { padding-left: 12px !important; color: var(--gray-500); }

/* 8. FOOTER */
.sheet-footer {
  margin-top: auto;
  padding-top: 6px;
  border-top: 2px solid var(--accent);
  text-align: center;
  flex-shrink: 0;
}
.footer-tagline {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 11px;
  font-style: italic;
  color: var(--accent);
  margin-bottom: 4px;
}
.footer-qr-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.footer-qr {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.footer-qr canvas {
  width: 56px;
  height: 56px;
}
.qr-label {
  font-size: 7px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-700);
}
.footer-contact-center {
  flex: 1;
  text-align: center;
}
.footer-contact {
  font-size: 9px;
  color: var(--gray-500);
  margin-bottom: 2px;
}
.footer-manila {
  font-size: 8px;
  color: var(--gray-500);
  letter-spacing: 0.05em;
}

/* ═══════════════════════════════════
   @MEDIA PRINT
   ═══════════════════════════════════ */
@media print {
  .sidebar { display: none !important; }

  body {
    background: none;
    display: block;
  }

  #sheet-area {
    padding: 0;
    display: block;
  }

  .sheet.a4 {
    box-shadow: none;
    width: 100%;
    min-height: auto;
    max-height: 297mm;
    border-radius: 0;
    overflow: hidden;
  }

  .sheet-content {
    padding: 5mm 10mm 5mm;
    height: 297mm;
    max-height: 297mm;
    overflow: hidden;
  }

  /* Force single page: no page breaks inside */
  .sheet-content, .sheet-content * {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .sheet-content {
    break-after: avoid;
    page-break-after: avoid;
  }

  [contenteditable="true"],
  [contenteditable="true"]:hover,
  [contenteditable="true"]:focus {
    box-shadow: none !important;
  }

  /* Ensure images and backgrounds print correctly */
  .hero-image, .brand-logo, .manila-logo-small, .cert-item img {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .no-badge-icon, .no-badge-icon::after, .cert-item, .origin-badge, .cert-text-badge,
  .footer-qr canvas {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  @page {
    size: A4 portrait;
    margin: 0;
  }
}

/* ═══════════════════════════════════
   RESPONSIVE (small screens)
   ═══════════════════════════════════ */
@media screen and (max-width: 900px) {
  .sidebar {
    width: 100%;
    min-width: auto;
    height: auto;
    position: relative;
    border-right: none;
    border-bottom: 1px solid var(--gray-200);
  }
  body { flex-direction: column; }
  #sheet-area { padding: 16px; }
  .sheet.a4 { width: 100%; min-height: auto; }
}

/* ═══════════════════════════════════
   PRODUCT ADMIN PAGE
   ═══════════════════════════════════ */
.admin-page {
  max-width: 900px;
  margin: 0 auto;
  padding: 30px 20px;
}
.admin-page h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--carbon);
  margin-bottom: 6px;
}
.admin-page .admin-subtitle {
  font-size: 13px;
  color: var(--gray-500);
  margin-bottom: 24px;
}
.admin-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  align-items: center;
}
.admin-toolbar .btn { flex-shrink: 0; }
.admin-toolbar a { text-decoration: none; }

/* Product cards */
.product-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.product-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
}
.product-card-thumb {
  width: 100px;
  height: 70px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--gray-100);
}
.product-card-info { flex: 1; min-width: 0; }
.product-card-info h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 2px;
}
.product-card-info p {
  font-size: 12px;
  color: var(--gray-500);
  margin-bottom: 6px;
}
.product-card-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
  align-self: center;
}
.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}
.btn-danger {
  background: transparent;
  color: var(--orange);
  border: 1px solid var(--orange);
}
.btn-danger:hover { background: #fff5f0; }

/* Product edit form */
.product-form {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 24px;
  display: none;
}
.product-form.active { display: block; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.form-group.full { grid-column: 1 / -1; }
.form-group label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--gray-500);
}
.form-group input,
.form-group textarea,
.form-group select {
  padding: 8px 10px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13px;
}
.form-group textarea {
  min-height: 70px;
  resize: vertical;
}
.form-section-title {
  grid-column: 1 / -1;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  border-bottom: 1px solid var(--accent);
  padding-bottom: 4px;
  margin-top: 10px;
}
.form-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

/* ─── Photo Manager ─── */
.photo-manager-selected {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 70px;
  padding: 8px;
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  background: var(--gray-100);
}
.photo-manager-empty {
  font-size: 12px;
  color: var(--gray-500);
  text-align: center;
  padding: 16px 0;
}
.photo-manager-item {
  position: relative;
  width: 90px;
  height: 65px;
  border-radius: 4px;
  overflow: hidden;
  cursor: grab;
  border: 2px solid transparent;
  flex-shrink: 0;
  transition: border-color 0.15s;
}
.photo-manager-item:active { cursor: grabbing; }
.photo-manager-item.is-primary {
  border-color: var(--green);
}
.photo-manager-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-manager-item .pm-badge {
  position: absolute;
  top: 2px;
  left: 2px;
  background: var(--green);
  color: #fff;
  font-size: 8px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 2px;
  text-transform: uppercase;
}
.photo-manager-item .pm-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  display: none;
  padding: 0;
}
.photo-manager-item:hover .pm-remove { display: block; }
.photo-manager-item.drag-over {
  border-color: var(--orange);
  opacity: 0.7;
}

.photo-manager-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: #fff;
}
.photo-gallery-item {
  width: 75px;
  height: 55px;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.15s;
  position: relative;
  flex-shrink: 0;
}
.photo-gallery-item:hover { border-color: var(--green); transform: scale(1.05); }
.photo-gallery-item.already-added { opacity: 0.35; cursor: default; }
.photo-gallery-item.already-added:hover { border-color: transparent; transform: none; }
.photo-gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-gallery-item .pg-check {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  background: var(--green);
  color: #fff;
  border-radius: 50%;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
}
.photo-gallery-item .pg-remove {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 16px;
  height: 16px;
  background: rgba(200,30,30,0.8);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 11px;
  line-height: 16px;
  text-align: center;
  cursor: pointer;
  padding: 0;
  display: none;
  z-index: 2;
}
.photo-gallery-item:hover .pg-remove { display: block; }
.photo-gallery-item .pg-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 7px;
  padding: 1px 3px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

/* ─── LOGIN PAGE ─── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--gray-100);
}
.login-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.login-logo {
  height: 36px;
  width: auto;
  align-self: center;
}
.login-title {
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  color: var(--carbon);
}
.login-error {
  color: var(--orange);
  font-size: 13px;
  text-align: center;
  margin: 0;
}
.login-back {
  text-align: center;
  font-size: 12px;
  color: var(--gray-500);
  text-decoration: none;
}
.login-back:hover { color: var(--carbon); }
