:root {
  --bg: #0f1420;
  --bg-2: #161d2e;
  --panel: #1b2436;
  --panel-2: #212c42;
  --line: #2b3650;
  --text: #e8edf7;
  --muted: #93a0bd;
  --accent: #5b8cff;
  --accent-2: #38d39f;
  --warn: #ffb454;
  --danger: #ff6b6b;
  --good: #38d39f;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
a { color: var(--accent); }

#app { display: grid; grid-template-columns: 256px 1fr; height: 100vh; }

/* Sidebar */
.sidebar { background: linear-gradient(180deg,#141b2b,#0d1320); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 14px; }
.brand { display: flex; gap: 12px; align-items: center; padding: 6px 8px 18px; }
.brand-mark { width: 40px; height: 40px; border-radius: 12px; background: linear-gradient(135deg,var(--accent),var(--accent-2)); display: grid; place-items: center; font-weight: 800; font-size: 22px; color: #07101f; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 17px; }
.brand-text span { font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.nav button { display: flex; align-items: center; gap: 12px; background: transparent; border: 0; color: var(--muted); padding: 11px 12px; border-radius: 10px; cursor: pointer; font-size: 14.5px; text-align: left; transition: .15s; }
.nav button .ico { width: 20px; text-align: center; }
.nav button:hover { background: var(--panel); color: var(--text); }
.nav button.active { background: var(--panel-2); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-footer { margin-top: auto; display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); padding: 10px 8px 2px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--good); box-shadow: 0 0 8px var(--good); }
.dot.err { background: var(--danger); }

/* Content */
.content { display: flex; flex-direction: column; overflow: hidden; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 18px 28px; border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 0; font-size: 22px; }
.view { padding: 24px 28px; overflow-y: auto; }

/* Buttons */
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 9px 14px; border-radius: 10px; cursor: pointer; font-size: 13.5px; transition: .15s; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg,var(--accent),#4a7dff); border-color: transparent; color: #fff; font-weight: 600; }
.btn-accent { background: linear-gradient(135deg,var(--accent-2),#2bbf8e); border-color: transparent; color: #06241a; font-weight: 700; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn-danger { border-color: var(--danger); color: var(--danger); }

/* Cards & grid */
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(190px,1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.kpi { display: flex; flex-direction: column; gap: 6px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 700; }
.kpi .sub { font-size: 12px; color: var(--muted); }

.section-title { font-size: 15px; color: var(--muted); margin: 24px 0 12px; text-transform: uppercase; letter-spacing: .04em; }

/* Chips / filters */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip { border: 1px solid var(--line); background: var(--panel); color: var(--muted); padding: 7px 13px; border-radius: 999px; cursor: pointer; font-size: 13px; }
.chip.active { background: var(--accent); color: #fff; border-color: transparent; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; position: sticky; top: 0; background: var(--panel); }
tr:hover td { background: var(--panel-2); }
.thumb { width: 46px; height: 46px; border-radius: 8px; object-fit: cover; background: var(--panel-2); border: 1px solid var(--line); cursor: zoom-in; display: grid; place-items: center; color: var(--muted); font-size: 11px; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; border: 1px solid var(--line); color: var(--muted); }
.badge.ch { background: var(--bg-2); }
.badge.ok { color: var(--good); border-color: rgba(56,211,159,.4); }
.badge.warn { color: var(--warn); border-color: rgba(255,180,84,.4); }
.badge.err { color: var(--danger); border-color: rgba(255,107,107,.4); }
.badge.live { color: var(--accent-2); border-color: rgba(56,211,159,.4); }
.badge.mock { color: var(--muted); }

/* Order cards */
.orders-grid { grid-template-columns: repeat(auto-fill, minmax(380px,1fr)); }
.order-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.order-lines { margin: 10px 0; }
.order-line { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.breakdown { background: var(--bg-2); border-radius: 10px; padding: 12px; margin: 10px 0; font-size: 12.5px; }
.breakdown .row { display: flex; justify-content: space-between; padding: 3px 0; }
.breakdown .row.total { border-top: 1px solid var(--line); margin-top: 5px; padding-top: 7px; font-weight: 700; }
.margin-pill { font-weight: 700; }
.margin-pos { color: var(--good); }
.margin-neg { color: var(--danger); }
.order-actions { display: flex; gap: 8px; margin-top: 12px; }

/* Forms */
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); }
input, select, textarea { background: var(--bg-2); border: 1px solid var(--line); color: var(--text); padding: 9px 11px; border-radius: 9px; font-size: 13.5px; font-family: inherit; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(150px,1fr)); gap: 12px; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(5,9,16,.7); display: grid; place-items: center; z-index: 50; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: min(680px, 92vw); max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 16px; font-size: 19px; }
.modal-close { float: right; cursor: pointer; color: var(--muted); border: 0; background: transparent; font-size: 20px; }
.img-zoom { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: grid; place-items: center; z-index: 60; cursor: zoom-out; }
.img-zoom img { max-width: 86vw; max-height: 86vh; border-radius: 10px; }

/* Toast */
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--panel-2); border: 1px solid var(--line); padding: 14px 18px; border-radius: 12px; box-shadow: var(--shadow); opacity: 0; transform: translateY(10px); transition: .25s; z-index: 80; max-width: 360px; }
.toast.show { opacity: 1; transform: translateY(0); }
/* Тост не перехватывает касания (он поверх окон: на Android — во всю ширину внизу, над футером
   редактора), а скрытый — не занимает место для попадания (visibility, не только opacity). */
.toast { pointer-events: none; }
.toast:not(.show) { visibility: hidden; }
.toast.ok { border-color: var(--good); }
.toast.err { border-color: var(--danger); }
.toast.warn { border-color: var(--warn); }

/* Misc */
.muted { color: var(--muted); }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.subtabs { display: flex; gap: 6px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.subtabs button { background: transparent; border: 0; color: var(--muted); padding: 10px 16px; cursor: pointer; border-bottom: 2px solid transparent; font-size: 14px; }
.subtabs button.active { color: #fff; border-bottom-color: var(--accent); }
.bar { height: 8px; background: var(--bg-2); border-radius: 6px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg,var(--accent),var(--accent-2)); }
.right { text-align: right; }


/* Product inline editor */
.product-inline-table th,
.product-inline-table td { vertical-align: top; }
.product-inline-table input,
.product-inline-table textarea { width: 100%; min-width: 0; font-size: 12px; padding: 7px 8px; }
.product-inline-table textarea { resize: vertical; }
.editable-product-row td { transition: background .15s ease; }
.inline-status { display: inline-block; max-width: 180px; white-space: normal; }
.product-photo-hover { cursor: zoom-in; }
@media (max-width: 1200px) {
  .product-inline-table { min-width: 1180px; }
  .product-inline-table input,
  .product-inline-table textarea { font-size: 11.5px; }
}


/* Product inline editor usability patch */
.product-inline-table .inline-name,
.product-inline-table .inline-desc {
  white-space: pre-wrap;
  line-height: 1.35;
  overflow-y: auto;
}
.product-inline-table .inline-name { min-height: 110px; }
.product-inline-table .inline-desc { min-height: 180px; }
.product-inline-table .dirty-row td { background: rgba(255, 193, 7, .08); }
.product-inline-table td { padding-top: 12px; padding-bottom: 12px; }


/* Stable product photo hover preview */
.product-photo-hover,
.product-photo-hover:hover {
  transform: none !important;
  position: static !important;
  box-shadow: none !important;
}
.product-photo-preview {
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: rgba(5, 9, 16, .18);
}
.product-photo-preview,
.product-photo-preview * {
  pointer-events: none !important;
}
.product-photo-preview img {
  width: min(460px, 82vw);
  height: min(460px, 82vh);
  object-fit: contain;
  background: #fff;
  border-radius: 16px;
  padding: 10px;
  box-shadow: 0 28px 90px rgba(0,0,0,.55);
}


/* Marketplace sync and characteristics editor */
.product-inline-table .inline-attrs { min-height: 118px; white-space: pre-wrap; line-height: 1.35; }
.product-inline-table .btn { margin: 2px; }

/* Android app shell (native bottom nav, no sidebar) */
body.app-android #app { grid-template-columns: 1fr; height: 100vh; }
body.app-android .sidebar { display: none !important; }
body.app-android .content { min-height: 0; }
body.app-android .topbar { padding: 12px 16px; position: sticky; top: 0; z-index: 5; background: var(--bg); }
body.app-android .topbar h1 { font-size: 18px; }
body.app-android .view { padding: 12px 14px 24px; -webkit-overflow-scrolling: touch; }
body.app-android .toast { left: 16px; right: 16px; bottom: 16px; max-width: none; }
/* Открыто окно — тост сверху, чтобы не закрывать «Сохранить» / «← К товару» в нижнем футере. */
body.app-android:has(#modal-root .modal-overlay) .toast { top: 16px; bottom: auto; }
body.app-android .modal { width: min(680px, 96vw); padding: 16px; }
body.app-android .orders-grid { grid-template-columns: 1fr; }
body.app-android .card { padding: 14px; }
body.app-android .row-between { flex-wrap: wrap; gap: 10px; }
body.app-android .product-inline-table { display: none; }
body.app-android .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
body.app-android .subtabs { overflow-x: auto; flex-wrap: nowrap; }
@media (max-width: 480px) {
  body.app-android .kpis { grid-template-columns: 1fr; }
}

/* Mobile catalog cards */
.catalog-list { display: flex; flex-direction: column; gap: 12px; }
.catalog-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-2);
  overflow: hidden;
}
.catalog-card.dirty-row { box-shadow: inset 0 0 0 1px rgba(255, 193, 7, .35); }
.catalog-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.catalog-card-summary { flex: 1; min-width: 0; }
.catalog-card-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.catalog-card-sku { font-size: 12px; margin-top: 2px; }
.catalog-card-chevron { color: var(--muted); font-size: 18px; padding: 0 4px; }
.catalog-card-body { padding: 0 12px 12px; border-top: 1px solid var(--line); }
.catalog-fold { border: 1px solid var(--line); border-radius: 10px; margin-top: 10px; overflow: hidden; }
.catalog-fold-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.catalog-fold-chevron { color: var(--muted); width: 14px; }
.catalog-fold-body { padding: 10px 12px 12px; }
.catalog-fold-body textarea,
.catalog-fold-body input { width: 100%; min-width: 0; }
.catalog-inline-row { display: grid; grid-template-columns: 1fr; gap: 10px; }
.catalog-dims { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.catalog-card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.catalog-card-actions .btn { flex: 1 1 auto; }
.catalog-mp-out { width: 100%; margin-top: 6px; }
.catalog-price-preview { font-size: 11px; margin-top: 6px; }
.catalog-sentinel { text-align: center; padding: 16px; }
body.app-android .catalog-mobile-shell { padding: 12px; }
@media (max-width: 900px) {
  .catalog-mobile-shell { padding: 12px; }
  .product-inline-table { display: none; }
}
@media (min-width: 901px) {
  .catalog-list { display: none; }
}


.catalog-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.catalog-tabs button {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
}
.catalog-tabs button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.variations-table th,
.variations-table td {
  padding: 6px 8px;
  font-size: 13px;
}

/* Catalog editor: wider name/desc, compact dimensions */
.product-inline-table col.col-photo { width: 56px; }
.product-inline-table col.col-name { width: 20%; }
.product-inline-table col.col-desc { width: 26%; }
.product-inline-table col.col-attrs { width: 14%; }
.product-inline-table col.col-cost { width: 7%; }
.product-inline-table col.col-dims { width: 9%; }
.product-inline-table col.col-margin { width: 6%; }
.product-inline-table col.col-price { width: 8%; }
.product-inline-table col.col-actions { width: 10%; }

.product-inline-table .inline-name { min-height: 110px; rows: 5; }
.product-inline-table .inline-desc { min-height: 180px; }
.product-inline-table .catalog-dims-compact {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  max-width: 120px;
}
.product-inline-table .catalog-dims-compact input {
  padding: 5px 6px;
  font-size: 11px;
}
.product-inline-table .catalog-dims-compact input::placeholder { font-size: 10px; }
.product-inline-table td.catalog-dims-cell { max-width: 130px; }

.catalog-fold-body .inline-name { min-height: 120px; }
.catalog-fold-body .inline-desc { min-height: 200px; }
.catalog-dims-compact-mobile {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.catalog-dims-compact-mobile input { padding: 6px; font-size: 12px; }

/* Редактор вариации */
.variations-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.variation-row { cursor: pointer; }
.variation-row:hover td { background: var(--bg-2); }
.variation-sale { color: var(--accent-2); }
.variation-photo-strip { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.variation-photo-tile { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px; border: 1px solid var(--line); border-radius: 10px; min-width: 84px; }
.variation-photo-tile.main { border-color: var(--accent); }
.variation-photo-tile .thumb { width: 64px; height: 64px; }
.variation-check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.variation-editor .catalog-fold-body input[type=checkbox],
.variation-check input[type=checkbox] { width: auto; min-width: 0; }
.variation-editor .catalog-fold-body select { width: 100%; }
.variation-editor-footer { position: sticky; bottom: -22px; margin: 14px -22px -22px; padding: 12px 22px; background: var(--panel); border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; align-items: center; flex-wrap: wrap; z-index: 2; }
body.app-android .variation-editor-footer { bottom: -16px; margin: 14px -16px -16px; padding: 10px 16px; }
body.app-android .variation-editor-footer .btn { flex: 1 1 auto; }

/* Групповая выгрузка вариаций на Ozon */
.ozon-group-entry { display: flex; justify-content: flex-end; margin: 2px 0 6px; }
.ozon-group-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 4px 14px; font-size: 13px; margin-bottom: 8px; }
.ozon-group-map { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 4px 0; }
.ozon-group-map-label { min-width: 110px; font-size: 13px; }
.variation-editor .ozon-group-map select { flex: 1 1 220px; width: auto; min-width: 0; max-width: 100%; }
.ozon-group-table td { vertical-align: top; }
.ozon-group-name input { min-width: 220px; width: 100%; }
.ozon-group-var { display: flex; gap: 8px; align-items: center; }
.ozon-group-var .thumb { width: 40px; height: 40px; flex: none; }
.ozon-group-issue { font-size: 11.5px; margin-top: 2px; }
.ozon-group-issue.err { color: var(--danger); }
.ozon-group-issue.warn { color: var(--warn); }
.ozon-group-bad td { background: rgba(255, 107, 107, .05); }
.ozon-group-run { margin-top: 12px; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
