:root {
    --font-ui: "Trebuchet MS", "Segoe UI", sans-serif;
    --font-reading: Georgia, "Times New Roman", serif;
    --bg: #f5f8fb;
    --bg-alt: #e8eef3;
    --surface: rgba(255, 255, 255, 0.88);
    --surface-strong: #ffffff;
    --surface-soft: rgba(255, 255, 255, 0.62);
    --text: #102a43;
    --text-soft: #627d98;
    --border: rgba(15, 53, 87, 0.12);
    --shadow: 0 24px 60px rgba(16, 42, 67, 0.12);
    --primary: #0f6c5a;
    --primary-strong: #0a4f42;
    --danger: #a61b1b;
    --danger-bg: rgba(166, 27, 27, 0.08);
    --banner: #fff7d6;
    --banner-text: #5f4b00;
}

body[data-theme="dark"] {
    --bg: #0d1722;
    --bg-alt: #142131;
    --surface: rgba(17, 30, 44, 0.9);
    --surface-strong: #132333;
    --surface-soft: rgba(19, 35, 51, 0.74);
    --text: #edf4fb;
    --text-soft: #b1c2d4;
    --border: rgba(215, 227, 238, 0.1);
    --shadow: 0 28px 70px rgba(0, 0, 0, 0.35);
    --primary: #6ed7bb;
    --primary-strong: #2ab394;
    --danger: #ff7b7b;
    --danger-bg: rgba(255, 123, 123, 0.12);
    --banner: rgba(255, 228, 120, 0.14);
    --banner-text: #ffe28f;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: var(--font-ui);
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(15, 108, 90, 0.18), transparent 26%),
        radial-gradient(circle at bottom right, rgba(16, 42, 67, 0.16), transparent 24%),
        linear-gradient(145deg, var(--bg), var(--bg-alt));
}

.app-bg {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(120deg, rgba(255, 255, 255, 0.12), transparent 32%),
        radial-gradient(circle at 70% 20%, rgba(15, 108, 90, 0.12), transparent 18%);
}

.hidden {
    display: none !important;
}

.screen {
    position: relative;
    z-index: 1;
    padding: 24px;
}

.screen-login {
    min-height: 100vh;
    display: grid;
    place-items: center;
}

.login-panel {
    width: min(920px, 100%);
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 24px;
    align-items: stretch;
}

.brand-lockup {
    padding: 42px;
    border-radius: 28px;
    background: linear-gradient(160deg, rgba(10, 27, 44, 0.92), rgba(15, 108, 90, 0.88));
    color: #f5fffb;
    box-shadow: var(--shadow);
}

.brand-lockup h1 {
    margin: 18px 0 12px;
    font-size: clamp(2rem, 5vw, 3.8rem);
    line-height: 0.95;
}

.brand-lockup p {
    margin: 0;
    font-size: 1.05rem;
    line-height: 1.7;
    max-width: 34rem;
    color: rgba(255, 255, 255, 0.82);
}

.brand-pill {
    display: inline-flex;
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
    letter-spacing: 0.16em;
    text-transform: uppercase;
    font-size: 0.76rem;
}

.card,
.modal-card,
.panel {
    border: 1px solid var(--border);
    background: var(--surface);
    backdrop-filter: blur(18px);
    box-shadow: var(--shadow);
}

.card,
.modal-card {
    border-radius: 24px;
    padding: 24px;
}

.card-soft {
    background: var(--surface-soft);
}

.form-stack {
    display: grid;
    gap: 16px;
}

label {
    display: grid;
    gap: 8px;
    font-size: 0.95rem;
}

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

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px 16px;
    background: var(--surface-strong);
    color: var(--text);
}

textarea {
    resize: vertical;
    min-height: 120px;
}

.btn {
    border: 0;
    border-radius: 16px;
    padding: 12px 16px;
    cursor: pointer;
    transition: transform 0.18s ease, opacity 0.18s ease, background 0.18s ease;
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-strong));
    color: #ffffff;
}

.btn-lg {
    padding: 14px 18px;
}

.btn-ghost {
    background: rgba(127, 145, 167, 0.1);
    color: var(--text);
}

.btn-danger {
    background: var(--danger-bg);
    color: var(--danger);
}

.icon-btn {
    font-size: 1.2rem;
}

.security-note,
.banner {
    padding: 14px 16px;
    border-radius: 16px;
    background: var(--banner);
    color: var(--banner-text);
    line-height: 1.5;
}

.turnstile-row {
    display: grid;
    gap: 8px;
}

.screen-app {
    display: grid;
    gap: 18px;
}

.topbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 16px;
    align-items: center;
    padding: 18px 20px;
    border-radius: 24px;
}

.topbar-left,
.topbar-actions,
.inline-actions,
.message-row-top {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
}

.topbar-center {
    width: 100%;
}

.brand-mini {
    font-weight: 700;
    letter-spacing: 0.03em;
}

.subtle {
    color: var(--text-soft);
}

.search-input {
    min-width: 240px;
}

.workspace {
    display: grid;
    grid-template-columns: 280px 360px 1fr;
    gap: 18px;
    min-height: calc(100vh - 140px);
}

.panel {
    border-radius: 24px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.panel-header h2 {
    margin: 0;
    font-size: 1.05rem;
}

.folders-list,
.messages-list,
.contacts-list {
    display: grid;
    gap: 10px;
    overflow: auto;
}

.folder-item,
.message-row {
    width: 100%;
    border: 1px solid transparent;
    background: var(--surface-soft);
    color: var(--text);
    border-radius: 18px;
    padding: 14px 16px;
    text-align: left;
    cursor: pointer;
}

.folder-item small {
    display: block;
    margin-top: 4px;
    color: var(--text-soft);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.folder-item.is-active,
.message-row.is-active {
    border-color: rgba(15, 108, 90, 0.35);
    background: rgba(15, 108, 90, 0.12);
}

.message-row.is-unread strong,
.message-row.is-unread .message-row-subject {
    font-weight: 700;
}

.message-row-subject {
    margin: 8px 0 6px;
}

.message-row-preview {
    color: var(--text-soft);
    font-size: 0.92rem;
}

.detail-panel {
    overflow: hidden;
}

.message-empty {
    margin: auto;
    max-width: 30rem;
    text-align: center;
}

.message-empty h2 {
    margin-bottom: 12px;
}

.message-view {
    display: grid;
    gap: 16px;
    min-height: 0;
}

.message-header {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: flex-start;
}

.message-header h2 {
    margin: 0 0 6px;
    font-size: 1.35rem;
}

.move-bar {
    display: flex;
    gap: 10px;
}

.attachments h3 {
    margin: 0 0 10px;
}

.attachment-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.attachment-chip {
    display: inline-flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 14px;
    border-radius: 16px;
    text-decoration: none;
    background: rgba(15, 108, 90, 0.1);
    color: var(--text);
    min-width: 160px;
}

.attachment-chip small {
    color: var(--text-soft);
}

.iframe-wrap {
    flex: 1;
    min-height: 340px;
    border: 1px solid var(--border);
    border-radius: 20px;
    overflow: hidden;
    background: #ffffff;
}

#message-frame {
    width: 100%;
    min-height: 480px;
    border: 0;
    background: #ffffff;
}

.raw-text {
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.raw-text pre {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-family: var(--font-reading);
}

.modal {
    border: 0;
    padding: 0;
    background: transparent;
    width: min(960px, calc(100vw - 32px));
}

.modal::backdrop {
    background: rgba(8, 15, 24, 0.52);
    backdrop-filter: blur(5px);
}

.modal-card {
    max-height: min(90vh, 960px);
    overflow: auto;
}

.modal-actions {
    justify-content: flex-end;
}

.contacts-layout {
    display: grid;
    gap: 18px;
}

.contacts-grid {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 18px;
}

.contact-card {
    display: grid;
    gap: 10px;
    padding: 16px;
    border-radius: 18px;
    background: var(--surface-soft);
}

.toast-region {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 20;
    display: grid;
    gap: 10px;
}

.toast {
    min-width: 260px;
    max-width: 420px;
    padding: 14px 16px;
    border-radius: 16px;
    color: #ffffff;
    box-shadow: var(--shadow);
}

.toast-success {
    background: linear-gradient(135deg, #0f6c5a, #0c5749);
}

.toast-error {
    background: linear-gradient(135deg, #a61b1b, #7f1717);
}

body[data-density="compact"] .folder-item,
body[data-density="compact"] .message-row,
body[data-density="compact"] .contact-card {
    padding: 10px 12px;
}

@media (max-width: 1180px) {
    .workspace {
        grid-template-columns: 250px 320px 1fr;
    }
}

@media (max-width: 980px) {
    .login-panel,
    .contacts-grid,
    .workspace,
    .topbar {
        grid-template-columns: 1fr;
    }

    .topbar {
        align-items: stretch;
    }

    .topbar-actions {
        justify-content: flex-start;
    }

    .workspace {
        min-height: auto;
    }

    .folders-panel {
        display: none;
    }

    .folders-panel.is-open {
        display: flex;
    }

    .message-header,
    .move-bar {
        flex-direction: column;
        align-items: stretch;
    }
}

@media (max-width: 680px) {
    .screen {
        padding: 14px;
    }

    .card,
    .modal-card,
    .panel {
        border-radius: 20px;
    }

    .brand-lockup,
    .card,
    .modal-card {
        padding: 20px;
    }

    .inline-actions,
    .topbar-actions {
        flex-wrap: wrap;
    }
}
