/* Global reset & base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  transition: background 0.2s, color 0.2s;
}

body::-webkit-scrollbar       { width: 6px; }
body::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: var(--r-pill); }

/* ── App shell ──────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-lg);
  height: 48px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-sidebar);
}

.app-header .brand {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
}

.app-header .brand span {
  color: var(--text-muted);
  font-weight: 400;
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
}

.last-update {
  font-size: 12px;
  color: var(--text-muted);
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  transition: border-color 0.15s, color 0.15s;
}
.theme-toggle:hover { border-color: var(--border-hover); color: var(--text); }

/* ── Body: sidebar + content ─────────────────────────────────────────────── */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: var(--sp-md) 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.sidebar::-webkit-scrollbar       { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: var(--r-pill); }

.sidebar-section {
  padding: var(--sp-xs) var(--sp-md);
}

.sidebar-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: var(--sp-sm) var(--sp-md) var(--sp-xs);
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: var(--sp-xs) var(--sp-md);
}

/* Nav links (Реклама, Email) */
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-xs);
  padding: var(--sp-xs) var(--sp-md);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 0;
  transition: color 0.15s, background 0.15s;
  cursor: pointer;
}
.nav-item:hover  { color: var(--text); background: var(--border); }
.nav-item.active { color: var(--text); }
.nav-item.active::before {
  content: '';
  display: block;
  width: 3px;
  height: 14px;
  background: var(--primary);
  border-radius: var(--r-pill);
  margin-left: -12px;
  margin-right: 9px;
}

/* Period preset buttons */
.period-btn {
  display: block;
  width: calc(100% - var(--sp-lg));
  margin: 1px var(--sp-sm);
  padding: 5px var(--sp-sm);
  background: none;
  border: none;
  border-radius: var(--r-md);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.period-btn:hover  { background: var(--border); color: var(--text); }
.period-btn.active,
.period-btn.active:hover {
  background: var(--border-hover);
  color: var(--text);
  font-weight: 600;
}

/* Date range dropdown */
.date-dropdown {
  margin-top: var(--sp-xs);
}

.date-dropdown summary {
  list-style: none;
  padding: var(--sp-xs) var(--sp-md);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: var(--sp-xs);
}
.date-dropdown summary::-webkit-details-marker { display: none; }
.date-dropdown summary::before {
  content: '›';
  display: inline-block;
  transition: transform 0.15s;
  font-size: 14px;
  line-height: 1;
}
.date-dropdown[open] summary::before { transform: rotate(90deg); }

.date-dropdown-list {
  padding-bottom: var(--sp-xs);
}
.date-dropdown-list button {
  display: block;
  width: calc(100% - var(--sp-lg));
  margin: 1px var(--sp-sm);
  padding: 5px var(--sp-sm);
  background: none;
  border: none;
  border-radius: var(--r-md);
  color: var(--text-muted);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.date-dropdown-list button:hover  { background: var(--border); color: var(--text); }
.date-dropdown-list button.active { color: var(--primary); }

/* Theme toggle in sidebar */
.sidebar-theme {
  padding: var(--sp-xs) var(--sp-sm);
  margin-top: auto;
}
.sidebar-theme .theme-toggle {
  display: flex;
  align-items: center;
  gap: var(--sp-xs);
  width: calc(100% - var(--sp-lg));
  margin: 1px var(--sp-sm);
  padding: var(--sp-xs) var(--sp-sm);
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.sidebar-theme .theme-toggle:hover { border-color: var(--border-hover); color: var(--text); }

/* ── Main content area ───────────────────────────────────────────────────── */
.content {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-lg);
  display: flex;
  flex-direction: column;
  gap: var(--sp-lg);
}

.content::-webkit-scrollbar       { width: 6px; }
.content::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: var(--r-pill); }

/* ── Page tabs (АССА / ЖИЧУ) ─────────────────────────────────────────────── */
.page-tabs {
  display: flex;
  gap: var(--sp-xs);
  flex-shrink: 0;
}

.tab-btn {
  padding: var(--sp-xs) var(--sp-md);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.tab-btn:hover  { border-color: var(--border-hover); color: var(--text); }
.tab-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ── Section block ───────────────────────────────────────────────────────── */
.block {
  display: flex;
  flex-direction: column;
  gap: var(--sp-md);
}

.block-header {
  display: flex;
  align-items: baseline;
  gap: var(--sp-xs);
}

.block-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.block-id {
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.5;
  font-family: var(--font-mono);
}

/* ── Mobile ──────────────────────────────────────────────────────────────── */
.sidebar-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  padding: 4px 9px;
  cursor: pointer;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 199;
}

@media (max-width: 767px) {
  /* App shell: normal scrolling page on mobile */
  .app-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
    display: block;
  }

  .sidebar-toggle { display: block; }

  /* Body: block layout — sidebar is fixed overlay, content takes full width */
  .app-body {
    display: block;
    height: auto;
    overflow: visible;
  }

  /* Sidebar: fixed off-screen drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 220px;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.4);
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop.open { display: block; }

  /* Content: full width, normal scroll */
  .content {
    overflow-y: visible;
    padding: var(--sp-md);
    width: 100%;
  }

  /* Header stays sticky at top */
  .app-header {
    position: sticky;
    top: 0;
    z-index: 100;
  }

  /* KPI grids: 2 columns */
  .kpi-grid   { grid-template-columns: repeat(2, 1fr); }
  .kpi-grid-2 { grid-template-columns: repeat(2, 1fr); }

  .funnel-row { flex-direction: column; }

  .table-toolbar { flex-wrap: wrap; gap: var(--sp-xs); }

  /* Charts: limit height on mobile */
  .chart-wrap { max-height: 260px; }
}
