:root {
  --bg: #f3f1ec;
  --panel: #fffcf7;
  --ink: #1c1917;
  --muted: #78716c;
  --line: #e7e5e4;
  --accent: #0f766e;
  --accent-ink: #ecfdf5;
  --danger: #b91c1c;
  --warn: #b45309;
  --ok: #047857;
  --shadow: 0 10px 30px rgba(28, 25, 23, 0.06);
  --radius: 14px;
  font-family: "Segoe UI", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.08), transparent 28%),
    linear-gradient(180deg, #efeae2, var(--bg));
  min-height: 100vh;
  padding: 24px;
}

.top, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 16px;
}

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

h1, h2, h3 { margin: 0 0 6px; letter-spacing: -0.02em; }
.sub, .muted { color: var(--muted); margin: 0; }
.status { text-align: right; font-size: 0.92rem; }
.label { color: var(--muted); margin-right: 6px; }
.ok { color: var(--ok); font-weight: 600; }
.warn { color: var(--warn); font-weight: 600; max-width: 420px; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
}

.field { display: flex; flex-direction: column; gap: 6px; min-width: 140px; }
.field.grow { flex: 1; min-width: 260px; }
label { font-size: 0.85rem; color: var(--muted); }
input[type="text"],
input[type="number"],
input[type="search"],
input[type="password"] {
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 16px;
  font: inherit;
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }

.summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}
.summary.hidden { display: none; }

.converted-cell { min-width: 90px; }
.compare-hint {
  text-align: center;
  color: #d6d3d1;
  font-size: 0.85rem;
  margin-bottom: 8px;
}
.compare-nav {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.compare-nav button {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border-color: rgba(255,255,255,0.2);
}

.table-tools {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.table-tools label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  white-space: nowrap;
  cursor: pointer;
  font-size: 0.92rem;
  user-select: none;
}

/* Custom checkboxes — select / select-all / filters */
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  flex: 0 0 auto;
  border: 1.5px solid #a8a29e;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  display: inline-grid;
  place-content: center;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  vertical-align: middle;
}
input[type="checkbox"]::before {
  content: "";
  width: 10px;
  height: 10px;
  transform: scale(0);
  transition: transform 0.12s ease;
  clip-path: polygon(14% 44%, 0 65%, 40% 100%, 100% 18%, 80% 0, 38% 62%);
  background: var(--accent-ink);
}
input[type="checkbox"]:hover:not(:disabled) {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}
input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
input[type="checkbox"]:checked::before {
  transform: scale(1);
}
input[type="checkbox"]:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  background: #f5f5f4;
}
input[type="checkbox"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.28);
}

#tbody td.cell-check,
#tbody td:first-child {
  width: 44px;
  cursor: pointer;
}
#tbody tr[data-search] {
  cursor: pointer;
}
#tbody tr[data-search]:hover {
  background: rgba(15, 118, 110, 0.04);
}
#tbody tr[data-search]:has(input[type="checkbox"]:checked) {
  background: rgba(15, 118, 110, 0.08);
}
#tbody input[type="checkbox"] {
  width: 22px;
  height: 22px;
  border-radius: 7px;
}
#tbody input[type="checkbox"]::before {
  width: 12px;
  height: 12px;
}
.table-tools input[type="search"] {
  min-width: min(280px, 100%);
  flex: 1 1 180px;
}
.filter-wrap {
  position: relative;
  flex: 1 1 180px;
  min-width: min(280px, 100%);
  display: flex;
  align-items: center;
}
.filter-wrap input[type="text"],
.filter-wrap input[type="search"] {
  width: 100%;
  padding-right: 40px;
  min-width: 0;
  flex: 1 1 auto;
}
.filter-wrap input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}
.filter-clear {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: #e7e5e4;
  color: #44403c;
  font-size: 1.35rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}
.filter-clear[hidden] {
  display: none !important;
}
.filter-clear:hover {
  background: #d6d3d1;
  color: #1c1917;
}
.th-sort {
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.th-sort:hover { color: var(--ink); }
#sortSizeArrow { font-size: 0.85em; }
.table-wrap { overflow: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  font-size: 0.92rem;
}
th { color: var(--muted); font-weight: 600; }
tr.unmatched { opacity: 0.72; }
tr.hidden-row { display: none; }
.thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  background: #e7e5e4;
  border: 1px solid var(--line);
  display: block;
}
.thumb-btn,
.converted-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: zoom-in;
}
.thumb-btn:hover .thumb,
.converted-btn:hover .thumb {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.original-size {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
}
.converted-size {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ok);
}
.sku-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  max-width: 280px;
}
.sku-text {
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sku-search-btn {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  line-height: 1;
  font-size: 0.85rem;
}
.sku-search-btn:hover {
  border-color: var(--accent);
  background: #ecfdf5;
}
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}
.badge.ok { background: #d1fae5; color: var(--ok); }
.badge.bad { background: #fee2e2; color: var(--danger); }
.title { font-weight: 650; }
.cell-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 650;
}
.cell-link:hover { text-decoration: underline; }
.id-link { font-weight: 600; font-size: 0.86rem; }
.file { font-family: Consolas, monospace; font-size: 0.84rem; }
.file-link {
  font-family: Consolas, monospace;
  font-size: 0.84rem;
  font-weight: 600;
  word-break: break-all;
}
.empty td { text-align: center; color: var(--muted); padding: 28px; }

.log-wrap h2 { margin: 0; }
.log-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.log-tools {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.log-stat {
  font-size: 0.82rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: #f5f5f4;
}
.log-stat.ok { color: var(--ok); background: #d1fae5; }
.log-stat.err { color: var(--danger); background: #fee2e2; }
.log-stat.info { color: #334155; background: #e2e8f0; }
.log-filters { display: flex; gap: 4px; }
.log-filter.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.stop-btn {
  min-width: 72px;
}
.stop-btn:disabled {
  opacity: 0.4;
}
.log-stream {
  margin: 0;
  background: #1c1917;
  color: #f5f5f4;
  border-radius: 12px;
  padding: 10px;
  min-height: 180px;
  max-height: 360px;
  overflow: auto;
  font-size: 0.84rem;
  font-family: Consolas, "Courier New", monospace;
}
.log-line {
  display: grid;
  grid-template-columns: 78px 72px 1fr;
  gap: 8px;
  padding: 5px 6px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.log-line.hidden-log { display: none; }
.log-time { color: #a8a29e; }
.log-lvl {
  font-weight: 700;
  letter-spacing: 0.04em;
}
.log-line.success .log-lvl,
.log-line.success .log-msg { color: #6ee7b7; }
.log-line.error .log-lvl,
.log-line.error .log-msg { color: #fca5a5; }
.log-line.warn .log-lvl,
.log-line.warn .log-msg { color: #fcd34d; }
.log-line.info .log-lvl { color: #93c5fd; }
.log-msg { white-space: pre-wrap; word-break: break-word; }

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  max-width: min(520px, calc(100vw - 24px));
  width: calc(100% - 24px);
  box-shadow: var(--shadow);
}
.confirm { padding: 20px; }
.confirm p { white-space: pre-wrap; }
.confirm .actions { justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

.image-preview-dialog {
  max-width: min(96vw, 1100px);
  width: auto;
  padding: 0;
  border: none;
  background: transparent;
}
.image-preview-dialog::backdrop {
  background: rgba(28, 25, 23, 0.72);
}
.image-preview {
  position: relative;
  background: #0c0a09;
  border-radius: 16px;
  padding: 12px;
  box-shadow: var(--shadow);
  max-width: min(96vw, 1100px);
}
.zoom-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.zoom-toolbar button {
  min-width: 42px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  border-color: rgba(255,255,255,0.2);
}
.zoom-tip {
  color: #a8a29e;
  font-size: 0.78rem;
  margin-left: 8px;
}
.zoom-viewport {
  width: min(92vw, 1040px);
  height: min(72vh, 720px);
  overflow: hidden;
  border-radius: 10px;
  background: #1c1917;
  cursor: grab;
  position: relative;
  touch-action: none;
}
.zoom-viewport.is-panning {
  cursor: grabbing;
}
.zoom-viewport img {
  display: block;
  max-width: none;
  max-height: none;
  width: auto;
  height: auto;
  transform-origin: center center;
  user-select: none;
  -webkit-user-drag: none;
  position: absolute;
  left: 50%;
  top: 50%;
  will-change: transform;
}
.preview-caption {
  color: #e7e5e4;
  text-align: center;
  margin-top: 10px;
  font-size: 0.9rem;
  padding: 0 8px;
  word-break: break-word;
}
.preview-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: none;
  background: rgba(255,255,255,0.14);
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}

/* —— Login (self-contained; avoids shared .panel/.field quirks) —— */
.login-body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  min-height: 100dvh;
}
.login-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  margin: 0;
  padding: 28px 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.login-brand {
  text-align: center;
}
.login-brand h1 {
  margin: 0 0 8px;
  font-size: clamp(1.2rem, 4vw, 1.45rem);
  line-height: 1.25;
  letter-spacing: -0.02em;
}
.login-brand .sub {
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
}
.login-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fff7ed;
  color: var(--warn);
  font-weight: 600;
  font-size: 0.9rem;
  text-align: center;
}
.login-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  min-width: 0;
}
.login-field label {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}
.login-field input {
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 0;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
  line-height: 1.3;
  background: #fff;
  color: var(--ink);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}
.login-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}
.login-submit {
  width: 100%;
  margin: 0;
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 12px 16px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-size: 1rem;
  font-weight: 650;
  cursor: pointer;
}
.login-submit:hover {
  filter: brightness(1.05);
}
.login-submit:active {
  filter: brightness(0.96);
}
.logout-link {
  display: inline-block;
  margin-top: 8px;
  color: var(--accent);
  font-weight: 650;
  text-decoration: none;
}
.logout-link:hover { text-decoration: underline; }

/* —— Tablet —— */
@media (max-width: 900px) {
  body { padding: 16px; }
  .top { flex-direction: column; }
  .status { text-align: left; }
  .summary { grid-template-columns: 1fr 1fr; }
  .field.grow { min-width: 100%; flex: 1 1 100%; }
  .controls .actions {
    width: 100%;
  }
  .controls .actions button {
    flex: 1 1 auto;
  }
}

/* —— Phone —— */
@media (max-width: 720px) {
  body { padding: 12px; }
  .top, .panel { padding: 14px 14px; border-radius: 12px; }
  h1 { font-size: 1.25rem; }
  .sub { font-size: 0.88rem; }

  .controls {
    flex-direction: column;
    align-items: stretch;
  }
  .field,
  .field.grow {
    min-width: 0;
    width: 100%;
  }
  .controls .actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .controls .actions button {
    width: 100%;
  }

  .summary {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    font-size: 0.9rem;
  }

  .table-tools {
    flex-direction: column;
    align-items: stretch;
  }
  .table-tools label { white-space: normal; }
  .table-tools input[type="search"] {
    width: 100%;
    min-width: 0;
    font-size: 16px;
  }

  /* Card rows instead of wide table */
  .table-wrap {
    overflow: visible;
    padding-left: 14px;
    padding-right: 14px;
  }
  .table-wrap table,
  .table-wrap thead,
  .table-wrap tbody,
  .table-wrap th,
  .table-wrap td,
  .table-wrap tr {
    display: block;
    width: 100%;
  }
  .table-wrap thead { display: none; }
  .table-wrap tbody {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
  .table-wrap tr {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
    margin: 0;
  }
  .table-wrap tr.empty {
    text-align: center;
    padding: 20px 12px;
  }
  .table-wrap tr.empty td {
    border: none;
    padding: 0;
    display: block;
  }
  .table-wrap tr.empty td::before { display: none; }
  .table-wrap td {
    display: grid;
    grid-template-columns: 88px 1fr;
    gap: 8px;
    align-items: start;
    border-bottom: 1px solid var(--line);
    padding: 8px 0;
    font-size: 0.9rem;
  }
  .table-wrap td:last-child { border-bottom: none; padding-bottom: 0; }
  .table-wrap td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding-top: 2px;
  }
  .table-wrap td[data-label=""] {
    grid-template-columns: 1fr;
  }
  .table-wrap td[data-label=""]::before { display: none; }
  .table-wrap td.cell-check {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-top: 0;
    border-bottom: none;
  }
  .table-wrap td.cell-check::before {
    content: "Select";
    display: inline;
    text-transform: none;
    font-size: 0.9rem;
    color: var(--ink);
    letter-spacing: 0;
    font-weight: 600;
  }
  .table-wrap td.cell-media {
    grid-template-columns: 88px 1fr;
  }
  .table-wrap .thumb-btn,
  .table-wrap .converted-btn {
    align-items: flex-start;
  }
  .sku-row { max-width: 100%; }

  .log-line {
    grid-template-columns: 64px 56px 1fr;
    gap: 4px;
    font-size: 0.78rem;
  }
  .log-stream {
    max-height: 280px;
    min-height: 140px;
  }
  .zoom-viewport {
    width: min(94vw, 1040px);
    height: min(58vh, 520px);
  }
  .zoom-tip { display: none; }
  .compare-nav button {
    flex: 1 1 auto;
    min-width: 120px;
  }
}

@media (max-width: 420px) {
  .summary { grid-template-columns: 1fr; }
  .login-shell { padding: 16px 12px; }
  .login-card { padding: 22px 16px; }
}
