:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d9e0e7;
  --brand: #136f63;
  --brand-dark: #0d5148;
  --danger: #b42318;
  --soft: #e8f3f1;
  font-family: Inter, Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
button, input, textarea, select { font: inherit; }
button { border: 0; border-radius: 6px; padding: 10px 14px; cursor: pointer; background: #e7ecef; color: var(--ink); }
button:hover { filter: brightness(0.98); }
button.primary { background: var(--brand); color: #fff; }
button.secondary { background: #dde7ec; }
button.ghost { background: transparent; border: 1px solid var(--line); }
button.danger { background: #fee4e2; color: var(--danger); }
button:disabled { opacity: .55; cursor: not-allowed; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 10px 11px; background: #fff; color: var(--ink); }
label span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
.hidden { display: none !important; }
.eyebrow { margin: 0 0 6px; color: var(--brand); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(420px, 100%); display: grid; gap: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 28px; box-shadow: 0 20px 45px rgba(16, 24, 40, .08); }
.login-panel h1, .sidebar h1, .topbar h2, .editor h3 { margin: 0; }
.error { min-height: 20px; margin: 0; color: var(--danger); }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px 1fr; }
.sidebar { background: #101820; color: #fff; padding: 24px; display: flex; flex-direction: column; justify-content: space-between; }
.sidebar .eyebrow { color: #8ee0d2; }
nav { display: grid; gap: 8px; margin-top: 28px; }
.nav-btn { text-align: left; background: transparent; color: #d0d5dd; }
.nav-btn.active { background: rgba(255,255,255,.1); color: #fff; }
.sidebar-footer { display: grid; gap: 10px; color: #d0d5dd; }
.workspace { min-width: 0; }
.topbar { min-height: 86px; display: flex; justify-content: space-between; gap: 18px; align-items: center; padding: 22px 26px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar p { margin: 5px 0 0; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.actions select { width: 220px; }
.tab-panel { padding: 22px 26px; }
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.toolbar input { max-width: 440px; }
.toolbar #selectionLine { margin-left: auto; color: var(--muted); }
.list-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: -6px 0 16px;
}
.list-options label {
  display: flex;
  align-items: center;
  gap: 8px;
}
.list-options label span {
  margin: 0;
  white-space: nowrap;
}
.list-options select { width: 150px; }
.pager {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 13px;
}
.pager button { padding: 8px 11px; }
.content-grid { display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 18px; align-items: start; }
.table-wrap { position: relative; min-height: min(520px, calc(100vh - 170px)); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: auto; max-height: calc(100vh - 170px); }
table { width: 100%; border-collapse: collapse; min-width: 1080px; user-select: none; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; background: #f8fafc; color: #475467; font-size: 12px; z-index: 1; }
th:first-child, td:first-child { width: 54px; text-align: center; }
tr { cursor: pointer; }
tr:hover { background: #f8fbfb; }
tr.active { background: var(--soft); }
.product-title { font-weight: 700; }
.sub { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.status-pill { display: inline-flex; border-radius: 999px; padding: 4px 8px; background: #eef4ff; color: #3538cd; font-size: 12px; }
.status-active { background: #dcfae6; color: #067647; }
.status-draft { background: #fff4df; color: #b54708; }
.status-archived { background: #eef2f6; color: #475467; }
.editor, .settings-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 18px; display: grid; gap: 14px; }
.editor { position: sticky; top: 20px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.editor-actions { display: flex; gap: 10px; justify-content: flex-end; }
.toast { position: fixed; right: 20px; bottom: 20px; max-width: 440px; background: #101820; color: #fff; padding: 13px 15px; border-radius: 8px; box-shadow: 0 12px 30px rgba(16,24,40,.22); }
code { background: #eef2f6; border-radius: 4px; padding: 2px 5px; }
.install-row { display: grid; grid-template-columns: minmax(220px, 420px) auto; gap: 10px; align-items: center; }
.shops-list { display: grid; gap: 8px; }
.shop-item { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; background: #f8fafc; }
.shop-item span { color: var(--muted); font-size: 12px; }
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(16, 24, 32, .54); }
.modal-panel { position: relative; width: min(980px, 100%); max-height: min(760px, 92vh); overflow: auto; background: var(--panel); border-radius: 8px; border: 1px solid var(--line); box-shadow: 0 24px 70px rgba(16,24,40,.28); }
.modal-header { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 18px; background: var(--panel); border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 0; font-size: 20px; }
.images-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; padding: 18px; }
.image-card { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #f8fafc; }
.image-card img { display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: contain; background: #fff; }
.image-card span { display: block; padding: 8px 10px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.images-empty { padding: 24px; color: var(--muted); }

.table-loading {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(2px);
  color: var(--ink);
}

.table-loading small { color: var(--muted); }

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid #d9e0e7;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.push-progress {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 25;
  width: min(430px, calc(100vw - 32px));
  max-height: min(620px, calc(100vh - 32px));
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 22px 60px rgba(16,24,40,.24);
  padding: 16px;
  display: grid;
  gap: 12px;
  animation: pushPanelIn .24s ease both;
}

.push-progress-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.push-progress-header h3 { margin: 0; font-size: 18px; }

.push-progress-bar {
  height: 10px;
  overflow: hidden;
  background: #e7ecef;
  border-radius: 999px;
}

.push-progress-bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--brand);
  border-radius: inherit;
  transition: width .28s ease;
}

.push-progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.push-progress-current {
  margin: 0;
  color: var(--ink);
  line-height: 1.4;
}

.push-progress-summary {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.push-summary-list {
  display: grid;
  gap: 7px;
  max-height: 260px;
  overflow: auto;
}

.push-summary-item {
  display: grid;
  gap: 2px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.push-summary-item span {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.push-summary-item small { color: var(--muted); }
.push-summary-item.ok { border-color: #abefc6; background: #f6fef9; }
.push-summary-item.fail { border-color: #fecdca; background: #fffbfa; }
.push-summary-item.fail small { color: var(--danger); }

@keyframes pushPanelIn {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}

.products-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 0;
  gap: 0;
  align-items: start;
  transition: grid-template-columns .28s ease, gap .28s ease;
}

.products-layout.bulk-open {
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
}

.bulk-panel {
  min-width: 0;
  overflow: hidden;
  opacity: 0;
  transform: translateX(22px);
  pointer-events: none;
  background: var(--panel);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0;
  display: grid;
  gap: 14px;
  transition: opacity .24s ease, transform .28s ease, padding .28s ease, border-color .28s ease;
}

.products-layout.bulk-open .bulk-panel {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
  border-color: var(--line);
  padding: 18px;
}

.bulk-panel h3 { margin: 0; }

.row-check,
#selectAll {
  width: 20px;
  height: 20px;
  accent-color: var(--brand);
  cursor: pointer;
}

.product-thumb {
  width: 54px;
  height: 54px;
  display: block;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.product-thumb-empty {
  background: linear-gradient(135deg, #f8fafc, #e7ecef);
}

.modal-editor {
  position: relative;
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(16,24,40,.28);
}

.modal-editor .modal-header {
  cursor: grab;
  user-select: none;
}

.modal-editor .modal-header:active { cursor: grabbing; }

.editor-body {
  display: grid;
  gap: 14px;
  padding: 18px;
  max-height: calc(100vh - 124px);
  overflow: auto;
}

.group-modal-panel { width: min(460px, calc(100vw - 32px)); }
.group-modal-body { display: grid; gap: 14px; padding: 18px; }
.upload-modal-panel { width: min(520px, calc(100vw - 32px)); }
.upload-modal-body { display: grid; gap: 14px; padding: 18px; }
.confirm-modal-panel { width: min(500px, calc(100vw - 32px)); }
.confirm-modal-body { display: grid; gap: 16px; padding: 18px; }
.confirm-modal-body p { margin: 0; line-height: 1.5; color: var(--ink); }

input, textarea, select, button { user-select: auto; }

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; gap: 18px; }
  .content-grid { grid-template-columns: 1fr; }
  .editor { position: static; }
  .products-layout,
  .products-layout.bulk-open { grid-template-columns: 1fr; gap: 14px; }
  .bulk-panel,
  .products-layout.bulk-open .bulk-panel {
    opacity: 1;
    transform: none;
    pointer-events: auto;
    border-color: var(--line);
    padding: 18px;
  }
  .products-layout:not(.bulk-open) .bulk-panel { display: none; }
}

@media (max-width: 720px) {
  .topbar, .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar #selectionLine { margin-left: 0; }
  .list-options { align-items: stretch; flex-direction: column; }
  .list-options label { justify-content: space-between; }
  .list-options select { width: 180px; }
  .pager { justify-content: space-between; }
  .actions { justify-content: stretch; }
  .actions button { flex: 1 1 160px; }
  .actions select { width: 100%; }
  .install-row { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
}
