@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --bg-deep: #06080c;
    --bg-base: #0a0d14;
    --bg-elevated: #10141e;
    --bg-surface: #161c2a;
    --bg-hover: #1c2436;
    --bg-active: #222c42;
    --border: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.12);
    --border-accent: rgba(99, 131, 255, 0.3);
    --text-primary: #edf0f7;
    --text-secondary: #8892a8;
    --text-muted: #5a6378;
    --accent: #6383ff;
    --accent-hover: #7b97ff;
    --accent-glow: rgba(99, 131, 255, 0.15);
    --accent-soft: rgba(99, 131, 255, 0.08);
    --danger: #ff5c5c;
    --danger-soft: rgba(255, 92, 92, 0.1);
    --success: #3dd68c;
    --success-soft: rgba(61, 214, 140, 0.1);
    --warning: #ffb547;
    --warning-soft: rgba(255, 181, 71, 0.1);
    --star: #ffb547;
    --purple: #a78bfa;
    --purple-soft: rgba(167, 139, 250, 0.1);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
    --shadow-glow: 0 0 20px rgba(99, 131, 255, 0.1);
    --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-deep);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; transition: color 0.2s var(--ease); }
a:hover { color: var(--accent-hover); }

::selection { background: var(--accent-glow); color: var(--text-primary); }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== LAYOUT ===== */
.app-layout {
    min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
    background: var(--bg-base);
    border-right: 1px solid var(--border);
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    width: 260px;
    height: 100vh;
    overflow-y: auto;
    z-index: 20;
}

.sidebar-logo {
    padding: 0 20px 20px;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.sidebar-logo svg { width: 22px; height: 22px; fill: var(--accent); }

.sidebar-logo span {
    background: linear-gradient(135deg, var(--accent) 0%, var(--purple) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.compose-btn {
    margin: 0 16px 20px;
    padding: 11px 20px;
    background: linear-gradient(135deg, var(--accent) 0%, #5470e6 100%);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.25s var(--ease);
    box-shadow: 0 2px 12px rgba(99, 131, 255, 0.25);
    letter-spacing: 0.01em;
}
.compose-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(99, 131, 255, 0.35);
    color: #fff;
}
.compose-btn:active { transform: translateY(0); }

.nav-section {
    padding: 0 12px;
    margin-bottom: 8px;
}

.nav-section-label {
    padding: 8px 12px 4px;
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    color: var(--text-secondary);
    font-size: 13.5px;
    font-weight: 450;
    transition: all 0.2s var(--ease);
    cursor: pointer;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    position: relative;
}
.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.nav-item.active {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: var(--border-accent);
    font-weight: 500;
}
.nav-item.active svg { fill: var(--accent); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.7; }
.nav-item.active svg { opacity: 1; }

.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: 12px 16px;
}

.sidebar-footer {
    margin-top: auto;
    padding: 12px 12px 8px;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    margin-left: 260px;
    min-height: 100vh;
    background: var(--bg-deep);
}

/* ===== TOP BAR ===== */
.topbar {
    background: rgba(10, 13, 20, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 14px 28px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.search-box {
    flex: 1;
    position: relative;
}

.search-box input {
    width: 100%;
    padding: 10px 14px 10px 40px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 13.5px;
    font-family: inherit;
    outline: none;
    transition: all 0.25s var(--ease);
}
.search-box input:focus {
    border-color: var(--border-accent);
    background: var(--bg-surface);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-box input::placeholder { color: var(--text-muted); }
.search-box svg {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    fill: var(--text-muted);
}

.topbar-actions { display: flex; align-items: center; gap: 6px; }

/* ===== EMAIL LIST ===== */
.email-list { padding: 4px 0; }

.email-row {
    display: grid;
    grid-template-columns: 36px minmax(140px, 220px) 1fr auto;
    align-items: center;
    gap: 16px;
    padding: 14px 28px;
    cursor: pointer;
    transition: all 0.15s var(--ease);
    font-size: 14px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    position: relative;
}
.email-row:hover { background: var(--bg-elevated); }
.email-row.unread { background: rgba(99, 131, 255, 0.03); }
.email-row.unread::before {
    content: '';
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
}
.email-row.unread .email-sender { color: var(--text-primary); font-weight: 600; }
.email-row.unread .email-subject { color: var(--text-primary); font-weight: 600; }

.email-star {
    cursor: pointer;
    color: var(--text-muted);
    background: none;
    border: none;
    font-size: 16px;
    padding: 6px;
    line-height: 1;
    border-radius: 6px;
    transition: all 0.15s var(--ease);
}
.email-star:hover { background: var(--warning-soft); color: var(--star); }
.email-star.starred { color: var(--star); }

.email-sender {
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 450;
}

.email-subject-snippet {
    display: flex;
    gap: 8px;
    overflow: hidden;
    min-width: 0;
}
.email-subject {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 450;
    flex-shrink: 0;
    max-width: 45%;
}
.email-snippet {
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    font-weight: 400;
}

.email-date {
    color: var(--text-muted);
    font-size: 12px;
    white-space: nowrap;
    font-weight: 450;
    font-variant-numeric: tabular-nums;
}

/* ===== EMAIL DETAIL ===== */
.email-detail {
    max-width: 1100px;
    margin: 0 auto;
    padding: 32px 40px;
}

.email-detail-header {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.email-detail-subject {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 16px;
    letter-spacing: -0.02em;
    line-height: 1.3;
}

.email-detail-meta {
    display: flex;
    align-items: center;
    gap: 14px;
    color: var(--text-secondary);
    font-size: 13.5px;
}

.email-detail-avatar {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent) 0%, var(--purple) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
}

.email-detail-body {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    overflow-x: auto;
    color: var(--text-primary);
    line-height: 1.75;
    font-size: 14px;
}
.email-detail-body img { max-width: 100%; height: auto; border-radius: var(--radius-sm); }

.email-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

/* ===== BUTTONS ===== */
.btn {
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    gap: 7px;
    transition: all 0.2s var(--ease);
    font-family: inherit;
    letter-spacing: 0.01em;
}
.btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}
.btn:active { transform: translateY(0); }
.btn svg { width: 15px; height: 15px; }

.btn-primary {
    background: linear-gradient(135deg, var(--accent) 0%, #5470e6 100%);
    border-color: transparent;
    color: #fff;
    box-shadow: 0 2px 8px rgba(99, 131, 255, 0.25);
}
.btn-primary:hover {
    box-shadow: 0 4px 16px rgba(99, 131, 255, 0.35);
    border-color: transparent;
    color: #fff;
}

.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: rgba(255, 92, 92, 0.2); }

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); border-color: transparent; }

/* ===== AI PANEL ===== */
.ai-panel {
    background: var(--bg-elevated);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-top: 20px;
    position: relative;
    overflow: hidden;
}
.ai-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--accent), var(--purple), var(--accent));
    background-size: 200% 100%;
    animation: shimmer 3s linear infinite;
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.ai-panel-header {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.ai-summary, .ai-category, .ai-replies {
    padding: 14px 16px;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    margin-bottom: 10px;
    font-size: 13.5px;
    line-height: 1.65;
    border: 1px solid var(--border);
}

.ai-category-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 12px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--accent-soft);
    color: var(--accent);
    border: 1px solid var(--border-accent);
}

.ai-reply-option {
    padding: 12px 14px;
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s var(--ease);
}
.ai-reply-option:hover {
    border-color: var(--border-accent);
    background: var(--accent-soft);
    transform: translateX(4px);
}

.ai-reply-tone {
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--purple);
    margin-bottom: 6px;
}

/* ===== COMPOSE ===== */
.compose-form {
    max-width: 1000px;
    margin: 32px auto;
    padding: 0 40px;
}

.form-group { margin-bottom: 20px; }

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.form-group input, .form-group textarea {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: all 0.25s var(--ease);
}
.form-group input:focus, .form-group textarea:focus {
    border-color: var(--border-accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    background: var(--bg-surface);
}
.form-group textarea { min-height: 320px; resize: vertical; line-height: 1.7; }

/* ===== STATS ===== */
.stats-header {
    padding: 28px 28px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.stats-header h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.period-selector {
    display: flex;
    gap: 2px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    padding: 3px;
    border: 1px solid var(--border);
}

.period-btn {
    padding: 7px 16px;
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 12.5px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s var(--ease);
    font-family: inherit;
}
.period-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.period-btn.active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 8px rgba(99, 131, 255, 0.3);
}

.stat-numbers {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    padding: 0 28px 8px;
    margin-top: 20px;
}

.stat-number-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    text-align: center;
    transition: all 0.25s var(--ease);
}
.stat-number-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-number-value {
    font-size: 32px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent) 0%, var(--purple) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
}

.stat-number-label {
    font-size: 11.5px;
    color: var(--text-muted);
    margin-top: 4px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    padding: 20px 28px 28px;
}

.stat-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    transition: all 0.25s var(--ease);
}
.stat-card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-md);
}

.stat-card-title {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-card canvas { width: 100% !important; }

/* Heatmap */
.heatmap-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 3px;
    font-size: 10.5px;
}
.heatmap-table th {
    padding: 4px;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 10px;
}
.heatmap-table td {
    width: 26px;
    height: 26px;
    text-align: center;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 500;
    color: rgba(255,255,255,0.6);
    transition: transform 0.15s var(--ease);
}
.heatmap-table td:hover { transform: scale(1.3); z-index: 1; position: relative; }

/* ===== LOGIN ===== */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-deep);
    position: relative;
    overflow: hidden;
}
.login-container::before {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(99, 131, 255, 0.08) 0%, transparent 70%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.login-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 48px 44px;
    text-align: center;
    max-width: 420px;
    width: 100%;
    position: relative;
    box-shadow: var(--shadow-lg);
}

.login-card h1 {
    font-size: 26px;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--text-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-card p {
    color: var(--text-muted);
    margin-bottom: 32px;
    font-size: 14px;
    line-height: 1.6;
}

.google-btn {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 13px 28px;
    background: #fff;
    color: #1f1f1f;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s var(--ease);
    text-decoration: none;
    font-family: inherit;
}
.google-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    color: #1f1f1f;
}
.google-btn:active { transform: translateY(0); }
.google-btn svg { width: 20px; height: 20px; }

/* ===== LOADING ===== */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
    color: var(--text-muted);
    font-size: 13.5px;
    gap: 12px;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-hover);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* ===== PAGINATION ===== */
.pagination {
    display: flex;
    justify-content: center;
    padding: 20px;
    gap: 8px;
}

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 28px;
    right: 28px;
    padding: 14px 22px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 13.5px;
    font-weight: 500;
    z-index: 1000;
    display: none;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(12px);
}
.toast.show { display: flex; align-items: center; gap: 8px; animation: toastIn 0.35s var(--ease); }
.toast.success { border-color: rgba(61, 214, 140, 0.3); }
.toast.success::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--success); flex-shrink: 0; }
.toast.error { border-color: rgba(255, 92, 92, 0.3); }
.toast.error::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); flex-shrink: 0; }

@keyframes toastIn {
    from { transform: translateY(12px) scale(0.96); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 60px 24px;
    color: var(--text-muted);
}
.empty-state svg { width: 48px; height: 48px; fill: var(--text-muted); opacity: 0.4; margin-bottom: 16px; }
.empty-state p { font-size: 14px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { margin-left: 0 !important; }
    .email-row { grid-template-columns: 36px 1fr auto; padding: 12px 16px; }
    .email-sender { display: none; }
    .stat-numbers { grid-template-columns: repeat(2, 1fr); padding: 0 16px 8px; }
    .stats-header { padding: 20px 16px 0; }
    .stats-grid { padding: 16px; }
    .topbar { padding: 12px 16px; }
    .email-detail { padding: 20px 16px; }
    .compose-form { padding: 0 16px; }
}

/* ===== FOCUS STATES (A11y) ===== */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
