:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-hover: #f9fafb;
  --border: #e3e8ee;
  --border-light: #edf0f4;
  --text: #1a1f36;
  --text-secondary: #3c4257;
  --text-muted: #697386;
  --primary: #635bff;
  --primary-hover: #5349e0;
  --primary-light: #f0eeff;
  --success: #0cad55;
  --success-light: #e8f9ef;
  --warning: #e8912d;
  --warning-light: #fef5e8;
  --danger: #df1b41;
  --danger-light: #fde8ec;
  --radius: 8px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* Login */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #f6f8fa 0%, #edf0f4 100%);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.login-card h1 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.login-card .subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 28px;
}

.login-card form { display: flex; flex-direction: column; gap: 12px; }

.login-card input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.login-card input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

.login-card button {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 10px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s;
}

.login-card button:hover { background: var(--primary-hover); }

.error-msg {
  background: var(--danger-light);
  border: 1px solid #fbc1cc;
  color: var(--danger);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
}

/* Layout */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 10;
}

.sidebar-brand {
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.sidebar-brand h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.sidebar-brand small {
  color: var(--text-muted);
  font-size: 12px;
}

.sidebar nav { flex: 1; padding: 4px 0; }

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 450;
  transition: all 0.15s;
  border-left: 2px solid transparent;
}

.sidebar nav a:hover {
  color: var(--text);
  background: var(--bg);
}

.sidebar nav a.active {
  color: var(--primary);
  background: var(--primary-light);
  border-left-color: var(--primary);
  font-weight: 500;
}

.sidebar-footer {
  padding: 8px 20px;
  border-top: 1px solid var(--border);
}

.sidebar-footer:first-of-type { border-top: none; }

.sidebar-footer a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
}

.sidebar-footer a:hover { color: var(--text); }

/* Main content with optional right sidebar */
.main-area {
  flex: 1;
  margin-left: 220px;
  display: flex;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  padding: 28px 32px;
  max-width: 860px;
  min-width: 0;
}

.right-sidebar {
  width: 320px;
  border-left: 1px solid var(--border);
  background: var(--surface);
  padding: 28px 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

/* Header bar */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}

.last-updated {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 2px;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  font-weight: 450;
  white-space: nowrap;
}

.btn:hover { background: var(--bg); border-color: #cdd3dc; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { border-color: #fbc1cc; color: var(--danger); }
.btn-danger:hover { background: var(--danger-light); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-ghost { border: none; background: none; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--bg); }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.tab {
  padding: 10px 18px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-weight: 450;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tab:hover { color: var(--text); }

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 500;
}

.tab-count {
  background: var(--bg);
  color: var(--text-muted);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 500;
}

.tab.active .tab-count {
  background: var(--primary-light);
  color: var(--primary);
}

/* Insight cards */
.insights-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.insight-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  transition: all 0.15s;
  box-shadow: var(--shadow-sm);
}

.insight-card:hover { box-shadow: var(--shadow); }

.insight-card.priority-2 { border-left: 3px solid var(--danger); }
.insight-card.priority-1 { border-left: 3px solid var(--warning); }
.insight-card.priority-0 { border-left: 3px solid var(--border); }

.insight-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.insight-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  flex: 1;
}

.insight-badges {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}

.badge-email { background: var(--primary-light); color: var(--primary); }
.badge-calendar { background: var(--success-light); color: var(--success); }
.badge-priority { background: var(--warning-light); color: var(--warning); }
.badge-urgent { background: var(--danger-light); color: var(--danger); }

.insight-body {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 10px;
}

.insight-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
}

.insight-actions {
  display: flex;
  gap: 4px;
}

/* To Do sidebar */
.todo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.todo-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

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

.todo-input-row {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

.todo-input-row input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.todo-input-row input:focus { border-color: var(--primary); }

.todo-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.todo-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  transition: background 0.1s;
}

.todo-item:hover { background: var(--bg); }

.todo-item input[type="checkbox"] {
  margin-top: 2px;
  accent-color: var(--primary);
  cursor: pointer;
}

.todo-item-text {
  flex: 1;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.todo-item.completed .todo-item-text {
  text-decoration: line-through;
  color: var(--text-muted);
}

.todo-item-delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
  transition: opacity 0.1s;
}

.todo-item:hover .todo-item-delete { opacity: 1; }
.todo-item-delete:hover { color: var(--danger); }

.todo-divider {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 0 6px;
  font-weight: 500;
}

/* Weekly reference lists */
.weekly-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

.weekly-panel h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.weekly-panel ul {
  list-style: none;
  padding: 0;
}

.weekly-panel li {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 4px 0;
  line-height: 1.5;
  cursor: pointer;
  border-radius: 4px;
  padding-left: 6px;
}

.weekly-panel li:hover { background: var(--bg); }

.weekly-panel li::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
}

.weekly-panel.accomplishments li::before { background: var(--success); }
.weekly-panel.risks li::before { background: var(--warning); }
.weekly-panel.actions li::before { background: var(--primary); }

/* Accounts page */
.account-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
}

.account-info { display: flex; flex-direction: column; gap: 2px; }
.account-email { font-size: 14px; font-weight: 500; color: var(--text); }
.account-label { font-size: 12px; color: var(--text-muted); }

/* Stats cards */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}

.stat-value {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state h3 {
  font-size: 15px;
  margin-bottom: 6px;
  color: var(--text-secondary);
  font-weight: 500;
}

.empty-state p { font-size: 13px; }

/* Loading */
.loading-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-md);
}

.modal h3 {
  margin-bottom: 16px;
  font-size: 16px;
  font-weight: 600;
}

.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  font-weight: 500;
}

.form-group input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}

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

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* Table */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

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

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

/* Section headers */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-header h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

/* Tab content */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Source badges */
.badge-source {
  background: #f0f0f5;
  color: var(--text-secondary);
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 500;
  white-space: nowrap;
}

/* Source filter bar */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-bar label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  margin-right: 2px;
}

.filter-chip {
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 450;
}

.filter-chip:hover { border-color: var(--primary); color: var(--primary); }
.filter-chip.active { background: var(--primary); border-color: var(--primary); color: white; }

/* Mobile hamburger */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 20;
  align-items: center;
  padding: 0 16px;
  justify-content: space-between;
}

.mobile-header h2 { font-size: 16px; font-weight: 600; }

.hamburger {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text);
  padding: 4px 8px;
  line-height: 1;
}

.mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 25;
}

.mobile-overlay.active { display: block; }

/* Mobile todo toggle */
.mobile-todo-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  font-size: 20px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  z-index: 15;
  align-items: center;
  justify-content: center;
}

.mobile-todo-panel {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 60vh;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
  z-index: 30;
  padding: 20px;
  overflow-y: auto;
}

.mobile-todo-panel.active { display: block; }

/* Responsive */
@media (max-width: 1024px) {
  .right-sidebar { display: none; }
  .mobile-todo-toggle { display: flex; }
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.25s ease; z-index: 30; }
  .sidebar.open { transform: translateX(0); }
  .mobile-header { display: flex; }
  .main-area { margin-left: 0; padding-top: 52px; }
  .main-content { padding: 16px; }
  .stats-row { grid-template-columns: 1fr 1fr; }
  .mobile-todo-toggle { display: flex; }

  .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .page-header h1 { font-size: 18px; }
  .header-actions { width: 100%; justify-content: space-between; }

  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab { white-space: nowrap; padding: 10px 14px; font-size: 13px; }

  .insight-card { padding: 12px 14px; }
  .insight-header { flex-direction: column; gap: 6px; }
  .insight-actions { flex-wrap: wrap; }

  .filter-bar { margin-bottom: 12px; }

  /* Weekly grid single column on mobile */
  #view-weekly > div { grid-template-columns: 1fr !important; }

  /* Prevent iOS zoom on input focus */
  input, select, textarea { font-size: 16px !important; }
}
