:root {
    --bg: #f6f8f8;
    --surface: #ffffff;
    --surface-soft: #eef4f3;
    --ink: #152322;
    --muted: #657472;
    --border: #d8e1df;
    --primary: #0b746b;
    --primary-strong: #075b54;
    --accent: #c57c1d;
    --danger: #b33a3a;
    --shadow: 0 18px 42px rgba(22, 36, 34, 0.10);
    --radius: 8px;
    --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
}

a {
    color: inherit;
}

button,
input,
textarea {
    font: inherit;
}

button {
    border: 0;
}

.page-shell {
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: auto minmax(220px, 1fr) auto auto;
    gap: 14px;
    align-items: center;
    min-height: 64px;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(18px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--ink);
    font-weight: 800;
    text-decoration: none;
    letter-spacing: 0;
}

.brand-mark {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: var(--radius);
    background: var(--primary);
    color: #fff;
    font-size: 17px;
    font-weight: 800;
}

.topbar-search form {
    position: relative;
    max-width: 720px;
    margin: 0 auto;
}

.search-icon {
    position: absolute;
    top: 50%;
    left: 14px;
    width: 18px;
    height: 18px;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
}

.topbar-search input {
    width: 100%;
    min-height: 42px;
    padding: 10px 14px 10px 42px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-soft);
    color: var(--ink);
    outline: none;
}

.topbar-search input:focus,
input:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(11, 116, 107, 0.14);
}

.account-chip,
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 34px;
    padding: 0 10px;
    border: 1px solid #cfe0dc;
    border-radius: var(--radius);
    background: #f5fbf9;
    color: var(--primary-strong);
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.security-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--primary);
    box-shadow: 0 0 0 4px rgba(11, 116, 107, 0.12);
}

.icon {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
    flex: 0 0 auto;
}

.icon-button {
    display: inline-grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
}

.icon-button:hover {
    color: var(--ink);
    border-color: #b8c8c5;
}

.flash {
    max-width: 1180px;
    margin: 14px auto 0;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
}

.flash-success {
    border-color: #b9d9d4;
    background: #effaf7;
    color: var(--primary-strong);
}

.flash-error {
    border-color: #efc7c7;
    background: #fff3f3;
    color: #8f2d2d;
}

.mail-app {
    display: grid;
    grid-template-columns: 244px minmax(320px, 440px) minmax(420px, 1fr);
    gap: 0;
    height: calc(100vh - 64px);
    min-height: 620px;
}

.mail-nav {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 20px;
    border-right: 1px solid var(--border);
    background: #fbfdfd;
}

.compose-button,
.primary-button,
.secondary-button,
.danger-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 14px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
}

.compose-button,
.primary-button {
    background: var(--primary);
    color: #fff;
}

.compose-button:hover,
.primary-button:hover {
    background: var(--primary-strong);
}

.secondary-button {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink);
}

.secondary-button:hover {
    border-color: #afbfbc;
    background: #f8fbfa;
}

.danger-button {
    background: var(--danger);
    color: #fff;
}

.full {
    width: 100%;
}

.folder-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 40px;
    padding: 0 10px;
    border-radius: var(--radius);
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
}

.folder-link span {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.folder-link strong {
    min-width: 24px;
    padding: 1px 8px;
    border-radius: 999px;
    background: #fff0db;
    color: #8c5614;
    font-size: 12px;
    text-align: center;
}

.folder-link:hover,
.folder-link.active {
    background: #e7f2f0;
    color: var(--primary-strong);
}

.mail-identity {
    margin-top: auto;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
}

.mail-identity span,
.mail-identity strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mail-identity span {
    color: var(--muted);
    font-size: 13px;
}

.mail-identity strong {
    margin-top: 2px;
    font-size: 14px;
}

.message-list {
    display: flex;
    min-width: 0;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: #fafdfe;
}

.list-heading,
.detail-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.list-heading h1,
.detail-heading h1 {
    margin: 0;
    font-size: 24px;
    line-height: 1.15;
    letter-spacing: 0;
}

.list-heading p,
.detail-heading p,
.panel-heading p,
.empty-state p,
.settings-summary p,
.security-card p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.message-scroll {
    min-height: 0;
    overflow: auto;
    padding: 10px;
}

.message-row {
    display: block;
    padding: 14px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    color: var(--ink);
    text-decoration: none;
}

.message-row + .message-row {
    margin-top: 6px;
}

.message-row:hover,
.message-row.active {
    border-color: var(--border);
    background: var(--surface);
    box-shadow: 0 8px 24px rgba(22, 36, 34, 0.06);
}

.message-row.unread {
    background: #fffaf2;
}

.row-top {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    color: var(--muted);
    font-size: 13px;
}

.row-top strong {
    min-width: 0;
    overflow: hidden;
    color: var(--ink);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.row-top time {
    flex: 0 0 auto;
}

.message-row h2 {
    margin: 6px 0 4px;
    overflow: hidden;
    color: var(--ink);
    font-size: 15px;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-row p {
    display: -webkit-box;
    margin: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 13px;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.message-detail {
    min-width: 0;
    overflow: auto;
    background: var(--surface);
}

.read-panel,
.compose-panel {
    min-height: 100%;
}

.detail-heading {
    align-items: center;
    min-height: 88px;
}

.detail-heading time {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 13px;
}

.delivery-note {
    margin: 18px 24px 0;
    padding: 10px 12px;
    border: 1px solid #efd6b2;
    border-radius: var(--radius);
    background: #fff8ee;
    color: #835112;
    font-size: 13px;
    font-weight: 700;
}

.message-body {
    max-width: 820px;
    padding: 28px 24px 48px;
    color: #233230;
    font-size: 16px;
    line-height: 1.7;
    white-space: normal;
}

.compose-panel {
    padding-bottom: 32px;
}

.compose-panel label,
.auth-panel label,
.settings-panel label,
.secret-box label {
    display: block;
    margin: 16px 24px 7px;
    color: #40514e;
    font-size: 13px;
    font-weight: 800;
}

.compose-panel input,
.compose-panel textarea {
    width: calc(100% - 48px);
    margin: 0 24px;
}

input,
textarea {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    outline: none;
}

input {
    min-height: 42px;
    padding: 10px 12px;
}

textarea {
    min-height: 260px;
    padding: 12px;
    resize: vertical;
}

.auth-screen {
    display: grid;
    grid-template-columns: minmax(280px, 460px) minmax(320px, 430px);
    gap: 54px;
    align-items: center;
    max-width: 1060px;
    min-height: calc(100vh - 64px);
    margin: 0 auto;
    padding: 56px 24px;
}

.auth-screen.compact {
    grid-template-columns: minmax(300px, 430px);
    justify-content: center;
}

.auth-copy h1 {
    max-width: 460px;
    margin: 0;
    font-size: 48px;
    line-height: 1;
    letter-spacing: 0;
}

.auth-copy p {
    max-width: 430px;
    color: var(--muted);
    font-size: 17px;
}

.auth-panel,
.settings-panel,
.settings-summary {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.auth-panel {
    padding: 24px;
}

.panel-heading {
    margin-bottom: 18px;
}

.panel-heading h2 {
    margin: 0;
    font-size: 22px;
    line-height: 1.2;
}

.auth-panel label,
.settings-panel label {
    margin: 16px 0 7px;
}

.auth-panel input,
.settings-panel input {
    width: 100%;
}

.address-field {
    display: flex;
    align-items: stretch;
}

.address-field input {
    border-radius: var(--radius) 0 0 var(--radius);
}

.address-field span {
    display: inline-flex;
    align-items: center;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-left: 0;
    border-radius: 0 var(--radius) var(--radius) 0;
    background: var(--surface-soft);
    color: var(--muted);
    font-weight: 700;
    white-space: nowrap;
}

.auth-link {
    margin: 18px 0 0;
    color: var(--muted);
    text-align: center;
}

.auth-link a {
    color: var(--primary-strong);
    font-weight: 800;
}

.settings-page {
    display: grid;
    grid-template-columns: 320px minmax(360px, 760px);
    gap: 24px;
    max-width: 1160px;
    margin: 0 auto;
    padding: 28px 24px 56px;
}

.settings-summary {
    align-self: start;
    padding: 22px;
}

.settings-summary h1 {
    margin: 0 0 4px;
    font-size: 30px;
}

.security-card {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin: 22px 0;
    padding: 14px;
    border: 1px solid #cfe0dc;
    border-radius: var(--radius);
    background: #f5fbf9;
}

.settings-stack {
    display: grid;
    gap: 18px;
}

.settings-panel {
    padding: 22px;
}

.settings-panel .primary-button,
.settings-panel .secondary-button,
.settings-panel .danger-button {
    margin-top: 18px;
}

.secret-box {
    margin: 16px 0;
}

.secret-box label {
    margin: 0 0 6px;
}

.secret-box code {
    display: block;
    overflow-wrap: anywhere;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #f8fbfa;
    color: #243432;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 13px;
}

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

.empty-state h1,
.empty-state h2 {
    margin: 0 0 6px;
    color: var(--ink);
}

.standalone {
    max-width: 520px;
    margin: 80px auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.detail-empty {
    display: grid;
    min-height: 100%;
    place-content: center;
}

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

@media (max-width: 1060px) {
    .mail-app {
        grid-template-columns: 210px minmax(280px, 380px) minmax(360px, 1fr);
    }
}

@media (max-width: 860px) {
    .topbar {
        grid-template-columns: 1fr auto auto;
    }

    .topbar-search {
        grid-column: 1 / -1;
        order: 2;
    }

    .mail-app {
        display: block;
        height: auto;
        min-height: 0;
    }

    .mail-nav {
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .mail-nav nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
    }

    .message-list,
    .message-detail {
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .auth-screen,
    .settings-page {
        grid-template-columns: 1fr;
    }

    .auth-copy h1 {
        font-size: 38px;
    }
}

@media (max-width: 560px) {
    .topbar {
        padding: 10px 12px;
    }

    .account-chip {
        display: none;
    }

    .mail-nav,
    .list-heading,
    .detail-heading,
    .auth-screen,
    .settings-page {
        padding-left: 14px;
        padding-right: 14px;
    }

    .detail-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .compose-panel label,
    .compose-panel input,
    .compose-panel textarea {
        margin-left: 14px;
        margin-right: 14px;
        width: calc(100% - 28px);
    }
}
