:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --sidebar: #0f1c2e;
  --sidebar-2: #16263d;
  --text: #1a2332;
  --muted: #6b778c;
  --border: #e4e9f0;
  --primary: #2f6fed;
  --primary-2: #1f54c7;
  --danger: #d94848;
  --warn: #c47f17;
  --ok: #1f8a5b;
  --shadow: 0 10px 30px rgba(15, 28, 46, 0.08);
  --radius: 14px;
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
a { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}
.btn:hover { background: #f7f9fc; }
.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn.primary:hover { background: var(--primary-2); }
.btn.ghost {
  background: transparent;
  border-color: rgba(255,255,255,0.18);
  color: #d7e2f3;
}
.btn.ghost:hover { background: rgba(255,255,255,0.06); }
.btn.full { width: 100%; }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at top left, rgba(47,111,237,0.18), transparent 35%),
    linear-gradient(160deg, #0f1c2e, #1a3358 45%, #f4f6f9 45%);
}
.login-card {
  width: min(420px, calc(100vw - 32px));
  background: var(--panel);
  border-radius: 20px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-brand, .brand {
  display: flex;
  gap: 14px;
  align-items: center;
}
.login-brand h1 { margin: 0 0 4px; font-size: 22px; }
.login-brand p, .brand small { margin: 0; color: var(--muted); }
.logo-mark {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #2f6fed, #6aa2ff);
  color: #fff; font-weight: 700;
}
#login-form { display: grid; gap: 14px; margin-top: 24px; }
#login-form label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
#login-form input {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
}
#login-form input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,111,237,0.12); }
.error { color: var(--danger); margin: 0; font-size: 13px; }

.app-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  color: #e8eef8;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.brand strong { display: block; }
.brand small { color: #9fb0c9; }
.sidebar nav { display: grid; gap: 6px; }
.nav-item {
  text-align: left;
  border: 0;
  background: transparent;
  color: #c9d6ea;
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,0.06); }
.nav-item.active { background: rgba(47,111,237,0.28); color: #fff; }
.sidebar-foot { margin-top: auto; display: grid; gap: 10px; }
.user-chip {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255,255,255,0.06);
  font-size: 13px;
  color: #c9d6ea;
}

.main { padding: 22px 24px 40px; }
.topbar {
  display: flex; justify-content: space-between; align-items: end;
  margin-bottom: 18px; gap: 12px;
}
.topbar h2 { margin: 0; font-size: 24px; }
.topbar-meta { color: var(--muted); font-size: 13px; }

.view { display: none; }
.view.active { display: grid; gap: 16px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 8px; }
.kpi .sub { margin-top: 6px; font-size: 12px; color: var(--muted); }
.kpi.warn .value { color: var(--warn); }
.kpi.ok .value { color: var(--ok); }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.panel-head h3 { margin: 0; font-size: 15px; }
.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 280px);
  max-height: calc(100dvh - 280px);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
th, td { padding: 11px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th {
  color: var(--muted);
  font-weight: 600;
  background: #fafbfd;
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
  z-index: 2;
  box-shadow: 0 1px 0 var(--border);
}
tbody tr:hover { background: #f8fbff; }

.filters {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
}
.filters input[type="search"], .filters select {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 180px;
}
.check { display: inline-flex; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; }

.badge {
  display: inline-flex; align-items: center;
  padding: 3px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: #eef2f8; color: #44546a;
}
.badge.ok { background: #e7f7ef; color: var(--ok); }
.badge.warn { background: #fff4df; color: var(--warn); }
.badge.danger { background: #fdecec; color: var(--danger); }
.badge.info { background: #e8f0ff; color: var(--primary); }

.bars { padding: 16px; display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 90px 1fr 70px; gap: 10px; align-items: center; font-size: 13px; }
.bar-track { height: 10px; background: #eef2f8; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, #2f6fed, #6aa2ff); border-radius: 999px; }
.bar-fill.alt { background: linear-gradient(90deg, #1f8a5b, #57c08f); }
.bar-row span:last-child { text-align: right; color: var(--muted); }

.split-lists { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.split-lists > div { padding: 12px 16px 16px; }
.split-lists > div + div { border-left: 1px solid var(--border); }
.split-lists h4 { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.simple-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.simple-list li {
  display: grid; gap: 2px; padding: 10px 12px;
  background: #f7f9fc; border-radius: 10px; font-size: 13px;
}
.simple-list small { color: var(--muted); }

@media (max-width: 1100px) {
  .kpi-grid, .grid-2, .split-lists { grid-template-columns: 1fr; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 5; }
  .sidebar nav { grid-auto-flow: column; grid-auto-columns: max-content; overflow: auto; }
  .table-wrap { max-height: calc(100vh - 220px); max-height: calc(100dvh - 220px); }
}

.callout {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #f7f9fc;
  font-size: 13px;
  line-height: 1.5;
  color: #44546a;
}
.callout.warn {
  background: #fff7e8;
  border-color: #f0d7a3;
  color: #8a5a10;
}
.pager {
  display: flex; gap: 8px; align-items: center; justify-content: flex-end;
  padding: 12px 16px; border-top: 1px solid var(--border);
}
.pager button { min-width: 72px; }
.pager .muted { margin-right: auto; }
.filters input[type="date"] {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
}

.kpi-link {
  color: var(--primary);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 4px;
}
.kpi-link:hover { color: var(--primary-2); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal.hidden { display: none !important; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 28, 46, 0.45);
}
.modal-panel {
  position: relative;
  width: min(980px, calc(100vw - 32px));
  max-height: min(84vh, 860px);
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0 0 4px; font-size: 18px; }
.modal-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.modal-tabs { display: inline-flex; gap: 6px; }
.tab-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}
.tab-btn.active {
  background: rgba(47,111,237,0.12);
  border-color: rgba(47,111,237,0.35);
  color: var(--primary);
  font-weight: 600;
}
.modal-toolbar input[type="search"] {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 220px;
  flex: 1;
}
.modal-body { overflow: auto; }
.modal-body .table-wrap { max-height: none; }

.btn.danger-outline {
  border-color: rgba(217, 72, 72, 0.35);
  color: var(--danger);
  background: #fff;
}
.btn.danger-outline:hover { background: #fdecec; }

.np-modal-panel {
  width: min(980px, calc(100vw - 24px));
  max-height: min(90vh, 920px);
}
.np-modal-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.np-form {
  overflow: auto;
  padding: 8px 18px 20px;
  display: grid;
  gap: 12px;
}
.np-section {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fafbfd;
  padding: 12px 14px;
}
.np-section h4 {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--primary-2);
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
}
.form-grid label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.form-grid .span-2 { grid-column: 1 / -1; }
.form-grid input,
.form-grid select,
.form-grid textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
  width: 100%;
}
.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47,111,237,0.12);
}
.form-grid textarea { resize: vertical; min-height: 64px; }
.check-line {
  display: flex !important;
  align-items: center;
  gap: 8px;
  padding-top: 22px;
  color: var(--text) !important;
  font-size: 14px !important;
}
.check-line input { width: auto !important; }
.np-profit-box {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  border-radius: 10px;
  background: #eef4ff;
  border: 1px solid rgba(47,111,237,0.18);
  font-size: 13px;
  color: var(--muted);
}
.np-profit-box strong { display: block; margin-top: 4px; color: var(--text); font-size: 16px; }
.np-actions { display: inline-flex; gap: 6px; }
.np-actions .btn { padding: 6px 10px; font-size: 12px; }
.pager {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
@media (max-width: 800px) {
  .form-grid, .np-profit-box { grid-template-columns: 1fr; }
}


/* Truncate long cells; Excel-like column resize */
.resizable-table {
  table-layout: fixed;
  min-width: 1100px;
}
.resizable-table th,
.resizable-table td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Keep sticky headers: do not override th position with relative.
   sticky still establishes a containing block for the resize handle. */
.resizable-table td {
  position: relative;
}
.resizable-table thead th {
  position: sticky;
  top: 0;
  z-index: 4;
  background: #fafbfd;
}
.resizable-table th[data-col="list_sku"],
.resizable-table td.col-msku {
  width: 140px;
  max-width: 140px;
}
.resizable-table th[data-col="name"],
.resizable-table td.col-name {
  width: 160px;
  max-width: 160px;
}
.cell-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  max-width: 100%;
}
.col-resize-handle {
  position: absolute;
  top: 0;
  right: -3px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 3;
  user-select: none;
}
.col-resize-handle:hover,
.col-resize-handle.active {
  background: rgba(59, 130, 246, 0.35);
}
body.col-resizing {
  cursor: col-resize !important;
  user-select: none !important;
}
body.col-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

.resizable-table th[data-col="thumb"],
.resizable-table td.col-thumb {
  width: 56px;
  max-width: 56px;
  text-align: center;
  overflow: visible;
}
.np-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  background: #f1f5f9;
  vertical-align: middle;
  display: inline-block;
}
.np-thumb-empty {
  display: inline-block;
  width: 40px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  color: #94a3b8;
  background: #f8fafc;
  border-radius: 6px;
  font-size: 12px;
}

.btn.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.listing-result-btn {
  border: 0; background: transparent; padding: 0; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; max-width: 220px;
  font: inherit; color: inherit; text-align: left;
}
.listing-result-btn:hover { opacity: 0.85; text-decoration: underline; }
.listing-fb { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; display: inline-block; vertical-align: middle; }
.col-listing-action, .col-listing-result { white-space: nowrap; }

.col-review, .col-review-notes { white-space: nowrap; }
.col-review-notes .cell-ellipsis { max-width: 140px; display: inline-block; vertical-align: middle; }

.col-new-images { white-space: nowrap; }
.new-images-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: transparent; padding: 0; cursor: pointer;
}
.new-images-btn .np-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; }
.new-image-preview-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.gallery-panel { max-width: min(960px, 96vw); width: 96vw; }
.gallery-stage {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px;
  align-items: center; padding: 12px 16px;
}
.gallery-stage img {
  width: 100%; max-height: 70vh; object-fit: contain; background: #0f172a0d; border-radius: 10px;
}
.gallery-nav { min-width: 72px; }
.gallery-thumbs {
  display: flex; gap: 8px; overflow-x: auto; padding: 0 16px 16px;
}
.gallery-thumb {
  border: 2px solid transparent; border-radius: 8px; padding: 0; background: transparent; cursor: pointer;
}
.gallery-thumb.active { border-color: var(--primary); }
.gallery-thumb img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; display: block; }
