/* ============================================================
   Legion SaaS Platform — Design System & Styles
   Inspired by Linear / Notion / Stripe Dashboard
   ============================================================ */

/* ---------- ШРИФТ ---------- */
/* Inter (SIL Open Font License 1.1, текст лицензии рядом: assets/fonts/Inter-OFL.txt).
   Файл лежит у нас, а не на Google Fonts: нет внешних запросов и зависимости от чужих серверов.
   Один variable-файл с кириллицей, толщины 100-900. */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('assets/fonts/InterVariable.woff2') format('woff2');
}

/* ---------- CSS VARIABLES ---------- */
/* Брендинг LEGION: акцент = синий переключателя из логотипа (#00AAFF).
   Тёмная тема — по умолчанию. #00AAFF (--brand-blue) — только для декора
   (логотип, графики); текст и кнопки в светлой теме используют --accent
   (#0068B0), чтобы проходить WCAG AA. Контраст проверяет
   tests/frontend_theme_contrast.test.cjs. */
:root {
  /* Нативные элементы (список select, иконка календаря, скроллбары) следуют теме */
  color-scheme: dark;

  /* Colors — Dark Theme (default) */
  --bg-primary: #0a1118;
  --bg-secondary: #0f1923;
  --bg-tertiary: #14212d;
  --bg-elevated: #192836;
  --bg-hover: #203244;
  --bg-active: #263b50;

  --surface-1: #0d161f;
  --surface-2: #121e29;
  --surface-3: #182736;

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.16);
  /* Контур полей ввода: контраст ≥ 3:1 к фону поля (проверяет frontend_theme_contrast) */
  --field-border: #5d7388;

  --text-primary: #eaf1f7;
  --text-secondary: #9fb1c2;
  --text-tertiary: #7c8fa1;
  --text-inverse: #0a1118;

  /* Brand / Accent */
  --brand-blue: #00aaff;
  --accent: #00aaff;
  --accent-hover: #33bbff;
  --accent-muted: rgba(0, 170, 255, 0.15);
  --accent-subtle: rgba(0, 170, 255, 0.08);
  --on-accent: #04121c;
  --avatar-gradient: linear-gradient(135deg, #0068b0, #004e86);

  /* Semantic */
  --success: #2dd4a0;
  --success-muted: rgba(45, 212, 160, 0.15);
  --warning: #f5b83d;
  --warning-muted: rgba(245, 184, 61, 0.15);
  --warning-subtle: rgba(245, 184, 61, 0.12);
  --danger: #ff6b6b;
  --danger-muted: rgba(255, 107, 107, 0.15);
  --danger-subtle: rgba(255, 107, 107, 0.12);
  --info: #5b9dff;
  --info-muted: rgba(91, 157, 255, 0.15);

  /* Chart */
  --chart-bar: linear-gradient(180deg, #00aaff 0%, #0080d0 100%);
  --chart-bar-highlight: linear-gradient(180deg, #4dc3ff 0%, #00aaff 100%);

  /* Spacing */
  --sidebar-width: 260px;
  --sidebar-collapsed: 64px;
  --topbar-height: 56px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 220ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 320ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 16px 40px rgba(0, 0, 0, 0.55);
  --shadow-glow: 0 0 20px rgba(0, 170, 255, 0.18);
  --accent-shadow: rgba(0, 170, 255, 0.30);
  --accent-shadow-strong: rgba(0, 170, 255, 0.40);
}

/* ---------- LIGHT THEME ---------- */
[data-theme="light"] {
  color-scheme: light;

  --bg-primary: #f4f7fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #edf2f7;
  --bg-elevated: #ffffff;
  --bg-hover: #e6edf4;
  --bg-active: #dce6ef;

  --surface-1: #ffffff;
  --surface-2: #f6f9fc;
  --surface-3: #ecf1f6;

  --border-subtle: rgba(11, 22, 32, 0.06);
  --border-default: rgba(11, 22, 32, 0.10);
  --border-strong: rgba(11, 22, 32, 0.16);
  --field-border: #66798c;

  --text-primary: #0b1620;
  --text-secondary: #43566a;
  --text-tertiary: #566b7e;
  --text-inverse: #ffffff;

  --accent: #0068b0;
  --accent-hover: #00588f;
  --accent-muted: rgba(0, 104, 176, 0.12);
  --accent-subtle: rgba(0, 104, 176, 0.07);
  --on-accent: #ffffff;

  --success: #0b7a56;
  --success-muted: rgba(11, 122, 86, 0.12);
  --warning: #8a5a00;
  --warning-muted: rgba(138, 90, 0, 0.12);
  --warning-subtle: rgba(138, 90, 0, 0.09);
  --danger: #b42626;
  --danger-muted: rgba(180, 38, 38, 0.12);
  --danger-subtle: rgba(180, 38, 38, 0.08);
  --info: #1d5fc4;
  --info-muted: rgba(29, 95, 196, 0.12);

  --shadow-sm: 0 1px 2px rgba(11, 22, 32, 0.06);
  --shadow-md: 0 4px 12px rgba(11, 22, 32, 0.08);
  --shadow-lg: 0 8px 24px rgba(11, 22, 32, 0.12);
  --shadow-xl: 0 16px 40px rgba(11, 22, 32, 0.16);
  --shadow-glow: 0 0 20px rgba(0, 104, 176, 0.10);
  --accent-shadow: rgba(0, 104, 176, 0.25);
  --accent-shadow-strong: rgba(0, 104, 176, 0.35);
}

/* ---------- RESET & BASE ---------- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: var(--accent-hover); }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  font-size: inherit;
}

input {
  font-family: inherit;
  border: none;
  background: none;
  outline: none;
  color: inherit;
}

/* ---------- FORM CONTROLS (общие, по теме) ----------
   Нативные select/option/textarea/date-поля без своего цвета брали цвета
   браузера (чёрный текст на тёмном фоне). Правила ниже подчиняют их
   переменным темы; инлайновые background/border на страницах по-прежнему
   имеют приоритет. */
select,
textarea,
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="month"],
input[type="week"],
input[type="number"] {
  color: var(--text-primary);
  background-color: var(--bg-tertiary);
  font-family: inherit;
}

/* Текстовые поля остаются прозрачными (как раньше), задаём только цвет текста */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="tel"],
input[type="url"] {
  color: var(--text-primary);
}

option,
optgroup {
  color: var(--text-primary);
  background-color: var(--bg-elevated);
}

/* Единый видимый контур и фокус для ВСЕХ полей ввода (input, select, textarea).
   Специфичность — как у тега: классы и инлайновые стили страниц могут уточнять
   размер, но контур остаётся. */
input:where(:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="hidden"]):not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="color"]):not([type="image"])),
select,
textarea {
  border: 1px solid var(--field-border);
  border-radius: var(--radius-md);
  background-color: var(--bg-tertiary);
  padding: 8px 10px;
  font-size: 14px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.ob-form-group .ob-form-input { width: 100%; }
select:focus,
textarea:focus,
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="hidden"]):focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}
/* Поле поиска в меню уже обведено контейнером */
.sidebar-search input,
.sidebar-search input:focus {
  border: none;
  box-shadow: none;
  background: none;
  padding: 0;
}
/* Ошибка под полем */
.field-error {
  color: var(--danger);
  font-size: 12px;
  margin-top: 4px;
}
input.field-invalid,
select.field-invalid,
textarea.field-invalid,
input.field-invalid:focus,
select.field-invalid:focus,
textarea.field-invalid:focus {
  border-color: var(--danger);
}
input.field-invalid:focus,
select.field-invalid:focus,
textarea.field-invalid:focus {
  box-shadow: 0 0 0 3px var(--danger-muted);
}

/* Placeholder: --text-tertiary, контраст ≥ 4.5 в обеих темах (opacity:1 — Firefox тускнит) */
input::placeholder,
textarea::placeholder {
  color: var(--text-tertiary);
  opacity: 1;
}

/* Disabled: читаемый текст (≥ 4.5), отличие — фон и курсор, а не бледность */
select:disabled,
textarea:disabled,
input[type="text"]:disabled,
input[type="email"]:disabled,
input[type="password"]:disabled,
input[type="search"]:disabled,
input[type="tel"]:disabled,
input[type="url"]:disabled,
input[type="date"]:disabled,
input[type="datetime-local"]:disabled,
input[type="time"]:disabled,
input[type="month"]:disabled,
input[type="week"]:disabled,
input[type="number"]:disabled {
  color: var(--text-secondary);
  -webkit-text-fill-color: var(--text-secondary);
  opacity: 1;
  cursor: not-allowed;
}
select:disabled,
textarea:disabled,
input[type="date"]:disabled,
input[type="datetime-local"]:disabled,
input[type="time"]:disabled,
input[type="month"]:disabled,
input[type="week"]:disabled,
input[type="number"]:disabled {
  background-color: var(--bg-secondary);
}

/* ---------- SCROLLBAR ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ---------- APP LAYOUT ---------- */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ============================================================
   SIDEBAR & EXPAND/COLLAPSE ANIMATIONS
   ============================================================ */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  transition: width var(--transition-slow), min-width var(--transition-slow), box-shadow var(--transition-base);
  z-index: 100;
  position: relative;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed);
  min-width: var(--sidebar-collapsed);
}

/* TEMPORARY HOVER EXPAND (When collapsed) */
.sidebar.collapsed:hover {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  box-shadow: 8px 0 24px rgba(0, 0, 0, 0.4);
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
}

.sidebar.collapsed:hover .nav-section-title,
.sidebar.collapsed:hover .nav-item span,
.sidebar.collapsed:hover .nav-badge,
.sidebar.collapsed:hover .sidebar-search input,
.sidebar.collapsed:hover .sidebar-search kbd,
.sidebar.collapsed:hover .user-info {
  display: inline-block;
}

.sidebar.collapsed:hover .sidebar-search {
  padding: 8px 12px;
  justify-content: flex-start;
}

.sidebar.collapsed:hover .nav-item {
  justify-content: flex-start;
  padding: 8px 12px;
}

/* Header */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  min-height: 56px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Brand logo: две версии (белые/тёмные буквы) переключаются темой через CSS-переменные,
   без JS и перезагрузки; свёрнутая панель показывает только знак ON. */
:root { --logo-dark-disp: block; --logo-light-disp: none; }
[data-theme="light"] { --logo-dark-disp: none; --logo-light-disp: block; }

.brand-logo {
  height: auto;
  flex-shrink: 0;
  user-select: none;
}
.brand-logo--on-dark { display: var(--logo-dark-disp); }
.brand-logo--on-light { display: var(--logo-light-disp); }
.brand-logo--icon { display: none; }
.logo .brand-logo--full { width: 168px; }
.logo .brand-logo--icon { width: 40px; }
.brand-logo--auth { width: 220px; max-width: 70%; }
.brand-logo--onboarding { width: 120px; }

.sidebar.collapsed .brand-logo--full { display: none; }
.sidebar.collapsed .brand-logo--icon { display: block; }
.sidebar.collapsed:hover .brand-logo--on-dark { display: var(--logo-dark-disp); }
.sidebar.collapsed:hover .brand-logo--on-light { display: var(--logo-light-disp); }
.sidebar.collapsed:hover .brand-logo--icon { display: none; }

.sidebar-toggle {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-tertiary);
  transition: all var(--transition-fast);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
}
.sidebar-toggle:hover {
  background: var(--accent-muted);
  color: var(--accent);
  border-color: var(--accent);
  transform: scale(1.05);
}

.toggle-icon-expand { display: none; }
.sidebar.collapsed .toggle-icon-collapse { display: none; }
.sidebar.collapsed .toggle-icon-expand { display: block; }

.sidebar.collapsed .nav-section-title,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .nav-badge,
.sidebar.collapsed .sidebar-search input,
.sidebar.collapsed .sidebar-search kbd,
.sidebar.collapsed .user-info {
  display: none;
}

.sidebar.collapsed .sidebar-search {
  padding: 6px;
  justify-content: center;
}

.sidebar.collapsed .sidebar-header {
  justify-content: center;
  padding: 16px 8px 12px;
}

/* Свёрнутая панель: знак ON и кнопка разворота друг под другом (в 48px рядом не помещаются). */
.sidebar.collapsed:not(:hover) .sidebar-header {
  flex-direction: column;
  gap: 10px;
}

.sidebar.collapsed .nav-item {
  justify-content: center;
  padding: 10px;
}

.sidebar.collapsed .sidebar-user {
  justify-content: center;
}

/* Search */
.sidebar-search {
  margin: 0 12px 8px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.sidebar-search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.sidebar-search svg { color: var(--text-tertiary); flex-shrink: 0; }

.sidebar-search input {
  flex: 1;
  font-size: 13px;
  color: var(--text-primary);
}
.sidebar-search input::placeholder { color: var(--text-tertiary); }

.sidebar-search kbd {
  font-family: inherit;
  font-size: 11px;
  padding: 2px 6px;
  background: var(--bg-hover);
  border: 1px solid var(--border-default);
  border-radius: 4px;
  color: var(--text-tertiary);
  line-height: 1;
}

/* Navigation */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.nav-section { margin-bottom: 16px; }

.nav-section-title {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  padding: 8px 12px 4px;
  white-space: nowrap;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  text-decoration: none;
  position: relative;
  white-space: nowrap;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-subtle);
  color: var(--accent);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 16px;
  background: var(--accent);
  border-radius: 0 var(--radius-full) var(--radius-full) 0;
}

.nav-item svg { flex-shrink: 0; }

.nav-badge {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: var(--radius-full);
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.nav-badge.accent {
  background: var(--accent-muted);
  color: var(--accent);
}

/* Footer */
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border-subtle);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}
.sidebar-user:hover { background: var(--bg-hover); }

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--avatar-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  display: block;
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* ---------- TOPBAR ---------- */
.topbar {
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  backdrop-filter: blur(12px);
  gap: 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* EXPLICIT TOPBAR SIDEBAR TOGGLE BUTTON */
.topbar-sidebar-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}
.topbar-sidebar-toggle:hover {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 10px var(--accent-muted);
}

.mobile-menu-btn {
  display: none;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}
.mobile-menu-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.breadcrumb-item { color: var(--text-tertiary); }
.breadcrumb-item.current { color: var(--text-primary); font-weight: 500; }
.breadcrumb svg { color: var(--text-tertiary); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.topbar-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  position: relative;
}
.topbar-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.notification-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 7px;
  height: 7px;
  background: var(--danger);
  border-radius: var(--radius-full);
  border: 2px solid var(--bg-secondary);
}

.topbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border-default);
  margin: 0 8px;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 4px 4px;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}
.topbar-user:hover { background: var(--bg-hover); }

.topbar-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--avatar-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
}

.topbar-username {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.topbar-user svg { color: var(--text-tertiary); }

/* ---------- PAGE CONTENT ---------- */
.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 28px 40px;
}

/* Page Header */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.page-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.date-range-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  background: var(--bg-elevated);
}
.date-range-picker:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 1px 3px var(--accent-shadow);
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 2px 8px var(--accent-shadow-strong);
  transform: translateY(-1px);
}

/* ---------- STATS GRID ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  opacity: 0;
  transition: opacity var(--transition-base);
}

.stat-card:hover {
  border-color: var(--border-default);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.stat-card:hover::before { opacity: 1; }

#statRevenue::before  { background: linear-gradient(90deg, var(--brand-blue), #4dc3ff); }
#statUsers::before    { background: linear-gradient(90deg, #3b82f6, #60a5fa); }
#statProjects::before { background: linear-gradient(90deg, #10b981, #34d399); }
#statTasks::before    { background: linear-gradient(90deg, #f59e0b, #fbbf24); }

.stat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.stat-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.stat-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-icon.revenue  { background: var(--accent-muted); color: var(--accent); }
.stat-icon.users    { background: var(--info-muted); color: var(--info); }
.stat-icon.projects { background: var(--success-muted); color: var(--success); }
.stat-icon.tasks    { background: var(--warning-muted); color: var(--warning); }

.stat-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.stat-change {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
}
.stat-change.positive { color: var(--success); }
.stat-change.negative { color: var(--danger); }

.stat-period {
  color: var(--text-tertiary);
  font-weight: 400;
  margin-left: 2px;
}

.stat-sparkline {
  margin-top: 12px;
  height: 32px;
  display: flex;
  align-items: flex-end;
  gap: 2px;
}

.sparkline-bar {
  flex: 1;
  border-radius: 2px;
  min-height: 3px;
  transition: height var(--transition-slow);
}

/* ---------- CARDS ---------- */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color var(--transition-base);
}
.card:hover { border-color: var(--border-default); }

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 20px 16px;
  gap: 12px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

/* ---------- CONTENT GRID ---------- */
.content-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

/* ---------- CHART ---------- */
.chart-tabs {
  display: flex;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.chart-tab {
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 4px;
  color: var(--text-tertiary);
  transition: all var(--transition-fast);
}
.chart-tab:hover { color: var(--text-secondary); }
.chart-tab.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.chart-container {
  padding: 0 20px 20px;
  height: 240px;
  position: relative;
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  height: 100%;
  padding: 0 4px;
  position: relative;
  z-index: 2;
}

.chart-bar-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  height: 100%;
  justify-content: flex-end;
}

.chart-bar {
  width: 100%;
  max-width: 48px;
  height: var(--height, 50%);
  background: var(--chart-bar);
  border-radius: var(--radius-sm) var(--radius-sm) 2px 2px;
  transition: all var(--transition-base);
  position: relative;
  cursor: pointer;
  opacity: 0.75;
}
.chart-bar:hover {
  opacity: 1;
  transform: scaleY(1.02);
  transform-origin: bottom;
}
.chart-bar.highlight {
  background: var(--chart-bar-highlight);
  opacity: 1;
  box-shadow: 0 0 16px var(--accent-shadow);
}

.chart-tooltip {
  display: none;
  position: absolute;
  top: -32px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-active);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  box-shadow: var(--shadow-md);
}
.chart-bar:hover .chart-tooltip { display: block; }

.chart-label {
  font-size: 12px;
  color: var(--text-tertiary);
  font-weight: 500;
}

.project-status {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  flex-shrink: 0;
}

.status-active { background: var(--accent-muted); color: var(--accent); }
.status-review { background: var(--warning-muted); color: var(--warning); }
.status-done   { background: var(--success-muted); color: var(--success); }

/* ============================================================
   SETTINGS & MODULES PAGE
   ============================================================ */
.settings-tabs {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0px;
}

.settings-tab {
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  transition: all var(--transition-fast);
  position: relative;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.settings-tab:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.settings-tab.active {
  color: var(--accent);
  background: var(--bg-elevated);
  border-bottom-color: var(--accent);
}

.modules-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding: 16px 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}

.modules-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.modules-business-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
}

.btn-reset-modules {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
}
.btn-reset-modules:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.modules-section {
  margin-bottom: 32px;
}

.modules-section-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.modules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.module-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: all var(--transition-base);
}
.module-card:hover {
  border-color: var(--border-default);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.module-card.disabled {
  opacity: 0.6;
  background: var(--bg-tertiary);
  border-style: dashed;
}

.module-card.mandatory {
  border-color: var(--border-default);
}

.module-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.module-card-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
}

.module-card.disabled .module-card-icon {
  color: var(--text-tertiary);
}

.module-card-body {
  flex: 1;
}

.module-card-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.module-card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.module-card-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
}

.module-section-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 4px 8px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border-radius: 4px;
}

.module-recommended-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  background: var(--success-muted);
  color: var(--success);
  border-radius: 4px;
}

.module-mandatory-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  background: var(--danger-muted);
  color: var(--danger);
  border-radius: 4px;
}

/* Toggle Switch Styles */
.module-toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}
.module-toggle.locked {
  cursor: not-allowed;
  display: flex;
  align-items: center;
  justify-content: center;
}

.module-checkbox {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.module-toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-tertiary);
  transition: .4s;
  border-radius: 24px;
  border: 1px solid var(--border-strong);
}

.module-toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background-color: var(--text-secondary);
  transition: .4s;
  border-radius: 50%;
}

.module-checkbox:checked + .module-toggle-slider {
  background-color: var(--accent);
  border-color: var(--accent);
}

.module-checkbox:checked + .module-toggle-slider:before {
  transform: translateX(20px);
  background-color: #fff;
}

.module-lock-icon {
  font-size: 14px;
  color: var(--danger);
  opacity: 0.8;
  display: flex;
}

/* ============================================================
   ONBOARDING WIZARD
   ============================================================ */
#onboardingContainer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-y: auto;
  padding: 20px;
}

.onboarding-wizard {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 800px;
  min-height: 500px;
  display: flex;
  flex-direction: column;
}

.onboarding-header {
  padding: 24px;
  border-bottom: 1px solid var(--border-subtle);
}

.onboarding-progress {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.progress-step {
  flex: 1;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  transition: .3s;
}

.progress-step.active {
  background: var(--accent);
}

.progress-step.completed {
  background: var(--success);
}

.onboarding-body {
  padding: 32px;
  flex: 1;
  display: none;
}
.onboarding-body.active {
  display: block;
}

.onboarding-footer {
  padding: 20px 24px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Specific step styles */
.ob-step-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}
.ob-step-subtitle {
  color: var(--text-secondary);
  margin-bottom: 24px;
}
.ob-form-group {
  margin-bottom: 16px;
}
.ob-form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--text-secondary);
}
.ob-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  transition: border-color var(--transition-fast);
}
.ob-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}
.ob-error {
  color: var(--danger);
  font-size: 12px;
  margin-top: 4px;
  display: none;
}
.ob-error.visible {
  display: block;
}

/* Business Type Cards */
.ob-business-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.ob-business-card {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: all .2s;
  background: var(--bg-tertiary);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ob-business-card:hover {
  border-color: var(--accent-subtle);
  transform: translateY(-2px);
}
.ob-business-card.active {
  border-color: var(--accent);
  background: var(--accent-subtle);
  box-shadow: 0 4px 12px var(--accent-muted);
}
.ob-business-icon {
  font-size: 24px;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ob-business-card.active .ob-business-icon {
  background: var(--accent);
  color: var(--on-accent);
}
.ob-business-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
}
.ob-business-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Review Step */
.ob-review-box {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 24px;
}
.ob-review-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-subtle);
}
.ob-review-row:last-child {
  border-bottom: none;
}
.ob-review-label {
  color: var(--text-secondary);
  font-size: 14px;
}
.ob-review-value {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}
.ob-modules-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}
.ob-module-tag {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  padding: 4px 10px;
  border-radius: var(--radius-md);
  font-size: 12px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Module Grid override for Onboarding */
.ob-modules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  max-height: 400px;
  overflow-y: auto;
  padding-right: 8px;
}
.ob-modules-grid .module-card {
  padding: 16px;
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .content-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .sidebar-overlay.visible { display: block; }

  .topbar-sidebar-toggle { display: none; }
  .mobile-menu-btn { display: flex; }

  .page-content { padding: 20px 16px 40px; }
  .stats-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   DEV-ONLY: Business Type Switcher (Ctrl+Shift+D)
   Hidden by default. Visible only in development.
   ============================================================ */
.dev-switcher {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 300px;
  max-height: 480px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-size: 13px;
}

.dev-switcher.visible {
  display: flex;
  animation: devSlideUp 200ms ease-out;
}

@keyframes devSlideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dev-switcher-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.dev-switcher-tag {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--warning-muted);
  color: var(--warning);
}

.dev-switcher-title {
  flex: 1;
  font-weight: 600;
  color: var(--text-primary);
}

.dev-switcher-close {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-tertiary);
  transition: all var(--transition-fast);
}
.dev-switcher-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.dev-switcher-list {
  padding: 8px;
  overflow-y: auto;
  max-height: 360px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dev-switcher-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  text-align: left;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  width: 100%;
}

.dev-switcher-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.dev-switcher-btn.active {
  background: var(--accent-subtle);
  color: var(--accent);
}

.dev-switcher-btn.active::after {
  content: '✓';
  margin-left: auto;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}

.dev-bt-icon {
  font-size: 18px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
}

.dev-bt-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dev-switcher-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-top: 1px solid var(--border-subtle);
  font-size: 11px;
  color: var(--text-tertiary);
}

.dev-switcher-info strong {
  color: var(--text-secondary);
}
