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

:root {
    --ink: #0f0d1a;
    --surface: #faf9fc;
    --violet-deep: #312e81;
    --violet: #6366f1;
    --violet-light: #a78bfa;
    --violet-mist: #ede9fe;
    --warm: #f59e0b;
    --warm-light: #fef3c7;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --green: #10b981;
    --green-light: #d1fae5;
    --red: #ef4444;
    --red-light: #fee2e2;
    --blue: #3b82f6;
    --blue-light: #dbeafe;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.04);
}

body {
    font-family: 'DM Sans', -apple-system, sans-serif;
    background: var(--gray-50);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

/* ── Auth Pages ──────────────────────────────────────────────────── */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(165deg, #0f0d1a 0%, #1e1b4b 45%, #312e81 100%);
    padding: 2rem;
}

.auth-card {
    background: white;
    border-radius: 16px;
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.auth-logo {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 0.5rem;
}

.auth-logo i {
    background: linear-gradient(135deg, var(--violet), var(--warm));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-style: normal;
}

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

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

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-group input, .form-group textarea, .form-group select {
    width: 100%;
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--ink);
    background: white;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
    outline: none;
    border-color: var(--violet);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

.form-group textarea {
    min-height: 80px;
    resize: vertical;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.65rem 1.25rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--violet), var(--violet-light));
    color: white;
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }

.btn-secondary {
    background: var(--gray-100);
    color: var(--gray-700);
    border: 1px solid var(--gray-200);
}
.btn-secondary:hover { background: var(--gray-200); }

.btn-success {
    background: var(--green);
    color: white;
}
.btn-success:hover { opacity: 0.9; }

.btn-danger {
    background: var(--red);
    color: white;
}
.btn-danger:hover { opacity: 0.9; }

.btn-ghost {
    background: transparent;
    color: var(--violet);
    padding: 0.4rem 0.75rem;
}
.btn-ghost:hover { background: var(--violet-mist); }

.btn-full {
    width: 100%;
}

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

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

.auth-switch {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.9rem;
    color: var(--gray-500);
}
.auth-switch a {
    color: var(--violet);
    text-decoration: none;
    font-weight: 600;
}

.error-msg {
    background: var(--red-light);
    color: var(--red);
    padding: 0.6rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 1rem;
    display: none;
}
.error-msg.show { display: block; }

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

.sidebar {
    width: 240px;
    background: var(--ink);
    color: white;
    padding: 1.5rem 0;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
}

.sidebar-logo {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
    padding: 0 1.5rem;
    margin-bottom: 2rem;
}

.sidebar-logo i {
    background: linear-gradient(135deg, var(--violet-light), var(--warm));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-style: normal;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1.5rem;
    color: rgba(255,255,255,0.5);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.15s;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
}

.nav-item:hover { color: white; background: rgba(255,255,255,0.05); }
.nav-item.active { color: white; background: rgba(99,102,241,0.2); border-right: 2px solid var(--violet-light); }

.nav-item .icon {
    width: 20px;
    text-align: center;
    font-size: 1rem;
}

.nav-badge {
    margin-left: auto;
    background: var(--warm);
    color: var(--ink);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.15rem 0.5rem;
    border-radius: 100px;
}

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

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: rgba(255,255,255,0.5);
}

.sidebar-user .avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--violet), var(--violet-light));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: white;
}

.main-content {
    flex: 1;
    margin-left: 240px;
    padding: 2rem;
    max-width: 1100px;
}

/* ── Page Header ─────────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
}

.page-header h1 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.6rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.page-header p {
    color: var(--gray-500);
    font-size: 0.9rem;
    margin-top: 0.2rem;
}

/* ── Stats Grid ──────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-100);
}

.stat-card .stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-400);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.stat-card .stat-value {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 2rem;
    font-weight: 700;
    color: var(--ink);
    margin-top: 0.25rem;
}

.stat-card .stat-value.alert { color: var(--warm); }
.stat-card .stat-value.success { color: var(--green); }

/* ── Cards ───────────────────────────────────────────────────────── */
.card {
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--gray-100);
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}

.card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h2 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1rem;
    font-weight: 600;
}

.card-body {
    padding: 1.5rem;
}

.card-empty {
    text-align: center;
    padding: 3rem;
    color: var(--gray-400);
}

.card-empty .icon { font-size: 2rem; margin-bottom: 0.5rem; }

/* ── Conversation List ───────────────────────────────────────────── */
.convo-item {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--gray-50);
    transition: background 0.15s;
}
.convo-item:last-child { border-bottom: none; }
.convo-item:hover { background: var(--gray-50); }

.convo-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--violet-mist);
    color: var(--violet-deep);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.convo-info { flex: 1; min-width: 0; }

.convo-name {
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.convo-subject {
    font-size: 0.85rem;
    color: var(--gray-500);
    margin-top: 0.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.convo-meta {
    text-align: right;
    flex-shrink: 0;
}

.convo-time {
    font-size: 0.75rem;
    color: var(--gray-400);
}

.convo-actions {
    display: flex;
    gap: 0.35rem;
    margin-top: 0.35rem;
}

.badge-sm {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 100px;
    font-size: 0.7rem;
    font-weight: 600;
}

.badge-warning { background: var(--warm-light); color: #92400e; }
.badge-success { background: var(--green-light); color: #065f46; }
.badge-info { background: var(--blue-light); color: #1e40af; }
.badge-draft { background: var(--violet-mist); color: var(--violet-deep); }

/* ── Follow-up Card ──────────────────────────────────────────────── */
.followup-item {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--gray-50);
}
.followup-item:last-child { border-bottom: none; }

.followup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.followup-to {
    font-weight: 600;
    font-size: 0.9rem;
}

.followup-subject {
    font-size: 0.85rem;
    color: var(--gray-500);
    margin-bottom: 0.5rem;
}

.followup-body {
    background: var(--gray-50);
    border-radius: 8px;
    padding: 1rem;
    font-size: 0.85rem;
    line-height: 1.7;
    color: var(--gray-600);
    white-space: pre-wrap;
    margin-bottom: 0.75rem;
}

.followup-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* ── Queue Draft Preview ─────────────────────────────────────────── */
.followup-draft-preview {
    background: linear-gradient(135deg, #f5f3ff 0%, #faf9fc 100%);
    border: 1px solid rgba(99, 102, 241, 0.15);
    border-radius: 8px;
    padding: 0.875rem 1rem;
    margin-bottom: 0.75rem;
}

.followup-draft-preview.draft-empty {
    background: var(--gray-50);
    border-color: var(--gray-200);
}

.draft-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--violet);
    margin-bottom: 0.4rem;
}

.draft-empty .draft-label {
    color: var(--gray-400);
}

.draft-text {
    font-size: 0.85rem;
    line-height: 1.65;
    color: var(--gray-700);
    white-space: pre-wrap;
    margin-bottom: 0.5rem;
}

.draft-actions {
    display: flex;
    gap: 0.35rem;
}

.btn-xs {
    padding: 0.2rem 0.6rem;
    font-size: 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid var(--gray-200);
    background: white;
    color: var(--gray-600);
    font-weight: 500;
    transition: all 0.15s;
}

.btn-xs:hover:not(:disabled) {
    border-color: var(--violet-light);
    color: var(--violet);
    background: var(--violet-mist);
}

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

/* ── Modal ───────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 2rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}
.modal-overlay.show { opacity: 1; pointer-events: all; }

.modal {
    background: white;
    border-radius: 16px;
    width: 100%;
    max-width: 520px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--gray-400);
    padding: 0.25rem;
}

.modal-body { padding: 1.5rem; }

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--gray-100);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* ── Activity ────────────────────────────────────────────────────── */
.activity-item {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--gray-50);
    font-size: 0.85rem;
}
.activity-item:last-child { border-bottom: none; }

.activity-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--violet);
    margin-top: 0.4rem;
    flex-shrink: 0;
}

.activity-text { color: var(--gray-600); }
.activity-time { color: var(--gray-400); font-size: 0.75rem; margin-top: 0.15rem; }

/* ── Toast ───────────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: var(--ink);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: 10px;
    font-size: 0.85rem;
    box-shadow: var(--shadow-md);
    animation: toastIn 0.3s ease;
}

.toast.success { background: var(--green); }
.toast.error { background: var(--red); }

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

/* ── Loading ─────────────────────────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.spinner-dark {
    border-color: var(--gray-200);
    border-top-color: var(--violet);
}

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

.loading-state {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: var(--gray-400);
    gap: 0.5rem;
}

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { margin-left: 0; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
}

/* ── Settings Form ───────────────────────────────────────────────── */
.settings-form {
    display: grid;
    gap: 1rem;
    max-width: 600px;
}

.settings-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 600px) {
    .settings-row { grid-template-columns: 1fr; }
}

/* ── Welcome Banner ─────────────────────────────────────────────── */
.welcome-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.welcome-banner h1 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.6rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.welcome-banner p {
    color: var(--gray-500);
    font-size: 0.9rem;
    margin-top: 0.2rem;
}

/* ── Connect Email CTA ──────────────────────────────────────────── */
.cta-banner {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius);
    background: linear-gradient(135deg, var(--violet-mist) 0%, #f0ebff 100%);
    border: 1px solid rgba(99,102,241,0.15);
    margin-bottom: 1.5rem;
}

.cta-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--violet), var(--violet-light));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
    color: white;
}

.cta-content {
    flex: 1;
    min-width: 0;
}

.cta-content h3 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--violet-deep);
}

.cta-content p {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-top: 0.15rem;
    line-height: 1.5;
}

.btn-cta-connect {
    display: inline-flex;
    align-items: center;
    padding: 0.6rem 1.25rem;
    border-radius: 8px;
    background: var(--violet);
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-cta-connect:hover {
    background: var(--violet-deep);
    transform: translateY(-1px);
}

.cta-connected {
    background: linear-gradient(135deg, var(--green-light) 0%, #ecfdf5 100%);
    border-color: rgba(16,185,129,0.2);
}

.cta-connected .cta-content h3 {
    color: #065f46;
}

.cta-icon-success {
    background: linear-gradient(135deg, var(--green), #34d399) !important;
    font-size: 1.1rem;
}

.cta-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .welcome-banner { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
    .cta-banner { flex-direction: column; text-align: center; }
    .btn-cta-connect { width: 100%; justify-content: center; }
    .cta-actions { width: 100%; justify-content: center; }
}

/* ── Utilities ───────────────────────────────────────────────────── */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-sm { font-size: 0.85rem; }
.text-gray { color: var(--gray-500); }
.text-center { text-align: center; }
.hidden { display: none !important; }
.card-header-hint { font-size: 0.78rem; color: var(--gray-400); font-weight: 400; }
.card-header-actions { display: flex; align-items: center; gap: 0.75rem; }

/* ── Onboarding Widget ─────────────────────────────────────────────── */
.onboarding-widget {
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
  border-radius: 16px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  color: white;
}

.onboarding-header {
  margin-bottom: 1.25rem;
}

.onboarding-header h3 {
  margin: 0 0 0.25rem 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.onboarding-header p {
  margin: 0;
  font-size: 0.875rem;
  opacity: 0.8;
}

.onboarding-steps {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.onboarding-step {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 0.875rem 1rem;
  transition: all 0.2s ease;
}

.onboarding-step.disabled {
  opacity: 0.5;
  pointer-events: none;
}

.onboarding-step.done {
  background: rgba(34, 197, 94, 0.15);
}

.onboarding-step-check {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.onboarding-step.done .onboarding-step-check {
  background: #22c55e;
}

.onboarding-step-content {
  flex: 1;
  min-width: 0;
}

.onboarding-step-title {
  font-weight: 500;
  font-size: 0.9375rem;
  margin-bottom: 0.125rem;
}

.onboarding-step-desc {
  font-size: 0.78rem;
  opacity: 0.7;
}

.btn-onboarding {
  background: white;
  color: #1e1b4b;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-onboarding:hover {
  background: #f0f0f0;
  transform: translateY(-1px);
}

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

.onboarding-progress {
  height: 4px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
  margin-top: 1.25rem;
  overflow: hidden;
}

.onboarding-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #4ade80);
  border-radius: 2px;
  transition: width 0.4s ease;
}

.onboarding-count {
  text-align: center;
  font-size: 0.75rem;
  opacity: 0.7;
  margin-top: 0.5rem;
}
