/* MAVIKO PIM — дизайн-система.
   Правила: системный шрифт; веса только 400/500/600; оранжевый — акцент
   (основная кнопка, активный пункт меню, ссылки), а не фон; плотные таблицы
   для работы с номенклатурой; статусы — цветными метками (.badge). */

:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #f6f6f7;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --surface-hover: #f7f7f8;
  --border: #e7e7ea;
  --border-strong: #d6d6db;

  --text: #18181b;
  --text-2: #3f3f46;
  --muted: #71717a;
  --faint: #a1a1aa;

  --brand: #f07800;
  --brand-hover: #d96c00;
  --brand-soft: #fff4e6;
  --brand-text: #b45309;

  --success: #15803d;   --success-soft: #ecfdf3;  --success-border: #bbf0cf;
  --warning: #b45309;   --warning-soft: #fffaeb;  --warning-border: #fde2a8;
  --danger:  #dc2626;   --danger-soft:  #fef2f2;  --danger-border:  #fecaca;
  --info:    #2563eb;   --info-soft:    #eff6ff;  --info-border:    #c7dbfe;

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .12);
  --focus: 0 0 0 3px rgba(240, 120, 0, .18);

  --sidebar-w: 232px;
  --control-h: 34px;
}

/* --- База ----------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  font-weight: 400;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
h1 { font-size: 22px; line-height: 1.3; }
h2 { font-size: 16px; line-height: 1.4; }
h3 { font-size: 14px; line-height: 1.4; }
p { margin: 0; }
a { color: var(--brand-text); text-decoration: none; }
a:hover { color: var(--brand-hover); text-decoration: underline; text-underline-offset: 2px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
small, .small { font-size: 12px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* --- Макет ---------------------------------------------------------------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: var(--text); }
.sidebar-brand:hover { text-decoration: none; color: var(--text); }
.logo-mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: var(--brand); color: #fff;
  display: grid; place-items: center;
  font-weight: 600; font-size: 13px; letter-spacing: .02em;
}
.brand-name { font-weight: 600; font-size: 14px; line-height: 1.2; }
.brand-sub { font-size: 12px; color: var(--muted); line-height: 1.2; }
.nav { padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-section { padding: 14px 10px 6px; font-size: 11.5px; font-weight: 500; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: var(--radius);
  color: var(--text-2); font-weight: 500; font-size: 14px;
}
.nav-link:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--brand-soft); color: var(--brand-text); }
.nav-link .icon { color: var(--faint); }
.nav-link.active .icon { color: var(--brand); }
.sidebar-footer { margin-top: auto; padding: 12px 14px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  background: #f1f1f3; color: var(--text-2);
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
}
.user-meta { min-width: 0; flex: 1; }
.user-name { font-weight: 500; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 12px; color: var(--muted); }

.main { flex: 1; min-width: 0; }
.content { max-width: 1320px; margin: 0 auto; padding: 24px 32px 48px; }
.content.narrow { max-width: 880px; }

.icon { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-lg { width: 20px; height: 20px; }

/* --- Заголовок страницы ----------------------------------------------------- */
.breadcrumbs { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.breadcrumbs a { color: var(--muted); }
.breadcrumbs a:hover { color: var(--text); }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-header .subtitle { margin-top: 4px; color: var(--muted); font-size: 13.5px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* --- Карточки и секции ------------------------------------------------------ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card + .card, .stack > * + * { margin-top: 16px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-header .hint { font-size: 12.5px; color: var(--muted); }
.card-body { padding: 16px 18px; }
.card-footer { padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-2 > .card + .card, .grid-3 > .card + .card { margin-top: 0; }

/* Показатели сверху страницы */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 12px 14px; }
.stat-label { font-size: 12.5px; color: var(--muted); }
.stat-value { font-size: 20px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
a.stat { color: var(--text); }
a.stat:hover { border-color: var(--border-strong); text-decoration: none; color: var(--text); }

/* --- Кнопки ------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--control-h); padding: 0 12px;
  border-radius: var(--radius); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text-2);
  font: 500 13.5px/1 var(--font); white-space: nowrap;
  cursor: pointer; text-decoration: none; box-shadow: var(--shadow-sm);
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
}
.btn:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; border-color: #c9c9cf; }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-hover); border-color: transparent; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger); }
.btn-success { color: var(--success); }
.btn-success:hover { background: var(--success-soft); border-color: var(--success-border); color: var(--success); }
.btn-sm { height: 28px; padding: 0 9px; font-size: 12.5px; border-radius: var(--radius-sm); }
.btn-icon { width: var(--control-h); padding: 0; }
.btn-sm.btn-icon { width: 28px; }
.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }

/* --- Формы ---------------------------------------------------------------- */
.input, .select, .textarea,
input[type="text"], input[type="search"], input[type="number"], input[type="password"], input[type="email"], select, textarea {
  height: var(--control-h); padding: 0 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: 400 13.5px/1.2 var(--font);
  box-shadow: var(--shadow-sm);
  transition: border-color .12s, box-shadow .12s;
  min-width: 0;
}
textarea, .textarea { height: auto; min-height: 90px; padding: 8px 10px; line-height: 1.45; resize: vertical; }
select, .select {
  appearance: none; -webkit-appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
input::placeholder, textarea::placeholder { color: var(--faint); }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; margin: 0; accent-color: var(--brand); cursor: pointer; flex: none; }
input[type="file"] { font: inherit; font-size: 13px; }
.input-sm, select.input-sm { height: 28px; font-size: 12.5px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .label { font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.field .help { font-size: 12px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; color: var(--text-2); cursor: pointer; user-select: none; }
.w-full { width: 100%; }
.grow { flex: 1 1 220px; }

/* Строка фильтров над таблицей */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.filters .search { position: relative; flex: 1 1 280px; }
.filters .search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.filters .search input { width: 100%; padding-left: 32px; }
.filters .spacer { flex: 1; }
.toggle-chip {
  display: inline-flex; align-items: center; gap: 7px; height: var(--control-h); padding: 0 10px;
  border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--text-2);
  font-size: 13px; cursor: pointer; user-select: none; background: var(--surface);
}
.toggle-chip:has(input:checked) { border-style: solid; border-color: var(--brand); background: var(--brand-soft); color: var(--brand-text); }

/* --- Таблицы -------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.table th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); color: var(--muted);
  font-weight: 500; font-size: 12.5px; text-align: left; white-space: nowrap;
  padding: 9px 12px; border-bottom: 1px solid var(--border);
}
.table th a { color: var(--muted); }
.table th a:hover, .table th a.sorted { color: var(--text); text-decoration: none; }
.table td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-hover); }
.table tbody tr.selected td { background: var(--brand-soft); }
.table th.num { text-align: right; }
.table .col-check { width: 36px; padding-right: 0; }
.table .col-actions { width: 1%; white-space: nowrap; text-align: right; }
.table td.cell-main a { color: var(--text); font-weight: 500; }
.table td.cell-main a:hover { color: var(--brand-text); }
.table .sub { display: block; font-size: 12px; color: var(--muted); margin-top: 1px; }
.table-compact td, .table-compact th { padding: 7px 10px; }
.card > .table-wrap:first-child .table th:first-child { border-top-left-radius: var(--radius-lg); }
.card > .table-wrap:first-child .table th:last-child { border-top-right-radius: var(--radius-lg); }
tr.row-warning td:first-child { box-shadow: inset 3px 0 0 var(--warning); }
tr.row-danger td:first-child { box-shadow: inset 3px 0 0 var(--danger); }

/* --- Метки ---------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
  background: #f1f1f3; color: var(--text-2); border: 1px solid #e4e4e7;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .75; }
.badge.plain::before { display: none; }
.badge-success { background: var(--success-soft); color: var(--success); border-color: var(--success-border); }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: var(--warning-border); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger);  border-color: var(--danger-border); }
.badge-info    { background: var(--info-soft);    color: var(--info);    border-color: var(--info-border); }
.badge-brand   { background: var(--brand-soft);   color: var(--brand-text); border-color: #fbd9b0; }

/* Заполненность: число + тонкая полоска */
.progress { display: inline-flex; align-items: center; gap: 8px; min-width: 110px; }
.progress-bar { flex: 1; height: 6px; border-radius: 999px; background: #ededf0; overflow: hidden; min-width: 50px; }
.progress-bar > span { display: block; height: 100%; background: var(--success); border-radius: inherit; }
.progress.partial .progress-bar > span { background: var(--brand); }
.progress.empty .progress-bar > span { background: var(--danger); }
.progress-value { font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* --- Сообщения ------------------------------------------------------------ */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: var(--radius); border: 1px solid; font-size: 13.5px; margin-bottom: 16px; }
.alert .icon { margin-top: 2px; }
.alert-error   { background: var(--danger-soft);  border-color: var(--danger-border);  color: #991b1b; }
.alert-success { background: var(--success-soft); border-color: var(--success-border); color: #166534; }
.alert-info    { background: var(--info-soft);    border-color: var(--info-border);    color: #1e40af; }
.alert-warning { background: var(--warning-soft); border-color: var(--warning-border); color: #92400e; }
.secret { font-family: var(--mono); font-size: 14px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 2px 8px; user-select: all; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .icon { width: 28px; height: 28px; color: var(--faint); margin-bottom: 8px; }
.empty-title { color: var(--text-2); font-weight: 500; margin-bottom: 2px; }

/* Всплывающее уведомление (app.js → toast) */
.toast-host { position: fixed; right: 20px; bottom: 20px; z-index: 50; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #18181b; color: #fff; padding: 10px 14px; border-radius: var(--radius); box-shadow: var(--shadow-lg); font-size: 13.5px; max-width: 420px; animation: toast-in .16s ease-out; }
.toast.error { background: #991b1b; }
.toast.success { background: #166534; }
@keyframes toast-in { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }

/* --- Панель массовых действий (появляется при выделении строк) ---------- */
.bulkbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 14px; background: #fffaf3; border-bottom: 1px solid #fbe3c4;
}
.bulkbar .count { font-weight: 500; margin-right: 6px; }
.bulkbar .sep { width: 1px; height: 20px; background: #f3d3aa; margin: 0 4px; }

/* --- Постраничность ------------------------------------------------------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.pagination .pages { display: flex; gap: 4px; }

/* --- Вкладки -------------------------------------------------------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { padding: 8px 12px; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--text); border-bottom-color: var(--brand); }
.tab .count { margin-left: 6px; font-size: 12px; color: var(--faint); }

/* Список «название — значение» */
.meta-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px 24px; margin: 0; }
.meta-grid dt { font-size: 12.5px; color: var(--muted); margin-bottom: 2px; }
.meta-grid dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }

/* Дерево (категории) */
.tree { list-style: none; margin: 0; padding: 0; }
.tree .tree { padding-left: 22px; border-left: 1px dashed var(--border-strong); margin-left: 9px; }
.tree-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--radius-sm); }
.tree-item:hover { background: var(--surface-hover); }
.tree-item .actions { margin-left: auto; display: flex; gap: 4px; opacity: 0; transition: opacity .12s; }
.tree-item:hover .actions, .tree-item:focus-within .actions { opacity: 1; }

/* Диалог (нативный <dialog>) */
dialog { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 0; box-shadow: var(--shadow-lg); width: min(520px, calc(100vw - 32px)); color: var(--text); }
dialog::backdrop { background: rgba(24, 24, 27, .35); }
dialog .card-header { border-bottom: 1px solid var(--border); }

/* Шаги (загрузка файла) */
.steps { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.step { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.step .n { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--border-strong); font-size: 12px; font-weight: 500; background: var(--surface); }
.step.active { color: var(--text); }
.step.active .n { background: var(--brand); border-color: var(--brand); color: #fff; }
.step.done .n { background: var(--success-soft); border-color: var(--success-border); color: var(--success); }
.step + .step::before { content: ""; width: 24px; height: 1px; background: var(--border-strong); }

/* Зона загрузки файла */
.dropzone { border: 1.5px dashed var(--border-strong); border-radius: var(--radius-lg); padding: 28px; text-align: center; background: var(--surface-2); color: var(--muted); cursor: pointer; transition: border-color .12s, background .12s; }
.dropzone:hover, .dropzone.dragover { border-color: var(--brand); background: var(--brand-soft); }
.dropzone .file-name { color: var(--text); font-weight: 500; margin-top: 6px; }

/* --- Вход ----------------------------------------------------------------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(380px, 100%); }
.auth-card .card-body { padding: 24px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }

/* --- Адаптивность --------------------------------------------------------- */
@media (max-width: 960px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
  .sidebar-brand { padding: 10px 14px; }
  .brand-sub, .brand-name, .nav-section { display: none; }
  .nav-link { white-space: nowrap; }
  .nav { flex-direction: row; padding: 6px; }
  .sidebar-footer { margin-top: 0; margin-left: auto; border-top: 0; }
  .user-meta { display: none; }
  .content { padding: 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
