/* ===== DESIGN TOKENS (matches landing page) ===== */
:root {
    --deep: #0a0e1a;
    --surface: #111827;
    --card: #1a2234;
    --card-hover: #1f2942;
    --border: rgba(255,255,255,0.06);
    --border-active: rgba(14,165,233,0.3);
    --pond: #0ea5e9;
    --pond-glow: #38bdf8;
    --pond-dim: #0369a1;
    --mint: #34d399;
    --red: #f87171;
    --amber: #fbbf24;
    --text: #f1f5f9;
    --text-dim: #94a3b8;
    --text-muted: #64748b;
    --radius: 12px;
    --radius-sm: 8px;
}

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

html, body {
    height: 100%;
    font-family: 'DM Sans', -apple-system, sans-serif;
    background: var(--deep);
    color: var(--text);
    overflow: hidden;
    line-height: 1.6;
}

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

/* ===== BACKGROUND ===== */
.bg-gradient {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background:
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(14,165,233,0.12), transparent),
        radial-gradient(ellipse 60% 40% at 80% 80%, rgba(52,211,153,0.06), transparent);
    pointer-events: none;
    z-index: 0;
}

/* ===== LAYOUT ===== */
.app-layout {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ===== TOPBAR ===== */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: rgba(10,14,26,0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    flex-shrink: 0;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

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

.mode-badge {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.72rem;
    color: var(--amber);
    background: rgba(251,191,36,0.08);
    border: 1px solid rgba(251,191,36,0.15);
    padding: 0.25rem 0.7rem;
    border-radius: 100px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.mode-badge.live {
    color: var(--mint);
    background: rgba(52,211,153,0.08);
    border-color: rgba(52,211,153,0.15);
}

.mode-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.85rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn-primary {
    background: var(--pond);
    color: white;
}
.btn-primary:hover { background: var(--pond-glow); }

.btn-ghost {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
}
.btn-ghost:hover {
    background: var(--card);
    color: var(--text);
    border-color: var(--border-active);
}

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

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

/* ===== MAIN CONTENT ===== */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ===== EMAIL LIST ===== */
.email-list {
    width: 380px;
    min-width: 380px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: rgba(17,24,39,0.4);
}

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

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

.email-count {
    font-size: 0.7rem;
    color: var(--pond);
    background: rgba(14,165,233,0.1);
    border: 1px solid rgba(14,165,233,0.15);
    padding: 0.15rem 0.55rem;
    border-radius: 100px;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
}

.email-items {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--card) transparent;
}

.email-items::-webkit-scrollbar {
    width: 6px;
}
.email-items::-webkit-scrollbar-track {
    background: transparent;
}
.email-items::-webkit-scrollbar-thumb {
    background: var(--card);
    border-radius: 3px;
}

.email-item {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.12s ease;
    position: relative;
}

.email-item:hover {
    background: var(--card);
}

.email-item.active {
    background: var(--card);
    border-left: 2px solid var(--pond);
    padding-left: calc(1.25rem - 2px);
}

.email-item.unread::after {
    content: '';
    position: absolute;
    top: 1.25rem;
    right: 1rem;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--pond);
}

.email-item-from {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.email-item-from .star {
    color: var(--amber);
    font-size: 0.7rem;
}

.email-item-subject {
    font-size: 0.82rem;
    color: var(--text-dim);
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 1.5rem;
}

.email-item-snippet {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-item-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
    position: absolute;
    top: 1rem;
    right: 2rem;
}

.email-item.has-draft .email-item-subject::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--mint);
    margin-right: 0.4rem;
    vertical-align: middle;
}

/* ===== LOADING STATE ===== */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--pond);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin-bottom: 0.75rem;
}

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

/* ===== EMAIL DETAIL ===== */
.email-detail {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--card) transparent;
}

.email-detail::-webkit-scrollbar {
    width: 6px;
}
.email-detail::-webkit-scrollbar-thumb {
    background: var(--card);
    border-radius: 3px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    padding: 2rem;
}

.empty-state h3 {
    font-size: 1.1rem;
    color: var(--text-dim);
    margin: 1rem 0 0.5rem;
}

.empty-state p {
    font-size: 0.85rem;
    max-width: 300px;
}

/* ===== EMAIL VIEW ===== */
.email-view {
    padding: 2rem 2.5rem;
    max-width: 800px;
}

.email-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.email-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--pond-dim), var(--pond));
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    color: white;
    flex-shrink: 0;
}

.email-meta {
    flex: 1;
}

.email-from {
    font-weight: 600;
    font-size: 0.95rem;
}

.email-addr {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}

.email-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}

.email-subject {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 1.5rem;
    line-height: 1.3;
}

.email-body {
    font-size: 0.9rem;
    color: var(--text-dim);
    line-height: 1.8;
    white-space: pre-wrap;
    word-wrap: break-word;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border);
}

/* ===== DRAFT SECTION ===== */
.draft-section {
    margin-top: 2rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.draft-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: rgba(14,165,233,0.03);
}

.draft-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--pond);
}

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

.tone-select {
    font-family: 'DM Sans', sans-serif;
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
    background: var(--surface);
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    outline: none;
}
.tone-select:focus {
    border-color: var(--pond);
}

.draft-content {
    padding: 2rem;
    display: flex;
    justify-content: center;
}

.generate-draft-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, var(--pond), var(--pond-dim));
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}
.generate-draft-btn:hover {
    background: linear-gradient(135deg, var(--pond-glow), var(--pond));
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(14,165,233,0.3);
}

.draft-text {
    padding: 1.5rem;
    font-size: 0.88rem;
    color: var(--text);
    line-height: 1.8;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.draft-loading {
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.draft-loading-bar {
    width: 200px;
    height: 3px;
    background: var(--surface);
    border-radius: 2px;
    margin: 0 auto 1rem;
    overflow: hidden;
    position: relative;
}
.draft-loading-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: -40%;
    width: 40%;
    height: 100%;
    background: linear-gradient(90deg, transparent, var(--pond), transparent);
    animation: loading-slide 1.2s ease-in-out infinite;
}

@keyframes loading-slide {
    0% { left: -40%; }
    100% { left: 100%; }
}

.draft-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.65rem 1.25rem;
    border-top: 1px solid var(--border);
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}

.draft-model {
    color: var(--pond);
    background: rgba(14,165,233,0.08);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
}

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 100;
    max-width: 400px;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.error {
    border-color: rgba(248,113,113,0.3);
    color: var(--red);
}

.toast.success {
    border-color: rgba(52,211,153,0.3);
    color: var(--mint);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .email-list {
        width: 100%;
        min-width: unset;
        max-height: 40vh;
    }

    .main-content {
        flex-direction: column;
    }

    .email-view {
        padding: 1.5rem;
    }

    .topbar-right .btn span {
        display: none;
    }
}
