* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #f4f6f8;
  color: #1c2430;
}
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: #16233a;
  color: #fff;
  flex-wrap: wrap;
}
header .title { font-size: 18px; font-weight: 600; }
header .meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.badge {
  font-size: 12px;
  background: #2b4a6f;
  padding: 4px 10px;
  border-radius: 12px;
}
.badge.muted { background: #33415c; }
button {
  border: 0;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  background: #2f80ed;
  color: #fff;
}
button:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.5; cursor: default; }
button.muted { background: #55617a; }
.notice {
  margin: 10px 20px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
}
.notice.ok { background: #d9f2e3; color: #14532d; }
.notice.error { background: #fde0e0; color: #7f1d1d; }
.notice.info { background: #e3ecf7; color: #1e3a5f; }
.hidden { display: none !important; }

.table-wrap { overflow-x: auto; margin: 16px 20px; background: #fff; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { border-bottom: 1px solid #e5e9f0; padding: 6px 8px; text-align: right; white-space: nowrap; }
th { background: #f0f3f8; font-weight: 600; position: sticky; top: 0; }
td:first-child, th:first-child { text-align: left; }
td:nth-child(2), td:nth-child(3) { text-align: left; }
tr:hover td { background: #f8fafc; }
.mono { font-family: Consolas, monospace; }
input {
  width: 90px;
  padding: 5px 6px;
  border: 1px solid #ccd4e0;
  border-radius: 5px;
  text-align: right;
  font-size: 13px;
}
input.edited { border-color: #2f80ed; background: #eef5ff; }
td.target-given { background: #fff6e0; }

.skipped { margin: 16px 20px; background: #fff; border-radius: 10px; padding: 12px 16px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.skipped h3 { margin: 0 0 8px; font-size: 15px; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 35, .7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.login-card {
  background: #fff;
  padding: 28px 32px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 280px;
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-card input { width: 100%; padding: 10px; font-size: 15px; }
.error { color: #c0392b; font-size: 13px; }

/* Дашборд и панель фильтров */
.dashboard { margin: 14px 20px 0; display: flex; gap: 12px; flex-wrap: wrap; }
.dash-card { background: #fff; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,.08); padding: 10px 18px; min-width: 130px; }
.dash-value { font-size: 22px; font-weight: 700; }
.dash-label { font-size: 12px; color: #667; }
.toolbar { margin: 12px 20px 0; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.toolbar #search { width: 260px; }
.tabs { display: flex; gap: 6px; }
.tab { background: #eef2f7; color: #33415c; }
.tab.active { background: #2f80ed; color: #fff; }

/* Модуль «Ценообразование» */
.section-title { margin: 20px 20px 8px; font-size: 17px; }
.metrics { margin: 0 20px 16px; display: flex; gap: 8px; flex-wrap: wrap; }
.settings-form { max-width: 760px; }
.settings-block { border: 1px solid #e0e5ee; border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; background: #fafbfd; }
.settings-block summary { cursor: pointer; font-weight: 600; margin-bottom: 6px; }
.settings-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; }
.settings-row label { font-size: 13px; }
.settings-row input[type="text"] { width: 200px; text-align: left; }
a.badge { color: #fff; }

/* Таблицы разбора и лестница спроса */
.explain-table { width: 100%; margin: 10px 0; }
.explain-table td { padding: 5px 8px; border-bottom: 1px solid #eef1f6; }
.demand-table { width: 100%; max-width: 360px; margin-top: 6px; }
.demand-table td { padding: 4px 8px; border-bottom: 1px solid #eef1f6; }
.settings-row select { padding: 6px; border: 1px solid #ccd4e0; border-radius: 5px; }

/* ===== Новый каркас: левое меню ===== */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; min-width: 230px; background: #16233a; color: #dbe4f0;
  padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  box-sizing: border-box;
}
.sidebar .brand { font-size: 15px; font-weight: 700; color: #fff; padding: 4px 10px 14px; }
.sidebar .brand small { display: block; font-weight: 400; color: #7d93b3; font-size: 11px; }
#sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.menu-item {
  display: flex; align-items: center; gap: 10px; color: #c3d0e4;
  text-decoration: none; padding: 9px 10px; border-radius: 8px; font-size: 14px;
}
.menu-item:hover { background: #22345a; color: #fff; }
.menu-item.active { background: #2f80ed; color: #fff; font-weight: 600; }
.menu-icon { width: 20px; text-align: center; }
.menu-item.soon { opacity: 0.75; }
.content { flex: 1; padding: 16px 24px; min-width: 0; box-sizing: border-box; }
.burger { display: none; }

/* Режим работы (СИМУЛЯЦИЯ / УПРАВЛЕНИЕ) */
.mode-banner {
  display: flex; align-items: center; gap: 12px; margin-bottom: 16px;
  padding: 12px 16px; border-radius: 10px; font-size: 14px;
}
.mode-simulation { background: #fff7e0; border: 1px solid #f2d97a; color: #7a5c00; }
.mode-live { background: #d9f2e3; border: 1px solid #7cc9a0; color: #14532d; }
.mode-badge { font-weight: 700; padding: 3px 10px; border-radius: 12px; }
.mode-simulation .mode-badge { background: #f2d97a; }
.mode-live .mode-badge { background: #7cc9a0; }

/* Карточки обзора */
.overview-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.ov-card { background: #fff; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,.08); padding: 12px 14px; }
.ov-card .ov-value { font-size: 22px; font-weight: 700; }
.ov-card .ov-label { font-size: 12px; color: #667; margin-top: 2px; }
.ov-card.warn { border-left: 3px solid #e8a13c; }
.ov-card.bad { border-left: 3px solid #d9534f; }
.ov-card.ok { border-left: 3px solid #4cae6f; }

/* Статусные бейджи */
.badge-status { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.st-increase { background: #d9f2e3; color: #14532d; }
.st-decrease { background: #fde0e0; color: #7f1d1d; }
.st-hold { background: #e8ecf3; color: #33415c; }
.st-clearance { background: #fff3e0; color: #7a4c00; }
.st-oos { background: #fde8d9; color: #8a3c00; }
.st-loss { background: #fadcdc; color: #8f1d1d; }
.st-manual { background: #e3e8f5; color: #2b3a67; }

/* Tooltip-помощь */
.help { cursor: help; display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%; background: #dde5f0; color: #33415c;
  font-size: 11px; font-weight: 700; margin-left: 5px; }
.help-popup { display: none; position: absolute; z-index: 50; background: #fff; border: 1px solid #d0d8e4;
  border-radius: 8px; padding: 10px 12px; width: 280px; box-shadow: 0 4px 14px rgba(0,0,0,.12); font-size: 12px; }
.setting-item { position: relative; }
.setting-item:hover .help-popup { display: block; }

/* Переключатель режимов настроек */
.toggle-basic-advanced { display: flex; gap: 8px; margin: 0 0 14px; }

/* Мобильная версия */
@media (max-width: 900px) {
  .sidebar { position: fixed; left: -240px; transition: left .2s; z-index: 60; }
  .sidebar.open { left: 0; }
  .burger { display: inline-flex; margin-right: 8px; font-size: 20px; background: none; border: 0; color: #1c2430; cursor: pointer; }
  .content { padding: 12px; }
  .app { display: block; }
}

/* --- Блок «Требуют внимания» (обзор) --- */
.attention-list { display: flex; flex-direction: column; gap: 8px; max-width: 900px; }
.attention-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: #fff; border: 1px solid #eef1f6; border-left: 4px solid #667;
  border-radius: 8px; padding: 10px 14px;
}
.attention-item.warn { border-left-color: #e8a13c; }
.attention-item.bad { border-left-color: #d64541; background: #fff7f7; }
.btn-mini {
  display: inline-block; padding: 6px 12px; border-radius: 6px;
  background: #2f80ed; color: #fff !important; font-size: 12px; text-decoration: none;
  white-space: nowrap;
}
.btn-mini:hover { background: #2668c4; }

/* --- Подсказки настроек --- */
.setting-hint { font-size: 12px; color: #667; margin-top: 2px; display: block; }

/* --- Ячейка маржи с редактированием --- */
.margin-cell { cursor: pointer; }
.margin-cell:hover { color: #2f80ed; }
.margin-edit { white-space: nowrap; }

/* ===== Phase 1: read-only repricer dashboard ===== */
.repricer-dashboard { --dash-border: #dfe5ee; --dash-muted: #637083; }
.dashboard-header {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  margin: 0 0 14px; padding: 0; background: transparent; color: inherit;
}
.dashboard-heading { display: flex; align-items: center; gap: 8px; }
.dashboard-heading h1 { margin: 0; font-size: 25px; letter-spacing: .035em; }
.dashboard-updated { margin-top: 4px; color: var(--dash-muted); font-size: 13px; }
.dashboard-refresh { min-width: 146px; }
.button-secondary { background: #e8edf4; color: #28374d; }

.dashboard-message {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  border: 1px solid var(--dash-border); border-radius: 9px; padding: 9px 12px; margin-bottom: 12px; font-size: 13px;
}
.dashboard-message-ok { color: #166534; background: #effaf2; border-color: #b8e1c4; }
.dashboard-message-warn { color: #7a4c00; background: #fff8e6; border-color: #edd48c; }
.dashboard-message-error { color: #8f1d1d; background: #fff1f1; border-color: #efb7b7; }
.dashboard-message-error button { background: #b73333; }

.system-status {
  display: grid; grid-template-columns: repeat(5, minmax(135px, 1fr)); gap: 1px;
  overflow: hidden; margin-bottom: 14px; border: 1px solid var(--dash-border); border-radius: 10px; background: var(--dash-border);
}
.system-status > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 10px 12px; background: #fff; }
.system-status span { color: var(--dash-muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.system-status strong { overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.system-status small { color: #7a8595; font-size: 10px; }
.guard-ok { color: #16723a; }
.guard-bad { color: #a52828; }

.dashboard-kpis { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.dashboard-kpi {
  display: flex; flex-direction: column; min-height: 88px; padding: 12px 14px;
  border: 1px solid var(--dash-border); border-left: 4px solid #8391a5; border-radius: 10px; background: #fff;
  box-shadow: 0 1px 3px rgba(21, 35, 57, .06);
}
.dashboard-kpi span { color: var(--dash-muted); font-size: 12px; }
.dashboard-kpi strong { margin-top: auto; font-size: 22px; line-height: 1.15; }
.dashboard-kpi small { margin-top: 3px; color: #8791a0; font-size: 10px; }
.dashboard-kpi.kpi-good { border-left-color: #3a9b61; }
.dashboard-kpi.kpi-bad { border-left-color: #d14242; }
.dashboard-kpi.kpi-target { border-left-color: #367bd6; }
.dashboard-kpi.kpi-warn { border-left-color: #d99b2b; }
.dashboard-kpi.kpi-muted { background: #f8fafc; border-left-color: #9ba6b5; }
.dashboard-kpi.kpi-muted strong { color: #6f7b8a; font-size: 16px; }
.dashboard-kpi:last-child strong { font-size: 16px; }

.dashboard-controls {
  display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; padding: 12px;
  border: 1px solid var(--dash-border); border-radius: 10px; background: #fff;
}
.dashboard-controls label { display: flex; flex-direction: column; gap: 4px; min-width: 160px; color: var(--dash-muted); font-size: 11px; }
.dashboard-controls .filter-search-label { flex: 1 1 240px; }
.dashboard-controls input, .dashboard-controls select {
  width: 100%; height: 36px; padding: 6px 9px; border: 1px solid #c9d2df; border-radius: 7px;
  background: #fff; color: #1c2430; font-size: 13px; text-align: left;
}
.quick-filters { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; margin: 9px 0 0; }
.quick-filters button { padding: 6px 10px; background: #edf1f6; color: #34445b; font-size: 12px; }
.quick-filters button.active { background: #2f80ed; color: #fff; }
#dashboard-result-count { margin-left: auto; color: var(--dash-muted); font-size: 12px; }

.dashboard-table-wrap { margin: 12px 0 0; overflow-x: auto; border: 1px solid var(--dash-border); box-shadow: none; }
.pricing-table { min-width: 1860px; }
.pricing-table th, .pricing-table td { padding: 8px 9px; vertical-align: top; }
.pricing-table th { z-index: 1; color: #3f4d60; font-size: 11px; text-align: right; }
.pricing-table th:nth-child(2), .pricing-table td:nth-child(2),
.pricing-table th:nth-child(15), .pricing-table td:nth-child(15),
.pricing-table th:nth-child(16), .pricing-table td:nth-child(16) { text-align: left; }
.pricing-table th button { padding: 0; border-radius: 0; background: none; color: inherit; font-size: inherit; font-weight: 600; }
.pricing-table th button::after { content: " ↕"; color: #9aa5b5; }
.pricing-table th button.active[data-direction="asc"]::after { content: " ↑"; color: #2f80ed; }
.pricing-table th button.active[data-direction="desc"]::after { content: " ↓"; color: #2f80ed; }
.pricing-table td:first-child small { display: block; margin-top: 2px; color: var(--dash-muted); font-family: inherit; }
.pricing-table tr.row-loss td { background: #fffafa; }
.pricing-table tr.row-loss:hover td { background: #fff3f3; }
.status-stack { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; max-width: 290px; white-space: normal; }
.status-pill { display: inline-block; padding: 3px 7px; border-radius: 999px; font-size: 11px; line-height: 1.25; white-space: normal; }
.status-bad { background: #fbe1e1; color: #961f1f; }
.status-warn { background: #fff1ce; color: #7c5400; }
.status-good { background: #dcf3e4; color: #166534; }
.status-target { background: #dceaff; color: #174f9a; }
.status-muted { background: #e9edf2; color: #526174; }
.status-live { background: #dfeaff; color: #164f99; font-weight: 650; }
.status-shadow { border: 1px dashed #9aa8ba; background: #f5f7fa; color: #4c5b6d; }
.dashboard-empty { padding: 28px; color: var(--dash-muted); text-align: center; }

@media (max-width: 1180px) {
  .system-status { grid-template-columns: repeat(3, minmax(135px, 1fr)); }
  .dashboard-kpis { grid-template-columns: repeat(2, minmax(145px, 1fr)); }
}
@media (max-width: 650px) {
  .dashboard-header { align-items: flex-start; }
  .dashboard-heading h1 { font-size: 21px; }
  .dashboard-refresh { min-width: auto; padding: 8px 10px; }
  .system-status { grid-template-columns: 1fr 1fr; }
  .dashboard-kpis { grid-template-columns: 1fr 1fr; }
  .dashboard-controls label { flex: 1 1 140px; }
  #dashboard-result-count { width: 100%; margin-left: 0; }
}