:root {
    --bg: #ffffff;
    --bg-elevated: #f6f8fc;
    --text: #202124;
    --text-muted: #5f6368;
    --border: #e0e0e0;
    --accent: #1a73e8;
    --accent-contrast: #ffffff;
    --unread: #202124;
    --danger-bg: #fce8e6;
    --danger-text: #c5221f;
    --hover: #f1f3f4;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #202124;
        --bg-elevated: #292a2d;
        --text: #e8eaed;
        --text-muted: #9aa0a6;
        --border: #3c4043;
        --accent: #8ab4f8;
        --accent-contrast: #202124;
        --unread: #ffffff;
        --danger-bg: #3c1a1a;
        --danger-text: #f28b82;
        --hover: #303134;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { display: flex; flex-direction: column; height: 100vh; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.brand { font-size: 1.25rem; font-weight: 600; }

.topbar-user { display: flex; align-items: center; gap: 12px; color: var(--text-muted); font-size: 0.9rem; }

.link-button {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0;
}

.inline-form { display: inline; }

.app-body { display: flex; flex: 1; min-height: 0; }

.sidebar {
    width: 220px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    background: var(--bg-elevated);
    overflow-y: auto;
    padding: 12px 0;
}

.folder-list { list-style: none; margin: 0; padding: 0; }

.folder-list li a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 20px;
    color: var(--text);
    border-radius: 0 20px 20px 0;
    margin-right: 12px;
}

.folder-list li.active a { background: var(--hover); font-weight: 600; }
.folder-list li a:hover { background: var(--hover); text-decoration: none; }

.unread-badge {
    background: var(--accent);
    color: var(--accent-contrast);
    border-radius: 10px;
    padding: 1px 8px;
    font-size: 0.75rem;
}

.main-content { flex: 1; overflow-y: auto; padding: 20px 28px; }

.message-list-header h2 { margin-top: 0; text-transform: capitalize; }

.message-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }

.message-row a {
    display: grid;
    grid-template-columns: 20px 180px 1fr auto 60px;
    gap: 12px;
    align-items: center;
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

.message-row a:hover { background: var(--hover); text-decoration: none; }
.message-row.unread .message-from,
.message-row.unread .message-subject { font-weight: 700; color: var(--unread); }

.message-snippet { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-date { color: var(--text-muted); font-size: 0.85rem; text-align: right; }

.pagination { display: flex; gap: 8px; margin-top: 16px; }
.pagination a { padding: 4px 10px; border: 1px solid var(--border); border-radius: 4px; }
.pagination a.active { background: var(--accent); color: var(--accent-contrast); }

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

.message-view { max-width: 900px; }
.back-link { font-size: 0.9rem; }
.message-view-subject { margin: 12px 0 8px; }
.message-view-meta { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 16px; }

.attachment-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.attachment-chip {
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 6px 14px;
    font-size: 0.85rem;
    color: var(--text);
}
.attachment-size { color: var(--text-muted); }

.message-body-frame {
    width: 100%;
    min-height: 400px;
    border: none;
    background: #fff;
    border-radius: 4px;
}

.message-body-text { white-space: pre-wrap; font-family: inherit; }

.alert { padding: 10px 16px; border-radius: 6px; margin-bottom: 16px; }
.alert-error { background: var(--danger-bg); color: var(--danger-text); }

.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: var(--bg-elevated);
}

.auth-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 32px;
    width: 340px;
}

.auth-card h1 { margin-top: 0; font-size: 1.4rem; }
.auth-subtitle { color: var(--text-muted); font-size: 0.9rem; margin-top: -8px; }

.auth-card label { display: block; margin: 14px 0 4px; font-size: 0.85rem; color: var(--text-muted); }
.auth-card input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
}

.primary-button {
    margin-top: 20px;
    width: 100%;
    padding: 10px;
    background: var(--accent);
    color: var(--accent-contrast);
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
}

.primary-button:hover { opacity: 0.9; }
