/* ============================================================
   МП Панда · единая тема «Финансы Pro»
   Подключается на всех страницах через:
   <link rel="stylesheet" href="/static/theme.css">
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');
:root {
  /* Палитра */
  --bg: #f1f5f9;
  --bg-sidebar: #0f172a;
  --bg-card: #ffffff;
  --bg-hover: #e2e8f0;
  --bg-subtle: #f8fafc;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-inverse: #f8fafc;

  --border: #cbd5e1;
  --border-strong: #94a3b8;
  --border-subtle: #e2e8f0;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-text: #ffffff;
  --accent-subtle: #dbeafe;

  --success: #16a34a;
  --success-subtle: #dcfce7;
  --warning: #f59e0b;
  --warning-subtle: #fef3c7;
  --danger: #dc2626;
  --danger-subtle: #fee2e2;
  --info: #0ea5e9;
  --info-subtle: #e0f2fe;

  /* Сайдбар (тёмная палитра) */
  --side-bg: #0f172a;
  --side-text: #cbd5e1;
  --side-text-muted: #64748b;
  --side-hover: #1e293b;
  --side-active-bg: #2563eb;
  --side-active-text: #ffffff;

  /* Геометрия */
  --radius: 4px;
  --radius-lg: 6px;
  --radius-pill: 9999px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 4px 12px rgba(15, 23, 42, .08);

  /* Типографика */
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-heading: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  --letter-spacing: 0;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  letter-spacing: var(--letter-spacing);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* =================== ЛАЙАУТ ================== */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* Обёртка для существующих страниц — не ломает их inline стили */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.app-shell > .app-content {
  background: var(--bg);
  min-width: 0;
  overflow-x: hidden;
}
body.has-shell { margin: 0; padding: 0 !important; background: var(--bg); }

/* =================== САЙДБАР ================== */
.sidebar {
  background: var(--side-bg);
  color: var(--side-text);
  padding: 24px 16px;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
  /* Всегда резервируем место под полосу прокрутки — иначе на вкладках, где меню
     чуть выше экрана, появляется скролл и съедает ширину, а на других нет →
     левое меню «прыгает» между вкладками. */
  scrollbar-gutter: stable;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-heading);
  font-weight: 700; font-size: 18px;
  color: white;
  margin-bottom: 28px;
  text-decoration: none;
}
.brand .logo {
  width: 32px; height: 32px;
  background: #e2e8f0;
  border-radius: 50%;
  position: relative;
  flex-shrink: 0;
}
.brand .logo::before, .brand .logo::after {
  content: ''; position: absolute;
  width: 10px; height: 10px;
  background: #e2e8f0;
  border-radius: 50%;
  top: -3px;
}
.brand .logo::before { left: 3px; }
.brand .logo::after { right: 3px; }
.brand .logo span {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 22px; height: 14px;
  background: var(--side-bg);
  border-radius: 8px;
}

.nav-group {
  font-size: 11px; font-weight: 600;
  color: var(--side-text-muted);
  text-transform: uppercase;
  letter-spacing: .8px;
  margin: 20px 12px 8px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  color: var(--side-text);
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 2px;
  text-decoration: none;
  font-size: 14px;
}
.nav-item:hover { background: var(--side-hover); color: white; }
.nav-item.active {
  background: var(--side-active-bg);
  color: var(--side-active-text);
}
.nav-item .ico {
  width: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
  transition: font-size .12s ease;
}

/* Кнопка сворачивания меню */
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 24px; }
.brand-row .brand { margin-bottom: 0; }
.side-toggle {
  background: transparent; border: 1px solid var(--side-text-muted, #475569);
  color: var(--side-text); width: 26px; height: 26px; border-radius: 6px;
  cursor: pointer; font-size: 14px; line-height: 1; flex-shrink: 0; padding: 0;
}
.side-toggle:hover { background: var(--side-hover); color: #fff; }

/* ===== Свёрнутое меню (десктоп): только иконки, крупнее ×~2 ===== */
body.sidebar-collapsed .app-shell { grid-template-columns: 76px 1fr; }
body.sidebar-collapsed .sidebar { padding: 18px 8px; }
body.sidebar-collapsed .nav-item .lbl,
body.sidebar-collapsed .brand .lbl { display: none; }
body.sidebar-collapsed .nav-item { justify-content: center; padding: 11px 0; }
body.sidebar-collapsed .nav-item .ico { width: auto; font-size: 30px; }
body.sidebar-collapsed .brand-row { flex-direction: column; gap: 12px; margin-bottom: 16px; }
body.sidebar-collapsed .brand { gap: 0; }
/* группы-заголовки превращаются в тонкий разделитель */
body.sidebar-collapsed .nav-group {
  font-size: 0; line-height: 0; height: 1px; margin: 10px 6px; padding: 0;
  background: var(--side-text-muted, #475569); opacity: .3; overflow: hidden;
}

/* =================== КОНТЕНТ ================== */
.content {
  padding: 20px 28px;
  max-width: 1500px;
}
/* Единый отступ страницы: 20px сверху / 28px по бокам.
   Для вкладок без обёртки .content контент лежит прямо в <main class="app-content">.
   Страницы со своей обёрткой (.content / .adv-wrap / .wb-wrap / .page-inner)
   задают отступ сами — обнуляем у app-content, чтобы не задваивать. */
.app-content { padding: 20px 28px; }
.app-content:has(> .content),
.app-content:has(> .adv-wrap),
.app-content:has(> .wb-wrap),
.app-content:has(> .page-inner) { padding: 0; }
.toolbar {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.toolbar h1 {
  font-family: var(--font-heading);
  margin: 0; font-size: 24px; font-weight: 700;
  letter-spacing: var(--letter-spacing);
}
.toolbar .subtitle {
  font-size: 13px; color: var(--text-muted); margin-top: 4px;
}
.toolbar .actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* =================== КНОПКИ ================== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  font: inherit; font-size: 13px; font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--bg-hover); }
.btn.primary {
  background: var(--accent); color: var(--accent-text);
  border-color: var(--accent);
}
.btn.primary:hover { background: var(--accent-hover); color: white; }
.btn.success {
  background: var(--success); color: white; border-color: var(--success);
}
.btn.success:hover { filter: brightness(1.1); color: white; }
.btn.danger {
  background: white; color: var(--danger); border-color: #fecaca;
}
.btn.small { padding: 4px 10px; font-size: 12px; }

/* Tabs */
.tabs {
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--bg-hover); border-radius: var(--radius);
  border: 1px solid var(--border);
}
.tabs button {
  border: 0; background: transparent;
  padding: 5px 12px; border-radius: var(--radius);
  font: inherit; font-size: 12px; font-weight: 500;
  cursor: pointer; color: var(--text-secondary);
}
.tabs button.active {
  background: var(--bg-card); color: var(--text-primary);
  box-shadow: var(--shadow);
}

/* Формы */
input[type="text"], input[type="number"], input[type="date"], select, textarea {
  font: inherit;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-primary);
}
input[type="text"]:focus, input[type="number"]:focus, input[type="date"]:focus,
select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
input[type="checkbox"] { accent-color: var(--accent); }

/* =================== АЛЕРТЫ ================== */
.alert-row { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.alert {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-card);
}
.alert.warn { border-color: #fed7aa; background: var(--warning-subtle); color: #9a3412; }
.alert.danger { border-color: #fecaca; background: var(--danger-subtle); color: #991b1b; }
.alert.info { border-color: #bfdbfe; background: var(--info-subtle); color: #1e40af; }
.alert.success { border-color: #bbf7d0; background: var(--success-subtle); color: #166534; }

/* =================== KPI КАРТОЧКИ ================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px; margin-bottom: 24px;
}
@media (max-width: 1200px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 640px)  { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
.kpi {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.kpi .label {
  font-size: 11px; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 8px;
}
.kpi .value {
  font-family: var(--font-mono);
  font-size: 28px; font-weight: 600;
  line-height: 1; letter-spacing: -.01em;
}
.kpi .delta {
  margin-top: 8px;
  font-size: 12px; font-weight: 600;
  display: inline-flex; gap: 4px; align-items: center;
}
.kpi .delta.up { color: var(--success); }
.kpi .delta.down { color: var(--danger); }
.kpi .delta.neutral { color: var(--text-muted); }

/* =================== ПАНЕЛИ И ТАБЛИЦЫ ================== */
.row-2col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 24px; }
@media (max-width: 1100px) { .row-2col { grid-template-columns: 1fr; } }

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.panel-title { font-size: 14px; font-weight: 600; color: var(--text-primary); margin-bottom: 2px; }
.panel-subtitle { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }

.chart-wrap { position: relative; height: 220px; }
.chart-wrap svg { width: 100%; height: 100%; }
.chart-grid line { stroke: var(--border-subtle); stroke-width: 1; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.chart-area { fill: var(--accent); opacity: .08; }
.chart-axis { fill: var(--text-muted); font-size: 10px; font-family: var(--font-mono); }

.bar-list { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 1fr 80px; gap: 10px; align-items: center; }
.bar-row .name { font-size: 13px; font-weight: 500; }
.bar-row .bar-bg {
  height: 6px; background: var(--bg-hover); border-radius: 3px;
  margin-top: 6px; overflow: hidden;
}
.bar-row .bar-fill { height: 100%; background: var(--accent); border-radius: 3px; }
.bar-row .num { font-family: var(--font-mono); font-weight: 600; font-size: 13px; text-align: right; }

/* Таблицы */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}
table.data {
  width: 100%; border-collapse: collapse;
  font-size: 13px;
}
table.data th, table.data td {
  text-align: left; padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
}
table.data thead th {
  background: var(--bg-subtle);
  font-size: 11px; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .5px;
  position: sticky; top: 0; z-index: 1;
}
table.data td.num, table.data th.num {
  text-align: right; font-family: var(--font-mono);
}
table.data tr:hover td { background: var(--bg-subtle); }
table.data .photo {
  width: 36px; height: 36px; border-radius: var(--radius);
  background: linear-gradient(135deg, var(--bg-hover), var(--border-subtle));
}
table.data .pct-up { color: var(--success); font-weight: 600; }
table.data .pct-down { color: var(--danger); font-weight: 600; }

/* Утилиты */
.muted { color: var(--text-muted); font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.scroll { overflow: auto; }
.badge {
  display: inline-flex; align-items: center;
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: var(--radius-pill);
  background: var(--bg-hover); color: var(--text-secondary);
}
.badge.success { background: var(--success-subtle); color: #166534; }
.badge.warning { background: var(--warning-subtle); color: #92400e; }
.badge.danger { background: var(--danger-subtle); color: #991b1b; }
.badge.info { background: var(--info-subtle); color: #1e40af; }

/* =================== МОБИЛЬНАЯ АДАПТАЦИЯ ================== */
/* Кнопка-гамбургер для открытия sidebar */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 102;
  width: 40px; height: 40px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
}

@media (max-width: 900px) {
  .app-shell, .layout {
    grid-template-columns: 1fr !important;
  }
  /* на мобильных меню открывается гамбургером, сворачивание не нужно */
  .side-toggle { display: none; }
  body.sidebar-collapsed .app-shell { grid-template-columns: 1fr !important; }
  body.sidebar-collapsed .nav-item .lbl, body.sidebar-collapsed .brand .lbl { display: inline; }
  body.sidebar-collapsed .nav-group { font-size: 11px; height: auto; background: none; opacity: 1; }
  .sidebar {
    position: fixed !important;
    top: 0; left: 0; bottom: 0;
    width: 260px;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 101;
    box-shadow: 4px 0 24px rgba(0,0,0,.2);
  }
  body.sidebar-open .sidebar {
    transform: translateX(0);
  }
  body.sidebar-open::after {
    content: '';
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 100;
  }
  .mobile-menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .app-content, main.content { padding-top: 60px !important; }
  .content { padding: 60px 12px 16px !important; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .actions { justify-content: flex-start; }
  .kpi-grid { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
  .kpi { padding: 12px !important; }
  .kpi .value { font-size: 22px !important; }
  .row-2col { grid-template-columns: 1fr !important; }
  .panel { padding: 14px !important; }
  .table-wrap { overflow-x: auto; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr !important; }
  .kpi .value { font-size: 20px !important; }
}

/* ========== Спиннеры и индикаторы загрузки ========== */

/* Inline-спиннер для кнопок */
.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(0, 0, 0, .15);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
.spinner-lg {
  width: 18px;
  height: 18px;
  border-width: 2.5px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Глобальный индикатор в правом верхнем углу — для длительных операций */
.global-loader {
  position: fixed;
  top: 12px;
  right: 12px;
  background: var(--bg-elev, #fff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text, #111);
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  z-index: 10000;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  animation: slideIn 0.2s ease-out;
}
.global-loader .spinner { margin-right: 0; border-top-color: #6c46ff; }
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Полупрозрачный overlay на блок данных пока он обновляется */
.is-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.55;
  transition: opacity 0.2s;
}
.is-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border: 3px solid rgba(108, 70, 255, .25);
  border-top-color: #6c46ff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  pointer-events: none;
}

/* Disabled-кнопка во время операции — показывает курсор «занято» */
button[disabled].is-loading, button.is-loading {
  cursor: wait;
  opacity: 0.7;
}
