:root {
  --bg: #f0f2f5;
  --ink: #050505;
  --muted: #65676b;
  --card: #fff;
  --line: #dadde1;
  --line-soft: #e4e6eb;
  --accent: #1877f2;
  --accent-hover: #166fe5;
  --accent-tint: #e7f3ff;
  --green: #31a24c;
  --green-tint: #e7f7ed;
  --amber: #b45309;
  --danger: #e41e3f;
  --danger-tint: #ffebe9;
  --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: 1420px;
  margin: 0 auto;
  padding: 20px 16px 56px;
}

h1, h2 { margin: 0; letter-spacing: 0; }

h1 {
  font-size: 28px;
  font-weight: 800;
}

h2 {
  font-size: 20px;
  font-weight: 800;
}

p {
  color: var(--muted);
  margin: 4px 0 0;
  font-size: 15px;
}

button, input, textarea, select {
  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);
}

.panel {
  background: var(--card);
  border: none;
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}

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

.panel-head span {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-align: right;
}

.product-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(260px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input, textarea, select {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #f0f2f5;
  color: var(--ink);
  padding: 10px 12px;
  transition: border-color .15s, box-shadow .15s, background .15s;
}

input {
  min-height: 42px;
}

textarea {
  min-height: 42px;
  resize: vertical;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  background: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 9px 16px;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}

.btn:hover {
  background: var(--accent-hover);
}

.btn.secondary {
  background: var(--line-soft);
  color: var(--ink);
}

.btn.secondary:hover {
  background: #d8dadf;
}

.btn:disabled {
  cursor: wait;
  opacity: .68;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(156px, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.status-card {
  text-align: left;
  border: none;
  border-radius: 8px;
  background: var(--card);
  padding: 14px 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.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: 800;
}

.status-card.used strong {
  color: var(--green);
}

.status-card.shopee strong {
  color: var(--amber);
}

.status-card.tiktok strong {
  color: #111827;
}

.status-card.used.tiktok strong {
  color: var(--green);
}

.status-card.active {
  box-shadow: inset 0 0 0 2px var(--accent), var(--shadow);
}

.tools-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}

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

.product-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 16px;
  align-items: start;
}

.product-side {
  display: grid;
  gap: 16px;
  position: sticky;
  top: 16px;
}

.sheet-category-panel h2 {
  margin-bottom: 4px;
}

.sheet-category-panel p {
  margin-bottom: 12px;
  font-size: 13px;
}

.sheet-category-list {
  display: grid;
  gap: 8px;
}

.sheet-category-filter {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #f0f2f5;
  color: var(--ink);
  padding: 8px 10px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 900;
  text-align: left;
}

.sheet-category-filter:hover {
  background: var(--line-soft);
}

.sheet-category-filter.active {
  background: #fff4d6;
  border-color: #facc15;
  color: #8a5a00;
}

.sheet-category-filter small {
  color: inherit;
  opacity: .78;
  font-size: 12px;
  font-weight: 900;
}

.priority-head {
  margin-bottom: 14px;
}

.priority-kicker {
  display: block;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .02em;
  margin-bottom: 4px;
}

.priority-form {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.priority-list {
  display: grid;
  gap: 10px;
}

.priority-card {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #fafbfc;
  padding: 10px;
  cursor: grab;
  transition: opacity .15s, box-shadow .15s, transform .15s;
}

.priority-card-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

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

.priority-card.is-drop-target {
  box-shadow: inset 0 3px 0 var(--accent), var(--shadow);
}

.priority-card.is-drop-target.drop-after {
  box-shadow: inset 0 -3px 0 var(--accent), var(--shadow);
}

.priority-drag-handle {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--line-soft);
  color: var(--muted);
  font-size: 15px;
  font-weight: 900;
  line-height: 1;
}

.priority-name {
  color: var(--ink);
  font-size: 15px;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.priority-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.priority-delete {
  background: var(--danger-tint);
  color: var(--danger);
}

.priority-empty {
  margin-top: 10px;
}

.result-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.data-status {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-align: right;
}

.product-list {
  display: grid;
  gap: 10px;
}

.product-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  position: relative;
  z-index: 0;
  background: var(--card);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 10px;
}

.product-row:hover,
.product-row:focus-within {
  z-index: 20;
}

.product-row.is-used {
  box-shadow: inset 0 0 0 1px rgba(49, 162, 76, .32), var(--shadow);
}

.product-thumb {
  width: 72px;
  aspect-ratio: 1;
  color: var(--accent);
  position: relative;
  z-index: 30;
  display: block;
  font-size: 24px;
  font-weight: 900;
}

.product-thumb.has-preview {
  cursor: zoom-in;
}

.product-thumb:focus {
  outline: none;
}

.product-thumb:focus .thumb-frame {
  box-shadow: 0 0 0 3px var(--accent-tint), 0 0 0 1px var(--accent);
}

.thumb-frame {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  background: #eef2f7;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.thumb-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-popover {
  position: absolute;
  left: calc(100% + 14px);
  top: -8px;
  width: min(640px, calc(100vw - 32px));
  max-width: 720px;
  min-width: 360px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 14px 34px rgba(0,0,0,.24);
  padding: 8px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(6px) scale(.98);
  transform-origin: top left;
  transition: opacity .14s ease, transform .14s ease, visibility .14s ease;
  z-index: 50;
}

.thumb-popover img {
  display: block;
  width: 100%;
  max-height: min(720px, calc(100vh - 48px));
  object-fit: contain;
  border-radius: 6px;
  background: #f0f2f5;
}

.product-thumb.has-preview:hover .thumb-popover,
.product-thumb.has-preview:focus .thumb-popover,
.product-thumb.has-preview:focus-within .thumb-popover {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.product-main {
  position: relative;
  z-index: 1;
  min-width: 0;
}

.product-top {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  justify-content: space-between;
}

.product-title {
  color: var(--ink);
  font-size: 16px;
  font-weight: 900;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.product-title:hover {
  color: var(--accent);
}

.product-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.product-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.product-category-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 7px;
}

.product-meta a {
  color: var(--accent);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.product-note {
  margin-top: 7px;
  color: #202124;
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.preview-error {
  margin-top: 7px;
  color: var(--amber);
  font-size: 12px;
  font-weight: 700;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.action {
  min-height: 34px;
  border: none;
  border-radius: 8px;
  background: #f0f2f5;
  color: var(--ink);
  padding: 7px 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.action:hover {
  background: var(--line-soft);
}

.action.like {
  background: var(--accent-tint);
  color: var(--accent);
}

.action.like.is-used {
  background: var(--green-tint);
  color: var(--green);
}

.action.delete {
  background: var(--danger-tint);
  color: var(--danger);
}

.channel-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent);
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 900;
}

.channel-badge.shopee {
  background: #fff7ed;
  color: var(--amber);
}

.channel-badge.tiktok {
  background: #ecfeff;
  color: #0f766e;
  box-shadow: inset 0 0 0 1px #a5f3fc;
}

.product-category-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: #fff7ed;
  color: #9a3412;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 900;
}

.category-mode {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  background: #eef2f7;
  color: var(--muted);
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 900;
}

.category-mode.manual {
  background: #e7f7ed;
  color: var(--green);
}

.product-category-select {
  display: inline-flex;
  align-items: center;
  grid-template-columns: none;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.product-category-select span {
  white-space: nowrap;
}

.product-category-select select {
  width: auto;
  min-width: 124px;
  min-height: 32px;
  padding: 5px 28px 5px 9px;
  border-color: var(--line-soft);
  background: #fff;
  font-size: 13px;
  font-weight: 800;
}

.note-editor {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.note-editor-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.empty {
  color: var(--amber);
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  padding: 14px 16px;
  font-weight: 700;
}

@media (max-width: 1120px) {
  main {
    max-width: 760px;
  }

  .product-workspace {
    grid-template-columns: 1fr;
  }

  .product-side {
    position: static;
  }
}

@media (max-width: 780px) {
  main {
    padding: 16px 12px 40px;
  }

  h1 {
    font-size: 24px;
  }

  .product-form,
  .tools-panel,
  .status-strip {
    grid-template-columns: 1fr;
  }

  .results-head,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .result-tools {
    align-items: stretch;
    justify-content: stretch;
  }

  .data-status {
    text-align: left;
  }

  .btn,
  .tools-panel .btn {
    width: 100%;
  }

  .nav-btn {
    flex: 1 1 auto;
    padding: 8px 10px;
  }
}

@media (max-width: 560px) {
  .product-row {
    grid-template-columns: 58px minmax(0, 1fr);
    gap: 10px;
  }

  .product-thumb {
    width: 58px;
    font-size: 20px;
  }

  .thumb-popover {
    left: 0;
    top: calc(100% + 10px);
    width: min(440px, calc(100vw - 40px));
    max-width: none;
    min-width: 0;
  }

  .product-top {
    display: grid;
    gap: 4px;
  }

  .product-time {
    white-space: normal;
  }

  .row-actions .action {
    flex: 1 1 auto;
  }

  .product-category-select {
    width: 100%;
    align-items: stretch;
  }

  .product-category-select select {
    flex: 1 1 auto;
    width: 100%;
  }
}
