:root {
    --bg: #f7f7f5;
    --surface: #ffffff;
    --text: #1d1d1f;
    --muted: #6b6b70;
    --border: #e4e4e1;
    --accent: #2f6fdf;
    --accent-text: #ffffff;
    --unread: #1d1d1f;
    --error: #b3261e;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #161618;
        --surface: #1f1f22;
        --text: #ececee;
        --muted: #9a9aa2;
        --border: #313136;
        --accent: #6d9bf1;
        --accent-text: #0e1420;
        --unread: #ffffff;
        --error: #f2b8b5;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: inherit; }

.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand { font-weight: 700; text-decoration: none; letter-spacing: -0.01em; }
.who { margin-left: auto; color: var(--muted); font-size: 0.9em; overflow: hidden; text-overflow: ellipsis; }

main { max-width: 60rem; margin: 0 auto; padding: 1rem; }

h1 { font-size: 1.4rem; margin: 0.5rem 0 1rem; }

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

button {
    font: inherit;
    cursor: pointer;
    border-radius: 6px;
}

button.primary {
    background: var(--accent);
    color: var(--accent-text);
    border: none;
    padding: 0.55rem 1.1rem;
    font-weight: 600;
}

button.link {
    background: none;
    border: none;
    color: var(--accent);
    padding: 0;
}

.signin { text-align: center; margin-top: 18vh; }
.signin h1 { font-size: 2rem; margin-bottom: 0.25rem; }
.signin .primary { margin-top: 1rem; }

.notice {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
}

.threads {
    list-style: none;
    margin: 0;
    padding: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.threads li + li { border-top: 1px solid var(--border); }

.threads a {
    display: grid;
    grid-template-columns: 12rem minmax(0, 1fr) auto;
    grid-template-areas: "from text time";
    gap: 0.75rem;
    align-items: baseline;
    padding: 0.6rem 1rem;
    text-decoration: none;
    color: var(--muted);
}

.threads a:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }

.threads .from { grid-area: from; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.threads .subject { grid-area: text; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.threads .snippet { display: none; }
.threads time { grid-area: time; font-size: 0.85em; white-space: nowrap; }

.threads .unread .from,
.threads .unread .subject { color: var(--unread); font-weight: 700; }

@media (max-width: 47.99rem) {
    .threads a {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas: "from time" "subject subject" "snippet snippet";
        gap: 0.1rem 0.75rem;
    }
    .threads .subject { grid-area: subject; }
    .threads .snippet { grid-area: snippet; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

.small { font-size: 0.85em; }

/* Secondary buttons (Archive, Reply, …) */
button:not(.primary):not(.link),
a.button:not(.primary) {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0.4rem 0.9rem;
}

a.button {
    display: inline-block;
    border-radius: 6px;
    text-decoration: none;
    padding: 0.45rem 1rem;
}

a.button.primary {
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
}

button:disabled { opacity: 0.6; cursor: default; }

.search { flex: 1; max-width: 32rem; }

.search input,
.compose input,
.compose select,
.compose textarea {
    width: 100%;
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.45rem 0.7rem;
}

.search input:focus,
.compose :is(input, select, textarea):focus {
    outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
    border-color: var(--accent);
}

@media (max-width: 40rem) {
    .who { display: none; }
    .search { max-width: none; }
}

.list-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.list-header h1 { margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.load-more { display: block; margin: 1rem auto; }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    margin-bottom: 1rem;
}

.toolbar-link { margin-left: auto; color: var(--accent); font-size: 0.9em; }

.thread-subject { font-size: 1.35rem; margin: 0 0 1rem; overflow-wrap: anywhere; }

.message {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 0.75rem;
    overflow: hidden;
}

.message-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.15rem 1rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
}

.message-header .sender { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-header time { font-size: 0.85em; white-space: nowrap; }
.message-header .summary { grid-column: 1 / -1; font-size: 0.9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.images-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.75rem;
    margin: 0 1rem 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    font-size: 0.9em;
}

/* HTML email is shown on white like Gmail, since most emails assume a light background. */
.mail-frame {
    display: block;
    width: calc(100% - 2rem);
    margin: 0 1rem 1rem;
    border: none;
    border-radius: 6px;
    background: #fff;
}

.mail-text {
    margin: 0 1rem 1rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.mail-text a { color: var(--accent); }

.attachments {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0 1rem 1rem;
    padding: 0;
}

.message-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0 1rem 1rem;
}

.compose {
    display: grid;
    gap: 0.6rem;
    padding: 0 1rem 1rem;
}

main > .compose { padding: 0; }

.compose .field {
    display: grid;
    grid-template-columns: 4.5rem minmax(0, 1fr);
    align-items: center;
    gap: 0.5rem;
}

.compose .field span { color: var(--muted); font-size: 0.9em; }
.compose textarea { resize: vertical; min-height: 10rem; line-height: 1.5; }
.compose p { margin: 0; }

.compose-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 1.5rem;
    transform: translateX(-50%);
    max-width: calc(100% - 2rem);
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    background: var(--text);
    color: var(--bg);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 900;
}

/* Blazor's built-in error bar and loading indicator */
#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    color: #1d1d1f;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto;
}

.loading-progress circle {
    fill: none;
    stroke: var(--border);
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--accent);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}
