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

:root {
  --bg: #0a0a0f;
  --surface: #12121a;
  --surface-2: #1a1a26;
  --surface-3: #222233;
  --border: #2a2a3a;
  --text: #e8e8ef;
  --text-dim: #8888a0;
  --accent: #6ee7b7;
  --accent-glow: rgba(110, 231, 183, 0.15);
  --amber: #fbbf24;
  --red: #f87171;
  --blue: #60a5fa;
  --purple: #a78bfa;
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

h1, h2, h3, h4 { font-family: 'Space Grotesk', sans-serif; }

/* ─── LAYOUT ─── */
.app-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 56px 1fr;
  min-height: 100vh;
}

.app-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 50;
}

.app-header .logo {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -0.5px;
  text-decoration: none;
  color: var(--text);
}
.app-header .logo span { color: var(--accent); }

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-user {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.btn-logout {
  font-size: 0.8rem;
  color: var(--text-dim);
  background: none;
  border: 1px solid var(--border);
  padding: 0.3rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-logout:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

/* ─── SIDEBAR ─── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.5rem 0;
  overflow-y: auto;
}

.sidebar-section {
  padding: 0 0.75rem;
  margin-bottom: 1.5rem;
}

.sidebar-label {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-dim);
  padding: 0 0.75rem;
  margin-bottom: 0.5rem;
}

.sidebar-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-dim);
  transition: all 0.15s;
  text-decoration: none;
}

.sidebar-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar-item.active {
  background: var(--accent-glow);
  color: var(--accent);
}

.sidebar-item .icon {
  width: 20px;
  text-align: center;
  margin-right: 0.6rem;
  font-size: 0.95rem;
}

.sidebar-item .label { flex: 1; }

.sidebar-badge {
  font-size: 0.7rem;
  font-weight: 600;
  min-width: 20px;
  text-align: center;
  padding: 0.1rem 0.4rem;
  border-radius: 10px;
  background: var(--surface-3);
  color: var(--text-dim);
}

.sidebar-item.active .sidebar-badge {
  background: rgba(110, 231, 183, 0.2);
  color: var(--accent);
}

.badge-urgent {
  background: rgba(248, 113, 113, 0.15) !important;
  color: var(--red) !important;
}

/* ─── MAIN CONTENT ─── */
.main-content {
  overflow-y: auto;
  background: var(--bg);
}

/* ─── EMAIL LIST ─── */
.email-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.email-list-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.email-list-actions {
  display: flex;
  gap: 0.5rem;
}

.email-list {
  display: flex;
  flex-direction: column;
}

.email-row {
  display: grid;
  grid-template-columns: 32px 180px 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.85rem 1.5rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.email-row:hover {
  background: var(--surface);
}

.email-row.unread {
  background: var(--surface);
}

.email-row.unread .email-from {
  color: var(--text);
  font-weight: 500;
}

.email-row.unread .email-subject {
  color: var(--text);
  font-weight: 500;
}

.email-category-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  justify-self: center;
}

.dot-urgent { background: var(--red); box-shadow: 0 0 8px rgba(248, 113, 113, 0.4); }
.dot-needs_reply { background: var(--amber); box-shadow: 0 0 8px rgba(251, 191, 36, 0.3); }
.dot-fyi { background: var(--blue); }
.dot-spam { background: #666; }
.dot-uncategorized { background: var(--text-dim); }

.email-from {
  font-size: 0.85rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-subject-col {
  min-width: 0;
}

.email-subject {
  font-size: 0.85rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-snippet {
  font-size: 0.8rem;
  color: #555;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 0.1rem;
}

.email-time {
  font-size: 0.75rem;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ─── EMAIL DETAIL ─── */
.email-detail {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem;
}

.email-detail-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  cursor: pointer;
  margin-bottom: 1.5rem;
  padding: 0.3rem 0;
  border: none;
  background: none;
  transition: color 0.15s;
}
.email-detail-back:hover { color: var(--accent); }

.email-detail-header {
  margin-bottom: 2rem;
}

.email-detail-subject {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.5px;
  margin-bottom: 1rem;
}

.email-detail-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.email-detail-from {
  font-size: 0.9rem;
}

.email-detail-from strong {
  color: var(--text);
}

.email-detail-from .email-addr {
  color: var(--text-dim);
  font-size: 0.8rem;
}

.email-detail-date {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.email-detail-badges {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.badge {
  font-size: 0.7rem;
  font-weight: 600;
  font-family: 'Space Grotesk', sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
}

.badge-cat-urgent { background: rgba(248, 113, 113, 0.15); color: var(--red); }
.badge-cat-needs_reply { background: rgba(251, 191, 36, 0.15); color: var(--amber); }
.badge-cat-fyi { background: rgba(96, 165, 250, 0.15); color: var(--blue); }
.badge-cat-spam { background: rgba(102, 102, 102, 0.2); color: #888; }

.badge-priority {
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.email-ai-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.ai-card-label {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

.ai-card-summary {
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 0.75rem;
  line-height: 1.6;
}

.ai-card-action {
  font-size: 0.85rem;
  color: var(--text-dim);
  padding: 0.6rem 0.8rem;
  background: var(--surface-2);
  border-radius: 6px;
  border-left: 3px solid var(--accent);
}

.email-detail-body {
  font-size: 0.92rem;
  line-height: 1.8;
  color: var(--text);
  white-space: pre-wrap;
  padding: 1.5rem 0;
  border-top: 1px solid var(--border);
}

.email-actions-bar {
  display: flex;
  gap: 0.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

/* ─── BUTTONS ─── */
.btn {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}

.btn:hover {
  background: var(--surface-2);
  border-color: var(--text-dim);
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border: none;
  font-weight: 600;
}

.btn-primary:hover {
  opacity: 0.85;
  background: var(--accent);
}

.btn-sm {
  font-size: 0.8rem;
  padding: 0.35rem 0.75rem;
}

.btn-danger {
  border-color: rgba(248, 113, 113, 0.3);
  color: var(--red);
}
.btn-danger:hover {
  background: rgba(248, 113, 113, 0.1);
}

/* ─── DAILY BRIEFING ─── */
.briefing-page {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem;
}

.briefing-header {
  margin-bottom: 2rem;
}

.briefing-header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 0.3rem;
}

.briefing-date {
  font-size: 0.9rem;
  color: var(--text-dim);
}

.briefing-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 2rem;
}

.briefing-stat {
  background: var(--surface);
  padding: 1.25rem 1rem;
  text-align: center;
}

.briefing-stat-num {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.briefing-stat-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.stat-urgent .briefing-stat-num { color: var(--red); }
.stat-reply .briefing-stat-num { color: var(--amber); }
.stat-fyi .briefing-stat-num { color: var(--blue); }
.stat-spam .briefing-stat-num { color: #666; }

.briefing-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.briefing-summary-label {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--accent);
  margin-bottom: 1rem;
}

.briefing-summary-content {
  font-size: 0.92rem;
  line-height: 1.8;
  color: var(--text);
}

.briefing-summary-content h2 {
  font-size: 1.1rem;
  margin: 1rem 0 0.5rem;
}

.briefing-summary-content strong {
  color: var(--accent);
}

.briefing-summary-content ul, .briefing-summary-content ol {
  padding-left: 1.5rem;
  margin: 0.5rem 0;
}

.briefing-summary-content li {
  margin-bottom: 0.3rem;
}

.briefing-section-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text);
}

/* ─── CLASSIFY PAGE ─── */
.classify-page {
  max-width: 700px;
  margin: 0 auto;
  padding: 2rem;
}

.classify-page h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 0.5rem;
}

.classify-desc {
  color: var(--text-dim);
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-family: 'Space Grotesk', sans-serif;
}

.form-input {
  width: 100%;
  padding: 0.65rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  transition: border-color 0.15s;
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
}

textarea.form-input {
  min-height: 180px;
  resize: vertical;
}

.classify-result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  margin-top: 1.5rem;
}

.classify-result-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.classify-result-cat {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1rem;
  font-weight: 600;
}

/* ─── LOGIN ─── */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
}

.login-logo {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1.5rem;
  text-align: center;
  margin-bottom: 0.5rem;
}
.login-logo span { color: var(--accent); }

.login-subtitle {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 2rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-form .form-input {
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
}

.login-form .btn-primary {
  padding: 0.75rem;
  font-size: 0.95rem;
}

.magic-link-sent {
  text-align: center;
}

.magic-link-sent h3 {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

.magic-link-sent p {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

.magic-link-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  font-size: 0.8rem;
  word-break: break-all;
  color: var(--accent);
  margin-bottom: 1rem;
  cursor: pointer;
  transition: background 0.15s;
}

.magic-link-box:hover {
  background: var(--surface-3);
}

.magic-link-note {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.login-back {
  text-align: center;
  margin-top: 1.5rem;
}

.login-back a {
  color: var(--text-dim);
  font-size: 0.85rem;
  text-decoration: none;
}
.login-back a:hover { color: var(--accent); }

/* ─── LOADING / EMPTY STATES ─── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 0.75rem;
}

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

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  text-align: center;
}

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.empty-desc {
  color: var(--text-dim);
  font-size: 0.9rem;
}

/* ─── TOAST ─── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1.25rem;
  font-size: 0.85rem;
  color: var(--text);
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
  z-index: 999;
  animation: slideUp 0.3s ease;
}

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

/* ─── RESPONSIVE ─── */
@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    width: 260px;
    height: calc(100vh - 56px);
    z-index: 40;
    box-shadow: 4px 0 20px rgba(0,0,0,0.3);
  }

  .sidebar.open { display: block; }

  .email-row {
    grid-template-columns: 24px 1fr auto;
    padding: 0.75rem 1rem;
  }

  .email-from { display: none; }

  .email-subject-col::before {
    content: attr(data-from);
    display: block;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 0.15rem;
  }

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

  .menu-toggle {
    display: block !important;
  }
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0.25rem;
  margin-right: 0.75rem;
}

.handled-badge {
  font-size: 0.7rem;
  color: var(--accent);
  background: var(--accent-glow);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  margin-left: 0.5rem;
}
