:root {
  --midea-blue: #0064c8;
  --midea-logo-blue: #2196d3; /* official logo background blue */
  --midea-blue-dark: #004e9c;
  --midea-blue-light: #e8f2fc;
  --ink: #16232f;
  --ink-soft: #5a6b7b;
  --line: #e3e9ef;
  --bg: #f5f8fb;
  --card: #ffffff;
  --danger: #c0392b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(22, 35, 47, 0.06), 0 8px 24px rgba(22, 35, 47, 0.08);
  --shadow-hover: 0 2px 4px rgba(0, 100, 200, 0.10), 0 14px 34px rgba(0, 100, 200, 0.18);
}

* { box-sizing: border-box; }

/* The hidden attribute must always win, even over elements with explicit display rules (e.g. .btn) */
[hidden] { display: none !important; }

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

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  row-gap: 0;
  align-items: center;
  gap: 18px;
  padding: 0 28px;
  min-height: 62px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
/* Logo block bleeds from the top edge and hangs below the header, like midea.com */
.topbar-logo {
  height: 92px;
  align-self: flex-start;
  margin-bottom: -30px;
  position: relative;
  z-index: 1;
}

/* The Midea SVG logotype is white-fill — show it on its brand-blue chip.
   (The header uses midea_logo.png, which carries its own blue background.) */
img[src*="midea_logo.svg"] {
  background: var(--midea-logo-blue);
  border-radius: 6px;
  padding: 5px 9px;
}
.topbar-nav { display: flex; gap: 6px; }
.topbar-nav-link {
  font: inherit;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--ink-soft);
  background: none;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.topbar-nav-link:hover { color: var(--midea-blue); background: var(--midea-blue-light); }
.topbar-nav-link.active { color: var(--midea-blue); background: var(--midea-blue-light); }
.topbar-spacer { flex: 1; }
.auth-badge {
  font-size: 12px;
  font-weight: 600;
  color: #1c7c43;
  background: #e8f7ee;
  border: 1px solid #bfe8cf;
  border-radius: 999px;
  padding: 4px 12px;
}

/* ---------- Layout / stages ---------- */

main { max-width: 1180px; margin: 0 auto; padding: 36px 28px 72px; }
.stage { animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.hero { text-align: center; margin: 18px 0 34px; }
.hero h1, .stage-head h1 { font-size: 30px; font-weight: 700; margin: 0 0 8px; letter-spacing: -0.02em; }
.hero p, .stage-head p { color: var(--ink-soft); font-size: 16px; margin: 0; }
.stage-head { text-align: center; margin: 10px 0 30px; }

.link-btn {
  background: none;
  border: none;
  color: var(--midea-blue);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
}
.link-btn:hover { text-decoration: underline; }

/* ---------- Product cards ---------- */

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 22px;
}

.product-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  cursor: pointer;
  text-align: left;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  font: inherit;
  color: inherit;
}
.product-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
  border-color: var(--midea-blue);
}

.product-card-top { display: flex; align-items: center; justify-content: space-between; min-height: 40px; }
.product-card-top img { height: 18px; max-width: 140px; object-fit: contain; }
/* Balance perceived size across very different logo aspect ratios */
.product-card-top img[src*="midea_logo"] { height: 36px; }
.product-card-top img[src*="teka_logo"] { height: 56px; }
.product-type {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--midea-blue);
  background: var(--midea-blue-light);
  border-radius: 999px;
  padding: 4px 10px;
}

.product-photo {
  height: 190px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #fbfdff 0%, #f0f5fa 100%);
  border-radius: 10px;
  padding: 14px;
}
.product-photo img { max-height: 100%; max-width: 100%; object-fit: contain; }

.product-card h3 { margin: 0; font-size: 16.5px; font-weight: 650; line-height: 1.35; }
.product-model { font-size: 12.5px; color: var(--ink-soft); margin: 2px 0 0; font-variant-numeric: tabular-nums; }
.product-tagline { font-size: 13.5px; color: var(--ink-soft); font-style: italic; margin: 6px 0 0; }

.feature-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.feature-chips span {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
}

/* ---------- Add Product form ---------- */

.add-form { max-width: 960px; margin: 0 auto; }
.add-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 1.6fr;
  gap: 24px;
  margin-bottom: 26px;
}
@media (max-width: 820px) { .add-grid { grid-template-columns: 1fr; } }

.image-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 280px;
  background: var(--card);
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 14.5px;
  transition: border-color 0.15s ease;
}
.image-drop:hover { border-color: var(--midea-blue); }
.image-drop small { font-size: 12.5px; }
.image-drop img { max-width: 100%; max-height: 320px; object-fit: contain; }

.add-fields { display: flex; flex-direction: column; gap: 16px; }
.add-fields label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 650;
  color: var(--ink-soft);
  flex: 1;
}
.add-fields input, .add-fields select {
  font: inherit;
  font-size: 14.5px;
  font-weight: 400;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 14px;
}
.add-fields input:focus, .add-fields select:focus {
  outline: none;
  border-color: var(--midea-blue);
  box-shadow: 0 0 0 3px var(--midea-blue-light);
}
.field-row { display: flex; gap: 14px; }
@media (max-width: 560px) { .field-row { flex-direction: column; } }

/* ---------- Manage Products ---------- */

.manage-table-wrap {
  max-width: 1000px;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}
.manage-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.manage-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.manage-table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.manage-table tr:last-child td { border-bottom: none; }
.manage-thumb {
  width: 56px;
  height: 56px;
  object-fit: contain;
  background: var(--bg);
  border-radius: 8px;
  padding: 4px;
}
.manage-table td strong { display: block; font-size: 14.5px; }
.manage-table td small { color: var(--ink-soft); font-style: italic; }
.manage-model { font-variant-numeric: tabular-nums; color: var(--ink-soft); white-space: nowrap; }
.manage-actions { text-align: right; white-space: nowrap; }
.manage-actions .btn + .btn { margin-left: 8px; }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }

/* ---------- History ---------- */

.history-list {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.history-card {
  display: flex;
  gap: 20px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.history-thumb {
  flex: none;
  width: 110px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.history-thumb img {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.history-noimg {
  font-size: 12px;
  color: var(--ink-soft);
  padding: 30px 0;
}
.history-body { flex: 1; min-width: 0; }
.history-title { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.history-title strong { font-size: 15.5px; }
.history-date { margin-left: auto; font-size: 12.5px; color: var(--ink-soft); white-space: nowrap; }
.history-meta { margin: 6px 0 14px; font-size: 13px; color: var(--ink-soft); }
.history-links { display: flex; flex-wrap: wrap; gap: 8px; }
.history-empty { text-align: center; color: var(--ink-soft); }
@media (max-width: 560px) { .history-card { flex-direction: column; } .history-thumb { width: 140px; } }

/* ---------- Progress / panels ---------- */

.progress-panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 48px 30px;
  text-align: center;
  max-width: 560px;
  margin: 0 auto;
}
.progress-step { font-size: 16px; font-weight: 600; margin: 18px 0 6px; }
.progress-hint { color: var(--ink-soft); font-size: 13.5px; margin: 0; }

.spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto 18px;
  border: 4px solid var(--midea-blue-light);
  border-top-color: var(--midea-blue);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.step-list {
  list-style: none;
  margin: 0 auto 14px;
  padding: 0;
  max-width: 340px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.step { display: flex; align-items: center; gap: 10px; font-size: 14.5px; }
.step-pending { color: var(--ink-soft); opacity: 0.55; }
.step-active .step-label { font-weight: 650; }
.step-done { color: var(--ink-soft); }
.step-icon {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.step-icon.done { color: #1c7c43; font-weight: 800; }
.step-icon.pending { color: var(--line); }
.step-duration { margin-left: auto; font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.mini-spinner {
  width: 14px;
  height: 14px;
  border: 2.5px solid var(--midea-blue-light);
  border-top-color: var(--midea-blue);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
.elapsed { font-variant-numeric: tabular-nums; }

.error-panel {
  max-width: 640px;
  margin: 22px auto 0;
  background: #fdf1ef;
  border: 1px solid #f2c9c2;
  color: var(--danger);
  border-radius: var(--radius);
  padding: 18px 22px;
  font-size: 14px;
  word-break: break-word;
}

/* ---------- Previews / results ---------- */

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 22px;
  margin-bottom: 26px;
}
.preview-card {
  margin: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.preview-card img { display: block; width: 100%; background: #eef2f6; min-height: 120px; object-fit: contain; }
.preview-card figcaption {
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

.actions { display: flex; gap: 12px; justify-content: center; }

.btn {
  font: inherit;
  font-size: 15px;
  font-weight: 650;
  border-radius: 10px;
  padding: 12px 26px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.1s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--midea-blue); border: 1px solid var(--midea-blue); color: #fff; }
.btn-primary:hover { background: var(--midea-blue-dark); }
.btn-ghost { background: var(--card); border: 1px solid var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--midea-blue); color: var(--midea-blue); }
.btn-small { font-size: 13px; padding: 7px 16px; border-radius: 8px; }
.topbar-disconnect { font-size: 12.5px; color: var(--ink-soft); }
.topbar-disconnect:hover { color: var(--danger); }

.result-grid {
  display: grid;
  grid-template-columns: auto minmax(260px, 1fr);
  gap: 26px;
  align-items: start;
  justify-content: center;
  max-width: 760px;
  margin: 0 auto;
}
@media (max-width: 640px) { .result-grid { grid-template-columns: 1fr; justify-items: center; } }

/* Canva design thumbnails are small (~283px wide) — never upscale them */
.result-grid .preview-card { width: 283px; max-width: 100%; }
.result-grid .preview-card img { width: 100%; }

.result-side { display: flex; flex-direction: column; gap: 14px; }

.file-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.file-card:hover { border-color: var(--midea-blue); box-shadow: var(--shadow-hover); }
.file-icon {
  background: #d93025;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  border-radius: 8px;
  padding: 12px 10px;
  letter-spacing: 0.04em;
}
.file-meta { display: flex; flex-direction: column; gap: 2px; }
.file-meta strong { font-size: 14.5px; }
.file-meta small { color: var(--ink-soft); font-size: 12.5px; }
