/* =========================================================
   AfterSolves Loyalty — Design System
   Inspired by Apple, Linear, Notion, Arc Browser
   ========================================================= */

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #0A0A0A;
  background: #FAFAFA;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01', 'ss03';
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
img { max-width: 100%; display: block; }
input, textarea, select { outline: none; }

/* ---------- Design Tokens ---------- */
:root {
  /* Backgrounds */
  --bg-app: #FAFAFA;
  --bg-canvas: #FAFAFA;
  --bg-card: rgba(255, 255, 255, 0.72);
  --bg-card-solid: #FFFFFF;
  --bg-elevated: #FFFFFF;
  --bg-hover: rgba(0, 0, 0, 0.03);
  --bg-active: rgba(0, 0, 0, 0.06);
  --bg-sidebar: rgba(255, 255, 255, 0.6);

  /* Text */
  --text-primary: #0A0A0A;
  --text-secondary: #6B7280;
  --text-tertiary: #9CA3AF;
  --text-inverse: #FFFFFF;

  /* Borders */
  --border-subtle: rgba(0, 0, 0, 0.06);
  --border-default: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.12);

  /* Accents */
  --accent: #0A0A0A;
  --accent-hover: #2A2A2A;
  --accent-active: #000000;

  /* Status */
  --success: #16A34A;
  --success-bg: rgba(22, 163, 74, 0.08);
  --warning: #D97706;
  --warning-bg: rgba(217, 119, 6, 0.08);
  --danger: #DC2626;
  --danger-bg: rgba(220, 38, 38, 0.08);
  --info: #2563EB;
  --info-bg: rgba(37, 99, 235, 0.08);

  /* Radii */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-2xl: 24px;
  --r-pill: 999px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.03);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.10), 0 4px 16px rgba(0, 0, 0, 0.05);

  /* Spacing */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;

  /* Layout */
  --sidebar-w: 248px;
  --sidebar-w-collapsed: 72px;
  --topbar-h: 60px;

  /* Transitions */
  --t-fast: 120ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-slow: 320ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Glass */
  --glass-blur: saturate(180%) blur(20px);
  --glass-blur-light: saturate(180%) blur(12px);
}

/* ---------- App Layout ---------- */
#app { display: flex; height: 100vh; width: 100%; overflow: hidden; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  transition: width var(--t-base), transform var(--t-base);
  z-index: 40;
  position: relative;
}
.sidebar.collapsed { width: var(--sidebar-w-collapsed); }
.sidebar.collapsed .brand-text,
.sidebar.collapsed .sidebar-nav-item-label,
.sidebar.collapsed .sidebar-section-label,
.sidebar.collapsed .user-info,
.sidebar.collapsed .sidebar-collapse svg { opacity: 0; pointer-events: none; }
.sidebar.collapsed .sidebar-collapse { transform: rotate(180deg); }
.sidebar.collapsed .sidebar-nav-item { justify-content: center; padding: 10px; }
.sidebar.collapsed .user-card { justify-content: center; }

.sidebar-header {
  padding: 16px 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { flex-shrink: 0; display: flex; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; transition: opacity var(--t-fast); }
.brand-name { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; color: var(--text-primary); }
.brand-sub { font-size: 11px; color: var(--text-tertiary); font-weight: 500; }

.sidebar-collapse {
  transition: transform var(--t-base);
  flex-shrink: 0;
}
.sidebar-collapse svg { transition: opacity var(--t-fast); }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,0.1) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.08); border-radius: 3px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }

.sidebar-section { margin-bottom: 18px; }
.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  padding: 0 10px 6px;
  transition: opacity var(--t-fast);
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
  margin-bottom: 2px;
  position: relative;
  white-space: nowrap;
}
.sidebar-nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-nav-item.active { background: var(--bg-active); color: var(--text-primary); }
.sidebar-nav-item.active::before {
  content: '';
  position: absolute;
  left: -10px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}
.sidebar-nav-item-icon { flex-shrink: 0; display: flex; }
.sidebar-nav-item-label { transition: opacity var(--t-fast); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.sidebar-nav-item-badge {
  background: var(--accent);
  color: var(--text-inverse);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--r-pill);
  line-height: 1.4;
}
.sidebar-nav-item-dot {
  width: 6px;
  height: 6px;
  background: var(--danger);
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--r-sm);
  transition: background var(--t-fast);
  cursor: pointer;
}
.user-card:hover { background: var(--bg-hover); }
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}
.avatar.sm { width: 24px; height: 24px; font-size: 10px; }
.avatar.lg { width: 48px; height: 48px; font-size: 16px; }
.avatar.xl { width: 64px; height: 64px; font-size: 22px; }
.user-info { flex: 1; min-width: 0; transition: opacity var(--t-fast); }
.user-name { font-size: 13px; font-weight: 600; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 11px; color: var(--text-tertiary); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 39;
  opacity: 0;
  transition: opacity var(--t-base);
}
.sidebar-overlay.visible { display: block; opacity: 1; }

/* ---------- Main ---------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  background: rgba(250, 250, 250, 0.72);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.topbar-center { flex: 1; display: flex; justify-content: center; min-width: 0; }
.topbar-divider { width: 1px; height: 20px; background: var(--border-default); margin: 0 4px; }

.sidebar-toggle { display: none; }

.breadcrumbs { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary); }
.breadcrumbs a { color: var(--text-secondary); transition: color var(--t-fast); }
.breadcrumbs a:hover { color: var(--text-primary); }
.breadcrumbs .crumb-current { color: var(--text-primary); font-weight: 500; }
.breadcrumbs .crumb-sep { color: var(--text-tertiary); }

/* Global search */
.global-search {
  position: relative;
  width: 100%;
  max-width: 440px;
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  padding: 0 12px;
  height: 38px;
  transition: all var(--t-fast);
}
.global-search:focus-within {
  background: #FFFFFF;
  border-color: rgba(0,0,0,0.18);
  box-shadow: 0 0 0 4px rgba(0,0,0,0.04);
}
.search-icon { color: var(--text-tertiary); flex-shrink: 0; }
.global-search input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 0 10px;
  font-size: 13.5px;
  color: var(--text-primary);
}
.global-search input::placeholder { color: var(--text-tertiary); }
.search-kbd {
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-tertiary);
  background: rgba(0,0,0,0.04);
  border: 1px solid var(--border-subtle);
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.search-results {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  max-height: 420px;
  overflow-y: auto;
  z-index: 50;
  padding: 6px;
}
.search-results.open { display: block; }
.search-results-section { padding: 6px; }
.search-results-section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  padding: 4px 8px;
}
.search-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--t-fast);
}
.search-result-item:hover { background: var(--bg-hover); }
.search-result-item-icon { color: var(--text-tertiary); flex-shrink: 0; }
.search-result-item-text { flex: 1; min-width: 0; }
.search-result-item-title { font-size: 13px; color: var(--text-primary); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result-item-sub { font-size: 11px; color: var(--text-tertiary); }
.search-result-item-type {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  background: var(--bg-hover);
  padding: 2px 6px;
  border-radius: 4px;
}
.search-empty { padding: 24px; text-align: center; color: var(--text-tertiary); font-size: 13px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 14px;
  height: 36px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  font-weight: 500;
  transition: all var(--t-fast);
  white-space: nowrap;
  border: 1px solid transparent;
  user-select: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--text-inverse); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:active:not(:disabled) { background: var(--accent-active); }
.btn-secondary { background: var(--bg-card-solid); color: var(--text-primary); border-color: var(--border-default); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--border-strong); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }
.btn-danger { background: var(--danger); color: var(--text-inverse); }
.btn-danger:hover:not(:disabled) { background: #B91C1C; }
.btn-success { background: var(--success); color: var(--text-inverse); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-lg { height: 42px; padding: 0 18px; font-size: 14.5px; }
.btn-icon { padding: 0; width: 36px; }
.btn-icon.btn-sm { width: 30px; }
.btn-block { width: 100%; }

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  transition: all var(--t-fast);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn.lg { width: 40px; height: 40px; }
.icon-btn.has-badge { position: relative; }
.icon-btn .dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 7px;
  height: 7px;
  background: var(--danger);
  border-radius: 50%;
  border: 2px solid var(--bg-app);
}

/* ---------- View Container ---------- */
.view {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 32px 32px 64px;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,0.1) transparent;
}
.view::-webkit-scrollbar { width: 8px; }
.view::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.08); border-radius: 4px; }
.view::-webkit-scrollbar-track { background: transparent; }

/* ---------- Page Header ---------- */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.page-title-group { min-width: 0; }
.page-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 4px;
  line-height: 1.2;
}
.page-subtitle {
  font-size: 13.5px;
  color: var(--text-secondary);
  max-width: 640px;
}
.page-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ---------- Card ---------- */
.card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur-light);
  -webkit-backdrop-filter: var(--glass-blur-light);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-solid {
  background: var(--bg-card-solid);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.card-pad { padding: 20px; }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
}
.card-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.card-subtitle { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }
.card-body { padding: 20px; }
.card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-subtle);
  background: rgba(0,0,0,0.01);
}

/* ---------- Stat Cards ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur-light);
  -webkit-backdrop-filter: var(--glass-blur-light);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: 18px;
  transition: all var(--t-base);
  position: relative;
  overflow: hidden;
}
.stat-card:hover {
  border-color: var(--border-default);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.stat-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.stat-card-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: none;
  letter-spacing: 0;
}
.stat-card-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  background: var(--bg-hover);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-card-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.1;
  margin-bottom: 6px;
}
.stat-card-meta { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.stat-card-change {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
}
.stat-card-change.up { color: var(--success); background: var(--success-bg); }
.stat-card-change.down { color: var(--danger); background: var(--danger-bg); }
.stat-card-change.neutral { color: var(--text-secondary); background: var(--bg-hover); }
.stat-card-period { color: var(--text-tertiary); }
.stat-card-spark { margin-top: 12px; height: 32px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  padding: 10px 16px;
  background: rgba(0,0,0,0.015);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
  user-select: none;
}
.table th.sortable { cursor: pointer; transition: color var(--t-fast); }
.table th.sortable:hover { color: var(--text-secondary); }
.table th.sortable .sort-icon { opacity: 0.4; margin-left: 4px; }
.table th.sortable.sorted .sort-icon { opacity: 1; }
.table td {
  padding: 12px 16px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background var(--t-fast); }
.table tbody tr:hover { background: var(--bg-hover); }
.table-cell-primary { font-weight: 500; color: var(--text-primary); }
.table-cell-secondary { color: var(--text-secondary); }
.table-cell-mono { font-family: 'SF Mono', 'Menlo', monospace; font-size: 12px; }
.table-cell-truncate { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-row-actions { display: flex; gap: 4px; opacity: 0; transition: opacity var(--t-fast); }
.table tbody tr:hover .table-row-actions { opacity: 1; }
.table-row-actions .icon-btn { width: 28px; height: 28px; }

/* ---------- Badges & Pills ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: 11.5px;
  font-weight: 500;
  border-radius: var(--r-pill);
  background: var(--bg-hover);
  color: var(--text-secondary);
  line-height: 1.5;
  white-space: nowrap;
}
.badge-dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: rgba(0,0,0,0.05); color: var(--text-secondary); }
.badge-dark { background: var(--accent); color: var(--text-inverse); }

.tier-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid var(--border-default);
  background: var(--bg-card-solid);
}

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.form-label .req { color: var(--danger); }
.form-hint { font-size: 11.5px; color: var(--text-tertiary); margin-top: 4px; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  background: var(--bg-card-solid);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  font-size: 13.5px;
  color: var(--text-primary);
  transition: all var(--t-fast);
}
.form-textarea { height: auto; padding: 10px 12px; min-height: 80px; resize: vertical; line-height: 1.5; }
.form-input:hover, .form-select:hover, .form-textarea:hover { border-color: var(--border-strong); }
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: rgba(0,0,0,0.2);
  box-shadow: 0 0 0 4px rgba(0,0,0,0.04);
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-tertiary); }
.form-select { appearance: none; background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 14px; padding-right: 32px; cursor: pointer; }

.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }

/* Toggle switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}
.toggle input { display: none; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: rgba(0,0,0,0.12);
  border-radius: var(--r-pill);
  transition: background var(--t-fast);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  top: 2px;
  background: #FFF;
  border-radius: 50%;
  transition: transform var(--t-fast);
  box-shadow: var(--shadow-sm);
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

/* Checkbox */
.checkbox {
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--t-fast);
  background: #FFF;
}
.checkbox.checked { background: var(--accent); border-color: var(--accent); }
.checkbox.checked svg { display: block; }
.checkbox svg { display: none; color: #FFF; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 20px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--text-primary); border-bottom-color: var(--accent); }
.tab-count {
  background: var(--bg-hover);
  color: var(--text-tertiary);
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: var(--r-pill);
  font-weight: 600;
}
.tab.active .tab-count { background: var(--accent); color: var(--text-inverse); }

/* ---------- Filter Bar ---------- */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.filter-bar .search-box {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 320px;
}
.filter-bar .search-box input {
  width: 100%;
  height: 36px;
  padding: 0 12px 0 36px;
  background: var(--bg-card-solid);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  font-size: 13px;
  transition: all var(--t-fast);
}
.filter-bar .search-box input:focus { border-color: rgba(0,0,0,0.2); box-shadow: 0 0 0 4px rgba(0,0,0,0.04); }
.filter-bar .search-box .search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-tertiary); }

.filter-select {
  height: 36px;
  padding: 0 32px 0 12px;
  background: var(--bg-card-solid);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  font-size: 13px;
  color: var(--text-primary);
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
  cursor: pointer;
  transition: all var(--t-fast);
}
.filter-select:hover { border-color: var(--border-strong); }

/* Date range pills */
.date-range-pills {
  display: inline-flex;
  background: var(--bg-card-solid);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  padding: 3px;
  gap: 2px;
}
.date-range-pill {
  padding: 5px 12px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: 5px;
  cursor: pointer;
  transition: all var(--t-fast);
}
.date-range-pill:hover { color: var(--text-primary); }
.date-range-pill.active { background: var(--accent); color: var(--text-inverse); }

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  flex-wrap: wrap;
}
.pagination-info { font-size: 12.5px; color: var(--text-secondary); }
.pagination-controls { display: flex; align-items: center; gap: 4px; }
.pagination-btn {
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: all var(--t-fast);
}
.pagination-btn:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }
.pagination-btn.active { background: var(--accent); color: var(--text-inverse); }
.pagination-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- Grid utilities ---------- */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; } .gap-6 { gap: 24px; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; } .mt-8 { margin-top: 32px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; } .mb-8 { margin-bottom: 32px; }
.text-sm { font-size: 12.5px; } .text-xs { font-size: 11.5px; } .text-lg { font-size: 16px; } .text-xl { font-size: 20px; }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-primary { color: var(--text-primary); }
.font-medium { font-weight: 500; } .font-semibold { font-weight: 600; } .font-bold { font-weight: 700; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.w-full { width: 100%; }

/* ---------- Progress ---------- */
.progress {
  height: 6px;
  background: rgba(0,0,0,0.06);
  border-radius: var(--r-pill);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: var(--r-pill);
  transition: width var(--t-slow);
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  opacity: 0;
  animation: fadeIn var(--t-base) forwards;
}
@keyframes fadeIn { to { opacity: 1; } }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: modalIn var(--t-base) forwards;
}
.modal.lg { max-width: 720px; }
.modal.xl { max-width: 960px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.modal-title { font-size: 16px; font-weight: 600; color: var(--text-primary); }
.modal-subtitle { font-size: 12.5px; color: var(--text-tertiary); margin-top: 2px; }
.modal-body { padding: 22px; overflow-y: auto; flex: 1; }
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 22px;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

/* ---------- Toast ---------- */
.toast-root {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
  max-width: 380px;
  pointer-events: auto;
  animation: toastIn var(--t-base) forwards;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}
.toast.removing { animation: toastOut var(--t-base) forwards; }
@keyframes toastOut {
  to { opacity: 0; transform: translateX(20px); }
}
.toast-icon { flex-shrink: 0; }
.toast-icon.success { color: var(--success); }
.toast-icon.error { color: var(--danger); }
.toast-icon.info { color: var(--info); }
.toast-content { flex: 1; min-width: 0; }
.toast-title { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.toast-msg { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.toast-close { color: var(--text-tertiary); padding: 2px; }

/* ---------- Empty State ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
}
.empty-state-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--r-lg);
  background: var(--bg-hover);
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}
.empty-state-title { font-size: 15px; font-weight: 600; color: var(--text-primary); margin-bottom: 4px; }
.empty-state-desc { font-size: 13px; color: var(--text-secondary); max-width: 320px; margin-bottom: 16px; }

/* ---------- Skeleton ---------- */
.skeleton {
  background: linear-gradient(90deg, rgba(0,0,0,0.04) 25%, rgba(0,0,0,0.07) 37%, rgba(0,0,0,0.04) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--r-sm);
}
@keyframes shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}
.skeleton-text { height: 12px; margin-bottom: 6px; }
.skeleton-text.short { width: 60%; }
.skeleton-text.long { width: 100%; }
.skeleton-circle { width: 32px; height: 32px; border-radius: 50%; }

/* ---------- Dropdown Menu ---------- */
.dropdown {
  position: relative;
  display: inline-block;
}
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 50;
  display: none;
  animation: dropdownIn var(--t-fast) forwards;
}
@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.dropdown-menu.open { display: block; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text-primary);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--t-fast);
  white-space: nowrap;
}
.dropdown-item:hover { background: var(--bg-hover); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger:hover { background: var(--danger-bg); }
.dropdown-divider { height: 1px; background: var(--border-subtle); margin: 4px 0; }
.dropdown-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-tertiary); padding: 6px 10px 4px; }

/* ---------- Avatar Group ---------- */
.avatar-group { display: inline-flex; }
.avatar-group .avatar {
  border: 2px solid var(--bg-card-solid);
  margin-left: -8px;
}
.avatar-group .avatar:first-child { margin-left: 0; }

/* ---------- View Transitions ---------- */
.view > * { animation: viewIn var(--t-base) forwards; }
@keyframes viewIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Tooltip ---------- */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--text-inverse);
  font-size: 11px;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-fast);
  z-index: 100;
}
[data-tooltip]:hover::after { opacity: 1; }

/* ---------- Chart Container ---------- */
.chart-container { width: 100%; position: relative; }
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}
.chart-legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.chart-legend-dot { width: 8px; height: 8px; border-radius: 2px; }

/* ---------- Misc utilities ---------- */
.divider { height: 1px; background: var(--border-subtle); margin: 16px 0; }
.divider-v { width: 1px; background: var(--border-subtle); align-self: stretch; }
.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); position: relative; }
.pulse-dot::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  background: var(--success);
  opacity: 0.3;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { transform: scale(0.8); opacity: 0.4; }
  100% { transform: scale(1.8); opacity: 0; }
}
.mono { font-family: 'SF Mono', 'Menlo', monospace; }
.no-data { color: var(--text-tertiary); font-style: italic; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clickable { cursor: pointer; }
.spin { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-xl);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar.collapsed { width: var(--sidebar-w); }
  .sidebar.collapsed .brand-text,
  .sidebar.collapsed .sidebar-nav-item-label,
  .sidebar.collapsed .sidebar-section-label,
  .sidebar.collapsed .user-info { opacity: 1; pointer-events: auto; }
  .sidebar.collapsed .sidebar-nav-item { justify-content: flex-start; padding: 8px 10px; }
  .sidebar.collapsed .sidebar-collapse { transform: rotate(0deg); }
  .sidebar-toggle { display: inline-flex; }
  .sidebar-collapse { display: none; }
  .view { padding: 20px 16px 48px; }
  .topbar { padding: 0 16px; }
  .topbar-center { display: none; }
  .search-kbd { display: none; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page-title { font-size: 22px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .table-row-actions { opacity: 1; }
}

@media (max-width: 600px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-card-value { font-size: 22px; }
  .stat-card-icon { width: 28px; height: 28px; }
  .topbar-right .btn-text { display: none; }
  .topbar-right .btn-primary { width: 36px; padding: 0; }
  .page-header { flex-direction: column; align-items: stretch; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar .search-box { max-width: none; }
  .filter-bar .filter-select { width: 100%; }
  .date-range-pills { width: 100%; overflow-x: auto; }
  .tabs { padding-bottom: 0; }
  .modal { border-radius: var(--r-lg); max-height: 95vh; }
  .modal-body { padding: 16px; }
  .modal-header { padding: 14px 16px; }
  .modal-footer { padding: 12px 16px; flex-wrap: wrap; }
  .modal-footer .btn { flex: 1; }
  .card-pad { padding: 16px; }
  .card-header { padding: 12px 16px; }
  .card-body { padding: 16px; }
  .table th, .table td { padding: 10px 12px; }
  .toast-root { left: 16px; right: 16px; bottom: 16px; }
  .toast { min-width: 0; max-width: none; }
  .view { padding: 16px 12px 80px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-divider { display: none; }
  .breadcrumbs { font-size: 12px; }
  .grid-auto { grid-template-columns: 1fr; }
  .pagination { flex-direction: column; align-items: stretch; gap: 8px; }
  .pagination-controls { justify-content: center; }
}

@media (max-width: 380px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card-value { font-size: 24px; }
}

/* Mobile bottom safe area */
@supports (padding: max(0px)) {
  .view { padding-bottom: max(48px, env(safe-area-inset-bottom)); }
}
