:root {
    color-scheme: dark;
    --bg: #0b1020;
    --panel: #111827;
    --panel-soft: #172033;
    --panel-strong: #1f2937;
    --line: rgba(148, 163, 184, 0.18);
    --text: #f8fafc;
    --muted: #94a3b8;
    --muted-strong: #cbd5e1;
    --accent: #38bdf8;
    --accent-strong: #0ea5e9;
    --danger: #f87171;
    --shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(56, 189, 248, 0.14), transparent 32rem),
        radial-gradient(circle at bottom right, rgba(14, 165, 233, 0.1), transparent 28rem),
        var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.login-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(430px, 100%);
    border: 1px solid var(--line);
    border-radius: 24px;
    background: rgba(17, 24, 39, 0.88);
    box-shadow: var(--shadow);
    padding: 34px;
}

.login-card .brand-mark {
    margin-bottom: 22px;
}

.login-card h1 {
    margin: 0;
    font-size: 28px;
    letter-spacing: -0.03em;
}

.login-copy {
    margin: 12px 0 24px;
    color: var(--muted);
    line-height: 1.6;
}

.login-form {
    display: grid;
    gap: 16px;
}

.login-form label {
    display: grid;
    gap: 8px;
    color: var(--muted-strong);
    font-size: 13px;
    font-weight: 800;
}

.login-form input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.78);
    color: var(--text);
    outline: none;
    padding: 12px 13px;
}

.login-form input:focus {
    border-color: rgba(56, 189, 248, 0.65);
    box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.1);
}

.login-message {
    min-height: 22px;
    margin: 16px 0 0;
    color: var(--muted-strong);
}

button,
input,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

.app-shell {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 28px 20px;
    border-right: 1px solid var(--line);
    background: rgba(8, 13, 26, 0.78);
    backdrop-filter: blur(18px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-mark {
    display: grid;
    width: 44px;
    height: 44px;
    place-items: center;
    border: 1px solid rgba(56, 189, 248, 0.45);
    border-radius: 14px;
    background: linear-gradient(145deg, rgba(56, 189, 248, 0.22), rgba(14, 165, 233, 0.08));
    color: #e0f2fe;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.brand h1,
.panel-heading h2,
.detail-header h2,
.compose-header h2 {
    margin: 0;
}

.brand h1 {
    font-size: 15px;
    font-weight: 700;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--accent);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.compose-button,
.primary-button {
    border: 0;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #04111f;
    font-weight: 800;
    box-shadow: 0 12px 30px rgba(14, 165, 233, 0.22);
}

.compose-button {
    padding: 13px 18px;
}

.folder-nav {
    display: grid;
    gap: 6px;
}

.folder-link,
.ghost-button,
.danger-button,
.icon-button {
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted-strong);
}

.folder-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 11px 12px;
    border-radius: 12px;
    text-align: left;
}

.folder-link:hover,
.folder-link.active {
    border-color: var(--line);
    background: rgba(148, 163, 184, 0.1);
    color: var(--text);
}

.folder-count {
    min-width: 26px;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(56, 189, 248, 0.16);
    color: #bae6fd;
    font-size: 12px;
    text-align: center;
}

.sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: auto;
    color: var(--muted);
    font-size: 12px;
}

.auth-status {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: #22c55e;
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.12);
}

.logout-button {
    border: 1px solid rgba(248, 113, 113, 0.24);
    border-radius: 999px;
    background: rgba(248, 113, 113, 0.08);
    color: #fecaca;
    padding: 7px 10px;
    font-size: 12px;
    font-weight: 700;
}

.logout-button:hover {
    border-color: rgba(248, 113, 113, 0.5);
    background: rgba(248, 113, 113, 0.14);
    color: #fee2e2;
}

.main-panel {
    display: flex;
    min-width: 0;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--line);
}

.search-wrap {
    flex: 1;
}

.search-input,
.compose-form input,
.compose-form textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.78);
    color: var(--text);
    outline: none;
}

.search-input {
    padding: 13px 16px;
}

.search-input:focus,
.compose-form input:focus,
.compose-form textarea:focus {
    border-color: rgba(56, 189, 248, 0.65);
    box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.1);
}

.content-grid {
    display: grid;
    grid-template-columns: minmax(360px, 0.72fr) minmax(420px, 1fr);
    min-height: 0;
    flex: 1;
    gap: 1px;
    background: var(--line);
}

.mail-list-panel,
.mail-detail-panel {
    min-width: 0;
    background: rgba(11, 16, 32, 0.76);
}

.panel-heading,
.detail-header {
    padding: 22px 24px;
    border-bottom: 1px solid var(--line);
}

.panel-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
}

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

.mail-list {
    max-height: calc(100vh - 143px);
    overflow: auto;
}

.mail-item {
    width: 100%;
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) auto;
    gap: 14px;
    padding: 16px 24px;
    border: 0;
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
    background: transparent;
    color: inherit;
    text-align: left;
}

.mail-item:hover,
.mail-item.active {
    background: rgba(56, 189, 248, 0.08);
}

.avatar {
    display: grid;
    width: 40px;
    height: 40px;
    place-items: center;
    border-radius: 999px;
    background: rgba(56, 189, 248, 0.14);
    color: #bae6fd;
    font-weight: 800;
}

.mail-subject,
.sender {
    margin: 0;
    color: var(--text);
    font-weight: 750;
}

.mail-preview {
    margin: 5px 0 0;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mail-date,
#detailDate {
    color: var(--muted);
    font-size: 12px;
}

.detail-meta {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) auto;
    gap: 14px;
    align-items: center;
    margin-top: 18px;
}

.detail-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
}

.ghost-button,
.danger-button,
.icon-button {
    padding: 10px 13px;
    border-color: var(--line);
    border-radius: 10px;
    background: rgba(148, 163, 184, 0.08);
}

.ghost-button:hover,
.icon-button:hover {
    border-color: rgba(56, 189, 248, 0.45);
    color: var(--text);
}

.danger-button {
    color: #fecaca;
}

.danger-button:hover {
    border-color: rgba(248, 113, 113, 0.55);
    background: rgba(248, 113, 113, 0.12);
}

.message-body {
    margin: 0;
    padding: 24px;
    color: #dbeafe;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.7;
    white-space: pre-wrap;
}

.empty-state {
    padding: 56px 24px;
    color: var(--muted);
    text-align: center;
}

.empty-state h3 {
    margin: 0 0 8px;
    color: var(--text);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.72);
    backdrop-filter: blur(10px);
}

.compose-modal {
    position: fixed;
    right: 32px;
    bottom: 32px;
    width: min(560px, calc(100vw - 40px));
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--panel);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.compose-header,
.compose-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--line);
}

.compose-footer {
    border-top: 1px solid var(--line);
    border-bottom: 0;
}

.compose-form {
    display: grid;
    gap: 14px;
    padding: 18px;
}

.compose-form label {
    display: grid;
    gap: 7px;
    color: var(--muted-strong);
    font-size: 13px;
    font-weight: 700;
}

.compose-form input,
.compose-form textarea {
    padding: 12px 13px;
}

.primary-button {
    padding: 11px 16px;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%);
    max-width: calc(100vw - 32px);
    padding: 12px 16px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.94);
    color: var(--text);
    box-shadow: var(--shadow);
}

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

[hidden] {
    display: none !important;
}

@media (max-width: 980px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .folder-nav {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }

    .content-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .topbar,
    .panel-heading,
    .detail-header,
    .mail-item,
    .message-body {
        padding-left: 16px;
        padding-right: 16px;
    }

    .folder-nav {
        grid-template-columns: 1fr 1fr;
    }

    .detail-meta {
        grid-template-columns: 40px 1fr;
    }

    #detailDate {
        grid-column: 2;
    }
}
