:root {
    --border: #d8dde2;
    --muted: #6b7280;
    --bg: #f5f6f8;
    --accent: #0a64bc;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: #111;
    font-size: 14px;
}

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

header.top {
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 10px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

header.top .brand {
    font-weight: 600;
    color: #111;
}

header.top nav { display: flex; gap: 16px; align-items: center; }

main { margin: 18px auto; padding: 0 18px; }

.card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.list-row {
    display: grid;
    grid-template-columns: 240px 1fr 160px;
    gap: 12px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    align-items: baseline;
}
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: #f9fafb; }
.list-row .from { font-weight: 600; color: #111; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .subj { min-width: 0; overflow: hidden; }
.list-row .subj > a { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.list-row .when { color: var(--muted); text-align: right; font-size: 13px; }
.list-row .att { font-size: 12px; color: var(--muted); }
.list-row .snippet {
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.list-row .snippet mark { background: #fff3cd; color: inherit; padding: 0 2px; border-radius: 2px; }

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    gap: 12px;
    flex-wrap: wrap;
}

.search input[type=text] {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    width: 280px;
}
.search button { padding: 8px 14px; border: 0; border-radius: 6px; background: var(--accent); color: #fff; cursor: pointer; }

.pager {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--muted);
}
.pager a, .pager span {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
}
.pager a.disabled { color: var(--muted); pointer-events: none; }

.headers {
    background: #fafbfc;
    border-bottom: 1px solid var(--border);
    padding: 14px 18px;
}
.headers .h-row { display: grid; grid-template-columns: 90px 1fr; gap: 10px; padding: 2px 0; }
.headers .h-row .h-name { color: var(--muted); font-size: 13px; }
.headers h2 { margin: 0 0 8px 0; font-size: 18px; }

.body-area {
    padding: 18px;
    background: #fff;
}
.body-area pre.plain {
    white-space: pre-wrap;
    word-break: break-word;
    font-family: inherit;
    font-size: 14px;
    margin: 0;
}

.attachments {
    border-top: 1px solid var(--border);
    padding: 14px 18px;
    background: #fafbfc;
}
.attachments h3 { margin: 0 0 8px 0; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.attachments ul { margin: 0; padding-left: 18px; }

.raw-headers {
    border-top: 1px solid var(--border);
    padding: 14px 18px;
    background: #fff;
}
.raw-headers details summary { cursor: pointer; color: var(--muted); }
.raw-headers table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.raw-headers th, .raw-headers td { text-align: left; padding: 4px 8px; border-bottom: 1px dashed var(--border); font-size: 12px; vertical-align: top; }
.raw-headers th { color: var(--muted); width: 200px; }
.raw-headers td { word-break: break-all; }

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

.login-wrap {
    min-height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-card { width: 320px; padding: 24px; }
.login-card h1 { margin: 0 0 16px 0; font-size: 18px; }
.login-card label { display: block; margin: 8px 0 4px; font-size: 13px; color: var(--muted); }
.login-card input { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; }
.login-card button { width: 100%; margin-top: 14px; padding: 10px; border: 0; border-radius: 6px; background: var(--accent); color: #fff; cursor: pointer; }
.login-card .err { background: #fee2e2; color: #991b1b; padding: 8px; border-radius: 6px; margin-bottom: 10px; font-size: 13px; }

.indexing { padding: 30px; text-align: center; }
.indexing .spinner {
    display: inline-block;
    width: 32px; height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.html-body { max-width: 100%; overflow-x: auto; }
.html-body img { max-width: 100%; height: auto; }
.html-body table { max-width: 100%; }
