:root {
    --bg: #edf1f8;
    --panel: #ffffff;
    --panel-soft: #f7f9fd;
    --ink: #111827;
    --ink-soft: #374151;
    --muted: #6b7280;
    --line: #e4e8f0;
    --dark: #0b1220;
    --dark-2: #111b2e;
    --dark-3: #17243c;
    --accent: #4f6bff;
    --accent-2: #8b5cf6;
    --accent-soft: #eef1ff;
    --accent-grad: linear-gradient(120deg, #4f6bff 0%, #6f5cff 48%, #8b5cf6 100%);
    --danger: #ef4444;
    --success: #0f9f6e;
    --radius: 14px;
    --shadow: 0 18px 50px rgba(15, 23, 42, 0.12);
    --shadow-soft: 0 6px 22px rgba(15, 23, 42, 0.07);
    --sidebar-w: 224px;
    --list-w: 380px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cbd3e1; border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }

/* ─── Brand ─── */
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
    width: 38px; height: 38px; border-radius: 11px;
    display: grid; place-items: center;
    background: var(--accent-grad);
    color: #fff; font-weight: 800; font-size: 20px;
    box-shadow: 0 8px 22px rgba(79, 107, 255, 0.35);
    flex: 0 0 auto;
}
.brand-name { font-weight: 800; letter-spacing: 0.14em; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }
.brand--top .brand-name { color: #fff; }
.brand--top .brand-sub { color: #93a4c4; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand--login { margin-bottom: 26px; }
.brand--login .brand-name { font-size: 18px; }
.brand--login .brand-sub { font-size: 12px; }

/* ─── Login ─── */
.login-view {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px;
    position: relative;
    overflow: hidden;
    background: radial-gradient(circle at 20% 10%, #1c2b4d 0%, #0b1220 45%, #070b14 100%);
}
.login-orb {
    position: absolute; border-radius: 50%; filter: blur(20px); opacity: 0.55; pointer-events: none;
}
.login-orb--one {
    width: 520px; height: 520px; left: -140px; top: -160px;
    background: radial-gradient(circle, rgba(79, 107, 255, 0.55), transparent 68%);
}
.login-orb--two {
    width: 620px; height: 620px; right: -200px; bottom: -260px;
    background: radial-gradient(circle, rgba(139, 92, 246, 0.42), transparent 68%);
}
.login-card {
    position: relative; z-index: 1;
    width: min(430px, 100%);
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 22px;
    padding: 34px 34px 24px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(14px);
}
.login-card h1 { margin: 0 0 8px; font-size: 26px; letter-spacing: -0.02em; }
.login-intro { margin: 0 0 24px; line-height: 1.5; }
.login-card form { display: flex; flex-direction: column; gap: 15px; }
.login-foot {
    margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line);
    display: flex; flex-direction: column; gap: 3px;
    color: var(--muted); font-size: 11.5px;
}
.login-foot span:first-child { text-transform: uppercase; letter-spacing: 0.12em; font-size: 10px; color: #9aa4b8; }

/* ─── Fields / buttons ─── */
.field { display: flex; flex-direction: column; gap: 7px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.field > span em { font-style: normal; font-weight: 400; color: #9aa4b8; }
.field input, .field select, .compose-text, #signature-text {
    width: 100%; border: 1px solid #d8dfeb; background: #fff; color: var(--ink);
    border-radius: 10px; padding: 11px 12px; outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .compose-text:focus, #signature-text:focus {
    border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 107, 255, 0.13);
}
.btn {
    border: 0; border-radius: 10px; padding: 10px 16px;
    font-weight: 600; font-size: 13.5px; display: inline-flex; align-items: center;
    justify-content: center; gap: 8px; transition: transform 0.12s, box-shadow 0.15s, background 0.15s, opacity 0.15s;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn-primary {
    background: var(--accent-grad); color: #fff;
    box-shadow: 0 8px 20px rgba(79, 107, 255, 0.28);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 11px 26px rgba(79, 107, 255, 0.38); }
.btn-ghost { background: #f1f4fa; color: var(--ink-soft); }
.btn-ghost:hover:not(:disabled) { background: #e8edf7; }
.btn-link { background: none; color: var(--accent); padding: 4px 2px; font-size: 12.5px; }
.btn-link:hover { text-decoration: underline; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 11px; font-size: 12.5px; }
.icon-btn {
    width: 36px; height: 36px; border: 0; border-radius: 10px;
    background: transparent; color: inherit; display: grid; place-items: center;
    transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: rgba(148, 163, 184, 0.16); }
.icon-btn svg, .btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.form-error {
    background: #fff1f1; border: 1px solid #ffd4d4; color: #b42318;
    border-radius: 9px; padding: 9px 11px; font-size: 12.5px; margin-top: 12px;
}

/* ─── App shell ─── */
.app-view { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
    height: 64px; flex: 0 0 64px;
    background: var(--dark);
    color: #e8eefb;
    display: flex; align-items: center; gap: 24px;
    padding: 0 20px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.14);
    position: relative; z-index: 20;
}
.brand--top { min-width: 180px; }
.topbar-center { flex: 1; display: flex; justify-content: center; }
.mailbox-picker {
    display: flex; align-items: center; gap: 9px;
    background: rgba(148, 163, 184, 0.09);
    border: 1px solid rgba(148, 163, 184, 0.18);
    padding: 5px 8px 5px 12px; border-radius: 10px;
}
.mailbox-picker > span { font-size: 10px; text-transform: uppercase; letter-spacing: 0.13em; color: #8fa1c2; }
.mailbox-picker select {
    background: transparent; border: 0; outline: none;
    color: #f1f5ff; font-weight: 600; font-size: 13px; max-width: 290px;
}
.mailbox-picker select option { color: #111827; background: #fff; }
.topbar-actions { display: flex; align-items: center; gap: 4px; min-width: 180px; justify-content: flex-end; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 3px 6px 3px 3px; margin: 0 4px; }
.avatar {
    width: 30px; height: 30px; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--accent-grad); color: #fff; font-weight: 700; font-size: 13px;
}
.user-name { font-size: 12.5px; color: #cbd5e1; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.layout {
    flex: 1; min-height: 0;
    display: grid;
    grid-template-columns: var(--sidebar-w) var(--list-w) minmax(0, 1fr);
}

/* ─── Sidebar ─── */
.sidebar {
    background: var(--dark-2);
    color: #cbd5e1;
    display: flex; flex-direction: column;
    min-height: 0;
    border-right: 1px solid rgba(148, 163, 184, 0.1);
    padding: 16px 12px 12px;
}
.compose-wrap { padding: 0 4px 16px; }
.compose-wrap .btn { padding: 11px 14px; border-radius: 11px; }
.folders { display: flex; flex-direction: column; gap: 3px; }
.folder-btn {
    border: 0; background: transparent; color: #b8c5dc;
    display: flex; align-items: center; gap: 10px;
    width: 100%; padding: 9px 10px; border-radius: 9px;
    font-size: 13px; text-align: left; transition: background 0.15s, color 0.15s;
}
.folder-btn:hover { background: rgba(148, 163, 184, 0.1); color: #fff; }
.folder-btn.active { background: rgba(79, 107, 255, 0.2); color: #fff; }
.folder-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; opacity: 0.9; }
.folder-name { flex: 1; }
.folder-count {
    min-width: 20px; padding: 2px 6px; border-radius: 20px;
    background: var(--accent); color: #fff; font-size: 10.5px; font-weight: 700; text-align: center;
}
.sidebar-mailboxes { margin-top: auto; padding: 18px 4px 8px; border-top: 1px solid rgba(148, 163, 184, 0.12); }
.sidebar-mailboxes-title { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.14em; color: #7d8fae; margin: 0 6px 7px; }
.mailbox-link {
    display: flex; align-items: center; gap: 8px; width: 100%;
    border: 0; background: transparent; color: #aebbd2;
    padding: 7px 6px; border-radius: 8px; font-size: 11.5px; text-align: left;
}
.mailbox-link:hover { background: rgba(148, 163, 184, 0.08); color: #fff; }
.mailbox-link.active { color: #fff; }
.mailbox-dot { width: 6px; height: 6px; border-radius: 50%; background: #5d7294; flex: 0 0 6px; }
.mailbox-link.active .mailbox-dot { background: #7c8cff; box-shadow: 0 0 9px rgba(124, 140, 255, 0.8); }
.mailbox-link .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mailbox-link .count { font-size: 10px; color: #8fa1c2; }
.sidebar-note { color: #60718f; font-size: 10px; padding: 8px 6px 2px; line-height: 1.5; }
.sidebar-note span { color: #7d8fae; }

/* ─── Message list ─── */
.list-pane {
    background: var(--panel);
    border-right: 1px solid var(--line);
    display: flex; flex-direction: column; min-height: 0;
}
.list-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 19px 20px 14px; border-bottom: 1px solid var(--line);
}
.list-head h2 { margin: 0 0 3px; font-size: 19px; letter-spacing: -0.02em; }
.list { flex: 1; overflow-y: auto; }
.mail-row {
    width: 100%; border: 0; border-bottom: 1px solid #edf0f6;
    background: transparent; text-align: left;
    padding: 13px 18px 13px 16px; display: flex; gap: 11px;
    transition: background 0.12s;
    position: relative;
}
.mail-row:hover { background: #f7f9fd; }
.mail-row.active { background: var(--accent-soft); }
.mail-row.unread { background: #fbfcff; }
.mail-row.unread:hover { background: #f4f7ff; }
.mail-row.active::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
    background: var(--accent-grad);
}
.mail-dot { width: 7px; height: 7px; border-radius: 50%; background: transparent; flex: 0 0 7px; margin-top: 7px; }
.mail-row.unread .mail-dot { background: var(--accent); box-shadow: 0 0 7px rgba(79, 107, 255, 0.55); }
.mail-main { min-width: 0; flex: 1; }
.mail-line { display: flex; align-items: baseline; gap: 10px; }
.mail-from {
    flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 13px; color: var(--ink-soft);
}
.mail-row.unread .mail-from { color: var(--ink); font-weight: 700; }
.mail-date { font-size: 10.5px; color: #9aa4b8; white-space: nowrap; }
.mail-subject {
    margin-top: 3px; font-size: 13px; color: var(--ink-soft);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mail-row.unread .mail-subject { color: var(--ink); font-weight: 600; }
.mail-clip { color: #9aa4b8; display: flex; align-items: center; }
.mail-clip svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2; }
.list-empty { padding: 60px 24px; text-align: center; color: var(--muted); line-height: 1.6; }
.list-more { padding: 12px; text-align: center; border-top: 1px solid var(--line); }
.skeleton {
    height: 64px; margin: 8px 14px; border-radius: 10px;
    background: linear-gradient(90deg, #f1f4fa 25%, #e8edf7 37%, #f1f4fa 63%);
    background-size: 400% 100%; animation: shimmer 1.3s infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* ─── Reader ─── */
.reader-pane { background: var(--panel); min-height: 0; position: relative; display: flex; flex-direction: column; }
.empty-state {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; padding: 40px; color: var(--muted);
}
.empty-icon {
    width: 68px; height: 68px; border-radius: 20px; display: grid; place-items: center;
    background: var(--accent-soft); color: var(--accent); margin-bottom: 18px;
}
.empty-icon svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.empty-state h2 { color: var(--ink); margin: 0 0 6px; font-size: 19px; }
.empty-state p { margin: 0; }
.reader { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }
.reader-head { padding: 22px 26px 16px; border-bottom: 1px solid var(--line); background: #fff; position: sticky; top: 0; z-index: 2; }
.reader-title-row { display: flex; align-items: flex-start; gap: 16px; }
.reader-title-row h2 { flex: 1; margin: 0; font-size: 21px; line-height: 1.3; letter-spacing: -0.02em; word-break: break-word; }
.reader-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.msg-meta { margin-top: 13px; display: flex; flex-direction: column; gap: 4px; }
.meta-row { display: flex; gap: 9px; font-size: 12px; line-height: 1.55; }
.meta-label {
    flex: 0 0 42px; color: #9aa4b8; font-size: 10px; text-transform: uppercase;
    letter-spacing: 0.09em; padding-top: 2px;
}
.meta-value { color: var(--ink-soft); word-break: break-word; }
.attachments { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 13px; }
.attachment {
    display: inline-flex; align-items: center; gap: 7px;
    background: #f3f6fc; border: 1px solid #e3e9f4; border-radius: 8px;
    padding: 6px 9px; color: var(--ink-soft); text-decoration: none; font-size: 11.5px;
    max-width: 270px;
}
.attachment:hover { border-color: #c8d3e8; background: #edf2fb; }
.attachment svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; flex: 0 0 auto; }
.attachment .att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment .att-size { color: #9aa4b8; font-size: 10px; white-space: nowrap; }
.msg-body { flex: 1; padding: 18px 26px 40px; background: #fff; }
.msg-body iframe { width: 100%; border: 0; min-height: 320px; background: #fff; display: block; }
.plain-body {
    margin: 0; white-space: pre-wrap; word-break: break-word;
    font-family: inherit; font-size: 14px; line-height: 1.65; color: var(--ink-soft);
}
.reader-back { margin-right: 2px; font-size: 18px; }

/* ─── Modals ─── */
.modal {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(9, 16, 30, 0.56);
    backdrop-filter: blur(3px);
    display: flex; align-items: center; justify-content: center;
    padding: 22px;
}
.modal-card {
    width: min(780px, 100%); max-height: 92vh; overflow: hidden;
    background: #fff; border-radius: 18px; box-shadow: var(--shadow);
    display: flex; flex-direction: column; animation: modalIn 0.16s ease-out;
}
.setting-card, .signature-card { width: min(590px, 100%); }
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(0.99); } to { opacity: 1; transform: none; } }
.modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 22px 14px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 18px; letter-spacing: -0.02em; }
.compose-card form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.compose-meta {
    display: grid; grid-template-columns: 190px 1fr; gap: 10px 14px;
    padding: 14px 22px 0;
}
.compose-meta .field > span { font-size: 10.5px; }
.compose-text {
    margin: 14px 22px 0; min-height: 250px; resize: vertical;
    line-height: 1.6; font-size: 13.5px;
}
.signature-card .muted { margin: 14px 22px 0; line-height: 1.5; }
.signature-text { min-height: 170px; }
.compose-foot {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 13px 22px 16px; border-top: 1px solid var(--line); margin-top: 14px;
}
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-soft); }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }

/* ─── Toast ─── */
.toast {
    position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
    background: #101a2c; color: #f8fafc; border: 1px solid rgba(148, 163, 184, 0.25);
    padding: 11px 16px; border-radius: 11px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
    font-size: 13px; z-index: 200; max-width: min(520px, calc(100vw - 32px));
    animation: toastIn 0.18s ease-out;
}
.toast.error { background: #7f1d1d; border-color: #b91c1c; }
.toast.success { background: #064e3b; border-color: #0f9f6e; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.mobile-only { display: none; }

/* ─── Responsive ─── */
@media (max-width: 1240px) {
    :root { --sidebar-w: 208px; --list-w: 350px; }
    .brand--top { min-width: 150px; }
    .topbar-actions { min-width: 150px; }
}

@media (max-width: 1020px) {
    :root { --sidebar-w: 194px; --list-w: 320px; }
    .user-name { display: none; }
    .brand-text { display: none; }
    .brand--top { min-width: 44px; }
    .topbar-actions { min-width: 44px; }
    .topbar-center { justify-content: flex-start; }
}

@media (max-width: 900px) {
    .mobile-only { display: grid; }
    html, body { height: 100%; }
    .app-view { min-height: 100vh; }
    .topbar {
        height: auto; min-height: 60px; flex-wrap: wrap; gap: 10px;
        padding: 10px 13px; position: sticky; top: 0;
    }
    .brand--top { min-width: 42px; }
    .topbar-center { order: 3; flex: 1 0 100%; }
    .mailbox-picker { width: 100%; }
    .mailbox-picker select { flex: 1; max-width: none; }
    .topbar-actions { margin-left: auto; min-width: 0; gap: 0; }
    .layout { display: flex; flex-direction: column; min-height: 0; }
    .sidebar {
        display: block; padding: 10px 10px 8px; border-right: 0;
        border-bottom: 1px solid rgba(148, 163, 184, 0.12);
    }
    .compose-wrap { float: left; padding: 0 8px 0 0; width: auto; }
    .compose-wrap .btn { padding: 8px 12px; font-size: 12.5px; }
    .folders { flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 2px; }
    .folder-btn { width: auto; padding: 7px 10px; font-size: 12px; white-space: nowrap; }
    .folder-btn svg { display: none; }
    .folder-count { min-width: 17px; padding: 1px 5px; }
    .sidebar-mailboxes, .sidebar-note { display: none; }
    .list-pane { border-right: 0; min-height: 0; flex: 1; }
    .reader-pane { display: none; flex: 1; min-height: 0; }
    body.reading .list-pane { display: none; }
    body.reading .reader-pane { display: flex; }
    body.reading .sidebar { display: none; }
    .reader { flex: 1; }
    .reader-head { padding: 15px 16px 12px; }
    .reader-title-row h2 { font-size: 18px; }
    .reader-actions { gap: 4px; }
    .reader-actions .btn { padding: 6px 8px; font-size: 11.5px; }
    .msg-body { padding: 14px 16px 30px; }
    .modal { padding: 0; align-items: flex-end; }
    .modal-card { max-height: 96vh; border-radius: 16px 16px 0 0; }
    .compose-meta { grid-template-columns: 1fr; padding: 12px 16px 0; }
    .compose-text { margin: 12px 16px 0; min-height: 200px; }
    .compose-foot { padding: 11px 16px 14px; }
    .modal-head { padding: 15px 16px 12px; }
}

@media (max-width: 560px) {
    .brand-mark { width: 34px; height: 34px; border-radius: 9px; font-size: 17px; }
    .topbar { padding: 8px 10px; }
    .topbar-actions .icon-btn { width: 32px; height: 32px; }
    .user-chip { margin: 0; }
    .avatar { width: 28px; height: 28px; }
    .list-head { padding: 14px 15px 11px; }
    .list-head h2 { font-size: 17px; }
    .mail-row { padding: 11px 13px 11px 12px; }
    .mail-from { font-size: 12.5px; }
    .mail-subject { font-size: 12.5px; }
    .reader-actions { flex-direction: column; align-items: flex-end; }
    .reader-actions .btn { padding: 5px 8px; }
    .reader-title-row { gap: 8px; }
    .compose-foot { gap: 7px; }
    .compose-foot .btn { padding: 8px 11px; }
}
