/* ============================================================
   CommunityAds — Dashboard Layout (dashboard.css)
   Sidebar, topbar, tables, KPI cards, charts
   ============================================================ */

body.dash-body { background: var(--bg); }

/* ---------- Shell ---------- */
.dash-shell {
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto; z-index: 100;
  transition: width var(--t-base), transform var(--t-base);
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  height: var(--header-h); padding: 0 var(--s-5);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar .brand { font-size: 18px; }
.sidebar .brand-mark { width: 30px; height: 30px; font-size: 14px; border-radius: 8px; }
.sidebar-collapse {
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
}
.sidebar-collapse:hover { background: var(--bg); color: var(--text-strong); }

.sidebar-nav { flex: 1; padding: var(--s-4) var(--s-3); }
.nav-group-label {
  padding: var(--s-3) var(--s-3) var(--s-2);
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: #98A2B3;
}
.nav-group + .nav-group { margin-top: var(--s-3); }
.nav-item {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 10px var(--s-3); border-radius: var(--r-sm);
  color: var(--text); font-size: var(--fs-base); font-weight: 500;
  margin-bottom: 2px;
  transition: all var(--t-fast);
  position: relative;
}
.nav-item i { width: 20px; text-align: center; color: var(--muted); font-size: 15px; }
.nav-item:hover { background: var(--bg); color: var(--text-strong); }
.nav-item:hover i { color: var(--text-strong); }
.nav-item.active {
  background: var(--primary-light); color: var(--primary); font-weight: 600;
}
.nav-item.active i { color: var(--primary); }
.nav-item .nav-badge {
  margin-left: auto; padding: 2px 8px;
  background: var(--danger); color: #fff;
  border-radius: var(--r-pill); font-size: 11px; font-weight: 700;
}
.nav-item.active .nav-badge { background: var(--primary); }

.sidebar-foot {
  padding: var(--s-3); border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.user-mini {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-2); border-radius: var(--r-sm);
  transition: background var(--t-fast); width: 100%;
}
.user-mini:hover { background: var(--bg); }
.user-mini-info { flex: 1; min-width: 0; text-align: left; }
.user-mini-name {
  font-size: var(--fs-sm); font-weight: 600; color: var(--text-strong);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-mini-role { font-size: 11px; color: var(--muted); }
.user-mini > i { color: var(--muted); font-size: 12px; }

/* Collapsed sidebar */
.dash-shell.collapsed { grid-template-columns: 76px 1fr; }
.dash-shell.collapsed .sidebar { width: 76px; }
.dash-shell.collapsed .sidebar .brand span,
.dash-shell.collapsed .nav-group-label,
.dash-shell.collapsed .nav-item span,
.dash-shell.collapsed .nav-item .nav-badge,
.dash-shell.collapsed .user-mini-info,
.dash-shell.collapsed .user-mini > i { display: none; }
.dash-shell.collapsed .nav-item { justify-content: center; padding: 12px; }
.dash-shell.collapsed .sidebar-head { justify-content: center; padding: 0; }
.dash-shell.collapsed .sidebar-collapse { display: none; }

/* ---------- Main area ---------- */
.dash-main { min-width: 0; display: flex; flex-direction: column; }
.dash-topbar {
  height: var(--header-h); background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--s-6); gap: var(--s-4);
  position: sticky; top: 0; z-index: 90;
}
.topbar-left { display: flex; align-items: center; gap: var(--s-3); flex: 1; min-width: 0; }
.topbar-menu-btn {
  display: none; width: 40px; height: 40px; border-radius: var(--r-sm);
  align-items: center; justify-content: center; color: var(--text-strong);
}
.topbar-menu-btn:hover { background: var(--bg); }
.topbar-search {
  flex: 1; max-width: 420px; position: relative;
}
.topbar-search i {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 14px;
}
.topbar-search input {
  width: 100%; height: 40px; padding: 0 var(--s-4) 0 40px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--bg); color: var(--text-strong); font-size: var(--fs-sm);
  outline: none; transition: all var(--t-fast);
}
.topbar-search input:focus { background: var(--card); border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,91,255,.1); }
.topbar-search kbd {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: var(--card); border: 1px solid var(--border);
  padding: 1px 6px; border-radius: 4px; font-size: 11px; color: var(--muted);
}
.topbar-right { display: flex; align-items: center; gap: var(--s-2); }
.icon-btn {
  width: 40px; height: 40px; border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--text); position: relative;
  transition: all var(--t-fast);
}
.icon-btn:hover { background: var(--bg); color: var(--primary); }
.icon-btn .dot {
  position: absolute; top: 8px; right: 8px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger); border: 2px solid var(--card);
}
.topbar-avatar {
  display: flex; align-items: center; gap: var(--s-2);
  padding: 4px 8px 4px 4px; border-radius: var(--r-sm);
  transition: background var(--t-fast);
}
.topbar-avatar:hover { background: var(--bg); }
.topbar-avatar .name { font-size: var(--fs-sm); font-weight: 600; color: var(--text-strong); }
.topbar-avatar > i { color: var(--muted); font-size: 12px; }

/* ---------- Page content ---------- */
.page {
  padding: var(--s-6);
  flex: 1;
}
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--s-4); margin-bottom: var(--s-6); flex-wrap: wrap;
}
.page-title {
  font-size: var(--fs-2xl); font-weight: 800;
  letter-spacing: -0.02em; color: var(--text-strong);
  margin-bottom: 4px;
}
.page-sub { color: var(--muted); font-size: var(--fs-base); }
.page-actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }

/* ---------- KPI cards ---------- */
.kpi-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: var(--s-4); margin-bottom: var(--s-6);
}
.kpi {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--s-5);
  transition: all var(--t-base);
}
.kpi:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.kpi-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--s-3);
}
.kpi-label {
  font-size: var(--fs-sm); color: var(--muted); font-weight: 500;
}
.kpi-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.kpi-icon.primary { background: var(--primary-light); color: var(--primary); }
.kpi-icon.success { background: var(--success-bg); color: var(--success); }
.kpi-icon.warning { background: var(--warning-bg); color: var(--warning); }
.kpi-icon.info    { background: var(--info-bg); color: var(--info); }
.kpi-value {
  font-size: 26px; font-weight: 800; color: var(--text-strong);
  letter-spacing: -0.02em; line-height: 1.1;
}
.kpi-foot {
  display: flex; align-items: center; gap: 6px;
  margin-top: var(--s-3); font-size: var(--fs-xs);
  color: var(--muted);
}
.kpi-delta { font-weight: 600; display: inline-flex; align-items: center; gap: 3px; }
.kpi-delta.up { color: var(--success); }
.kpi-delta.down { color: var(--danger); }

/* ---------- Chart cards ---------- */
.chart-grid {
  display: grid; grid-template-columns: 2fr 1fr; gap: var(--s-4);
  margin-bottom: var(--s-6);
}
.chart-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--s-5);
}
.chart-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--s-4); gap: var(--s-3);
  flex-wrap: wrap;
}
.chart-title {
  font-size: var(--fs-lg); font-weight: 700; color: var(--text-strong);
}
.chart-sub { font-size: var(--fs-sm); color: var(--muted); margin-top: 2px; }
.chart-canvas-wrap { position: relative; height: 280px; }
.chart-canvas-wrap.sm { height: 220px; }

.legend {
  display: flex; gap: var(--s-4); flex-wrap: wrap;
  font-size: var(--fs-sm); color: var(--muted);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; }

/* ---------- Data tables ---------- */
.table-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-lg); overflow: hidden;
}
.table-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-5); border-bottom: 1px solid var(--border);
  gap: var(--s-3); flex-wrap: wrap;
}
.table-head h3 { font-size: var(--fs-lg); font-weight: 700; }
.table-head .sub { font-size: var(--fs-sm); color: var(--muted); margin-top: 2px; }
.table-tools { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.table-search {
  position: relative; min-width: 200px;
}
.table-search i {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  font-size: 12px; color: var(--muted);
}
.table-search input {
  height: 36px; padding: 0 var(--s-3) 0 32px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--card); font-size: var(--fs-sm); color: var(--text-strong);
  outline: none; width: 100%;
}
.table-search input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,91,255,.1); }

.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 720px; }
.data-table thead th {
  text-align: left; padding: 12px var(--s-5);
  font-size: var(--fs-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); background: #F9FAFB;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
[data-theme="dark"] .data-table thead th { background: #0F141C; }
.data-table tbody td {
  padding: 14px var(--s-5);
  font-size: var(--fs-sm); color: var(--text);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background var(--t-fast); }
.data-table tbody tr:hover { background: #FAFBFC; }
[data-theme="dark"] .data-table tbody tr:hover { background: #0F141C; }
.data-table .cell-strong { font-weight: 600; color: var(--text-strong); }
.data-table .cell-muted { color: var(--muted); font-size: var(--fs-xs); }
.cell-user { display: flex; align-items: center; gap: var(--s-3); }
.cell-user .name { font-weight: 600; color: var(--text-strong); }
.cell-user .sub { font-size: var(--fs-xs); color: var(--muted); }

.row-actions {
  display: flex; align-items: center; gap: 4px;
}
.row-action {
  width: 32px; height: 32px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); transition: all var(--t-fast);
}
.row-action:hover { background: var(--primary-light); color: var(--primary); }
.row-action.danger:hover { background: var(--danger-bg); color: var(--danger); }

/* Pagination */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-4) var(--s-5); border-top: 1px solid var(--border);
  font-size: var(--fs-sm); color: var(--muted); gap: var(--s-3);
  flex-wrap: wrap;
}
.pagination-btns { display: flex; gap: 4px; }
.page-btn {
  min-width: 32px; height: 32px; padding: 0 8px;
  border-radius: 6px; font-size: var(--fs-sm); font-weight: 500;
  color: var(--text); display: inline-flex; align-items: center; justify-content: center;
}
.page-btn:hover { background: var(--bg); }
.page-btn.active { background: var(--primary); color: #fff; }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- Sidebar drawer (mobile) ---------- */
.sidebar-scrim {
  display: none; position: fixed; inset: 0;
  background: rgba(16,24,40,.5); z-index: 95;
  opacity: 0; visibility: hidden; transition: all var(--t-base);
}
.sidebar-scrim.open { opacity: 1; visibility: visible; }

/* ---------- Empty / loading states ---------- */
.empty-state {
  text-align: center; padding: var(--s-12) var(--s-6);
  color: var(--muted);
}
.empty-state .icon {
  width: 64px; height: 64px; margin: 0 auto var(--s-4);
  border-radius: 16px; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; color: var(--muted);
}
.empty-state h3 { font-size: var(--fs-lg); color: var(--text-strong); margin-bottom: var(--s-2); }
.empty-state p { max-width: 360px; margin: 0 auto var(--s-5); }

.skeleton {
  background: linear-gradient(90deg, var(--bg) 25%, var(--border) 37%, var(--bg) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: 6px;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ---------- Notice / alert ---------- */
.notice {
  display: flex; align-items: flex-start; gap: var(--s-3);
  padding: var(--s-4); border-radius: var(--r-md);
  font-size: var(--fs-sm); line-height: 1.55;
  border: 1px solid transparent;
}
.notice i { font-size: 16px; margin-top: 1px; flex-shrink: 0; }
.notice.info { background: var(--info-bg); color: var(--info); border-color: rgba(11,165,236,.2); }
.notice.success { background: var(--success-bg); color: var(--success); border-color: rgba(18,183,106,.2); }
.notice.warning { background: var(--warning-bg); color: #B54708; border-color: rgba(247,144,9,.25); }
.notice.danger { background: var(--danger-bg); color: var(--danger); border-color: rgba(240,68,56,.2); }
.notice strong { display: block; margin-bottom: 2px; }