/* mailarchive — minimalist light/dark theme. No external assets. */

:root {
    color-scheme: light;
    --bg: #f7f7f8;
    --surface: #ffffff;
    --text: #1c1e21;
    --text-muted: #6b7280;
    --accent: #3457c4;
    --accent-contrast: #ffffff;
    --hairline: #e4e5e9;
    --hairline-strong: #d2d4da;
    --hover: rgba(28, 30, 33, 0.04);
    --notice-bg: #fdf6e4;
    --notice-border: #e8d9a8;
    --error: #b3261e;
    --error-bg: #fdecea;
}

/* System preference supplies dark defaults until a manual choice exists. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #141619;
        --surface: #1d2025;
        --text: #e7e9ec;
        --text-muted: #9aa1ab;
        --accent: #8da8ff;
        --accent-contrast: #10131c;
        --hairline: #2a2e35;
        --hairline-strong: #3a3f48;
        --hover: rgba(231, 233, 236, 0.05);
        --notice-bg: #2b2617;
        --notice-border: #55491f;
        --error: #f2a099;
        --error-bg: #3a1f1c;
    }
}

/* Manual choice wins over system preference. */
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #141619;
    --surface: #1d2025;
    --text: #e7e9ec;
    --text-muted: #9aa1ab;
    --accent: #8da8ff;
    --accent-contrast: #10131c;
    --hairline: #2a2e35;
    --hairline-strong: #3a3f48;
    --hover: rgba(231, 233, 236, 0.05);
    --notice-bg: #2b2617;
    --notice-border: #55491f;
    --error: #f2a099;
    --error-bg: #3a1f1c;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 0.9375rem;
    line-height: 1.55;
    background: var(--bg);
    color: var(--text);
    /* Keeps the footer at the bottom of short pages (login, errors). */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

a:hover {
    text-decoration: underline;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 2px;
}

h1 {
    font-size: 1.375rem;
    font-weight: 600;
    margin: 0 0 1rem;
}

h2 {
    font-size: 1.0625rem;
    font-weight: 600;
    margin: 1.5rem 0 0.5rem;
}

.muted {
    color: var(--text-muted);
}

/* Header */

.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--hairline);
}

.site-header-inner {
    max-width: 76rem;
    margin: 0 auto;
    padding: 0.65rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.brand {
    font-weight: 650;
    color: var(--text);
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.brand:hover {
    text-decoration: none;
    color: var(--accent);
}

.crumbs {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.875rem;
}

.crumb-sep {
    color: var(--text-muted);
    margin: 0 0.35rem;
}

.header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Buttons + forms */

button {
    font: inherit;
    font-size: 0.875rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--hairline-strong);
    border-radius: 6px;
    padding: 0.35rem 0.8rem;
    cursor: pointer;
}

button:hover {
    background: var(--hover);
}

button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-contrast);
}

.logout-form {
    display: inline;
}

input[type="text"],
input[type="password"],
input[type="search"] {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--hairline-strong);
    border-radius: 6px;
    padding: 0.45rem 0.65rem;
    width: 100%;
}

input:focus-visible {
    outline-offset: 0;
    border-color: var(--accent);
}

/* Content shell */

.content {
    max-width: 60rem;
    margin: 0 auto;
    padding: 1.75rem 1.25rem 3rem;
    width: 100%;
    box-sizing: border-box;
    flex: 1 0 auto;
}

/* Footer */

.site-footer {
    border-top: 1px solid var(--hairline);
    padding: 1.25rem;
}

.site-footer p {
    max-width: 60rem;
    margin: 0 auto;
    color: var(--text-muted);
    font-size: 0.8125rem;
    text-align: center;
}

.site-footer a {
    color: var(--text-muted);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.site-footer a:hover,
.site-footer a:focus-visible {
    color: var(--accent);
}

.footer-sep {
    margin: 0 0.35rem;
    opacity: 0.6;
}

.content:has(.message-view) {
    max-width: 76rem;
}

/* Login */

.auth-card {
    max-width: 22rem;
    margin: 3.5rem auto 0;
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: 10px;
    padding: 1.75rem;
}

.auth-card .muted {
    margin-top: -0.5rem;
    font-size: 0.875rem;
}

.auth-card label {
    display: block;
    margin: 1rem 0 0.3rem;
    font-size: 0.8125rem;
    font-weight: 550;
    color: var(--text-muted);
}

.cf-turnstile {
    margin-top: 1.25rem;
    min-height: 65px;
}

.auth-card button {
    margin-top: 1.25rem;
    width: 100%;
    padding: 0.55rem;
}

.form-error {
    background: var(--error-bg);
    color: var(--error);
    border-radius: 6px;
    padding: 0.55rem 0.75rem;
    font-size: 0.875rem;
}

/* Home / accounts */

.domain-block {
    padding: 0.25rem 0 0.75rem;
    border-bottom: 1px solid var(--hairline);
}

.domain-block:last-child {
    border-bottom: none;
}

.domain-block h2 a {
    color: var(--text);
}

.domain-block h2 a:hover {
    color: var(--accent);
}

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

.account-list li {
    border-top: 1px solid var(--hairline);
}

.account-list li:first-child {
    border-top: none;
}

.account-list a {
    display: block;
    padding: 0.5rem 0.25rem;
}

/* Folder view */

.folder-layout {
    display: grid;
    grid-template-columns: 13rem minmax(0, 1fr);
    gap: 2rem;
    align-items: start;
}

.sidebar-title {
    margin: 0 0 0.75rem;
    font-size: 0.9375rem;
    word-break: break-all;
}

.folder-list {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 0.875rem;
}

.folder-list a {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.3rem 0.55rem;
    border-radius: 6px;
    color: var(--text);
}

.folder-list a:hover {
    background: var(--hover);
    text-decoration: none;
}

.folder-list .active a {
    background: var(--hover);
    color: var(--accent);
    font-weight: 600;
}

.folder-count {
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    font-weight: 400;
}

.reindex-form {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--hairline);
}

.reindex-form button {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.search-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.search-form input[type="search"] {
    flex: 1;
}

.list-meta {
    margin: 0 0 0.75rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* Message table */

.table-wrap {
    /* no overflow-x — table-layout:fixed below prevents horizontal scroll */
}

.msg-table {
    table-layout: fixed;
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.msg-table th {
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0.45rem 0.65rem;
    border-bottom: 1px solid var(--hairline-strong);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.msg-table td {
    padding: 0.55rem 0.65rem;
    border-bottom: 1px solid var(--hairline);
    vertical-align: top;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.msg-table tbody tr:hover {
    background: var(--hover);
}

.msg-table .num {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.col-subject a {
    color: var(--text);
}

.col-subject a:hover {
    color: var(--accent);
}

.col-from {
    color: var(--text-muted);
}

.col-date {
    width: 9rem;
    color: var(--text-muted);
}

.col-size {
    width: 5.5rem;
}

.attach-mark {
    margin-left: 0.3rem;
    font-size: 0.8125rem;
}

/* Sort links in table headers */

.sort-link {
    color: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.sort-link:hover {
    color: var(--accent);
    text-decoration: none;
}

.sort-active {
    color: var(--accent);
    font-weight: 700;
}

.sort-arrow {
    font-size: 0.625rem;
}

/* Pager */

.pager {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 1rem 0;
    font-size: 0.875rem;
    flex-wrap: wrap;
}

.pager-arrow {
    white-space: nowrap;
    padding: 4px 10px;
    border: 1px solid var(--hairline-strong);
    border-radius: 6px;
}

.pager-arrow:hover {
    background: var(--hover);
    text-decoration: none;
}

.pager-numbers {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.pager-numbers a,
.pager-current,
.pager-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.25rem;
    height: 2.25rem;
    padding: 0 5px;
    border-radius: 6px;
    border: 1px solid var(--hairline-strong);
    font-variant-numeric: tabular-nums;
}

.pager-ellipsis {
    border-color: transparent;
}

.pager-numbers a:hover {
    background: var(--hover);
    text-decoration: none;
}

.pager-current {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-contrast);
    font-weight: 600;
}

.pager-off {
    color: var(--text-muted);
    opacity: 0.5;
}

.pager-off.pager-arrow {
    border-color: var(--hairline);
}

/* Message view */

.msg-head h1 {
    margin-bottom: 0.5rem;
}

.msg-hdrs {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.15rem 1rem;
    margin: 0 0 1.25rem;
    font-size: 0.875rem;
}

.msg-hdrs dt {
    color: var(--text-muted);
}

.msg-hdrs dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.notice {
    background: var(--notice-bg);
    border: 1px solid var(--notice-border);
    border-radius: 6px;
    padding: 0.55rem 0.75rem;
    font-size: 0.875rem;
}

.attachments {
    border: 1px solid var(--hairline);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-bottom: 1.25rem;
}

.attachments h2 {
    margin: 0 0 0.4rem;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

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

.attachments li {
    padding: 0.25rem 0;
    font-size: 0.875rem;
}

.attachments .muted {
    margin-left: 0.5rem;
    font-size: 0.8125rem;
}

/* Rendered HTML mail: isolate from app styles; emails assume a light canvas. */
.mail-html {
    all: revert;
    overflow-x: auto;
    /* Containing block for the message: a hostile mail cannot escape this box to
       paint over the application UI. */
    position: relative;
    contain: layout paint style;
    transform: translateZ(0);
    background: #ffffff;
    color: #1c1e21;
    border: 1px solid var(--hairline);
    border-radius: 8px;
    padding: 1.25rem;
    color-scheme: light;
}

.mail-html img {
    max-width: 100%;
}

.mail-text {
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: 8px;
    padding: 1.25rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 0.9375rem;
    margin: 0;
}

/* Error page */

.error-page {
    max-width: 30rem;
    margin: 3.5rem auto 0;
    text-align: center;
}

@media (max-width: 44rem) {
    .folder-layout {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .crumbs {
        display: none;
    }
}

/* Grid and flex children default to min-width:auto, so a wide table pushes the
   page instead of scrolling inside its own box. */
.folder-layout,
.folder-layout > *,
.message-list,
.table-wrap {
    min-width: 0;
}

/* Rebuild-index overlay */

.loader-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loader-overlay[hidden] {
    display: none;
}

.loader-box {
    background: var(--surface);
    border-radius: 12px;
    padding: 2rem 2.5rem;
    text-align: center;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
    max-width: 20rem;
}

.spinner {
    width: 2.25rem;
    height: 2.25rem;
    border: 3px solid var(--hairline);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: ldspin 0.7s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes ldspin {
    to { transform: rotate(360deg); }
}

.loader-msg {
    font-weight: 600;
    margin: 0;
}

.loader-sub {
    margin: 0.5rem 0 0;
    font-size: 0.8125rem;
    color: var(--text-muted);
}
