:root {
  --primary: #16a34a;
  --primary-dark: #15803d;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #0891b2;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Topbar === */
.topbar { background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow); }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 16px; height: 56px; }
.brand { font-weight: 700; font-size: 1.05rem; color: var(--text); white-space: nowrap; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 8px 12px; border-radius: 6px; color: var(--muted); font-size: .92rem; }
.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a.active { background: var(--primary); color: #fff; }
.userbox { display: flex; align-items: center; gap: 12px; }
.user { font-size: .9rem; color: var(--muted); }
.btn-logout { color: var(--danger); font-size: .9rem; }

.container { max-width: 1280px; margin: 0 auto; padding: 24px 16px 60px; }

/* === Buttons === */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border: 1px solid var(--border); background: var(--card); border-radius: var(--radius); cursor: pointer; font-size: .92rem; color: var(--text); }
.btn:hover { background: var(--bg); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-sm { padding: 4px 8px; font-size: .82rem; }
.btn-block { width: 100%; justify-content: center; }

/* === Forms === */
label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: .9rem; }
label > span { font-weight: 500; color: var(--muted); }
input, select, textarea { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: .95rem; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
input:disabled, textarea:disabled { background: #f8fafc; color: var(--muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* === Alerts === */
.alert { padding: 10px 14px; border-radius: var(--radius); margin: 12px 0; font-size: .9rem; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-info { background: #e0f2fe; color: #155e75; border: 1px solid #7dd3fc; }

/* === Login === */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #2563eb, #0891b2); }
.login-card { background: #fff; padding: 36px; border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.2); width: 360px; max-width: 92vw; }
.login-card h1 { margin: 0 0 4px; font-size: 1.4rem; }
.login-subtitle { color: var(--muted); margin: 0 0 20px; }
.login-hint { text-align: center; color: var(--muted); font-size: .82rem; margin-top: 16px; }

/* === Cards / stats === */
.stats-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin: 20px 0; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; box-shadow: var(--shadow); }
.stat-num { font-size: 1.8rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }
.stat-draft .stat-num { color: var(--muted); }
.stat-ready .stat-num { color: var(--primary); }
.stat-active .stat-num { color: var(--success); }
.stat-sent .stat-num { color: #7c3aed; }

/* === API status === */
.api-status-card { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin: 16px 0; }
.status-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.status-pending { background: var(--warning); animation: pulse 1.2s infinite; }
.status-ok { background: var(--success); }
.status-error { background: var(--danger); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* === Dashboard layout === */
.dash-row { display: grid; grid-template-columns: 1fr 2fr; gap: 16px; margin-top: 20px; }
.dash-col { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.sync-card .sync-label { color: var(--muted); font-size: .85rem; }
.sync-date { font-size: 1.1rem; font-weight: 600; margin: 4px 0 12px; }

/* === Tables === */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.table th { background: #f8fafc; font-weight: 600; color: var(--muted); }
.log-table td, .log-table th { font-size: .82rem; }
.thumb { width: 50px; height: 50px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.thumb-lg { width: 80px; height: 80px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }

/* === Badges === */
.badge { padding: 2px 8px; border-radius: 12px; font-size: .76rem; font-weight: 600; text-transform: lowercase; }
.badge-draft { background: #e2e8f0; color: #475569; }
.badge-ready { background: #dbeafe; color: #1d4ed8; }
.badge-active { background: #dcfce7; color: #166534; }
.badge-sent { background: #ede9fe; color: #6d28d9; }

/* === Products list === */
.filter-bar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filter-bar input, .filter-bar select { width: auto; }
.bulk-actions { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.products-table .name-cell a { font-weight: 500; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }

/* === Pagination === */
.pagination { display: flex; gap: 4px; justify-content: center; margin-top: 16px; }
.pagination a { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; color: var(--text); }
.pagination a:hover { background: var(--bg); text-decoration: none; }
.pagination a.cur { background: var(--primary); color: #fff; border-color: var(--primary); }

/* === Taobao search grid === */
.search-form { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 20px; }
.taobao-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.taobao-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.taobao-card img { width: 100%; height: 140px; object-fit: cover; border-radius: 6px; background: var(--bg); }
.taobao-card h3 { margin: 0; font-size: .9rem; }
.taobao-cat { color: var(--muted); font-size: .8rem; }
.taobao-price { font-weight: 700; color: var(--danger); }
.taobao-id { font-size: .76rem; color: var(--muted); }
.add-btn { margin-top: auto; }

/* === Product edit === */
.breadcrumbs { font-size: .85rem; color: var(--muted); margin-bottom: 16px; }
.edit-layout { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.edit-col-left, .edit-col-right { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.translate-row { display: flex; gap: 6px; align-items: center; margin-bottom: 12px; }
.translate-row select { width: auto; }
.label-span { font-weight: 500; color: var(--muted); font-size: .9rem; display: block; margin-bottom: 6px; }
.images-grid { display: flex; gap: 8px; flex-wrap: wrap; }
.features-table { font-size: .85rem; }
.edit-actions { display: flex; gap: 8px; align-items: center; margin-top: 20px; flex-wrap: wrap; }

/* Блок цены */
.price-block { background: #f8fafc; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.price-convert { display: flex; align-items: center; gap: 8px; margin: 8px 0; padding: 8px 10px; background: #fff; border-radius: 6px; border: 1px dashed var(--border); }
.convert-arrow { font-size: 1.1rem; color: var(--primary); }
.convert-line { font-size: .92rem; }
.convert-line code, .price-listprice code, .price-block code { background: #e0f2fe; padding: 1px 5px; border-radius: 4px; font-size: .82rem; }
.price-listprice { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 8px 0; font-size: .9rem; padding: 8px 10px; background: #fff; border-radius: 6px; border: 1px solid #86efac; }
.price-listprice strong { color: var(--success); font-size: 1.05rem; }
#btnRecalc { margin-top: 4px; }

/* === Дерево категорий (выбор только дочерних категорий) === */
.cat-picker { position: relative; }
.cat-selected-box {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 38px; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); cursor: pointer;
}
.cat-selected-box:hover { border-color: var(--primary); }
.cat-placeholder { color: var(--muted); font-size: .9rem; }
.cat-picker-arrow { color: var(--muted); font-size: .8rem; flex-shrink: 0; }
.cat-chip {
  display: inline-flex; align-items: center; gap: 8px; background: #eff6ff; color: var(--primary-dark);
  border: 1px solid #bfdbfe; border-radius: 6px; padding: 4px 8px; font-size: .88rem;
}
.cat-chip-remove {
  color: var(--danger); font-weight: 700; cursor: pointer; line-height: 1; padding: 0 2px;
}
.cat-chip-remove:hover { color: #991b1b; }

.cat-dropdown-panel {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 20;
  max-height: 320px; overflow-y: auto; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px;
}
.cat-dropdown-panel.open { display: block; }

.cat-tree, .cat-tree ul.cat-children { list-style: none; margin: 0; padding: 0; }
.cat-tree ul.cat-children { padding-left: 18px; display: none; }
.cat-node.expanded > ul.cat-children { display: block; }

.cat-row { display: flex; align-items: center; gap: 6px; padding: 5px 6px; border-radius: 6px; }
.cat-row-parent { cursor: pointer; }
.cat-row-parent:hover { background: var(--bg); }
.cat-toggle { width: 14px; flex-shrink: 0; color: var(--muted); font-size: .72rem; transition: transform .15s; }
.cat-node.expanded > .cat-row-parent .cat-toggle { transform: rotate(90deg); }
.cat-toggle-spacer { width: 14px; flex-shrink: 0; }
.cat-parent-label { font-weight: 600; color: var(--text); font-size: .9rem; }
.cat-leaf-label {
  font-size: .88rem; color: var(--text); cursor: pointer; padding: 2px 6px; border-radius: 4px;
}
.cat-leaf-label:hover { background: #dbeafe; color: var(--primary-dark); }
.cat-hint { margin-top: 4px; }

/* === Settings === */
.settings-layout { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; background: var(--card); }
legend { font-weight: 600; padding: 0 8px; color: var(--primary); }
.settings-actions { display: flex; gap: 8px; }
.check-panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; height: fit-content; }

/* === Modal === */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal-box { background: #fff; border-radius: 12px; padding: 24px; width: 360px; max-width: 92vw; max-height: 88vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal-box-lg { width: 640px; max-width: 95vw; }
.modal-box h3 { margin-top: 0; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* === Превью товара === */
.preview-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.preview-header h3 { margin: 0; font-size: 1.1rem; flex: 1; word-break: break-word; }
.preview-close { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--muted); padding: 0; line-height: 1; }
.preview-close:hover { color: var(--danger); }
.preview-body { display: flex; flex-direction: column; gap: 16px; }
.preview-meta { background: #f8fafc; border-radius: var(--radius); padding: 12px; }
.preview-meta-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.preview-meta-row:last-child { margin-bottom: 0; }
.price-cny { color: var(--danger); font-size: 1.05rem; }
.preview-section h4 { margin: 0 0 8px; font-size: .9rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.preview-desc { line-height: 1.6; font-size: .92rem; white-space: pre-wrap; }
.preview-images { display: flex; gap: 8px; flex-wrap: wrap; }
.sku-table { font-size: .85rem; }
.sku-table .sku-key { color: var(--muted); font-weight: 500; width: 40%; }
.sku-table .sku-val { font-weight: 500; }
.preview-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.taobao-card-actions { display: flex; gap: 6px; margin-top: auto; }
.taobao-card .preview-trigger { cursor: pointer; }
.taobao-card img.preview-trigger:hover { opacity: .85; }
.taobao-card-added { border-color: #86efac; background: #f0fdf4; }
.taobao-card-added .taobao-id::before { content: '✔ '; color: var(--success); }

.footer { text-align: center; padding: 20px; color: var(--muted); border-top: 1px solid var(--border); background: var(--card); }

/* === Responsive === */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-row, .edit-layout, .settings-layout { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .nav { flex-wrap: wrap; }
  .topbar-inner { flex-wrap: wrap; height: auto; padding: 8px 12px; }
}
/* --- Блок ТН ВЭД (product_edit) --- */
.tnved-block { margin-bottom: 16px; }
.tnved-selected {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; margin-bottom: 6px;
  background: #f5f7fa; border: 1px solid #d7dde3; border-radius: 6px;
}
.tnved-selected .tnved-code { font-weight: 600; font-family: monospace; }
.tnved-selected .tnved-name { color: #555; font-size: 13px; flex: 1; }
.tnved-clear { cursor: pointer; color: #999; font-size: 18px; line-height: 1; padding: 0 4px; }
.tnved-clear:hover { color: #d33; }
.tnved-search { position: relative; }
.tnved-search input { width: 100%; }
.tnved-results {
  list-style: none; margin: 2px 0 0; padding: 0;
  position: absolute; left: 0; right: 0; z-index: 30;
  background: #fff; border: 1px solid #d7dde3; border-radius: 6px;
  max-height: 280px; overflow-y: auto; display: none;
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
}
.tnved-results.open { display: block; }
.tnved-results li { padding: 7px 10px; cursor: pointer; border-bottom: 1px solid #eee; font-size: 13px; }
.tnved-results li:last-child { border-bottom: none; }
.tnved-results li:hover { background: #eef4ff; }
.tnved-results .tnved-code { font-family: monospace; font-weight: 600; margin-right: 6px; }
.tnved-results .tnved-name { color: #555; }

/* Фикс ховера цветных кнопок: раньше .btn:hover делал фон светлым, а текст оставался белым */
.btn-danger:hover  { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.btn-success:hover { background: #15803d; border-color: #15803d; color: #fff; }

/* =====================================================================
   Освежение интерфейса (WinRace): шапка, кнопки, иконки, карточки
   ===================================================================== */
:root { --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 12px rgba(16,24,40,.05); --brand: #16a34a; --brand-dark:#15803d; }

body { background: #f6f8f7; }

/* Шапка */
.topbar { background: #fff; border-bottom: 1px solid #e6ebe8; box-shadow: 0 1px 0 rgba(16,24,40,.03); }
.topbar-inner { height: 62px; gap: 20px; }
.brand { display: inline-flex; align-items: center; gap: 11px; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  background: linear-gradient(135deg, #16a34a, #22c55e);
  color: #fff; font-weight: 800; font-size: .95rem; letter-spacing: .5px;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 8px rgba(22,163,74,.28);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text b { font-size: 1.08rem; color: #0f172a; font-weight: 700; }
.brand-text small { font-size: .7rem; color: #94a3b8; font-weight: 500; letter-spacing: .3px; }
.nav a { font-weight: 500; border-radius: 8px; transition: background .15s, color .15s; }
.nav a.active { background: var(--brand); color: #fff; box-shadow: 0 2px 6px rgba(22,163,74,.25); }
.nav a:hover:not(.active) { background: #eef6f1; color: var(--brand-dark); }

/* Кнопки — мягче и с переходами */
.btn { border-radius: 9px; font-weight: 500; transition: background .15s, border-color .15s, box-shadow .15s, transform .05s; }
.btn:active { transform: translateY(1px); }
.btn-primary { box-shadow: 0 2px 6px rgba(22,163,74,.22); }
.btn-primary:hover { box-shadow: 0 3px 10px rgba(22,163,74,.3); }

/* Квадратные иконки-кнопки (под фото и т.п.) — ровные и одинаковые */
.photo-actions { display: flex; gap: 5px; justify-content: center; margin-top: 2px; }
.icon-btn {
  width: 32px; height: 32px; padding: 0; border: 1px solid #e2e8f0; background: #fff;
  border-radius: 8px; cursor: pointer; color: #64748b; font-size: .85rem; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; transition: all .15s;
}
.icon-btn:hover { background: var(--brand); color: #fff; border-color: var(--brand); transform: translateY(-1px); box-shadow: 0 3px 8px rgba(22,163,74,.25); }
.icon-btn.danger:hover { background: var(--danger); border-color: var(--danger); box-shadow: 0 3px 8px rgba(220,38,38,.25); }

/* Карточки/панели чуть премиальнее */
.card, .panel, .stat-card, .edit-col-left, .edit-col-right { border-radius: 12px; }
.thumb-lg { border-radius: 10px !important; box-shadow: 0 2px 6px rgba(16,24,40,.1); }
