/* RAD Dashboard — Blue-gray professional theme */
:root {
  --bg-page: #F3F4F6;
  --bg-card: #FFFFFF;
  --bg-card-hover: #F9FAFB;
  --bg-sidebar: #1E293B;
  --bg-sidebar-hover: #334155;
  --accent: #3B82F6;
  --accent-bright: #60A5FA;
  --accent-dim: rgba(59, 130, 246, 0.12);
  --text-page: #111827;
  --text-page-secondary: #6B7280;
  --text-page-muted: #9CA3AF;
  --text-sidebar: #E2E8F0;
  --text-sidebar-muted: #94A3B8;
  --border: #E5E7EB;
  --border-hover: #D1D5DB;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.1);
  /* Category colors */
  --cat-client: #EF4444;
  --cat-client-bg: rgba(239,68,68,0.1);
  --cat-followup: #F59E0B;
  --cat-followup-bg: rgba(245,158,11,0.1);
  --cat-newsletter: #6B7280;
  --cat-newsletter-bg: rgba(107,114,128,0.1);
  --cat-billing: #8B5CF6;
  --cat-billing-bg: rgba(139,92,246,0.1);
  --cat-fyi: #14B8A6;
  --cat-fyi-bg: rgba(20,184,166,0.1);
  /* Urgency */
  --urgency-5: #EF4444;
  --urgency-4: #F97316;
  --urgency-3: #EAB308;
  /* Status */
  --green: #22C55E;
  --green-dim: rgba(34,197,94,0.15);
  --red: #EF4444;
  --red-dim: rgba(239,68,68,0.12);
  --blue: #3B82F6;
  --blue-dim: rgba(59,130,246,0.12);
  --border-light: rgba(0,0,0,0.08);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-page);
  color: var(--text-page);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* ─── Sidebar ─── */
.sidebar {
  width: 240px;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logo h1 {
  font-size: 17px;
  font-weight: 700;
  color: #FFFFFF;
  letter-spacing: -0.01em;
}

.sidebar-logo span {
  font-size: 11px;
  color: var(--text-sidebar-muted);
  display: block;
  margin-top: 2px;
}

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

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

.sidebar-nav a:hover {
  color: #FFFFFF;
  background: rgba(255,255,255,0.04);
}

.sidebar-nav a.active {
  color: #FFFFFF;
  background: rgba(59,130,246,0.15);
  border-left-color: var(--accent);
}

.sidebar-nav a svg { width: 18px; height: 18px; flex-shrink: 0; }

.nav-badge {
  display: none;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 700;
  margin-left: auto;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-sync {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-sidebar-muted);
}

.sidebar-sync svg { opacity: 0.5; }

/* ─── Main Content ─── */
.main-content {
  flex: 1;
  margin-left: 240px;
  padding: 28px 36px;
  min-width: 0;
  background: var(--bg-page);
  min-height: 100vh;
  overflow-y: auto;
}

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

.page-header h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-page);
  letter-spacing: -0.02em;
}

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

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-page-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

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

/* ─── Filter Bar ─── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.filter-bar .search-input {
  flex: 1;
  min-width: 200px;
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  color: var(--text-page);
  outline: none;
  transition: border-color 0.15s;
}

.filter-bar .search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.filter-bar .search-input::placeholder { color: var(--text-page-muted); }

.filter-bar select {
  width: auto;
  min-width: 160px;
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  color: var(--text-page);
  cursor: pointer;
  appearance: auto;
  outline: none;
}

.filter-bar select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* ─── Email Cards ─── */
.email-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.email-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.15s;
  border-left: 4px solid var(--border);
}

.email-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-hover);
}

/* Category left-border colors */
.email-card--client-request { border-left-color: var(--cat-client); }
.email-card--follow-up-needed { border-left-color: var(--cat-followup); }
.email-card--newsletter { border-left-color: var(--cat-newsletter); }
.email-card--billing { border-left-color: var(--cat-billing); }
.email-card--fyi { border-left-color: var(--cat-fyi); }

/* Flagged highlight */
.email-card--flagged {
  background: #FFFBEB;
  border-color: #FDE68A;
}

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

.email-card-from { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.from-name { font-weight: 600; font-size: 14px; color: var(--text-page); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.from-address { font-size: 12px; color: var(--text-page-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.email-card-meta { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.email-card-subject {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-page);
  margin-bottom: 4px;
  line-height: 1.4;
}

.email-card-summary {
  font-size: 13px;
  color: var(--text-page-secondary);
  line-height: 1.5;
  margin-bottom: 8px;
}

.email-time { font-size: 12px; color: var(--text-page-muted); white-space: nowrap; }

/* ─── Urgency Indicators ─── */
.urgency {
  font-weight: 800;
  font-size: 12px;
  letter-spacing: -0.05em;
}

.urgency-5 { color: var(--urgency-5); }
.urgency-4 { color: var(--urgency-4); }
.urgency-3 { color: var(--urgency-3); }

/* ─── Category Badges ─── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge-client { background: var(--cat-client-bg); color: var(--cat-client); }
.badge-followup { background: var(--cat-followup-bg); color: var(--cat-followup); }
.badge-newsletter { background: var(--cat-newsletter-bg); color: var(--cat-newsletter); }
.badge-billing { background: var(--cat-billing-bg); color: var(--cat-billing); }
.badge-fyi { background: var(--cat-fyi-bg); color: var(--cat-fyi); }
.badge-default { background: rgba(107,114,128,0.1); color: #6B7280; }

/* ─── Action Buttons ─── */
.email-card-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-primary { background: var(--accent); color: #FFFFFF; }
.btn-primary:hover { background: #2563EB; }

.btn-success { background: #22C55E; color: #FFFFFF; }
.btn-success:hover { background: #16A34A; }

.btn-secondary { background: #F3F4F6; color: var(--text-page-secondary); border: 1px solid var(--border); }
.btn-secondary:hover { background: #E5E7EB; color: var(--text-page); }

.btn-warning { background: rgba(245,158,11,0.1); color: #D97706; }
.btn-warning:hover { background: rgba(245,158,11,0.2); }

.btn-warning-active { background: #F59E0B; color: #FFFFFF; }
.btn-warning-active:hover { background: #D97706; }

.btn-ghost { background: transparent; color: var(--text-page-muted); }
.btn-ghost:hover { background: #F3F4F6; color: var(--text-page-secondary); }

.btn-danger { background: #EF4444; color: #FFFFFF; }
.btn-danger:hover { background: #DC2626; }

/* ─── Email Body (expanded) ─── */
.email-card-body {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.email-body-iframe {
  width: 100%;
  min-height: 200px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #FFFFFF;
}

.email-body-text {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: var(--text-page);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  max-height: 400px;
  overflow-y: auto;
  padding: 12px;
  background: #F9FAFB;
  border-radius: var(--radius);
}

.email-body-footer {
  margin-top: 12px;
  display: flex;
  gap: 8px;
}

.email-body-loading, .email-body-error {
  padding: 20px;
  text-align: center;
  color: var(--text-page-muted);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.email-body-error { color: var(--red); }

/* ─── Stats Section ─── */
.stats-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}

.stats-section h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-page);
  margin-bottom: 20px;
}

.bar-chart { display: flex; flex-direction: column; gap: 12px; }

.bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bar-label {
  width: 120px;
  font-size: 13px;
  color: var(--text-page-secondary);
  text-align: right;
  flex-shrink: 0;
}

.bar-track {
  flex: 1;
  height: 24px;
  background: #F3F4F6;
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
  min-width: 2px;
}

.bar-client { background: var(--cat-client); }
.bar-followup { background: var(--cat-followup); }
.bar-newsletter { background: var(--cat-newsletter); }
.bar-billing { background: var(--cat-billing); }
.bar-fyi { background: var(--cat-fyi); }

.bar-value {
  width: 36px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-page);
  text-align: right;
}

/* ─── Toasts ─── */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-page);
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.3s ease;
  min-width: 260px;
  max-width: 380px;
}

.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--blue); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ─── Loading / Empty ─── */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

.loading-center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
  color: var(--text-page-muted);
  gap: 12px;
  font-size: 14px;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-page-muted);
}

.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 14px; }

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-logo span, .sidebar-nav a span, .sidebar-footer span, .nav-badge { display: none; }
  .sidebar-logo h1 { font-size: 14px; }
  .sidebar-nav a { justify-content: center; padding: 12px; }
  .main-content { margin-left: 60px; padding: 16px; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .email-card-header { flex-direction: column; align-items: flex-start; }
  .email-card-meta { margin-top: 4px; }
}
