/* NS · Ткани — менеджер v2. Светлая тема, фиолетовый акцент, выровненная сетка. */
:root {
  --bg: #f6f5f9;
  --card: #ffffff;
  --line: #e9e7f0;
  --line-strong: #dcd9e8;
  --text: #211d2e;
  --muted: #7d7889;
  --accent: #7c3aed;
  --accent-strong: #6d28d9;
  --accent-soft: #f2ecfe;
  --danger: #d92d20;
  --danger-soft: #fdecea;
  --ok: #178a50;
  --ok-soft: #e5f6ec;
  --warn: #b45309;
  --warn-soft: #fdf1df;
  --radius: 14px;
  --shadow: 0 12px 32px rgba(33, 29, 46, .12);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15.5px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
#app { min-height: 100vh; display: flex; flex-direction: column; }
.boot { display: flex; align-items: center; justify-content: center; min-height: 60vh; color: var(--muted); }
svg { flex: none; }

/* ---------- шапка ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(255, 255, 255, .96); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar-static { position: static; }
.topbar-in {
  max-width: 1060px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 16px;
  padding-top: calc(8px + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; min-height: 44px; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 9px; color: #fff;
  background: linear-gradient(135deg, #8b5cf6, var(--accent-strong));
  font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.brand-name { font-weight: 700; letter-spacing: .2px; }
.brand-sub { display: block; font-size: 12px; font-weight: 500; color: var(--muted); line-height: 1.1; }
.topbar-user { display: flex; align-items: center; gap: 6px; min-width: 0; }
.topbar-name {
  font-size: 13.5px; color: var(--muted); max-width: 32vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.icon-btn {
  width: 42px; height: 42px; border: none; border-radius: 10px;
  background: transparent; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: none;
}
.topbar .icon-btn:hover { background: #f2f0f7; color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; }

/* ---------- обёртки ---------- */
main.wrap { width: 100%; max-width: 1060px; margin: 0 auto; padding: 16px 16px 48px; flex: 1; }
main.wrap-ed { width: 100%; max-width: 880px; margin: 0 auto; padding: 0 16px 130px; flex: 1; }

/* ---------- список ---------- */
.search-row { display: flex; gap: 10px; margin-bottom: 6px; }
.search-box { flex: 1; position: relative; min-width: 0; }
.search-box svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-box input {
  width: 100%; height: 48px; padding: 0 14px 0 42px;
  border: 1px solid var(--line-strong); border-radius: 12px;
  background: #fff; font-size: 16px; color: var(--text);
}
.search-box input::placeholder { color: #a49eb2; }
.search-box input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.list-meta { color: var(--muted); font-size: 13.5px; margin: 10px 2px; min-height: 18px; display: flex; justify-content: space-between; gap: 10px; }
.list-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.list-card {
  display: flex; gap: 12px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; text-decoration: none; color: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.list-card:hover { border-color: #c9b8f5; box-shadow: 0 4px 16px rgba(124, 58, 237, .08); }
.row-thumb {
  width: 62px; height: 62px; border-radius: 10px; object-fit: cover;
  background: #f1eff6; flex: none; display: inline-flex; align-items: center; justify-content: center;
  color: #b6b0c4;
}
.row-thumb-empty { border: 1px solid var(--line); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.row-title { font-weight: 700; font-size: 16px; }
.row-sub { color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.row-price { text-align: right; white-space: nowrap; font-weight: 700; font-size: 15.5px; font-variant-numeric: tabular-nums; }
.row-price s { display: block; color: var(--muted); font-weight: 500; font-size: 12.5px; }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; padding: 3px 9px; border-radius: 99px; font-weight: 600;
}
.badge-dot::before { content: ''; width: 6px; height: 6px; border-radius: 99px; background: currentColor; }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-off { background: var(--danger-soft); color: var(--danger); }
.b-sold { background: #edeaf4; color: #5f5a75; }
.b-hidden { background: #f1eff6; color: #8b869c; }
.b-new { background: var(--accent-soft); color: var(--accent-strong); }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 18px 0 6px; color: var(--muted); font-size: 14px; }
.pager .icon-btn { color: var(--text); border: 1px solid var(--line-strong); background: #fff; }
.pager .icon-btn:hover { background: #f6f4fb; }
.pager .icon-btn:disabled { color: #b6b0c4; background: #fff; }
.empty { text-align: center; color: var(--muted); padding: 56px 16px; }
.empty-error { color: var(--danger); }
.empty-actions { text-align: center; padding-bottom: 32px; }
.skeleton-row {
  height: 86px; border-radius: var(--radius); margin-bottom: 10px;
  background: linear-gradient(90deg, #edeaf3, #f5f3f9, #edeaf3);
  background-size: 200% 100%; animation: sk 1.2s infinite;
}
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 12px;
  border: 1px solid var(--line-strong); background: #fff; color: var(--text);
  font-size: 15.5px; font-weight: 600; cursor: pointer; text-decoration: none;
  font-family: inherit; transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-primary:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.btn-sm { min-height: 40px; padding: 6px 16px; border-radius: 10px; font-size: 14.5px; }
.btn-block { width: 100%; }
.btn-danger-ghost { color: var(--danger); border-color: #f2c9c4; flex: none; width: 48px; padding: 10px 0; }
.btn-danger-ghost:not(:disabled):hover { background: var(--danger-soft); }
.btn-dashed {
  width: 100%; border: 1.5px dashed #c9b8f5; background: #fbfaff; color: var(--accent-strong);
  min-height: 44px; font-weight: 600;
}
.btn-dashed:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- карточка/поля ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin-bottom: 14px; }
.card h2 {
  font-size: 12px; margin: 0 0 14px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .8px; font-weight: 700;
  display: flex; align-items: baseline; gap: 8px;
}
.h2-sub { text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 12px; color: #a49eb2; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
.field { margin-bottom: 14px; position: relative; min-width: 0; }
.grid2 .field { margin-bottom: 0; }
.card .grid2 { margin-bottom: 14px; }
.card .grid2:last-child { margin-bottom: 0; }
.field > label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field > label em {
  font-style: normal; font-weight: 600; font-size: 11px; color: var(--accent-strong);
  background: var(--accent-soft); border-radius: 99px; padding: 2px 8px; margin-left: 6px;
  vertical-align: 1px;
}
.field input, .field textarea {
  width: 100%; min-height: 46px; padding: 10px 13px; border: 1px solid var(--line-strong); border-radius: 10px;
  font-size: 16px; background: #fff; color: var(--text); font-family: inherit;
}
.field input::placeholder, .field textarea::placeholder { color: #a49eb2; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field textarea { min-height: 110px; resize: vertical; }
.hint { font-size: 13px; color: var(--muted); margin: 0 0 14px; line-height: 1.5; }
.hint-error { color: var(--danger); font-weight: 600; }
.form-error {
  background: var(--danger-soft); color: var(--danger); border: 1px solid #f2c9c4;
  padding: 10px 14px; border-radius: 10px; margin: 12px 0; font-size: 14.5px; font-weight: 500;
}

/* ---------- ошибка «выбери из списка» ---------- */
.field-invalid input, .field-invalid .chips { border-color: var(--danger) !important; box-shadow: 0 0 0 3px var(--danger-soft) !important; }
.field-invalid { animation: shake .3s; }
.field-invalid::after {
  content: 'Выбери значение из списка';
  position: absolute; left: 2px; bottom: -17px;
  font-size: 12px; font-weight: 600; color: var(--danger); pointer-events: none;
}
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* ---------- шапка редактора ---------- */
.ed-bar {
  position: sticky; top: 0; z-index: 15;
  background: rgba(255, 255, 255, .96); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  margin: 0 -16px 16px;
}
.ed-bar-in {
  max-width: 880px; margin: 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.ed-back {
  display: inline-flex; align-items: center; gap: 2px; min-height: 44px;
  color: var(--muted); text-decoration: none; font-size: 14.5px; font-weight: 600; flex: none;
}
.ed-back:hover { color: var(--text); }
.ed-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.ed-label { color: var(--muted); font-size: 13.5px; }
.ed-title b { font-size: 16.5px; word-break: break-word; }
.site-link { color: var(--accent-strong); font-size: 13.5px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.site-link:hover { text-decoration: underline; }
.ed-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.ed-actions .icon-btn { color: var(--danger); }
.ed-actions .icon-btn:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- автодополнение ---------- */
.suggest-box {
  position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px; z-index: 40;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 242px; overflow-y: auto; overflow-anchor: none;
}
.suggest-item {
  display: block; width: 100%; text-align: left; padding: 11px 14px;
  border: none; background: none; font-size: 15px; color: var(--text); cursor: pointer; font-family: inherit;
}
.suggest-item + .suggest-item { border-top: 1px solid #f2f0f7; }
.suggest-item.active, .suggest-item:hover { background: var(--accent-soft); }

/* ---------- чипсы (мультивыбор) ---------- */
.chips {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 7px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: #fff;
  min-height: 46px;
}
.chips .chips-input {
  flex: 1; min-width: 120px; border: none; outline: none;
  font-size: 16px; padding: 6px; background: transparent; color: var(--text); font-family: inherit;
}
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--accent-soft); color: var(--accent-strong);
  border-radius: 99px; padding: 4px 6px 4px 11px; font-size: 14px; font-weight: 600;
}
.chip-x { border: none; background: none; color: inherit; cursor: pointer; display: inline-flex; padding: 3px; border-radius: 99px; }
.chip-x:hover { background: rgba(0, 0, 0, .08); }

/* ---------- состав: строки материал + процент ---------- */
.comp-row { display: grid; grid-template-columns: 1fr 104px 38px; gap: 8px; margin-bottom: 8px; }
.comp-mat { position: relative; min-width: 0; }
.comp-mat input, .comp-pct input {
  width: 100%; min-height: 46px; padding: 10px 13px; border: 1px solid var(--line-strong); border-radius: 10px;
  font-size: 16px; background: #fff; color: var(--text); font-family: inherit;
}
.comp-mat input:focus, .comp-pct input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.comp-pct { position: relative; }
.comp-pct input { padding-right: 30px; text-align: right; }
.comp-pct span {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  color: #a49eb2; font-size: 15px; pointer-events: none;
}
.comp-x {
  width: 38px; height: 46px; border: none; border-radius: 10px; background: transparent;
  color: #a49eb2; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.comp-x:hover { background: var(--danger-soft); color: var(--danger); }
.comp-sum { font-size: 13px; font-weight: 600; color: var(--muted); min-height: 18px; margin: 2px 2px 10px; }
.comp-sum.bad { color: var(--danger); }

/* ---------- переключатели ---------- */
.flags-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.switch-card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: #f8f7fb; border: 1px solid #efedf5; border-radius: 12px;
  padding: 10px 14px; min-height: 52px; cursor: pointer; font-size: 15px; font-weight: 600;
}
.switch-card input { display: none; }
.switch-sub { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }
.switch { width: 46px; height: 28px; border-radius: 99px; background: #d9d5e3; position: relative; transition: .18s; flex: none; }
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 99px; background: #fff; transition: .18s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
}
.switch-card input:checked + .switch { background: var(--accent); }
.switch-card input:checked + .switch::after { left: 21px; }

/* ---------- фото ---------- */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(98px, 1fr)); gap: 10px; }
.ph { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: #f1eff6; border: 1px solid var(--line); }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph-tag {
  position: absolute; left: 6px; top: 6px; z-index: 2;
  background: var(--accent); color: #fff; font-size: 10.5px; font-weight: 700;
  padding: 3px 8px; border-radius: 99px; letter-spacing: .3px;
}
.ph-btn {
  position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; z-index: 2;
  border: none; border-radius: 99px; background: rgba(33, 29, 46, .65); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.ph-btn:hover { background: rgba(33, 29, 46, .85); }
.ph-nav { position: absolute; bottom: 6px; left: 6px; z-index: 2; display: flex; gap: 4px; }
.ph-nav button {
  width: 28px; height: 28px; border: none; border-radius: 8px;
  background: rgba(255, 255, 255, .92); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  font-size: 15px; font-weight: 700; padding: 0;
}
.ph-nav button:hover { background: #fff; color: var(--accent-strong); }
.ph-add {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); cursor: pointer; border: 1.5px dashed #cfc9de; font-size: 13px; font-weight: 600;
  background: #fbfaff; border-radius: 12px;
}
.ph-add span small { display: block; font-weight: 500; color: #a49eb2; }
.ph-add:hover { border-color: var(--accent); color: var(--accent-strong); }
.card-photos.dragging .ph-add, .card-photos.dragging { border-color: var(--accent); }
.card-photos.dragging { box-shadow: 0 0 0 3px var(--accent-soft); }
.ph-busy { display: flex; align-items: center; justify-content: center; }
.ph-pending { opacity: .85; }
.ph-broken img { display: none; }
.ph-broken::before {
  content: 'нет файла'; position: absolute; inset: 0; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px;
}
.spin {
  width: 22px; height: 22px; border-radius: 99px;
  border: 3px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- нижняя панель сохранения (мобильная) ---------- */
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: rgba(255, 255, 255, .96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.savebar-in { display: flex; gap: 10px; width: 100%; max-width: 880px; margin: 0 auto; }
.savebar .btn-primary { flex: 1; }
.savebar .btn-danger-ghost { flex: none; width: 48px; padding: 10px 0; }

/* ---------- вход ---------- */
.center-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 390px; text-align: center; padding: 28px 24px; }
.login-card .logo {
  width: 56px; height: 56px; border-radius: 14px; color: #fff;
  background: linear-gradient(135deg, #8b5cf6, var(--accent-strong));
  font-size: 26px; font-weight: 700; display: flex; align-items: center; justify-content: center; margin: 0 auto 14px;
}
.login-card h1 { margin: 0; font-size: 21px; }
.login-card .muted { color: var(--muted); margin: 4px 0 20px; font-size: 14px; }
.login-card .field { text-align: left; }

/* ---------- тосты ---------- */
#toasts {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 100;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: 92vw;
}
.toast {
  background: #2c2839; color: #fff; padding: 11px 18px; border-radius: 99px;
  font-size: 14.5px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
  transition: .25s; max-width: 92vw;
}
.toast-ok { background: var(--ok); }
.toast-err { background: var(--danger); }
.toast-warn { background: var(--warn); }
.toast.out { opacity: 0; transform: translateY(6px); }

/* ---------- адаптив ---------- */
@media (min-width: 760px) {
  .list-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .card { padding: 20px; }
}
@media (min-width: 760px) {
  .savebar { display: none; }
  main.wrap-ed { padding-bottom: 48px; }
}
@media (max-width: 759px) {
  .ed-actions .btn-sm, .ed-actions .icon-btn { display: none; }
  .ed-back span { display: none; }
}
@media (max-width: 480px) {
  .grid2 { grid-template-columns: 1fr; gap: 0; }
  .card .grid2 .field, .grid2 .field { margin-bottom: 14px; }
  .flags-grid { grid-template-columns: 1fr; }
  .btn-add-label span.txt { display: none; }
  .comp-row { grid-template-columns: 1fr 92px 38px; }
}
