/* ============================================================
   Alfred Email — Dashboard Styles
   Warm cream palette, clean and professional
   ============================================================ */

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

:root {
  --cream:       #f0ede8;
  --cream-dark:  #e8e3db;
  --cream-border:#d8d1c6;
  --ink:         #1a1714;
  --ink-muted:   #6b6560;
  --ink-faint:   #a09890;
  --accent:      #2d5be3;
  --accent-soft: #eef1fc;
  --urgent:      #d63030;
  --urgent-soft: #fdf0f0;
  --reply:       #c47b00;
  --reply-soft:  #fff8ec;
  --calendar:    #2d5be3;
  --calendar-soft:#eef1fc;
  --fyi:         #6b6560;
  --fyi-soft:    #f5f3f0;
  --marketing:   #b0a898;
  --marketing-soft:#fafaf9;
  --success:     #1a8a5a;
  --radius:      10px;
  --shadow:      0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-lg:   0 4px 16px rgba(0,0,0,0.12), 0 1px 4px rgba(0,0,0,0.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--cream);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.5;
  font-size: 14px;
}

/* ── Layout ── */

.layout { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.topbar {
  background: white;
  border-bottom: 1px solid var(--cream-border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  box-shadow: 0 1px 0 var(--cream-border);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  color: var(--ink);
  letter-spacing: -0.3px;
}

.topbar-brand .logo {
  width: 28px;
  height: 28px;
  background: var(--ink);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 14px;
  font-weight: 800;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.auth-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-muted);
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--cream);
  border: 1px solid var(--cream-border);
}

.auth-badge .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ink-faint);
}
.auth-badge.connected .dot { background: var(--success); }
.auth-badge.connected { color: var(--success); background: #f0faf5; border-color: #b8e8d0; }

.btn-sync {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--ink);
  color: white;
  border: none;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-sync:hover { opacity: 0.85; }
.btn-sync:disabled { opacity: 0.5; cursor: default; }
.btn-sync .spin { display: none; }
.btn-sync.syncing .spin { display: inline; animation: spin 1s linear infinite; }

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

/* ── Stats bar ── */

.statsbar {
  background: white;
  border-bottom: 1px solid var(--cream-border);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid transparent;
}

.stat-pill.urgent { background: var(--urgent-soft); color: var(--urgent); border-color: #f5c6c6; }
.stat-pill.reply { background: var(--reply-soft); color: var(--reply); border-color: #f5dfa0; }
.stat-pill.calendar { background: var(--calendar-soft); color: var(--calendar); border-color: #c3d1f8; }
.stat-pill.total { background: var(--fyi-soft); color: var(--ink-muted); border-color: var(--cream-border); }
.stat-pill.today { background: var(--cream); color: var(--ink-muted); border-color: var(--cream-border); }

.stat-pill .num { font-size: 15px; font-weight: 700; }

/* ── Main area ── */

.main { display: flex; flex: 1; overflow: hidden; }

/* ── Sidebar / Filters ── */

.sidebar {
  width: 180px;
  flex-shrink: 0;
  background: white;
  border-right: 1px solid var(--cream-border);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.filter-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: none;
  background: none;
  border-radius: 8px;
  font-size: 13px;
  color: var(--ink-muted);
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 0.12s;
  font-weight: 400;
}

.filter-btn:hover { background: var(--cream); color: var(--ink); }
.filter-btn.active { background: var(--cream-dark); color: var(--ink); font-weight: 600; }

.filter-btn .count {
  margin-left: auto;
  font-size: 11px;
  background: var(--cream-border);
  color: var(--ink-muted);
  border-radius: 10px;
  padding: 1px 6px;
  min-width: 20px;
  text-align: center;
}

.filter-btn.urgent-filter .count { background: var(--urgent-soft); color: var(--urgent); }
.filter-btn.reply-filter .count { background: var(--reply-soft); color: var(--reply); }

/* ── Email list ── */

.email-list-panel {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.email-list-panel::-webkit-scrollbar { width: 4px; }
.email-list-panel::-webkit-scrollbar-track { background: transparent; }
.email-list-panel::-webkit-scrollbar-thumb { background: var(--cream-border); border-radius: 4px; }

.email-card {
  background: white;
  border: 1px solid var(--cream-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: box-shadow 0.12s, border-color 0.12s, transform 0.08s;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  position: relative;
}

.email-card:hover {
  box-shadow: var(--shadow);
  border-color: #c8c0b4;
  transform: translateY(-1px);
}

.email-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(45, 91, 227, 0.15);
}

.email-card .cat-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
}

.cat-dot.urgent { background: var(--urgent); }
.cat-dot.needs_reply { background: var(--reply); }
.cat-dot.calendar { background: var(--calendar); }
.cat-dot.fyi { background: #b0a898; }
.cat-dot.marketing { background: #d8d1c6; }

.email-card-body { flex: 1; min-width: 0; }

.email-card-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}

.email-sender {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
  max-width: 120px;
}

.email-date {
  font-size: 11px;
  color: var(--ink-faint);
  margin-left: auto;
  white-space: nowrap;
  flex-shrink: 0;
}

.email-subject {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}

.email-snippet {
  font-size: 12px;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-action-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 2px;
}

.email-action-pill.urgent { background: var(--urgent-soft); color: var(--urgent); }
.email-action-pill.needs_reply { background: var(--reply-soft); color: var(--reply); }
.email-action-pill.calendar { background: var(--calendar-soft); color: var(--calendar); }
.email-action-pill.fyi { background: var(--fyi-soft); color: var(--fyi); }
.email-action-pill.marketing { background: var(--marketing-soft); color: var(--marketing); }

/* ── Detail panel ── */

.detail-panel {
  width: 440px;
  flex-shrink: 0;
  background: white;
  border-left: 1px solid var(--cream-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.detail-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--ink-faint);
  gap: 12px;
  padding: 40px;
  text-align: center;
}

.detail-empty .icon { font-size: 40px; opacity: 0.4; }
.detail-empty p { font-size: 14px; }

.detail-content { display: flex; flex-direction: column; height: 100%; overflow: hidden; }

.detail-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--cream-border);
  flex-shrink: 0;
}

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

.detail-subject {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
}

.detail-cat-badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.detail-cat-badge.urgent { background: var(--urgent-soft); color: var(--urgent); }
.detail-cat-badge.needs_reply { background: var(--reply-soft); color: var(--reply); }
.detail-cat-badge.calendar { background: var(--calendar-soft); color: var(--calendar); }
.detail-cat-badge.fyi { background: var(--fyi-soft); color: var(--fyi); }
.detail-cat-badge.marketing { background: var(--marketing-soft); color: var(--marketing); }

.detail-meta {
  font-size: 12px;
  color: var(--ink-muted);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.detail-meta span { display: flex; gap: 6px; }
.detail-meta strong { color: var(--ink); font-weight: 500; }

/* ── AI Summary box ── */

.ai-summary {
  margin: 16px 24px 0;
  background: var(--cream);
  border: 1px solid var(--cream-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  flex-shrink: 0;
}

.ai-summary-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--ink-faint);
  margin-bottom: 8px;
}

.ai-summary-topic {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}

.ai-summary-action {
  font-size: 12px;
  color: var(--ink-muted);
  display: flex;
  gap: 6px;
  align-items: flex-start;
}

.ai-summary-action::before {
  content: '→';
  color: var(--accent);
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}

.followup-notice {
  margin-top: 8px;
  font-size: 11px;
  color: var(--reply);
  display: flex;
  gap: 5px;
  align-items: center;
}

/* ── Draft reply ── */

.draft-section {
  margin: 12px 24px 0;
  flex-shrink: 0;
}

.draft-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--ink-faint);
  margin-bottom: 8px;
}

.draft-box {
  background: white;
  border: 1px solid var(--cream-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.draft-text {
  padding: 12px 14px;
  font-size: 13px;
  color: var(--ink);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 80px;
  max-height: 160px;
  overflow-y: auto;
  outline: none;
  border: none;
  resize: none;
  width: 100%;
  font-family: inherit;
}

.draft-text::-webkit-scrollbar { width: 3px; }
.draft-text::-webkit-scrollbar-thumb { background: var(--cream-border); }

/* ── Body scroll area ── */

.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 24px 16px;
}

.detail-body::-webkit-scrollbar { width: 4px; }
.detail-body::-webkit-scrollbar-thumb { background: var(--cream-border); border-radius: 4px; }

.body-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--ink-faint);
  margin-bottom: 8px;
}

.body-text {
  font-size: 13px;
  color: var(--ink-muted);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Actions ── */

.detail-actions {
  padding: 16px 24px;
  border-top: 1px solid var(--cream-border);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.12s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}
.btn-primary:hover { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.4; cursor: default; }

.btn-secondary {
  background: white;
  color: var(--ink);
  border-color: var(--cream-border);
}
.btn-secondary:hover { background: var(--cream); border-color: #b8b0a4; }

.btn-ghost {
  background: transparent;
  color: var(--ink-muted);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--cream); color: var(--ink); }

.btn-danger {
  background: var(--urgent-soft);
  color: var(--urgent);
  border-color: #f5c6c6;
}
.btn-danger:hover { background: #fbe4e4; }

/* ── Snooze dropdown ── */

.snooze-wrapper { position: relative; }

.snooze-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  background: white;
  border: 1px solid var(--cream-border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 2px;
  min-width: 160px;
  z-index: 100;
}

.snooze-menu.open { display: flex; }

.snooze-option {
  padding: 7px 12px;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink);
  border: none;
  background: none;
  text-align: left;
  width: 100%;
  transition: background 0.1s;
}
.snooze-option:hover { background: var(--cream); }

/* ── Toast notifications ── */

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
}

.toast {
  background: var(--ink);
  color: white;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.success { background: #1a5c3a; }
.toast.error { background: #8a1a1a; }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Auth prompt ── */

.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 23, 20, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  backdrop-filter: blur(4px);
}

.auth-card {
  background: white;
  border-radius: 16px;
  padding: 40px;
  max-width: 440px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.auth-card h2 { font-size: 22px; font-weight: 700; margin-bottom: 10px; }
.auth-card p { color: var(--ink-muted); margin-bottom: 28px; font-size: 14px; line-height: 1.6; }

.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 24px;
  background: white;
  color: var(--ink);
  border: 2px solid var(--cream-border);
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.12s;
}
.btn-google:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ── Empty state ── */

.empty-state {
  padding: 60px 24px;
  text-align: center;
  color: var(--ink-faint);
}

.empty-state .icon { font-size: 36px; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 14px; }

/* ── Loading ── */

.skeleton {
  background: linear-gradient(90deg, var(--cream-dark) 25%, var(--cream) 50%, var(--cream-dark) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
  height: 14px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Responsive ── */

@media (max-width: 900px) {
  .detail-panel { display: none; }
  .detail-panel.mobile-visible {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 200;
    width: 100%;
  }
  .sidebar { width: 56px; }
  .filter-btn span { display: none; }
  .filter-btn .count { display: none; }
}

/* ── Rules link in topbar ── */
.rules-link {
  font-size: 13px;
  color: var(--ink-muted);
  text-decoration: none;
  padding: 5px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--cream);
  transition: background 0.15s;
  white-space: nowrap;
}
.rules-link:hover { background: var(--hover); }
