/* ─── DESIGN TOKENS (matching landing page) ─────────────────────── */
:root {
    --ink: #0a0a0a;
    --chalk: #fafaf9;
    --warm: #f5f0eb;
    --accent: #e85d26;
    --accent-light: #ff7a45;
    --accent-bg: #fef3ee;
    --muted: #6b6560;
    --border: #e0dbd5;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --purple: #8b5cf6;
    --cyan: #06b6d4;
    --radius: 12px;
    --radius-sm: 8px;
    --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.06), 0 2px 4px rgba(0,0,0,0.04);
}

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

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

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

/* ─── TOP NAV ────────────────────────────────────────────────────── */
.top-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(250, 250, 249, 0.92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 0 2rem;
    display: flex;
    align-items: center;
    gap: 2rem;
    height: 60px;
}

.logo {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 1.3rem;
    letter-spacing: -0.03em;
    color: var(--ink);
    text-decoration: none;
    flex-shrink: 0;
}
.logo span { color: var(--accent); }

.nav-tabs {
    display: flex;
    gap: 0.25rem;
    flex: 1;
}

.nav-tab {
    background: none;
    border: none;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    color: var(--muted);
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}
.nav-tab:hover { color: var(--ink); background: var(--warm); }
.nav-tab.active { color: var(--ink); background: var(--warm); font-weight: 600; }

.nav-right {
    flex-shrink: 0;
}

/* ─── VIEWS ──────────────────────────────────────────────────────── */
.view { display: none; padding: 2rem 0 4rem; }
.view.active { display: block; }

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* ─── PAGE HEADER ────────────────────────────────────────────────── */
.page-header {
    margin-bottom: 2rem;
}
.page-header h1 {
    font-size: 1.8rem;
    letter-spacing: -0.03em;
    font-weight: 700;
}
.page-header .subtitle {
    color: var(--muted);
    font-size: 1rem;
    margin-top: 0.25rem;
}
.header-actions {
    margin-top: 1rem;
}

/* ─── BUTTONS ────────────────────────────────────────────────────── */
.btn {
    font-family: 'DM Sans', sans-serif;
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: white;
    color: var(--ink);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.btn:hover { border-color: var(--muted); box-shadow: var(--shadow); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-primary {
    background: var(--ink);
    color: white;
    border-color: var(--ink);
}
.btn-primary:hover { background: #222; }
.btn-accent {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}
.btn-accent:hover { background: var(--accent-light); border-color: var(--accent-light); }
.btn-success {
    background: var(--success);
    color: white;
    border-color: var(--success);
}
.btn-success:hover { opacity: 0.9; }
.btn-danger {
    background: white;
    color: var(--danger);
    border-color: var(--danger);
}
.btn-danger:hover { background: #fef2f2; }
.btn-ghost {
    background: none;
    border: none;
    color: var(--muted);
    padding: 0.5rem 0;
}
.btn-ghost:hover { color: var(--ink); }
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ─── CARDS ──────────────────────────────────────────────────────── */
.card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-header h3 {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}
.card-body { padding: 1.5rem; }

/* ─── STATS GRID ─────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}
.stat-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
}
.stat-card.accent {
    background: var(--accent-bg);
    border-color: #fcd5c0;
}
.stat-number {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 2.2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--ink);
}
.stat-card.accent .stat-number { color: var(--accent); }
.stat-label {
    font-size: 0.85rem;
    color: var(--muted);
    margin-top: 0.25rem;
}

/* ─── TWO COL ────────────────────────────────────────────────────── */
.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

/* ─── BADGES ─────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}
.badge-customer_inquiry { background: #dbeafe; color: #1d4ed8; }
.badge-lead { background: #d1fae5; color: #065f46; }
.badge-support { background: #fef3c7; color: #92400e; }
.badge-spam { background: #f3f4f6; color: #4b5563; }
.badge-review { background: #ede9fe; color: #5b21b6; }
.badge-appointment { background: #cffafe; color: #0e7490; }
.badge-other { background: #f3f4f6; color: #6b7280; }

.badge-new { background: var(--accent-bg); color: var(--accent); }
.badge-processed { background: #dbeafe; color: #1d4ed8; }
.badge-responded { background: #d1fae5; color: #065f46; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-approved { background: #d1fae5; color: #065f46; }
.badge-rejected { background: #fee2e2; color: #991b1b; }
.badge-urgent {
    background: #fee2e2;
    color: #dc2626;
    animation: pulse-badge 2s infinite;
}
@keyframes pulse-badge {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.priority-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.priority-normal { background: var(--border); }
.priority-high { background: var(--warning); }
.priority-urgent { background: var(--danger); animation: pulse-badge 1.5s infinite; }

/* ─── FILTER BAR ─────────────────────────────────────────────────── */
.filter-bar {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* ─── INPUTS ─────────────────────────────────────────────────────── */
.text-input, .select-input {
    font-family: 'DM Sans', sans-serif;
    font-size: 0.875rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: white;
    color: var(--ink);
    outline: none;
    transition: border-color 0.2s;
}
.text-input:focus, .select-input:focus {
    border-color: var(--accent);
}
.text-input.textarea {
    resize: vertical;
    min-height: 80px;
    width: 100%;
}
.text-input { min-width: 200px; }

/* ─── FORM ───────────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 1.25rem;
}
.form-group label {
    display: block;
    font-weight: 500;
    font-size: 0.875rem;
    margin-bottom: 0.4rem;
    color: var(--ink);
}
.form-group .text-input,
.form-group .select-input {
    width: 100%;
}
.form-row {
    display: flex;
    gap: 2rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
}
.toggle-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}
.settings-card {
    max-width: 640px;
}
.settings-card .card-body { padding: 2rem; }

/* ─── EMAIL LIST ─────────────────────────────────────────────────── */
.email-list {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: white;
}

.email-row {
    display: grid;
    grid-template-columns: 8px 1fr auto auto;
    gap: 1rem;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}
.email-row:last-child { border-bottom: none; }
.email-row:hover { background: var(--warm); }
.email-row.unread { font-weight: 600; }

.email-meta {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 0;
}
.email-from {
    font-size: 0.9rem;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.email-subject {
    font-size: 0.85rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.email-preview {
    font-size: 0.8rem;
    color: #9ca3af;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 400px;
}
.email-badges {
    display: flex;
    gap: 0.4rem;
    flex-shrink: 0;
}
.email-time {
    font-size: 0.8rem;
    color: var(--muted);
    white-space: nowrap;
    flex-shrink: 0;
}

/* ─── EMAIL DETAIL ───────────────────────────────────────────────── */
.back-btn {
    margin-bottom: 1.5rem;
}
.email-detail-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
}

.email-detail-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
}
.email-detail-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin-bottom: 0.75rem;
}
.email-detail-meta {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: center;
    font-size: 0.85rem;
    color: var(--muted);
}
.email-detail-body {
    padding: 1.5rem;
    font-size: 0.95rem;
    line-height: 1.8;
    white-space: pre-wrap;
    word-break: break-word;
    color: #374151;
}

/* ─── DRAFT PANEL ────────────────────────────────────────────────── */
.draft-panel .card-header {
    background: var(--warm);
}
.draft-panel .card-header h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.draft-text {
    padding: 1.5rem;
    font-size: 0.925rem;
    line-height: 1.8;
    white-space: pre-wrap;
    color: #374151;
    min-height: 120px;
    border-bottom: 1px solid var(--border);
}
.draft-actions {
    padding: 1rem 1.5rem;
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.draft-edit-area {
    width: 100%;
    min-height: 200px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.925rem;
    line-height: 1.8;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 0.75rem;
    resize: vertical;
    outline: none;
}
.draft-edit-area:focus { border-color: var(--accent); }

/* ─── DRAFTS LIST ────────────────────────────────────────────────── */
.drafts-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.draft-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.draft-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--warm);
}
.draft-card-header-left {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.draft-card-from {
    font-weight: 600;
    font-size: 0.9rem;
}
.draft-card-subject {
    font-size: 0.8rem;
    color: var(--muted);
}
.draft-card-body {
    padding: 1.25rem 1.5rem;
    font-size: 0.9rem;
    line-height: 1.7;
    white-space: pre-wrap;
    color: #374151;
    max-height: 200px;
    overflow-y: auto;
}
.draft-card-actions {
    padding: 0.75rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.5rem;
}

/* ─── CATEGORY BAR ───────────────────────────────────────────────── */
.category-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
}
.category-bar-label {
    font-size: 0.85rem;
    font-weight: 500;
    min-width: 120px;
}
.category-bar-track {
    flex: 1;
    height: 8px;
    background: #f3f4f6;
    border-radius: 4px;
    overflow: hidden;
}
.category-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s;
}
.category-bar-count {
    font-size: 0.8rem;
    color: var(--muted);
    min-width: 30px;
    text-align: right;
}

/* ─── ACTIVITY FEED ──────────────────────────────────────────────── */
.activity-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid #f3f4f6;
    font-size: 0.85rem;
}
.activity-item:last-child { border-bottom: none; }
.activity-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
    margin-top: 0.5rem;
}
.activity-text { color: #374151; flex: 1; }
.activity-time { color: #9ca3af; font-size: 0.75rem; white-space: nowrap; }

/* ─── EMPTY STATE ────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--muted);
    font-size: 0.95rem;
}
.empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    opacity: 0.4;
}

/* ─── TOAST ──────────────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--ink);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    box-shadow: var(--shadow-md);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s;
    z-index: 200;
}
.toast.show {
    transform: translateY(0);
    opacity: 1;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ─── 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;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── RESPONSIVE ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .top-nav {
        padding: 0 1rem;
        gap: 0.5rem;
        overflow-x: auto;
    }
    .nav-tabs { gap: 0; }
    .nav-tab { padding: 0.4rem 0.6rem; font-size: 0.8rem; }
    .container { padding: 0 1rem; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .two-col { grid-template-columns: 1fr; }
    .email-detail-layout { grid-template-columns: 1fr; }
    .filter-bar { flex-direction: column; }
    .text-input { min-width: 100%; }
    .email-row { grid-template-columns: 6px 1fr auto; }
    .email-preview { display: none; }
    .email-time { display: none; }
    .page-header h1 { font-size: 1.4rem; }
}
