*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: 'Inter', 'DM Sans', sans-serif;
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body { min-height: 100vh; }

/* ─── APP SHELL ─── */

.app { display: flex; min-height: 100vh; }

/* ─── SIDEBAR ─── */

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-logo {
  height: 64px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.nav-label {
  color: var(--text-tert);
  font-size: 10px;
  letter-spacing: 4px;
  font-weight: 500;
  padding: 0 20px;
  margin-top: 24px;
  margin-bottom: 12px;
  text-transform: uppercase;
}

.nav-list {
  list-style: none;
  padding: 0 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-sec);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
  user-select: none;
}

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

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

.nav-icon {
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
  width: 16px;
  text-align: center;
}

.sidebar-footer {
  margin-top: auto;
  padding: 20px;
  color: var(--text-tert);
  font-size: 11px;
}

/* ─── BOTTOM NAV (mobile PWA) ─── */

.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(60px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bn-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-tert);
  cursor: pointer;
  padding: 6px 0;
  transition: color 120ms ease;
  user-select: none;
}

.bn-item.active { color: var(--accent); }

.bn-icon  { font-size: 16px; line-height: 1; }

.bn-label {
  font-family: 'Inter', 'DM Sans', sans-serif;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* ─── MAIN ─── */

.main {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  padding: 32px;
  padding-top: 80px; /* 64px fixed topbar + 16px gap */
  overflow-y: auto;
}

/* ─── TOPBAR ─── */

.topbar {
  position: fixed;
  top: 0;
  left: 220px; /* sidebar width */
  right: 0;
  z-index: 30;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
}

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

.topbar-left.chat-mode {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 0;
  flex: 1;
}

.topbar-subtitle { color: var(--text-sec); font-size: 13px; }

/* ─── TAB PANELS ─── */

.tab-panel        { display: none; }
.tab-panel.active { display: block; }

/* ─── SCROLLBAR ─── */

::-webkit-scrollbar             { width: 6px; }
::-webkit-scrollbar-track       { background: var(--bg); }
::-webkit-scrollbar-thumb       { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #444444; }
*                               { scrollbar-width: thin; scrollbar-color: var(--border) var(--bg); }

/* ─── RESPONSIVE ─── */

@media (max-width: 900px) {
  .sidebar { width: 64px; }
  .sidebar-logo { justify-content: center; padding: 0 12px; }
  .sidebar .sf-wordmark, .nav-label, .sidebar-footer { display: none; }
  .nav-item { justify-content: center; padding: 10px; gap: 0; }
  .nav-item span:last-child { display: none; }
  .topbar { left: 64px; }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .bottom-nav { display: flex; }
  .topbar { left: 0; padding: 0 16px; }
  .main { padding-bottom: calc(60px + env(safe-area-inset-bottom) + 16px); }
  .stat-row { flex-wrap: wrap; }
  .stat-card { flex: 1 1 calc(50% - 8px); }
}

@media (max-width: 600px) {
  .main { padding: 16px; padding-top: 80px; padding-bottom: calc(60px + env(safe-area-inset-bottom) + 16px); }
  .lead-actions { flex-direction: column; }
}

@media (max-width: 480px) {
  .stat-card { flex: 1 1 100%; }
}
