* {
    box-sizing: border-box;
}

:root {
    --page: #f5f6f7;
    --surface: #ffffff;
    --surface-soft: #f1f3f4;
    --border: #e0e3e6;
    --text: #17191b;
    --muted: #687077;
    --red: #d71920;
    --danger-soft: #fff0f0;
}

html[data-theme="dark"] {
    --page: #111315;
    --surface: #191c1f;
    --surface-soft: #22262a;
    --border: #30353a;
    --text: #f1f3f4;
    --muted: #9ea5ab;
    --danger-soft: #2a191b;
    color-scheme: dark;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family:
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    background: var(--page);
    color: var(--text);
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

a {
    color: inherit;
    text-decoration: none;
}

.hidden {
    display: none !important;
}

.topbar {
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 0 22px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand img {
    display: block;
    width: 145px;
    height: auto;
}

.product-name {
    color: var(--muted);
    font-size: 14px;
    font-weight: 750;
}

.topnav {
    display: flex;
    align-items: center;
    gap: 20px;
    font-size: 14px;
    font-weight: 700;
}

.topnav a:hover,
.topnav .active {
    color: var(--red);
}

.theme-toggle,
.logout-button {
    height: 34px;
    padding: 0 13px;
    color: var(--text);
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 999px;
}

.login-page {
    min-height: calc(100vh - 72px);
    display: grid;
    place-items: center;
    padding: 32px 18px;
}

.login-card {
    width: min(430px, 100%);
    padding: 34px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: 0 16px 45px rgba(0, 0, 0, .08);
}

.login-logo {
    display: block;
    width: 190px;
    max-width: 80%;
    margin: 0 auto 24px;
}

.login-card h1 {
    margin: 0 0 8px;
    text-align: center;
    font-size: 26px;
}

.login-subtitle {
    margin: 0 0 28px;
    color: var(--muted);
    text-align: center;
    font-size: 14px;
    line-height: 1.5;
}

.field {
    margin-bottom: 16px;
}

.field label {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.field input {
    width: 100%;
    height: 46px;
    padding: 0 13px;
    color: var(--text);
    background: var(--page);
    border: 1px solid var(--border);
    border-radius: 11px;
    outline: none;
}

.login-button {
    width: 100%;
    height: 46px;
    margin-top: 4px;
    color: #fff;
    background: var(--red);
    border: 0;
    border-radius: 11px;
    font-weight: 850;
}

.login-error {
    margin-top: 14px;
    padding: 10px 12px;
    color: #b4232b;
    background: var(--danger-soft);
    border-radius: 10px;
    font-size: 13px;
}

.mail-layout {
    min-height: calc(100vh - 72px);
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr);
}

.sidebar {
    padding: 18px 14px;
    background: var(--surface);
    border-right: 1px solid var(--border);
}

.compose-button {
    width: 100%;
    margin-bottom: 20px;
    padding: 12px 15px;
    color: #fff;
    background: var(--red);
    border: 0;
    border-radius: 12px;
    font-weight: 850;
}

.folder-list {
    display: grid;
    gap: 4px;
}

.folder {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    color: var(--muted);
    background: transparent;
    border: 0;
    border-radius: 10px;
    text-align: left;
    font-size: 14px;
    font-weight: 650;
}

.folder:hover,
.folder.active {
    color: var(--text);
    background: var(--surface-soft);
}

.folder-count {
    min-width: 22px;
    text-align: right;
    font-size: 12px;
}

.account-card {
    margin-top: 24px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

.account-email {
    font-size: 13px;
    font-weight: 800;
}

.account-meta {
    margin-top: 4px;
    color: var(--muted);
    font-size: 11px;
}

.mail-main {
    min-width: 0;
    padding: 24px;
}

.mail-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.mail-title {
    margin: 0;
    font-size: 26px;
}

.mail-search {
    width: min(380px, 50vw);
    height: 42px;
    padding: 0 14px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.mail-panel {
    overflow: hidden;
    min-height: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
}

.empty-state {
    min-height: 420px;
    display: grid;
    place-items: center;
    padding: 40px;
    text-align: center;
}

.empty-card {
    max-width: 480px;
}

.empty-card h2 {
    margin: 0 0 9px;
    font-size: 21px;
}

.empty-card p {
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
}

.message-row {
    display: grid;
    grid-template-columns:
        minmax(150px, 220px)
        minmax(0, 1fr)
        auto;
    gap: 18px;
    padding: 15px 18px;
    border-bottom: 1px solid var(--border);
}

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

.message-from {
    overflow: hidden;
    font-size: 14px;
    font-weight: 750;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-subject {
    overflow: hidden;
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-date {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.message-row.unread {
    background: var(--surface-soft);
}

@media (max-width: 760px) {
    .product-name {
        display: none;
    }

    .topnav a {
        display: none;
    }

    .brand img {
        width: 120px;
    }

    .mail-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .compose-button {
        width: auto;
        flex: 0 0 auto;
        margin: 0;
    }

    .folder-list {
        display: flex;
        gap: 6px;
    }

    .folder {
        width: auto;
        flex: 0 0 auto;
    }

    .folder-count,
    .account-card {
        display: none;
    }

    .mail-main {
        padding: 18px 14px;
    }

    .mail-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .mail-search {
        width: 100%;
    }
}


/* ========================================
   COMPOSE
   ======================================== */

.compose-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;

    display: grid;
    place-items: center;

    padding: 20px;

    background:
        rgba(
            0,
            0,
            0,
            .48
        );
}

.compose-window {
    width: min(
        680px,
        100%
    );

    max-height:
        calc(
            100vh - 40px
        );

    display: flex;
    flex-direction: column;

    overflow: hidden;

    background: var(--surface);

    border:
        1px solid
        var(--border);

    border-radius: 18px;

    box-shadow:
        0 22px 60px
        rgba(
            0,
            0,
            0,
            .25
        );
}

.compose-header {
    min-height: 56px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 18px;

    padding: 0 18px;

    border-bottom:
        1px solid
        var(--border);
}

.compose-close {
    width: 34px;
    height: 34px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    color: var(--muted);
    background: transparent;

    border: 0;
    border-radius: 50%;

    font-size: 24px;
    line-height: 1;
}

.compose-close:hover {
    color: var(--text);
    background: var(--surface-soft);
}

.compose-body {
    overflow-y: auto;

    padding: 18px;
}

.compose-field {
    margin-bottom: 15px;
}

.compose-field label {
    display: block;

    margin-bottom: 6px;

    color: var(--muted);

    font-size: 12px;
    font-weight: 800;
}

.compose-field input,
.compose-field select,
.compose-field textarea {
    width: 100%;

    padding: 11px 12px;

    color: var(--text);
    background: var(--page);

    border:
        1px solid
        var(--border);

    border-radius: 10px;

    outline: none;
}

.compose-field textarea {
    resize: vertical;
    min-height: 220px;
}

.compose-field input:focus,
.compose-field select:focus,
.compose-field textarea:focus {
    border-color: #9ea5ab;
}

.compose-status {
    margin-top: 10px;

    padding: 10px 12px;

    border-radius: 10px;

    color: var(--muted);
    background: var(--surface-soft);

    font-size: 13px;
    line-height: 1.45;
}

.compose-status.error {
    color: #b4232b;
    background: var(--danger-soft);
}

.compose-status.success {
    color: #247447;
    background: #edf8f1;
}

html[data-theme="dark"]
.compose-status.success {
    color: #93d5ae;
    background: #173022;
}

.compose-footer {
    display: flex;
    justify-content: flex-end;

    padding: 14px 18px;

    border-top:
        1px solid
        var(--border);
}

.send-button {
    min-width: 110px;

    padding: 11px 18px;

    color: #fff;
    background: var(--red);

    border: 0;
    border-radius: 10px;

    font-weight: 850;
}

.send-button:disabled {
    opacity: .6;
    cursor: wait;
}

@media (max-width: 700px) {

    .compose-modal {
        padding: 0;
    }

    .compose-window {
        width: 100%;
        height: 100vh;
        max-height: none;

        border: 0;
        border-radius: 0;
    }
}


/* ========================================
   MESSAGE VIEWER
   ======================================== */

.message-row {
    cursor: pointer;
}

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

.message-view {
    min-height: 420px;
}

.message-view-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 12px;

    padding: 14px 18px;

    border-bottom:
        1px solid
        var(--border);
}

.message-view-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;

    gap: 8px;
}

.message-action {
    min-height: 34px;

    padding: 0 12px;

    color: var(--text);
    background: var(--surface-soft);

    border:
        1px solid
        var(--border);

    border-radius: 9px;

    font-size: 13px;
    font-weight: 750;
}

.message-action:hover {
    border-color: #9ea5ab;
}

.message-action.primary {
    color: #ffffff;
    background: var(--red);
    border-color: var(--red);
}

.message-action.danger {
    color: #b4232b;
}

.message-view-content {
    padding: 24px;
}

.message-view-subject {
    margin:
        0
        0
        18px;

    font-size: 26px;
    line-height: 1.2;
}

.message-view-meta {
    display: grid;

    gap: 6px;

    margin-bottom: 24px;
    padding-bottom: 18px;

    border-bottom:
        1px solid
        var(--border);

    color: var(--muted);

    font-size: 13px;
}

.message-view-meta strong {
    color: var(--text);
}

.message-view-body {
    color: var(--text);

    font-size: 15px;
    line-height: 1.7;

    white-space: pre-wrap;
    word-break: break-word;
}

.message-view-empty {
    color: var(--muted);
    font-style: italic;
}

@media (max-width: 700px) {

    .message-view-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .message-view-actions {
        width: 100%;
    }

    .message-action {
        flex: 1 1 auto;
    }

    .message-view-content {
        padding: 18px;
    }

    .message-view-subject {
        font-size: 22px;
    }
}


/* ========================================
   DRAFTS
   ======================================== */

.draft-status {
    min-height: 18px;

    margin-top: -4px;
    margin-bottom: 8px;

    color: var(--muted);

    font-size: 12px;
    text-align: right;
}

.draft-row {
    display: grid;

    grid-template-columns:
        minmax(130px, 190px)
        minmax(0, 1fr)
        auto;

    gap: 18px;

    padding: 15px 18px;

    border-bottom:
        1px solid
        var(--border);

    cursor: pointer;
}

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

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

.draft-to {
    overflow: hidden;

    color: var(--muted);

    font-size: 14px;

    text-overflow: ellipsis;
    white-space: nowrap;
}

.draft-subject {
    overflow: hidden;

    font-size: 14px;
    font-weight: 750;

    text-overflow: ellipsis;
    white-space: nowrap;
}

.draft-date {
    color: var(--muted);

    font-size: 12px;
    white-space: nowrap;
}

@media (max-width: 700px) {

    .draft-row {
        grid-template-columns:
            1fr
            auto;

        gap: 5px 12px;
    }

    .draft-subject {
        grid-column:
            1 / -1;
    }
}


/* ========================================
   COMPOSE ATTACHMENTS
   ======================================== */

.compose-attachment-tools {
    display: flex;
    align-items: center;

    margin-top: -2px;
    margin-bottom: 10px;
}

.attach-button {
    display: inline-flex;
    align-items: center;

    min-height: 34px;

    padding: 0 12px;

    color: var(--text);
    background: var(--surface-soft);

    border:
        1px solid
        var(--border);

    border-radius: 9px;

    font-size: 13px;
    font-weight: 750;

    cursor: pointer;
}

.attach-button:hover {
    border-color: #9ea5ab;
}

.compose-attachment-list {
    display: flex;
    flex-wrap: wrap;

    gap: 8px;

    margin-bottom: 10px;
}

.attachment-chip {
    display: inline-flex;
    align-items: center;

    gap: 8px;

    max-width: 100%;

    padding: 7px 9px;

    background: var(--surface-soft);

    border:
        1px solid
        var(--border);

    border-radius: 9px;

    font-size: 12px;
}

.attachment-chip-name {
    overflow: hidden;

    max-width: 300px;

    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-chip-size {
    color: var(--muted);
}

.attachment-remove {
    padding: 0;

    color: var(--muted);
    background: transparent;

    border: 0;

    font-size: 16px;
    line-height: 1;
}

.attachment-remove:hover {
    color: var(--red);
}

.message-attachments {
    display: flex;
    flex-wrap: wrap;

    gap: 8px;

    margin-top: 24px;
    padding-top: 18px;

    border-top:
        1px solid
        var(--border);
}

.message-attachment-link {
    display: inline-flex;
    align-items: center;

    gap: 7px;

    padding: 8px 10px;

    color: var(--text);
    background: var(--surface-soft);

    border:
        1px solid
        var(--border);

    border-radius: 9px;

    font-size: 13px;
    font-weight: 700;
}
