:root {
  --bg: #f6f5f3;
  --surface: #ffffff;
  --border: #e6e3de;
  --text: #201d1a;
  --muted: #83786c;
  --accent: #b5522a;
  --accent-hover: #9c4522;
  --accent-soft: #fbeee7;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --success: #2f7d4f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(32, 29, 26, 0.04), 0 8px 24px rgba(32, 29, 26, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 10px; }
.brand-badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 6px;
  letter-spacing: 0.02em;
}
.topbar-right { margin-left: auto; }
.status-text { color: var(--muted); font-size: 12.5px; }

.screen { flex: 1; padding: 28px 24px 60px; max-width: 1120px; width: 100%; margin: 0 auto; }
.hidden { display: none !important; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel { padding: 24px; margin-bottom: 20px; }

h1 { font-size: 19px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 14px; }
h3 { font-size: 16px; margin: 0 0 6px; }
.muted { color: var(--muted); font-size: 13px; margin: 0 0 18px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field-label-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.field-label-row label { font-size: 12.5px; font-weight: 600; color: var(--muted); }

input[type="text"], input[type="number"], textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: #fffefd;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
input:focus, textarea:focus { border-color: var(--accent); }
input:disabled, textarea:disabled { opacity: 0.6; cursor: not-allowed; }
textarea { resize: vertical; line-height: 1.5; }

.spinner {
  display: inline-block; width: 13px; height: 13px; margin-left: 4px;
  border: 2px solid var(--accent-soft); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.input-with-suffix { position: relative; }
.input-with-suffix input { padding-right: 34px; }
.input-with-suffix .suffix {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 13px; pointer-events: none;
}
/* Валюта цены — выпадающий список прямо в поле: и WB, и Ozon принимают цену в
   валюте кабинета продавца, поэтому её выбирают, а не пересчитывают. */
.input-with-suffix .suffix-select {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: auto; padding: 2px 4px; border: none; background: transparent;
  color: var(--muted); font-size: 14px; cursor: pointer;
}

.hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
.counter { font-size: 12px; color: var(--muted); }
.counter.over { color: #c0392b; font-weight: 600; }

.target-picker { display: flex; gap: 10px; flex-wrap: wrap; }
.target-option {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 8px 14px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); font-size: 13.5px;
}
.target-option:has(input:checked) { border-color: var(--accent); color: var(--text); }

.publish-tabs { display: flex; gap: 8px; margin: 18px 0 -8px; }
.publish-tab {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  border-radius: 10px 10px 0 0; padding: 9px 18px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.publish-tab.active { background: var(--card); color: var(--text); border-bottom-color: var(--card); }

/* Метка способа сборки карточки: «фото товара» — товар вклеен из реального
   снимка, «сценка» — картинку целиком рисовала модель, её стоит проверить. */
.card-render-badge {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: rgba(255, 255, 255, 0.92); color: #2f6b3f;
}
.card-render-badge.scene { color: #8a5a20; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s, border-color 0.15s;
  font-family: inherit;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: #f1efeb; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid transparent; }
.btn-ghost:hover:not(:disabled) { background: #f1efeb; color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #f9dcd9; }
.btn-lg { width: 100%; padding: 13px; font-size: 14.5px; }
.btn-sm { padding: 6px 10px; font-size: 12px; }

.error-text { color: var(--danger); font-size: 13px; margin: 12px 0 0; }

.progress-log {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px; color: var(--muted); max-height: 260px; overflow-y: auto;
}
.progress-log .line { display: flex; gap: 8px; align-items: baseline; }
.progress-log .line::before { content: "›"; color: var(--accent); font-weight: 700; }
.progress-log .line.done { color: var(--success); }
.progress-log .line.error { color: var(--danger); }

.history-section h2 { margin-bottom: 0; }
.history-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.history-controls { display: flex; gap: 8px; }
.history-search, .history-sort {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 13px;
  font-family: inherit; background: #fffefd; color: var(--text); outline: none; transition: border-color 0.15s;
}
.history-search { min-width: 220px; }
.history-search:focus, .history-sort:focus { border-color: var(--accent); }
.history-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.history-item {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; box-shadow: var(--shadow); transition: transform 0.1s;
}
.history-item:hover { transform: translateY(-2px); }
.history-delete {
  position: absolute; top: 8px; right: 8px; width: 24px; height: 24px; border-radius: 50%;
  background: rgba(32,29,26,0.65); color: #fff; border: none; font-size: 16px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.15s, background 0.15s;
}
.history-item:hover .history-delete { opacity: 1; }
.history-delete:hover { background: var(--danger); }
.history-thumb { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; background: #efece7; display: block; }
.history-body { padding: 12px 14px; }
.history-title { font-size: 13px; font-weight: 600; line-height: 1.35; margin-bottom: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.history-meta { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }

.source-badge {
  display: inline-flex; align-items: center; font-size: 10.5px; font-weight: 700;
  padding: 2px 7px; border-radius: 6px; letter-spacing: 0.03em; text-transform: uppercase;
  background: var(--accent-soft); color: var(--accent-hover);
}

.preview-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 49px; z-index: 9;
}
.spacer { flex: 1; }
.save-state { font-size: 12.5px; color: var(--muted); }
.save-state.dirty { color: var(--accent); font-weight: 600; }

.preview-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 860px) { .preview-layout { grid-template-columns: 1fr; } }

.char-table { display: flex; flex-direction: column; gap: 8px; }
.char-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: center; }
.char-row input { padding: 8px 10px; font-size: 13px; }
.char-remove { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 16px; padding: 4px 8px; }
.char-remove:hover { color: var(--danger); }

.gallery-panel { position: sticky; top: 100px; }
.card-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.card-item {
  position: relative; border-radius: 12px; overflow: hidden; border: 1px solid var(--border);
  background: #efece7; cursor: grab; aspect-ratio: 3 / 4;
}
.card-item.dragging { opacity: 0.4; }
.card-item.drag-over { outline: 2px solid var(--accent); outline-offset: -2px; }
.card-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-role-badge {
  position: absolute; top: 8px; left: 8px; background: rgba(32,29,26,0.7); color: #fff;
  font-size: 10.5px; font-weight: 600; padding: 3px 7px; border-radius: 6px; letter-spacing: 0.03em;
}
.card-order-badge {
  position: absolute; top: 8px; right: 8px; background: rgba(32,29,26,0.7); color: #fff;
  font-size: 11px; font-weight: 700; width: 20px; height: 20px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.card-actions {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 4px; padding: 6px;
  background: linear-gradient(to top, rgba(0,0,0,0.55), transparent);
  opacity: 0; transition: opacity 0.15s;
}
.card-item:hover .card-actions { opacity: 1; }
.card-actions button {
  flex: 1; background: rgba(255,255,255,0.92); border: none; border-radius: 7px;
  font-size: 10.5px; font-weight: 600; padding: 5px 2px; cursor: pointer; color: var(--text);
}
.card-actions button:hover { background: #fff; }
.card-actions .card-delete { color: var(--danger); }

.card-drop-hint {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  text-align: center; padding: 10px; background: rgba(181,82,42,0.88); color: #fff;
  font-size: 12px; font-weight: 600; line-height: 1.4;
}
.card-item.drag-over .card-drop-hint { display: flex; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(32,29,26,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: var(--surface); border-radius: var(--radius); padding: 22px; width: 460px;
  max-width: calc(100vw - 40px); box-shadow: var(--shadow);
}
.modal textarea { margin-top: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 13px; box-shadow: var(--shadow); z-index: 60;
}
.toast.error { background: var(--danger); }

/* ---------- Wildberries: публикация ---------- */

.wb-panel { margin-top: 4px; }
.wb-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.wb-header h2 { margin-bottom: 2px; }
.wb-header .muted { margin: 0; }
.wb-header-actions { flex-shrink: 0; }

.wb-token-banner, .wb-published-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 16px;
}
.wb-token-banner { background: var(--danger-soft); color: var(--danger); }
.wb-published-banner { background: #e8f4ec; color: var(--success); font-weight: 600; }

.wb-grid { display: grid; grid-template-columns: 1fr 300px; gap: 24px; align-items: start; }
@media (max-width: 980px) { .wb-grid { grid-template-columns: 1fr; } }

.wb-section-label { margin-top: 18px; }

.wb-category-search { position: relative; }
.wb-category-results {
  position: absolute; z-index: 5; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); max-height: 260px; overflow-y: auto;
}
.wb-category-result {
  padding: 9px 12px; font-size: 13px; cursor: pointer; border-bottom: 1px solid var(--border);
}
.wb-category-result:last-child { border-bottom: none; }
.wb-category-result:hover { background: var(--accent-soft); }
.wb-category-result .parent { color: var(--muted); font-size: 11.5px; }
.wb-category-selected {
  margin-top: 8px; display: flex; align-items: center; gap: 8px;
  font-size: 13px; padding: 8px 12px; background: var(--accent-soft); color: var(--accent-hover);
  border-radius: 10px; font-weight: 600;
}

.input-with-button { display: flex; gap: 8px; }
.input-with-button input { flex: 1; }

.wb-checkbox {
  display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text);
  margin: 16px 0 4px; cursor: pointer;
}
.wb-checkbox input { width: 16px; height: 16px; }

.wb-dimensions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 640px) { .wb-dimensions { grid-template-columns: repeat(2, 1fr); } }

.wb-characteristics { display: flex; flex-direction: column; gap: 10px; }
.wb-char-field label { display: flex; gap: 6px; align-items: baseline; }
.wb-char-field .req { color: var(--accent); }
.wb-char-field .unit { color: var(--muted); font-weight: 400; }

.wb-side { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 100px; }
.wb-checklist { display: flex; flex-direction: column; gap: 7px; padding: 14px; background: #faf9f7; border: 1px solid var(--border); border-radius: 12px; }
.wb-check { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.wb-check .icon { flex-shrink: 0; width: 16px; text-align: center; }
.wb-check.ok { color: var(--muted); }
.wb-check.ok .icon { color: var(--success); }
.wb-check.warn { color: var(--text); font-weight: 600; }
.wb-check.warn .icon { color: var(--accent); }

.wb-progress-log { max-height: 180px; }
.wb-success { color: var(--success); font-size: 13px; margin: 0; }

/* ---------- вход, аккаунт, режим просмотра ---------- */

.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; margin: 0; }
.login-brand { margin-bottom: 10px; }
.login-card .btn-lg { margin-top: 4px; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.user-login { font-size: 12.5px; font-weight: 600; color: var(--muted); }

.view-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--border);
  color: var(--accent-hover);
  font-size: 13px;
  font-weight: 600;
}
.view-banner .btn { margin-left: auto; }
/* В режиме просмотра сервер всё равно запретит запись — прячем то, что
   заведомо приведёт к ошибке, чтобы админ не жал кнопки впустую. */
body.view-mode #startBtn,
body.view-mode #saveBtn,
body.view-mode #revertBtn,
body.view-mode #addCharBtn,
body.view-mode #wbPublishBtn,
body.view-mode #wbSettingsBtn { display: none; }

/* ---------- админка ---------- */

.admin-table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0 10px 8px;
  white-space: nowrap;
}
.admin-table td { padding: 10px; border-top: 1px solid var(--border); vertical-align: top; white-space: nowrap; }
.admin-table tr.row-blocked { opacity: 0.55; }
.admin-table .cell-details { white-space: normal; max-width: 320px; color: var(--muted); }
.user-cell { display: flex; align-items: center; gap: 6px; }
.muted-inline { color: var(--muted); font-size: 12px; }
.row-actions { display: flex; gap: 4px; }

.tag { font-size: 10.5px; font-weight: 700; padding: 2px 6px; border-radius: 5px; text-transform: uppercase; }
.tag-admin { background: var(--accent-soft); color: var(--accent); }
.tag-blocked { background: var(--danger-soft); color: var(--danger); }

.admin-form { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.admin-form .field { margin-bottom: 0; min-width: 200px; flex: 1; }
.admin-form .btn { height: 38px; }

.daily-chart { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: 8px; }
.daily-bar { flex: 1; min-width: 8px; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.daily-bar-fill { background: var(--accent); border-radius: 4px 4px 0 0; min-height: 3px; }
.daily-bar-label { font-size: 9.5px; color: var(--muted); text-align: center; margin-top: 4px; transform: rotate(-45deg); }
