:root {
    color-scheme: light;
    --page-bg: #f3f6f5;
    --surface: #ffffff;
    --surface-subtle: #edf2f0;
    --surface-hover: #f7faf9;
    --surface-strong: #e4ebe8;
    --text: #17201e;
    --text-secondary: #5f6d69;
    --text-tertiary: #7b8985;
    --border: #d6e0dc;
    --border-strong: #bccbc6;
    --primary: #0f766e;
    --primary-hover: #0b5f59;
    --primary-soft: #e1f3ef;
    --primary-contrast: #ffffff;
    --success: #18794e;
    --success-soft: #e4f5ec;
    --warning: #a15c00;
    --warning-soft: #fff2d8;
    --danger: #b42318;
    --danger-soft: #feebe9;
    --info: #2463a7;
    --info-soft: #e8f1fb;
    --focus: #0d9488;
    --overlay: rgba(10, 18, 16, 0.55);
    --reading-bg: #ffffff;
    --reading-text: #293330;
    --shadow-sm: 0 1px 2px rgba(18, 32, 28, 0.06);
    --shadow-md: 0 10px 28px rgba(18, 32, 28, 0.1);
    --radius-sm: 6px;
    --radius: 8px;
    --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --topbar-height: 64px;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --page-bg: #191c1a;
    --surface: #272b28;
    --surface-subtle: #303532;
    --surface-hover: #383e3a;
    --surface-strong: #414944;
    --text: #f7f9f8;
    --text-secondary: #c4ccc8;
    --text-tertiary: #9ca7a1;
    --border: #48514c;
    --border-strong: #626e68;
    --primary: #92d0c1;
    --primary-hover: #a6dfd2;
    --primary-soft: #334b45;
    --primary-contrast: #0d1714;
    --success: #8eb49b;
    --success-soft: #2d4033;
    --warning: #d0ad6c;
    --warning-soft: #443a25;
    --danger: #d18b84;
    --danger-soft: #472e2c;
    --info: #91adbb;
    --info-soft: #2c3d45;
    --focus: #9bd8ca;
    --overlay: rgba(0, 0, 0, 0.74);
    --reading-bg: #ffffff;
    --reading-text: #293330;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.28);
    --shadow-md: 0 12px 30px rgba(0, 0, 0, 0.36);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        color-scheme: dark;
        --page-bg: #191c1a;
        --surface: #272b28;
        --surface-subtle: #303532;
        --surface-hover: #383e3a;
        --surface-strong: #414944;
        --text: #f7f9f8;
        --text-secondary: #c4ccc8;
        --text-tertiary: #9ca7a1;
        --border: #48514c;
        --border-strong: #626e68;
        --primary: #92d0c1;
        --primary-hover: #a6dfd2;
        --primary-soft: #334b45;
        --primary-contrast: #0d1714;
        --success: #8eb49b;
        --success-soft: #2d4033;
        --warning: #d0ad6c;
        --warning-soft: #443a25;
        --danger: #d18b84;
        --danger-soft: #472e2c;
        --info: #91adbb;
        --info-soft: #2c3d45;
        --focus: #9bd8ca;
        --overlay: rgba(0, 0, 0, 0.74);
        --reading-bg: #ffffff;
        --reading-text: #293330;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.28);
        --shadow-md: 0 12px 30px rgba(0, 0, 0, 0.36);
    }
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    background: var(--page-bg);
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    margin: 0;
    background: var(--page-bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.5;
    letter-spacing: 0;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
    color: inherit;
    font: inherit;
    letter-spacing: 0;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

a {
    color: var(--primary);
}

[hidden] {
    display: none !important;
}

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

.skip-link {
    position: fixed;
    left: 12px;
    top: -80px;
    z-index: 200;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    background: var(--text);
    color: var(--surface);
    text-decoration: none;
}

.skip-link:focus {
    top: 12px;
}

:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--focus) 58%, transparent);
    outline-offset: 2px;
}

.icon {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
}

.brand {
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 720;
    text-decoration: none;
    white-space: nowrap;
}

.brand-mark {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    background: var(--primary);
    color: var(--primary-contrast);
}

.brand-mark .icon {
    width: 20px;
    height: 20px;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--text-tertiary);
    font-size: 0.72rem;
    font-weight: 720;
    letter-spacing: 0;
    text-transform: uppercase;
}

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

.button,
.text-button,
.icon-button,
.theme-option,
.folder-button,
.login-tab,
.floating-action {
    border: 0;
    cursor: pointer;
}

.button {
    min-height: 40px;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.875rem;
    font-weight: 680;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.button:hover:not(:disabled) {
    transform: translateY(-1px);
}

.button:active:not(:disabled) {
    transform: translateY(0);
}

.button:disabled {
    cursor: wait;
    opacity: 0.62;
}

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

.button-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.button-secondary {
    border-color: var(--border);
    background: var(--surface);
    color: var(--text);
}

.button-secondary:hover:not(:disabled),
.button-quiet:hover:not(:disabled) {
    border-color: var(--border-strong);
    background: var(--surface-hover);
}

.button-quiet {
    border-color: transparent;
    background: transparent;
    color: var(--text-secondary);
}

.button-auxiliary {
    border-color: color-mix(in srgb, var(--primary) 28%, var(--border));
    background: var(--primary-soft);
    color: var(--primary);
}

.button-auxiliary:hover {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 12%, var(--primary-soft));
}

.button-danger {
    border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
    background: var(--danger-soft);
    color: var(--danger);
}

.button-block {
    width: 100%;
}

.icon-button {
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-secondary);
}

.icon-button:hover {
    border-color: var(--border);
    background: var(--surface-subtle);
    color: var(--text);
}

.text-button {
    padding: 4px 0;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: transparent;
    color: var(--primary);
    font-size: 0.82rem;
    font-weight: 700;
}

.text-button:hover {
    color: var(--primary-hover);
}

.theme-switcher {
    width: 112px;
    height: 38px;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: var(--surface-subtle);
}

.theme-option {
    min-width: 0;
    border-radius: 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-tertiary);
}

.theme-option .icon {
    width: 16px;
    height: 16px;
}

.theme-option:hover {
    color: var(--text);
}

.theme-option.is-active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.notice {
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: flex-start;
    gap: 9px;
    font-size: 0.875rem;
}

.notice .icon {
    margin-top: 1px;
}

.notice-error {
    border-color: color-mix(in srgb, var(--danger) 28%, var(--border));
    background: var(--danger-soft);
    color: var(--danger);
}

/* Login */
.login-shell {
    min-height: 100svh;
    display: grid;
    grid-template-rows: auto 1fr;
}

.login-topbar {
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 18px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.login-main {
    min-height: 0;
    padding: 34px 20px 64px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-wrap {
    width: min(100%, 460px);
}

.product-intro {
    margin-bottom: 22px;
    text-align: center;
}

.product-mark {
    width: 52px;
    height: 52px;
    margin: 0 auto 14px;
    border-radius: var(--radius);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: var(--primary-contrast);
    box-shadow: var(--shadow-sm);
}

.product-mark .icon {
    width: 27px;
    height: 27px;
}

.product-intro h1 {
    margin: 0;
    color: var(--text);
    font-size: 1.65rem;
    line-height: 1.25;
}

.product-intro p {
    margin: 6px 0 0;
    color: var(--text-secondary);
    font-size: 0.92rem;
}

.auth-panel {
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-md);
}

.auth-utilities {
    min-height: 24px;
    margin-bottom: 14px;
    display: flex;
    justify-content: flex-end;
}

.login-tabs {
    height: 46px;
    margin-bottom: 20px;
    padding: 3px;
    border-radius: var(--radius);
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    background: var(--surface-subtle);
}

.login-tab {
    min-width: 0;
    padding: 8px 10px;
    border-radius: 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 680;
}

.login-tab.is-active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

.auth-panel .notice {
    margin-bottom: 18px;
}

.stack-form {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.field-group {
    min-width: 0;
}

.field-group > label {
    margin-bottom: 7px;
    display: block;
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 690;
}

.form-control {
    width: 100%;
    min-height: 42px;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    line-height: 1.4;
    transition: border-color 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}

.form-control::placeholder {
    color: var(--text-tertiary);
}

.form-control:hover {
    border-color: var(--border-strong);
}

.form-control:focus {
    border-color: var(--focus);
    outline: 0;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 18%, transparent);
}

textarea.form-control {
    min-height: 100px;
    resize: vertical;
}

.control-with-icon {
    position: relative;
}

.control-with-icon > .icon {
    position: absolute;
    left: 12px;
    top: 50%;
    z-index: 1;
    color: var(--text-tertiary);
    transform: translateY(-50%);
    pointer-events: none;
}

.control-with-icon .form-control {
    padding-left: 40px;
}

.control-with-icon-top > .icon {
    top: 14px;
    transform: none;
}

.field-hint {
    margin: 6px 0 0;
    color: var(--text-tertiary);
    font-size: 0.76rem;
}

/* Dialogs */
.modal-open {
    overflow: hidden;
}

.app-dialog {
    width: min(calc(100% - 32px), 520px);
    max-height: min(84vh, 760px);
    margin: auto;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: auto;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-md);
}

.app-dialog::backdrop {
    background: var(--overlay);
    backdrop-filter: blur(3px);
}

.dialog-header {
    padding: 20px 22px 14px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
}

.dialog-header h2 {
    margin: 0;
    font-size: 1.18rem;
}

.dialog-description {
    margin: 0;
    padding: 0 22px 18px;
    color: var(--text-secondary);
    font-size: 0.86rem;
}

.app-dialog > .stack-form,
.quick-login-dialog > .stack-form {
    padding: 0 22px 22px;
}

.dialog-actions {
    padding-top: 4px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.api-dialog {
    width: min(calc(100% - 32px), 760px);
}

.api-documentation {
    padding: 0 22px 24px;
}

.api-documentation section {
    padding: 18px 0;
    border-top: 1px solid var(--border);
}

.api-documentation h3 {
    margin: 0 0 10px;
    font-size: 0.9rem;
}

.api-documentation p {
    margin: 8px 0;
    font-size: 0.82rem;
}

.api-documentation code {
    max-width: 100%;
    border-radius: 4px;
    overflow-wrap: anywhere;
    color: var(--primary);
    font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
    font-size: 0.78rem;
}

.api-documentation > section > code,
.api-documentation pre {
    display: block;
    padding: 10px 12px;
    border: 1px solid var(--border);
    background: var(--surface-subtle);
}

.api-documentation pre {
    margin: 7px 0 12px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    white-space: pre-wrap;
}

.definition-list {
    margin: 0;
}

.definition-list > div {
    padding: 8px 0;
    display: grid;
    grid-template-columns: 95px minmax(0, 1fr);
    gap: 12px;
}

.definition-list dt,
.definition-list dd {
    margin: 0;
    font-size: 0.82rem;
}

.definition-list dd {
    color: var(--text-secondary);
}

.floating-action {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 40;
    min-height: 44px;
    padding: 10px 15px;
    border: 1px solid color-mix(in srgb, var(--primary) 52%, transparent);
    border-radius: var(--radius);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--primary);
    color: var(--primary-contrast);
    font-size: 0.84rem;
    font-weight: 720;
    box-shadow: var(--shadow-md);
    transition: background-color 160ms ease, transform 160ms ease;
}

.floating-action:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

/* Shared application top bar */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    height: var(--topbar-height);
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(12px);
}

.topbar-inner {
    width: min(100%, 1280px);
    height: 100%;
    margin: 0 auto;
    padding: 0 24px;
    display: grid;
    grid-template-columns: minmax(150px, 1fr) minmax(0, 1.4fr) minmax(270px, 1fr);
    align-items: center;
    gap: 20px;
}

.account-summary {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
}

.account-copy {
    position: relative;
    min-width: 0;
    max-width: 100%;
    padding: 4px 6px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}

.account-copy:hover {
    border-color: var(--border);
    background: var(--surface-hover);
    color: var(--text);
}

.account-copy.is-copied {
    border-color: color-mix(in srgb, var(--success) 26%, var(--border));
    background: color-mix(in srgb, var(--success-soft) 54%, transparent);
    color: var(--success);
}

.account-copy.is-copy-error {
    border-color: color-mix(in srgb, var(--danger) 26%, var(--border));
    background: color-mix(in srgb, var(--danger-soft) 54%, transparent);
    color: var(--danger);
}

.account-address {
    min-width: 0;
    overflow: hidden;
    color: var(--text-secondary);
    font-size: 0.84rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-copy .account-address {
    color: inherit;
}

.account-copy-icons {
    position: relative;
    width: 15px;
    height: 15px;
    flex: 0 0 15px;
}

.account-copy-icon,
.account-check-icon {
    position: absolute;
    inset: 0;
    width: 15px;
    height: 15px;
    transition: opacity 140ms ease, transform 140ms ease;
}

.account-check-icon {
    opacity: 0;
    transform: scale(0.7);
}

.account-copy.is-copied .account-copy-icon {
    opacity: 0;
    transform: scale(0.7);
}

.account-copy.is-copied .account-check-icon {
    opacity: 1;
    transform: scale(1);
}

.type-badge {
    flex: 0 0 auto;
    padding: 3px 7px;
    border: 1px solid color-mix(in srgb, var(--primary) 28%, var(--border));
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 0.7rem;
    font-weight: 730;
    white-space: nowrap;
}

.topbar-actions {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.refresh-icon {
    transform-origin: center;
}

.is-loading .refresh-icon,
.button.is-loading > .icon {
    animation: spin 800ms linear infinite;
}

/* Mailbox */
.mail-layout {
    width: min(100%, 1240px);
    min-height: calc(100vh - var(--topbar-height));
    margin: 0 auto;
    padding: 28px 24px 92px;
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 26px;
}

.folder-sidebar {
    min-width: 0;
    padding-right: 22px;
    border-right: 1px solid var(--border);
}

.folder-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.folder-button {
    width: 100%;
    min-height: 42px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    display: grid;
    grid-template-columns: 20px minmax(0, 1fr) auto;
    align-items: center;
    gap: 9px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.84rem;
    text-align: left;
}

.folder-button > span:not(.folder-count) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.folder-button:hover {
    background: var(--surface-subtle);
    color: var(--text);
}

.folder-button.is-active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 720;
}

.folder-count {
    min-width: 24px;
    padding: 1px 5px;
    border-radius: 999px;
    background: color-mix(in srgb, currentColor 10%, transparent);
    font-size: 0.7rem;
    text-align: center;
}

.mail-main {
    min-width: 0;
    align-self: start;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.list-notice {
    margin: 18px 18px 0;
}

.mail-panel-header {
    min-height: 78px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.mail-panel-header h1 {
    margin: 0;
    font-size: 1.18rem;
    line-height: 1.25;
}

.mail-count {
    color: var(--text-tertiary);
    font-size: 0.76rem;
    white-space: nowrap;
}

.email-list {
    width: 100%;
}

.email-row {
    min-height: 116px;
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: minmax(0, 1fr) 52px;
    align-items: stretch;
    color: inherit;
    user-select: text;
    transition: background-color 140ms ease;
}

.email-row-content {
    min-width: 0;
    padding: 15px 16px;
}

.email-row:last-child {
    border-bottom: 0;
}

.email-row:hover {
    background: var(--surface-hover);
}

.email-row.is-unread {
    background: color-mix(in srgb, var(--primary-soft) 46%, var(--surface));
}

.email-row.is-unread:hover {
    background: color-mix(in srgb, var(--primary-soft) 68%, var(--surface));
}

.email-row-top {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 16px;
}

.email-heading {
    min-width: 0;
    display: grid;
    grid-template-columns: 8px minmax(0, 1fr);
    align-items: start;
    gap: 8px;
}

.email-sender {
    min-width: 0;
    margin: 6px 0 0 16px;
    overflow: hidden;
    color: var(--text-tertiary);
    font-size: 0.75rem;
    font-weight: 400;
    line-height: 1.4;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: text;
    user-select: text;
}

.email-row.is-unread .email-subject {
    color: var(--text);
    font-weight: 740;
}

.unread-dot {
    width: 7px;
    height: 7px;
    flex: 0 0 7px;
    margin-top: 6px;
    border-radius: 50%;
    background: var(--primary);
}

.unread-dot.is-read {
    visibility: hidden;
}

.email-subject {
    min-width: 0;
    overflow: hidden;
    color: var(--text);
    font-size: 0.92rem;
    font-weight: 650;
    line-height: 1.4;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.email-preview {
    margin: 7px 0 0 16px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1.5;
    overflow-wrap: anywhere;
    white-space: normal;
    cursor: text;
    user-select: text;
}

.email-preview.is-empty {
    color: var(--text-tertiary);
    font-style: italic;
}

.email-date {
    color: var(--text-tertiary);
    font-size: 0.72rem;
    text-align: right;
    white-space: nowrap;
}

.email-open {
    min-width: 52px;
    min-height: 100%;
    border-left: 1px solid var(--border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-subtle);
    color: var(--primary);
    text-decoration: none;
    user-select: none;
    transition: background-color 140ms ease, color 140ms ease;
}

.email-open .icon {
    width: 24px;
    height: 24px;
}

.email-open:hover {
    background: var(--primary-soft);
    color: var(--primary-hover);
}

.empty-state {
    min-height: 310px;
    padding: 50px 22px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    text-align: center;
}

.empty-icon {
    width: 34px;
    height: 34px;
    margin-bottom: 12px;
    color: var(--text-tertiary);
}

.empty-state h2 {
    margin: 0;
    color: var(--text);
    font-size: 1rem;
}

.empty-state p {
    margin: 5px 0 0;
    font-size: 0.82rem;
}

/* Message detail */
.inline-message-host {
    min-height: calc(100vh - var(--topbar-height));
}

.inline-detail-open [data-page-refresh] {
    display: none;
}

.message-loading,
.message-load-error {
    min-height: 360px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    color: var(--text-secondary);
    text-align: center;
}

.message-loading {
    gap: 10px;
}

.message-loading::before {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--primary);
    border-radius: 50%;
    content: "";
    animation: spin 700ms linear infinite;
}

.message-load-error {
    padding: 28px;
    color: var(--danger);
}

.message-layout {
    width: min(100%, 1040px);
    margin: 0 auto;
    padding: 24px 24px 94px;
}

.message-toolbar {
    min-height: 42px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
}

.message-surface {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.message-header {
    padding: 24px 26px 20px;
    border-bottom: 1px solid var(--border);
}

.message-header h1 {
    margin: 0 0 18px;
    overflow-wrap: anywhere;
    font-size: 1.45rem;
    line-height: 1.35;
}

.message-meta {
    margin: 0;
    display: grid;
    gap: 7px;
}

.message-meta > div {
    min-width: 0;
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 10px;
    font-size: 0.82rem;
}

.message-meta dt {
    color: var(--text-tertiary);
}

.message-meta dd {
    min-width: 0;
    margin: 0;
    overflow-wrap: anywhere;
    color: var(--text-secondary);
}

.message-body-shell {
    min-height: 420px;
    overflow-x: auto;
    background: var(--reading-bg);
    color: var(--reading-text);
    color-scheme: light;
}

.message-body {
    width: 100%;
    min-height: 420px;
    border: 0;
    display: block;
    background: var(--reading-bg);
    color-scheme: light;
}

.empty-message-body {
    margin: 0;
    padding: 30px;
    color: #6b7572;
}

.message-links {
    padding: 20px 26px 24px;
    border-top: 1px solid var(--border);
    background: var(--surface-subtle);
}

.section-heading {
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-heading h2 {
    margin: 0;
    font-size: 0.9rem;
}

.message-links ul {
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 7px;
    list-style: none;
}

.message-links a {
    display: block;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--surface);
    font-size: 0.78rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Monitor dashboard */
.monitor-layout {
    width: min(100%, 1040px);
    margin: 0 auto;
    padding: 36px 24px 80px;
}

.page-heading {
    margin-bottom: 24px;
}

.page-heading h1 {
    margin: 0;
    font-size: 1.5rem;
}

.page-heading p {
    margin: 6px 0 0;
    color: var(--text-secondary);
    font-size: 0.86rem;
}

.monitor-status {
    padding: 22px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--danger);
    border-radius: var(--radius);
    display: grid;
    grid-template-columns: minmax(0, 1fr) repeat(2, minmax(120px, auto));
    align-items: center;
    gap: 24px;
    background: var(--surface);
}

.monitor-status[data-state="running"] {
    border-left-color: var(--success);
}

.status-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-title .icon {
    color: var(--primary);
}

.status-title h2 {
    margin: 0;
    font-size: 1rem;
}

.status-metric span {
    display: block;
    color: var(--text-tertiary);
    font-size: 0.72rem;
}

.status-metric strong {
    display: block;
    margin-top: 3px;
    font-size: 0.9rem;
}

.monitor-actions {
    margin-top: 24px;
    padding-top: 22px;
    border-top: 1px solid var(--border);
}

.monitor-actions h2 {
    margin: 0 0 13px;
    font-size: 0.95rem;
}

.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.toast {
    position: fixed;
    right: 22px;
    top: calc(var(--topbar-height) + 16px);
    z-index: 90;
    max-width: min(390px, calc(100% - 32px));
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 0.84rem;
    box-shadow: var(--shadow-md);
}

.toast[data-type="success"] {
    border-color: color-mix(in srgb, var(--success) 40%, var(--border));
    background: var(--success-soft);
    color: var(--success);
}

.toast[data-type="error"] {
    border-color: color-mix(in srgb, var(--danger) 40%, var(--border));
    background: var(--danger-soft);
    color: var(--danger);
}

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

@media (min-width: 721px) {
    .topbar-inner:has(.button-auxiliary) {
        grid-template-columns: auto minmax(0, 1fr) auto;
    }
}

@media (max-width: 900px) {
    .topbar-inner {
        grid-template-columns: auto minmax(0, 1fr) auto;
        padding: 0 18px;
        gap: 12px;
    }

    .mail-layout {
        grid-template-columns: 180px minmax(0, 1fr);
        padding-inline: 18px;
        gap: 18px;
    }

    .folder-sidebar {
        padding-right: 16px;
    }

}

@media (max-width: 720px) {
    :root {
        --topbar-height: 58px;
    }

    .mailbox-page {
        --topbar-height: 96px;
    }

    .app-topbar {
        height: auto;
        min-height: var(--topbar-height);
    }

    .topbar-inner {
        min-height: var(--topbar-height);
    }

    .mailbox-page .topbar-inner {
        padding-top: 8px;
        padding-bottom: 8px;
        grid-template-columns: auto minmax(0, 1fr);
        grid-template-areas:
            "brand actions"
            "account account";
        row-gap: 7px;
    }

    .mailbox-page .topbar-inner > .brand {
        grid-area: brand;
    }

    .mailbox-page .account-summary {
        grid-area: account;
        justify-content: flex-start;
    }

    .mailbox-page .account-address {
        display: block;
        flex: 0 1 auto;
    }

    .mailbox-page .topbar-actions {
        grid-area: actions;
    }

    .mail-layout {
        min-height: calc(100vh - var(--topbar-height));
        padding: 16px 12px 86px;
        display: block;
    }

    .folder-sidebar {
        margin-bottom: 12px;
        padding: 0;
        border-right: 0;
    }

    .folder-nav {
        padding-bottom: 4px;
        overflow-x: auto;
        flex-direction: row;
        scrollbar-width: thin;
    }

    .folder-button {
        width: auto;
        min-width: max-content;
        grid-template-columns: 18px auto auto;
    }

    .email-row {
        min-height: 0;
        grid-template-columns: minmax(0, 1fr) 44px;
    }

    .email-row-content {
        padding: 14px 13px;
    }

    .email-row-top {
        gap: 10px;
    }

    .email-preview {
        margin-top: 9px;
    }

    .email-open {
        min-width: 44px;
    }

    .message-layout {
        padding: 14px 12px 86px;
    }

    .message-header {
        padding: 20px 18px 18px;
    }

    .message-header h1 {
        font-size: 1.22rem;
    }

    .message-body-shell,
    .message-body {
        min-height: 360px;
    }

    .message-links {
        padding: 18px;
    }

    .monitor-layout {
        padding: 26px 16px 72px;
    }

    .monitor-status {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 18px;
    }

    .status-title {
        grid-column: 1 / -1;
    }
}

@media (max-width: 520px) {
    .mailbox-page:has(.button-auxiliary) .brand > span:last-child {
        display: none;
    }

    .login-topbar {
        padding: 14px 16px;
    }

    .login-main {
        padding: 24px 14px 48px;
        align-items: flex-start;
    }

    .product-intro {
        margin-bottom: 18px;
    }

    .product-intro h1 {
        font-size: 1.45rem;
    }

    .auth-panel {
        padding: 18px;
    }

    .brand > span:last-child {
        display: none;
    }

    .topbar-inner {
        padding: 0 12px;
        gap: 8px;
    }

    .topbar-actions {
        gap: 5px;
    }

    .topbar-actions .button {
        width: 38px;
        min-height: 38px;
        padding: 0;
    }

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

    .theme-switcher {
        width: 98px;
    }

    .mail-panel-header {
        min-height: 68px;
        padding: 13px;
    }

    .mail-panel-header h1 {
        font-size: 1.05rem;
    }

    .floating-action {
        right: 12px;
        bottom: 12px;
    }

    .app-dialog {
        width: calc(100% - 20px);
        max-height: 90vh;
    }

    .dialog-header {
        padding: 17px 17px 12px;
    }

    .dialog-description,
    .app-dialog > .stack-form,
    .quick-login-dialog > .stack-form,
    .api-documentation {
        padding-left: 17px;
        padding-right: 17px;
    }

    .dialog-actions {
        flex-direction: column-reverse;
    }

    .dialog-actions .button {
        width: 100%;
    }

    .definition-list > div {
        grid-template-columns: 1fr;
        gap: 3px;
    }

    .message-meta > div {
        grid-template-columns: 54px minmax(0, 1fr);
    }

    .action-row {
        flex-direction: column;
    }

    .action-row .button {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
