:root {
    color-scheme: light;
    --primary: #5b21b6;
    --primary-dark: #42147f;
    --primary-soft: #f1eafe;
    --ink: #172033;
    --muted: #66748d;
    --line: #dfe5ef;
    --surface: #ffffff;
    --background: #f5f3fb;
    --success: #087f5b;
    --danger: #b42318;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(circle at 15% 0%, rgba(91, 33, 182, .12), transparent 30rem),
        var(--background);
}

a {
    color: inherit;
}

button,
input {
    font: inherit;
}

.topbar {
    position: sticky;
    z-index: 10;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 76px;
    padding: 12px max(24px, calc((100vw - 1180px) / 2));
    border-bottom: 1px solid rgba(223, 229, 239, .9);
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(12px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}

.brand-mark {
    display: grid;
    width: 44px;
    height: 44px;
    place-items: center;
    border-radius: 13px;
    color: #fff;
    background: linear-gradient(145deg, #7c3aed, #4c1d95);
    box-shadow: 0 8px 18px rgba(91, 33, 182, .25);
    font-weight: 800;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    margin-top: 2px;
    color: var(--muted);
    font-size: .72rem;
}

.container {
    width: min(1180px, calc(100% - 32px));
    margin: 34px auto 70px;
}

.panel {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: 0 14px 40px rgba(43, 33, 72, .07);
}

.page-heading,
.message-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 22px;
}

.page-heading h1,
.detail-header h1,
.auth-card h1 {
    margin: 3px 0 6px;
    line-height: 1.18;
}

.page-heading h1 {
    font-size: clamp(1.65rem, 4vw, 2.25rem);
}

.eyebrow {
    margin: 0;
    color: var(--primary);
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.muted {
    margin: 0;
    color: var(--muted);
}

.button {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    padding: 9px 15px;
    border: 1px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    text-decoration: none;
    font-weight: 700;
}

.button.primary {
    color: #fff;
    background: var(--primary);
}

.button.primary:hover {
    background: var(--primary-dark);
}

.button.secondary {
    border-color: var(--line);
    background: #fff;
}

.button.danger-outline {
    border-color: #f4c7c3;
    color: var(--danger);
    background: #fff;
}

.button.full {
    width: 100%;
}

.search {
    display: flex;
    gap: 10px;
    padding: 18px;
    border-bottom: 1px solid var(--line);
}

input[type="search"],
input[type="password"] {
    width: 100%;
    min-height: 44px;
    padding: 10px 13px;
    border: 1px solid #cfd7e4;
    border-radius: 10px;
    color: var(--ink);
    background: #fff;
}

input:focus {
    border-color: var(--primary);
    outline: 3px solid rgba(91, 33, 182, .13);
}

.message-list {
    display: grid;
}

.message-row {
    display: flex;
    gap: 14px;
    padding: 17px 20px;
    border-bottom: 1px solid var(--line);
    text-decoration: none;
    transition: background .15s ease;
}

.message-row:last-child {
    border-bottom: 0;
}

.message-row:hover {
    background: #faf9fe;
}

.avatar {
    display: grid;
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 12px;
    color: var(--primary);
    background: var(--primary-soft);
    font-weight: 800;
}

.message-main {
    min-width: 0;
    flex: 1;
}

.message-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    min-width: 0;
}

.message-line strong,
.message-line .subject {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-line time,
.message-main small {
    color: var(--muted);
    font-size: .78rem;
}

.message-main small {
    display: block;
    overflow: hidden;
    margin-top: 5px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.badge {
    flex: 0 0 auto;
    padding: 3px 8px;
    border-radius: 999px;
    color: var(--primary);
    background: var(--primary-soft);
    font-size: .72rem;
    font-weight: 700;
}

.badge.safe {
    color: var(--success);
    background: #e7f8f1;
}

.empty {
    padding: 70px 24px;
    text-align: center;
}

.empty-icon,
.auth-icon {
    display: grid;
    width: 62px;
    height: 62px;
    margin: 0 auto 16px;
    place-items: center;
    border-radius: 18px;
    color: var(--primary);
    background: var(--primary-soft);
    font-size: 1.65rem;
}

.empty h2 {
    margin: 0 0 8px;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    padding: 18px;
    border-top: 1px solid var(--line);
    color: var(--muted);
}

.alert {
    margin-bottom: 18px;
    padding: 13px 16px;
    border-radius: 11px;
}

.alert.success {
    border: 1px solid #a7e2cf;
    color: #086847;
    background: #eafaf4;
}

.alert.danger {
    border: 1px solid #f5c3bf;
    color: var(--danger);
    background: #fff0ef;
}

.auth-card {
    width: min(450px, 100%);
    margin: 8vh auto 0;
    padding: 34px;
    text-align: center;
}

.auth-card .muted {
    margin: 10px 0 24px;
    line-height: 1.55;
}

.auth-card label {
    text-align: left;
    font-weight: 700;
}

.stack {
    display: grid;
    gap: 10px;
}

.message-detail {
    overflow: visible;
}

.detail-header,
.detail-section {
    padding: 25px 28px;
    border-bottom: 1px solid var(--line);
}

.detail-section:last-child {
    border-bottom: 0;
}

.detail-header h1 {
    overflow-wrap: anywhere;
    font-size: clamp(1.55rem, 4vw, 2.15rem);
}

.metadata,
.headers {
    display: grid;
    gap: 10px;
    margin: 22px 0 0;
}

.metadata div,
.headers div {
    display: grid;
    grid-template-columns: 135px minmax(0, 1fr);
    gap: 16px;
}

.metadata dt,
.headers dt {
    color: var(--muted);
    font-weight: 700;
}

.metadata dd,
.headers dd {
    min-width: 0;
    margin: 0;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.detail-section h2 {
    margin: 0 0 16px;
    font-size: 1.05rem;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.attachment {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 240px;
    padding: 11px 13px;
    border: 1px solid var(--line);
    border-radius: 11px;
    text-decoration: none;
}

.attachment:hover {
    border-color: #ad91e1;
    background: #faf8ff;
}

.attachment small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
}

.mail-frame {
    width: 100%;
    min-height: 620px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: #fff;
}

.text-body {
    overflow: auto;
    max-height: 600px;
    margin: 0;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: #f8fafc;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

details summary {
    cursor: pointer;
    font-weight: 800;
}

code {
    font-size: .88em;
}

.sr-only {
    position: absolute;
    overflow: hidden;
    width: 1px;
    height: 1px;
    padding: 0;
    border: 0;
    margin: -1px;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

@media (max-width: 680px) {
    .topbar {
        padding: 10px 16px;
    }

    .brand small {
        display: none;
    }

    .container {
        width: min(100% - 20px, 1180px);
        margin-top: 20px;
    }

    .page-heading,
    .message-toolbar {
        align-items: flex-start;
    }

    .search {
        flex-wrap: wrap;
    }

    .search input {
        flex: 1 0 100%;
    }

    .message-line {
        align-items: flex-start;
        flex-direction: column;
        gap: 5px;
    }

    .message-line time {
        order: -1;
    }

    .detail-header,
    .detail-section {
        padding: 20px 17px;
    }

    .metadata div,
    .headers div {
        grid-template-columns: 1fr;
        gap: 3px;
    }

    .mail-frame {
        min-height: 500px;
    }
}
