:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --primary-light: #e8f0fe;
  --bg: #f0f2f5;
  --bg-card: #ffffff;
  --sidebar-bg: #1e1e2d;
  --sidebar-text: #a2a3b7;
  --sidebar-active: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6c757d;
  --border: #e0e0e0;
  --success: #28a745;
  --danger: #dc3545;
  --warning: #ffc107;
  --info: #17a2b8;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --sidebar-width: 240px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* LOGIN */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e1e2d 0%, #1a73e8 100%);
}

.login-box {
  background: var(--bg-card);
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 400px;
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo h1 {
  font-size: 28px;
  letter-spacing: 4px;
  color: var(--primary);
  margin-bottom: 4px;
}

.login-logo p {
  color: var(--text-muted);
  font-size: 14px;
}

/* FORMS */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  transition: border-color 0.2s;
  background: var(--bg-card);
  color: var(--text);
}

.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* BUTTONS */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: 0.9; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-muted); }
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ALERTS */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 12px;
}

.alert-error { background: #fdeaea; color: var(--danger); border: 1px solid #f5c6cb; }
.alert-success { background: #e8f5e9; color: var(--success); border: 1px solid #c3e6cb; }
.alert-info { background: var(--primary-light); color: var(--primary); border: 1px solid #bee5eb; }

/* LAYOUT */
#app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.3s;
}

.sidebar-header {
  padding: 20px;
  text-align: center;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.sidebar-header h2 {
  color: #fff;
  font-size: 20px;
  letter-spacing: 3px;
}

.nav-menu {
  list-style: none;
  flex: 1;
  padding: 12px 0;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.nav-link:hover {
  background: rgba(255,255,255,0.05);
  color: #fff;
}

.nav-link.active {
  color: var(--sidebar-active);
  background: rgba(255,255,255,0.08);
  border-left-color: var(--primary);
}

.nav-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
  line-height: 1;
}


.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.05);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-info {
  display: flex;
  flex-direction: column;
}

.user-info span {
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}

.user-info small {
  color: var(--sidebar-text);
  font-size: 11px;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--bg-card);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar h3 {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
}

.topbar-right {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Reminder Bell */
.reminder-bell {
  position: relative;
}
.reminder-bell-btn {
  background: none;
  border: none;
  cursor: pointer;
  position: relative;
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: background 0.2s;
}
.reminder-bell-btn:hover {
  background: var(--bg);
}
.reminder-bell-icon {
  font-size: 20px;
  filter: grayscale(1) opacity(0.5);
  transition: filter 0.3s;
}
.reminder-bell-btn.bell-active .reminder-bell-icon {
  filter: none;
  animation: bellShake 0.6s ease-in-out;
}
@keyframes bellShake {
  0%, 100% { transform: rotate(0); }
  15% { transform: rotate(14deg); }
  30% { transform: rotate(-14deg); }
  45% { transform: rotate(10deg); }
  60% { transform: rotate(-8deg); }
  75% { transform: rotate(4deg); }
}
.reminder-bell-badge {
  position: absolute;
  top: 0;
  right: 2px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 8px;
  padding: 0 4px;
}
.reminder-bell-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  width: 340px;
  max-height: 420px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  z-index: 1000;
  overflow: hidden;
}
.reminder-bell-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.reminder-bell-items {
  max-height: 350px;
  overflow-y: auto;
}
.reminder-bell-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: default;
  transition: background 0.15s;
}
.reminder-bell-item:hover {
  background: var(--bg);
}
.reminder-bell-item:last-child {
  border-bottom: none;
}
.reminder-bell-dismiss {
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  padding: 1px 6px;
  color: var(--success);
  transition: all 0.15s;
  flex-shrink: 0;
}
.reminder-bell-dismiss:hover {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text);
}

.content-area {
  padding: 24px;
  flex: 1;
}

/* CARDS */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

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

.card-header h4 {
  font-size: 15px;
  font-weight: 600;
}

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

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
}

.stat-card .stat-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
}

.stat-card .stat-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.stat-card.stat-primary { border-left: 4px solid var(--primary); }
.stat-card.stat-success { border-left: 4px solid var(--success); }
.stat-card.stat-danger { border-left: 4px solid var(--danger); }
.stat-card.stat-warning { border-left: 4px solid var(--warning); }
.stat-card.stat-info { border-left: 4px solid var(--info); }

.stat-clickable {
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.stat-clickable:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

/* CHARTS GRID */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.chart-container {
  position: relative;
  height: 280px;
}

/* TABLES */
.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 10px 14px;
  text-align: left;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

th {
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
  background: var(--bg);
}

tr:hover td {
  background: var(--primary-light);
}

/* BADGES */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.badge-success { background: #e8f5e9; color: var(--success); }
.badge-danger { background: #fdeaea; color: var(--danger); }
.badge-warning { background: #fff8e1; color: #e65100; }
.badge-info { background: var(--primary-light); color: var(--primary); }

/* MODAL */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal {
  background: var(--bg-card);
  border-radius: 12px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h4 {
  font-size: 16px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* TOOLBAR */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar .search-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  min-width: 240px;
}

.toolbar .search-input:focus {
  outline: none;
  border-color: var(--primary);
}

/* PAGINATION */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.pagination button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  cursor: pointer;
  font-size: 13px;
}

.pagination button:hover { background: var(--bg); }
.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }
.pagination .page-info { font-size: 13px; color: var(--text-muted); }

/* Pager component (inline toolbar pagination) */
.pager {
  display: flex;
  align-items: center;
  gap: 6px;
}
.pager-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  border: none;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
  transition: all 0.15s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.pager-btn:hover:not(:disabled) {
  background: var(--primary-hover, #1d4ed8);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(37,99,235,0.35);
}
.pager-btn:disabled {
  background: var(--border);
  color: var(--text-muted);
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}
.pager-info {
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  background: var(--hover-bg, rgba(0,0,0,0.04));
  border-radius: var(--radius);
}
.pager-info small {
  color: var(--text-muted);
  font-weight: 400;
}

/* LOADING */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-muted);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* EMAIL TABS */
.email-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border);
}

.email-tab {
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  bottom: -2px;
}

.email-tab:hover {
  color: var(--primary);
  background: var(--primary-light);
}

.email-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: transparent;
}

/* SUB-TABS (filter buttons) */
.sub-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.sub-tab {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s;
}

.sub-tab:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.sub-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* RESPONSIVE */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .menu-toggle {
    display: block;
  }

  .charts-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .modal {
    margin: 16px;
  }
}

/* Analysis category cards */
.analysis-cat-card {
  transition: box-shadow 0.15s, opacity 0.15s;
}
.analysis-cat-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.analysis-cat-active {
  box-shadow: 0 0 0 2px var(--primary);
  opacity: 1;
}

/* ===== CLIENT PROFILE MODAL ===== */
.cp-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 30px 16px;
  overflow-y: auto;
}
.cp-modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 900px;
  max-height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
}
.cp-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}
.cp-header h3 { font-size: 15px; margin: 0; display: flex; align-items: center; gap: 4px; }
.cp-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}
.cp-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--bg);
  border-radius: var(--radius);
}
.cp-info-item { display: flex; flex-direction: column; gap: 2px; }
.cp-info-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; font-weight: 600; }
.cp-info-item > span:last-child { font-size: 13px; }
.cp-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.cp-summary-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.cp-summary-icon { font-size: 28px; }
.cp-summary-value { font-size: 22px; font-weight: 700; }
.cp-summary-label { font-size: 12px; color: var(--text-muted); }
.cp-summary-detail { font-size: 11px; margin-top: 2px; }
.cp-section {
  margin-bottom: 20px;
}
.cp-section h4 { font-size: 14px; margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.cp-table {
  width: 100%;
  font-size: 12px;
  border-collapse: collapse;
}
.cp-table th {
  text-align: left;
  padding: 6px 8px;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.cp-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--bg);
  white-space: nowrap;
}
.cp-table tr:hover td { background: var(--bg); }
.cp-search-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--bg);
}
.cp-search-item:hover { background: var(--primary-light); }
#cp-search-results {
  max-height: 200px;
  overflow-y: auto;
  border-bottom: 1px solid var(--border);
}
.client-link {
  cursor: pointer;
  color: var(--primary);
  text-decoration: none;
}
.client-link:hover { text-decoration: underline; }
.cp-search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}
.cp-search-icon {
  position: absolute;
  left: 10px;
  font-size: 13px;
  color: var(--text-muted);
  pointer-events: none;
}
.cp-search-input {
  width: 300px;
  padding: 8px 12px 8px 32px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.cp-search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,115,232,0.12);
  background: var(--bg-card);
}
.cp-search-input::placeholder { color: var(--text-muted); opacity: 0.7; }
.cp-close-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius);
  background: rgba(220,38,38,0.6);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1;
}
.cp-close-btn:hover {
  background: rgba(220,38,38,1);
  color: #fff;
}
