/* ===== Дизайн-токены ===== */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e3e6eb;
  --border-strong: #d2d7df;
  --text: #1a1f2b;
  --muted: #6b7280;
  --muted-2: #9aa1ad;
  --accent: #2f5bd6;
  --accent-hover: #2749ac;
  --accent-soft: #eaf0fd;
  --danger: #d64545;
  --danger-soft: #fbeaea;
  --ok: #237a4b;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --shadow-lg: 0 10px 30px rgba(16,24,40,.12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, "Liberation Mono", monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--text); background: var(--bg);
  font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased;
}
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0; }
h3 { font-size: 13px; margin: 0 0 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.sm { font-size: 12px; }
.strong { font-weight: 600; }
.mono { font-family: var(--mono); font-size: 12px; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ===== Каркас ===== */
.app { display: grid; grid-template-columns: 248px 1fr; height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 14px;
}
.brand { display: flex; gap: 11px; align-items: center; padding: 4px 6px 20px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 9px; flex: none;
  background: linear-gradient(145deg, var(--accent), #4b73e6);
  color: #fff; font-weight: 700; font-size: 13px; letter-spacing: .02em;
  display: grid; place-items: center;
}
.brand-name { font-weight: 650; font-size: 14px; letter-spacing: -.01em; }
.brand-sub { font-size: 11.5px; color: var(--muted-2); }

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 11px; border: none; background: transparent; cursor: pointer;
  border-radius: var(--radius-sm); font: inherit; color: var(--muted); text-align: left;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-ic { font-size: 15px; width: 18px; text-align: center; opacity: .9; }

.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding-top: 16px; border-top: 1px solid var(--border); }
.side-foot-title { font-size: 11px; color: var(--muted-2); margin-bottom: 4px; padding: 0 2px; }

.main { overflow: hidden; display: flex; }
#view { flex: 1; overflow-y: auto; padding: 28px 32px 60px; }

/* ===== Заголовки страниц ===== */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; gap: 16px; }
.page-head p { margin: 4px 0 0; }
.head-actions { display: flex; gap: 8px; flex: none; }
.empty-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ===== Кнопки ===== */
.btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
  transition: background .12s, border-color .12s, box-shadow .12s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted-2); }
.btn svg { width: 16px; height: 16px; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: var(--shadow); }
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--sm { padding: 6px 11px; font-size: 13px; }
.btn--sm svg { width: 15px; height: 15px; }
.btn--ghost { border-color: transparent; background: var(--surface-2); color: var(--muted); justify-content: center; }
.btn--ghost:hover { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.icon-btn {
  display: inline-grid; place-items: center; width: 30px; height: 30px; cursor: pointer;
  border: 1px solid transparent; background: transparent; border-radius: var(--radius-sm); color: var(--muted);
  transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn svg { width: 17px; height: 17px; }

/* ===== Карточки и таблицы ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card.pad { padding: 20px; }

.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 600; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr[data-open] { cursor: pointer; transition: background .1s; }
.table tbody tr[data-open]:hover { background: var(--accent-soft); }
.table td.pad { padding: 28px; }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; }
.table tfoot td { padding: 12px 16px; border-top: 2px solid var(--border); background: var(--surface-2); }

/* ===== Пустые состояния ===== */
.empty { text-align: center; padding: 70px 20px; max-width: 420px; margin: 40px auto; }
.empty-ic { width: 56px; height: 56px; margin: 0 auto 18px; color: var(--muted-2); }
.empty-ic svg { width: 100%; height: 100%; }
.empty h2 { margin-bottom: 8px; }
.empty p { margin: 0 0 22px; }

/* ===== Документ: шапка и вкладки ===== */
.doc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 16px; }
.doc-head-l { display: flex; align-items: center; gap: 12px; }
.doc-head-r { display: flex; gap: 8px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 22px; }
.tab {
  padding: 10px 16px; border: none; background: transparent; cursor: pointer; font: inherit;
  color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 8px; transition: color .12s, border-color .12s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.badge { background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 20px; }

/* ===== Формы ===== */
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; align-items: start; }
.fields { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 14px; }
.fields--inline { display: flex; gap: 14px; }
.fld { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.fld--wide { grid-column: 1 / -1; }
.fld > span { font-size: 12px; color: var(--muted); font-weight: 500; }
.input {
  width: 100%; padding: 8px 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font: inherit; font-size: 13.5px; background: var(--surface); color: var(--text); transition: border-color .12s, box-shadow .12s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { resize: vertical; line-height: 1.4; }
select.input { cursor: pointer; }
.chk { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text); cursor: pointer; padding: 6px 0; }
.chk input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ===== Таблица товаров ===== */
.items-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.items-toolbar-r { display: flex; gap: 8px; flex: none; }
.items td { padding: 6px 10px; }
.items th { padding: 10px; }
.cell {
  width: 100%; padding: 6px 9px; border: 1px solid transparent; border-radius: 6px;
  font: inherit; font-size: 13.5px; background: transparent; color: var(--text);
}
.cell:hover { border-color: var(--border); }
.cell:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }
.cell.right { text-align: right; }
.w-kol { width: 130px; }
.more-row.hidden { display: none; }
.more-row > td { background: var(--surface-2); }
.more-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 14px; padding: 6px 4px 12px; }
.mini { display: flex; flex-direction: column; gap: 4px; }
.mini > span { font-size: 11px; color: var(--muted); }
.mini em { font-style: normal; font-size: 10.5px; }

/* ===== XML ===== */
.xml-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.xml-head-r { display: flex; gap: 8px; }
.xml-view {
  margin: 0; padding: 16px 18px; background: #0f1523; color: #d7e0f0; border-radius: var(--radius);
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55; overflow-x: auto; white-space: pre;
  max-height: 62vh; overflow-y: auto; border: 1px solid #1c2536;
}

/* ===== Модалка ===== */
.dlg { border: none; border-radius: var(--radius); padding: 0; box-shadow: var(--shadow-lg); width: min(560px, 92vw); background: var(--surface); color: var(--text); }
.dlg::backdrop { background: rgba(16,24,40,.45); backdrop-filter: blur(2px); }
.dlg-form { padding: 24px; }
.dlg-form h2 { margin-bottom: 18px; }
.dlg-form .fields { margin-bottom: 20px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ===== Тосты ===== */
.toasts { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  background: var(--text); color: #fff; padding: 11px 16px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); font-size: 13.5px; font-weight: 500; opacity: 0; transform: translateY(8px);
  animation: toastIn .22s forwards;
}
.toast--err { background: var(--danger); }
.toast--out { animation: toastOut .3s forwards; }
@keyframes toastIn { to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

/* ===== Адаптив ===== */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; align-items: center; padding: 10px 14px; overflow-x: auto; }
  .brand { padding: 0 12px 0 0; }
  .brand-sub { display: none; }
  .nav { flex-direction: row; margin: 0; }
  .side-foot { display: none; }
  #view { padding: 18px 16px 48px; }
  .grid2 { grid-template-columns: 1fr; }
  .fields { grid-template-columns: 1fr; }
  .more-grid { grid-template-columns: repeat(2, 1fr); }
}
