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

:root {
    --logo-black: #000000;
    --logo-teal: #1db38c;
    --logo-teal-hover: #17a078;
    --logo-teal-soft: #3dd4ae;
    --logo-teal-glow: rgba(29, 179, 140, 0.35);
    --logo-purple: #3e467f;
    --logo-purple-dark: #323866;
    --logo-purple-deep: #252a4d;

    --surface: #ffffff;
    --surface-muted: #eef0f8;
    --text: #14151f;
    --text-muted: #4d5163;
    --border: #d5d8e8;
    --heading: #0a0a0f;
    --heading-section: var(--logo-purple);

    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 12px 40px rgba(62, 70, 127, 0.1);
    --font: "DM Sans", system-ui, -apple-system, sans-serif;
    --header-h: 72px;
}

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

html, body {
    font-family: var(--font);
    font-size: 15px;
    background: var(--surface-muted);
    color: var(--text);
    min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: var(--font); }

/* ── Header ── */
.header {
    position: sticky; top: 0; z-index: 100;
    height: var(--header-h);
    background: var(--logo-purple-deep);
    border-bottom: 1px solid var(--logo-purple-dark);
    display: flex; align-items: center;
    padding: 0 32px;
    gap: 24px;
}

.header-brand {
    display: flex; align-items: center; gap: 10px;
    text-decoration: none;
}
.header-brand svg { width: 32px; height: 32px; }
.header-brand-name {
    font-size: 18px; font-weight: 700;
    color: #fff;
}
.header-brand-name span { color: var(--logo-teal); }

.header-sep { flex: 1; }

.header-search {
    flex: 0 1 440px;
    position: relative;
}
.header-search input {
    width: 100%;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: var(--radius-sm);
    color: #fff;
    font-family: var(--font);
    font-size: 14px;
    padding: 9px 16px 9px 40px;
    outline: none;
    transition: border-color .2s, background .2s;
}
.header-search input::placeholder { color: rgba(255,255,255,0.4); }
.header-search input:focus {
    border-color: var(--logo-teal);
    background: rgba(255,255,255,0.12);
}
.header-search-icon {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    color: rgba(255,255,255,0.4); pointer-events: none;
}

.header-user {
    display: flex; align-items: center; gap: 10px;
    color: rgba(255,255,255,0.85);
    font-size: 14px; font-weight: 500;
}
.header-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--logo-teal);
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700; color: #fff;
    flex-shrink: 0;
}
.header-logout {
    background: none; border: 1px solid rgba(255,255,255,0.2);
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,0.7);
    font-size: 13px; padding: 6px 14px;
    transition: border-color .2s, color .2s;
}
.header-logout:hover { border-color: var(--logo-teal); color: var(--logo-teal); }

/* ── Layout ── */
.layout {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 24px;
}

/* ── Page title ── */
.page-title {
    font-size: 22px; font-weight: 700;
    color: var(--heading);
    margin-bottom: 24px;
}
.page-title span { color: var(--logo-purple); }

/* ── Stats bar ── */
.stats-bar {
    display: flex; gap: 16px;
    margin-bottom: 28px;
    flex-wrap: wrap;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 24px;
    flex: 1; min-width: 160px;
    box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--logo-purple); margin-top: 4px; }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── Toolbar ── */
.toolbar {
    display: flex; align-items: center; gap: 12px;
    margin-bottom: 16px; flex-wrap: wrap;
}
.toolbar-filter {
    display: flex; align-items: center; gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 12px;
    font-size: 13px;
    color: var(--text-muted);
}
.toolbar-filter select {
    border: none; outline: none;
    font-family: var(--font); font-size: 13px;
    color: var(--text); background: transparent;
    padding: 9px 4px;
    cursor: pointer;
}

/* ── Email list ── */
.email-list { display: flex; flex-direction: column; gap: 6px; }

.email-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    display: grid;
    grid-template-columns: 40px 1fr auto;
    align-items: center;
    gap: 14px;
    cursor: pointer;
    transition: border-color .15s, box-shadow .15s, transform .1s;
    text-decoration: none;
    color: inherit;
}
.email-item:hover {
    border-color: var(--logo-teal);
    box-shadow: 0 0 0 3px var(--logo-teal-glow);
    transform: translateY(-1px);
}
.email-item.unread .email-subject { font-weight: 700; }
.email-item.unread { border-left: 3px solid var(--logo-teal); }

.email-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: linear-gradient(135deg, var(--logo-purple), var(--logo-teal));
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 700; color: #fff; flex-shrink: 0;
}

.email-meta { min-width: 0; }
.email-from { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.email-subject { font-size: 14px; font-weight: 500; color: var(--heading); margin: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.email-preview { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.email-right { text-align: right; flex-shrink: 0; }
.email-date { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.email-badge {
    display: inline-block;
    margin-top: 6px;
    font-size: 11px; font-weight: 600;
    background: var(--logo-teal); color: #fff;
    border-radius: 20px; padding: 2px 8px;
}

/* ── Pagination ── */
.pagination {
    display: flex; align-items: center; justify-content: center;
    gap: 8px; margin-top: 28px;
}
.pagination a, .pagination span {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 500;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    transition: all .15s;
}
.pagination a:hover { border-color: var(--logo-teal); color: var(--logo-teal); }
.pagination .active { background: var(--logo-purple); border-color: var(--logo-purple); color: #fff; }
.pagination .dots { border: none; background: none; color: var(--text-muted); }

/* ── Empty state ── */
.empty {
    text-align: center;
    padding: 80px 24px;
    color: var(--text-muted);
}
.empty-icon { font-size: 48px; margin-bottom: 16px; opacity: .4; }
.empty h3 { font-size: 18px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.empty p { font-size: 14px; }

/* ── Email view ── */
.email-view-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.email-view-header {
    padding: 28px 32px;
    border-bottom: 1px solid var(--border);
}
.email-view-subject {
    font-size: 22px; font-weight: 700; color: var(--heading);
    margin-bottom: 18px;
}
.email-view-fields { display: flex; flex-direction: column; gap: 8px; }
.email-view-field { display: flex; gap: 12px; font-size: 14px; }
.email-view-label { font-weight: 600; color: var(--text-muted); min-width: 42px; }
.email-view-value { color: var(--text); }

.email-view-actions {
    padding: 16px 32px;
    border-bottom: 1px solid var(--border);
    display: flex; gap: 12px; align-items: center;
}

.email-view-body {
    padding: 32px;
    min-height: 300px;
}
.email-view-body iframe {
    width: 100%; border: none; min-height: 500px;
    border-radius: var(--radius-sm);
}
.email-view-body.plain {
    font-size: 14px; line-height: 1.7;
    color: var(--text);
    white-space: pre-wrap;
}

/* ── Buttons ── */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    font-family: var(--font); font-size: 14px; font-weight: 600;
    padding: 10px 20px; border-radius: var(--radius-sm);
    border: none; transition: all .2s; text-decoration: none;
}
.btn-primary {
    background: var(--logo-teal); color: #fff;
}
.btn-primary:hover { background: var(--logo-teal-hover); box-shadow: 0 4px 16px var(--logo-teal-glow); }
.btn-secondary {
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--logo-teal); color: var(--logo-teal); }
.btn-ghost {
    background: none; color: var(--text-muted);
    border: none; padding: 10px 16px;
}
.btn-ghost:hover { color: var(--logo-purple); }
.btn svg { width: 16px; height: 16px; }

/* ── Alert ── */
.alert {
    padding: 14px 18px; border-radius: var(--radius-sm);
    font-size: 14px; margin-bottom: 20px;
    display: flex; align-items: center; gap: 10px;
}
.alert-success { background: rgba(29,179,140,.1); color: #0f7a5a; border: 1px solid rgba(29,179,140,.3); }
.alert-error { background: rgba(220,53,69,.08); color: #b02a37; border: 1px solid rgba(220,53,69,.2); }

/* ── Login page ── */
.login-page {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--logo-purple-deep) 0%, var(--logo-purple) 50%, #2d5a8e 100%);
    padding: 24px;
}
.login-card {
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 32px 80px rgba(0,0,0,0.35);
    padding: 52px 48px;
    width: 100%; max-width: 440px;
    text-align: center;
}
.login-logo {
    display: flex; align-items: center; justify-content: center; gap: 12px;
    margin-bottom: 32px;
}
.login-logo-text {
    font-size: 28px; font-weight: 800;
    color: var(--logo-black);
}
.login-logo-text span { color: var(--logo-teal); }
.login-tagline {
    font-size: 15px; color: var(--text-muted);
    margin-bottom: 36px; line-height: 1.5;
}
.login-tagline strong { color: var(--text); }
.btn-ms {
    width: 100%;
    display: flex; align-items: center; justify-content: center; gap: 12px;
    padding: 14px 20px;
    background: var(--logo-purple);
    color: #fff;
    border: none; border-radius: var(--radius-sm);
    font-family: var(--font); font-size: 15px; font-weight: 600;
    cursor: pointer; transition: all .2s;
}
.btn-ms:hover {
    background: var(--logo-purple-dark);
    box-shadow: 0 8px 24px rgba(62,70,127,0.35);
    transform: translateY(-1px);
}
.login-divider {
    margin: 28px 0;
    display: flex; align-items: center; gap: 12px;
}
.login-divider::before, .login-divider::after {
    content: ''; flex: 1; height: 1px; background: var(--border);
}
.login-divider span { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.login-note {
    font-size: 12px; color: var(--text-muted); line-height: 1.6;
    margin-top: 28px;
}
.login-note a { color: var(--logo-teal); font-weight: 600; }

/* ── Back link ── */
.back-link {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 14px; font-weight: 500; color: var(--text-muted);
    margin-bottom: 20px; transition: color .15s;
}
.back-link:hover { color: var(--logo-teal); }

/* ── Search page ── */
.search-banner {
    background: var(--logo-purple-deep);
    border-radius: var(--radius);
    padding: 24px 28px;
    margin-bottom: 24px;
    display: flex; align-items: center; gap: 16px;
}
.search-banner-query {
    font-size: 20px; font-weight: 700; color: #fff;
}
.search-banner-count { font-size: 14px; color: rgba(255,255,255,0.6); margin-top: 2px; }
.search-highlight { color: var(--logo-teal); }

/* ── Impersonation banner ── */
.impersonate-banner {
    background: linear-gradient(90deg, var(--logo-teal) 0%, #17a078 100%);
    color: #fff;
    padding: 10px 32px;
    display: flex; align-items: center; gap: 12px;
    font-size: 13px; font-weight: 600;
}
.impersonate-banner svg { flex-shrink: 0; }
.impersonate-banner .ib-email {
    background: rgba(255,255,255,0.2);
    border-radius: 4px; padding: 2px 10px;
    font-size: 13px; font-weight: 700;
}
.impersonate-banner form { margin-left: auto; }
.impersonate-banner button {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.4);
    border-radius: var(--radius-sm);
    color: #fff; font-size: 12px; font-weight: 600;
    padding: 5px 14px; cursor: pointer;
    font-family: var(--font);
    transition: background .15s;
}
.impersonate-banner button:hover { background: rgba(255,255,255,0.28); }

/* ── Toast ── */
.toast {
    position: fixed; bottom: 28px; right: 28px;
    background: var(--logo-purple-deep);
    color: #fff; border-radius: var(--radius-sm);
    padding: 14px 20px; font-size: 14px; font-weight: 500;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    display: flex; align-items: center; gap: 10px;
    transform: translateY(80px); opacity: 0;
    transition: all .3s cubic-bezier(.4,0,.2,1);
    z-index: 9999;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--logo-teal); flex-shrink: 0; }

@media (max-width: 768px) {
    .header { padding: 0 16px; }
    .header-search { display: none; }
    .layout { padding: 20px 16px; }
    .email-item { grid-template-columns: 1fr auto; }
    .email-item .email-avatar { display: none; }
    .login-card { padding: 36px 24px; }
    .email-view-header, .email-view-body, .email-view-actions { padding: 20px; }
    .email-view-subject { font-size: 18px; }
}
