form {
    margin: 0;
    padding: 0;
}

tr.htmx-swapping td,
tr.htmx-swapping th {
    opacity: 0;
    transition: opacity 0.35s ease-out;
}

.htmx-indicator {
    display: none;
}

:root {
    --background: #f3f5f8;
    --surface: rgba(255, 255, 255, 0.94);
    --line-soft: rgba(27, 42, 56, 0.1);
    --ink: #1b2a34;
    --ink-soft: #667681;
    --primary: #1d3b4f;
    --primary-hover: #28506a;
    --accent: #7f8f9d;
    --shadow-soft: 0 8px 24px rgba(15, 23, 42, 0.05);
    --shadow-card: 0 4px 16px rgba(15, 23, 42, 0.04);
    --radius-xl: 16px;
    --radius-pill: 999px;
    --form-element-spacing-vertical: 0.44rem;
    --form-element-spacing-horizontal: 0.92rem;
    --font-body: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
    --font-display: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
}

html {
    font-size: 15px;
    background: var(--background);
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    font-family: var(--font-body);
    line-height: 1.58;
    background:
        radial-gradient(circle at top left, rgba(105, 131, 154, 0.08), transparent 32%),
        linear-gradient(180deg, #f7f9fb 0%, #eef2f6 100%);
    position: relative;
    overflow-x: hidden;
}

body::before,
body::after {
    content: "";
    position: fixed;
    z-index: 0;
    pointer-events: none;
    filter: blur(72px);
    opacity: 0.12;
}

body::before {
    width: 20rem;
    height: 20rem;
    top: -7rem;
    right: -7rem;
    background: rgba(133, 154, 176, 0.35);
}

body::after {
    width: 24rem;
    height: 24rem;
    left: -9rem;
    bottom: -10rem;
    background: rgba(123, 143, 157, 0.16);
}

body,
main,
header,
dialog {
    position: relative;
    z-index: 1;
}

h1,
h2,
h3,
h4,
.brand-copy strong,
.metric-card strong {
    font-family: var(--font-display);
    letter-spacing: -0.015em;
}

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

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

button,
input,
textarea,
select {
    font-family: inherit;
}

input,
textarea,
select {
    border-radius: 12px !important;
    border-color: rgba(29, 59, 79, 0.12) !important;
    background: rgba(255, 255, 255, 0.96) !important;
    box-shadow: none !important;
}

input:focus,
textarea:focus,
select:focus {
    border-color: rgba(29, 59, 79, 0.32) !important;
    box-shadow: 0 0 0 0.15rem rgba(29, 59, 79, 0.1) !important;
}

main.container {
    max-width: 1160px;
}

.app-main {
    padding: 1.05rem 0 3.8rem;
}

.site-header {
    padding: 0.95rem 1rem 0;
}

.topnav {
    max-width: 1240px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.9rem;
    padding: 0.68rem 0.82rem;
    border: 1px solid rgba(27, 42, 56, 0.08);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    box-shadow: var(--shadow-soft);
}

.topnav a {
    float: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-align: center;
    text-decoration: none;
    font-size: 0.84rem;
    padding: 0.62rem 0.82rem;
    border-radius: var(--radius-pill);
    transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.topnav a:hover {
    transform: translateY(-1px);
}

.brand-link {
    justify-self: start;
    justify-content: flex-start;
    padding: 0.18rem 0.4rem 0.18rem 0.12rem !important;
    background: transparent;
    color: var(--ink) !important;
}

.brand-mark {
    width: 1.95rem;
    height: 1.95rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.55rem;
    background: rgba(29, 59, 79, 0.04);
    border: 1px solid rgba(29, 59, 79, 0.14);
    color: var(--primary);
    font-family: var(--font-display);
    font-size: 0.8rem;
    font-weight: 700;
    box-shadow: none;
}

.brand-copy {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.05;
}

.brand-copy strong {
    font-size: 0.92rem;
    font-weight: 700;
}

.brand-copy small {
    margin-top: 0.18rem;
    color: var(--ink-soft);
    font-size: 0.68rem;
    letter-spacing: 0.02em;
}

.version {
    font-size: 0.62rem;
    color: rgba(27, 42, 56, 0.55);
    margin-left: 0.35rem;
}

.nav-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.55rem;
}

.nav-input {
    flex: 1 1 20rem;
    min-width: min(22rem, 100%);
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.18rem 0.4rem 0.18rem 0.68rem !important;
    background: rgba(248, 250, 252, 0.95);
    border: 1px solid rgba(29, 59, 79, 0.1);
    box-shadow: none;
}

.nav-input i {
    color: var(--ink-soft);
    font-size: 0.92rem;
}

.nav-input input {
    flex: 1;
    min-width: 0;
    margin: 0 !important;
    padding: 0 0.3rem !important;
    height: 2.15rem;
    border: none !important;
    background: transparent !important;
}

.nav-input input:focus {
    box-shadow: none !important;
}

.nav-ghost,
.nav-secondary {
    background: #f8fafc;
    border: 1px solid rgba(29, 59, 79, 0.08);
}

.nav-primary {
    color: #f8fbfd !important;
    background: #1d3b4f;
    box-shadow: 0 6px 14px rgba(29, 59, 79, 0.12);
}

.nav-ghost.is-empty {
    opacity: 0.55;
}

.topnav .icon {
    display: none;
}

.htmx-indicator {
    position: fixed;
    right: 1.4rem;
    bottom: 1.4rem;
    z-index: 50;
    border: none;
    background: rgba(22, 37, 34, 0.84);
    color: #fff9f2;
    padding: 0.85rem 1rem;
    border-radius: 999px;
    box-shadow: var(--shadow-card);
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    display: inline-flex;
}

.section-card {
    border-radius: var(--radius-xl);
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(27, 42, 56, 0.08);
    box-shadow: var(--shadow-card);
    padding: 1rem;
}

.text-center {
    text-align: center;
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.28rem 0.58rem;
    border-radius: var(--radius-pill);
    background: rgba(29, 59, 79, 0.06);
    color: var(--primary);
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.section-heading h1,
.section-heading h2 {
    margin-bottom: 0.7rem;
}

.section-heading p,
.hero-lead,
.polling-tip,
.table-header p,
.password-card p,
.admin-auth-card p {
    color: var(--ink-soft);
}

.hero-shell {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 0.85rem;
    align-items: stretch;
}

.hero-card h1 {
    font-size: clamp(1.55rem, 3vw, 2.2rem);
    margin: 0.72rem 0 0.8rem;
    line-height: 1.18;
    letter-spacing: -0.01em;
}

.hero-lead {
    max-width: 32rem;
    font-size: 0.9rem;
    line-height: 1.68;
    margin-bottom: 1rem;
}

.hero-actions,
.mailbox-actions,
.admin-actions,
.log-actions,
.detail-toolbar,
.raw-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
}

.hero-metrics {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
    margin-bottom: 0.8rem;
}

.metric-card {
    padding: 0.78rem 0.76rem;
    border-radius: 12px;
    background: #f8fafc;
    border: 1px solid rgba(29, 59, 79, 0.08);
}

.metric-card strong {
    display: block;
    font-size: 1.18rem;
    line-height: 1;
    margin-bottom: 0.28rem;
}

.metric-card span {
    color: var(--ink-soft);
    font-size: 0.8rem;
}

.metric-card.accent {
    background: #f4f7fa;
}

.feature-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 0.7rem;
}

.feature-list li {
    display: grid;
    gap: 0.2rem;
    padding: 0.72rem 0.8rem 0.72rem 0.88rem;
    border-radius: 12px;
    background: #fafbfd;
    border: 1px solid rgba(29, 59, 79, 0.08);
}

.feature-list span {
    font-weight: 700;
    font-size: 0.86rem;
}

.feature-list small {
    color: var(--ink-soft);
    font-size: 0.8rem;
    line-height: 1.55;
}

.mailbox-shell,
.message-layout,
.admin-shell {
    display: grid;
    gap: 0.85rem;
}

.mailbox-hero {
    display: grid;
    grid-template-columns: 1.6fr 0.9fr;
    gap: 0.9rem;
    align-items: start;
}

.mailbox-hero h1,
.message-overview h1 {
    margin: 0.55rem 0 0.45rem;
    font-size: clamp(1.35rem, 2.4vw, 1.95rem);
    word-break: break-word;
}

.action-row a[role="button"],
.detail-toolbar a,
.raw-actions a,
.table-button {
    padding: 0.54rem 0.74rem;
    border-radius: var(--radius-pill);
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid rgba(29, 59, 79, 0.08);
    color: var(--ink);
    text-decoration: none;
    font-size: 0.84rem;
}

.action-row a[role="button"]:hover,
.detail-toolbar a:hover,
.raw-actions a:hover,
.table-button:hover {
    background: rgba(255, 255, 255, 0.92);
}

.polling-tip {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.72rem 0.92rem;
    border-radius: 16px;
    background: rgba(32, 120, 91, 0.08);
    border: 1px solid rgba(32, 120, 91, 0.14);
    margin: 0;
}

.inbox-refreshing {
    opacity: 0.88;
}

.table-card,
.log-card,
.message-card {
    overflow: hidden;
}

.table-header,
.message-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.8rem;
}

.table-header h2,
.message-card-head h2,
.log-card h2 {
    margin: 0;
}

.table-scroll {
    overflow-x: auto;
}

table {
    width: 100%;
    margin: 0;
    border-collapse: separate;
    border-spacing: 0 0.6rem;
}

thead th {
    color: var(--ink-soft);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0 0.8rem 0.18rem;
}

tbody td,
tbody th {
    background: rgba(255, 255, 255, 0.92);
    padding: 0.76rem 0.78rem;
    border-top: 1px solid rgba(29, 59, 79, 0.08);
    border-bottom: 1px solid rgba(29, 59, 79, 0.08);
    vertical-align: middle;
}

tbody th:first-child,
tbody td:first-child {
    border-left: 1px solid rgba(29, 59, 79, 0.08);
    border-radius: 14px 0 0 14px;
}

tbody th:last-child,
tbody td:last-child {
    border-right: 1px solid rgba(29, 59, 79, 0.08);
    border-radius: 0 14px 14px 0;
}

.empty-state {
    display: grid;
    gap: 0.3rem;
    justify-items: center;
    padding: 1rem 0.6rem;
    color: var(--ink-soft);
}

.empty-state strong {
    color: var(--ink);
    font-size: 0.96rem;
}

.message-overview {
    padding-bottom: 1.2rem;
}

.message-meta-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.8rem;
    margin-top: 1rem;
}

.meta-card {
    padding: 0.9rem;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(29, 59, 79, 0.08);
}

.meta-card span {
    display: block;
    color: var(--ink-soft);
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.55rem;
}

.meta-card strong {
    display: block;
    word-break: break-word;
    font-size: 0.92rem;
}

.badge-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.34rem 0.62rem;
    border-radius: var(--radius-pill);
    background: rgba(29, 59, 79, 0.08);
    color: var(--primary);
    font-size: 0.8rem;
}

.message-body pre,
.log-card pre,
.raw-mail-card pre {
    margin: 0;
    padding: 1rem;
    border-radius: 16px;
    background: #f7f9fb;
    border: 1px solid rgba(29, 59, 79, 0.08);
    color: #20303b;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-x: auto;
}

.attachment-list {
    margin: 0;
    padding-left: 1rem;
}

.attachment-list li + li {
    margin-top: 0.45rem;
}

.attachment-empty {
    color: var(--ink-soft);
}

.admin-auth-card,
.password-card {
    max-width: 34rem;
    margin: 2.4rem auto 0;
}

.admin-auth-form,
.password-form {
    display: grid;
    gap: 0.9rem;
    margin-top: 1rem;
}

.error-panel {
    margin-top: 1rem;
    padding: 0.9rem 1rem;
    border-radius: 14px;
    background: rgba(182, 58, 42, 0.08);
    color: #8f2f22;
    border: 1px solid rgba(182, 58, 42, 0.14);
}

.log-grid {
    display: grid;
    gap: 1rem;
}

.log-card pre {
    max-height: 28rem;
}

.password-shell {
    max-width: 1040px;
    margin: 0 auto;
    padding: 2.4rem 1rem 3.2rem;
}

.password-card .brand-mark {
    margin-bottom: 1rem;
}

dialog article {
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(29, 59, 79, 0.08);
    box-shadow: var(--shadow-soft);
}

dialog footer {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
}

@media screen and (max-width: 980px) {
    .topnav {
        grid-template-columns: 1fr auto;
    }

    .nav-actions {
        display: none;
        grid-column: 1 / -1;
        width: 100%;
        justify-content: stretch;
    }

    .topnav.responsive .nav-actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .topnav.responsive .nav-actions > * {
        width: 100%;
    }

    .topnav .icon {
        display: inline-flex;
        justify-self: end;
        padding: 0.9rem;
        background: rgba(255, 255, 255, 0.62);
        border: 1px solid rgba(29, 59, 79, 0.08);
    }

    .nav-input {
        min-width: 100%;
    }

    .hero-shell,
    .mailbox-hero,
    .message-meta-grid {
        grid-template-columns: 1fr;
    }
}

@media screen and (max-width: 700px) {
    .site-header {
        padding: 0.8rem 0.8rem 0;
    }

    .topnav {
        padding: 0.72rem;
        border-radius: 14px;
    }

    .brand-copy small {
        display: none;
    }

    .hero-card h1 {
        font-size: 1.65rem;
    }

    .hero-metrics {
        grid-template-columns: 1fr;
    }

    .section-card {
        padding: 0.9rem;
    }

    tbody td,
    tbody th {
        padding: 0.7rem 0.68rem;
    }
}
