:root {
    --ink: #152437;
    --muted: #6c7786;
    --line: #e7e9ee;
    --panel: #ffffff;
    --canvas: #f4f5f7;
    --nav: #152437;
    --nav-soft: #21354c;
    --accent: #f5b63f;
    --accent-strong: #e09a13;
    --blue: #426ee8;
    --green: #2d9c6b;
    --red: #cc4b55;
    --shadow: 0 18px 48px rgba(21, 36, 55, .12);
    --radius: 18px;
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--canvas);
    font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.boot-screen, .auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
}
.boot-screen { align-content: center; gap: 12px; color: var(--muted); }
.brand-mark {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 15px;
    color: var(--nav);
    background: var(--accent);
    font-weight: 850;
    font-size: 25px;
}

.auth-page {
    grid-template-columns: minmax(320px, 1fr) minmax(380px, 560px);
    background: var(--nav);
}
.auth-story {
    align-self: stretch;
    padding: clamp(40px, 8vw, 110px);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    color: white;
    position: relative;
    overflow: hidden;
}
.auth-story::before, .auth-story::after {
    content: "";
    position: absolute;
    border-radius: 999px;
    filter: blur(2px);
}
.auth-story::before { width: 430px; height: 430px; background: #244e6b; right: -170px; top: -160px; }
.auth-story::after { width: 260px; height: 260px; border: 46px solid rgba(245,182,63,.15); left: -110px; bottom: -100px; }
.auth-logo { display: flex; align-items: center; gap: 14px; font-size: 21px; font-weight: 800; z-index: 1; }
.auth-copy { max-width: 680px; z-index: 1; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: 12px; font-weight: 800; color: var(--accent-strong); }
.auth-copy .eyebrow { color: var(--accent); }
.auth-copy h1 { font-size: clamp(38px, 5vw, 68px); line-height: 1.02; margin: 16px 0 22px; letter-spacing: -.04em; }
.auth-copy p { max-width: 580px; margin: 0; color: #bdc8d5; line-height: 1.65; font-size: 17px; }
.auth-note { color: #8fa0b4; z-index: 1; font-size: 13px; }
.auth-panel { min-height: 100vh; background: white; display: grid; align-content: center; padding: clamp(32px, 7vw, 86px); }
.auth-form { width: min(100%, 400px); margin: auto; }
.auth-form h2 { font-size: 31px; margin: 10px 0 8px; letter-spacing: -.025em; }
.auth-form > p { margin: 0 0 30px; color: var(--muted); line-height: 1.5; }

.field { display: grid; gap: 8px; margin-bottom: 18px; }
.field label { font-weight: 700; font-size: 13px; }
.field input, .field select {
    width: 100%;
    height: 46px;
    padding: 0 13px;
    border: 1px solid #d9dde4;
    border-radius: 11px;
    background: white;
    color: var(--ink);
    outline: none;
    transition: border .15s, box-shadow .15s;
}
.field textarea {
    width: 100%;
    padding: 13px;
    border: 1px solid #d9dde4;
    border-radius: 11px;
    background: white;
    color: var(--ink);
    outline: none;
    resize: vertical;
    line-height: 1.5;
}
.field textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(66,110,232,.13); }
.field input:focus, .field select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(66,110,232,.13); }
.field-help { color: var(--muted); font-size: 12px; margin-top: -2px; }
.password-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.password-row .btn { min-width: 94px; }

.btn {
    min-height: 42px;
    border: 0;
    border-radius: 11px;
    padding: 0 17px;
    font-weight: 750;
    color: var(--ink);
    background: #edf0f3;
    transition: transform .12s, background .12s, opacity .12s;
}
.btn:hover { transform: translateY(-1px); background: #e4e8ed; }
.btn:disabled { cursor: wait; opacity: .55; transform: none; }
.btn-primary { background: var(--accent); }
.btn-primary:hover { background: #ffc653; }
.btn-dark { background: var(--nav); color: white; }
.btn-dark:hover { background: var(--nav-soft); }
.btn-block { width: 100%; }
.btn-icon { width: 38px; height: 38px; min-height: 38px; padding: 0; display: grid; place-items: center; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 26px 18px;
    background: var(--nav);
    color: white;
    display: flex;
    flex-direction: column;
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 0 9px 28px; font-size: 19px; font-weight: 850; }
.sidebar-brand small { display: block; color: #8598ab; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; margin-top: 3px; }
.sidebar-nav { display: grid; gap: 5px; }
.nav-btn {
    border: 0;
    background: transparent;
    color: #acb8c7;
    border-radius: 12px;
    padding: 12px 13px;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    font-weight: 680;
}
.nav-btn:hover { color: white; background: rgba(255,255,255,.055); }
.nav-btn.active { color: white; background: var(--nav-soft); }
.nav-icon { width: 18px; height: 18px; display: inline-grid; place-items: center; font-size: 16px; }
.sidebar-foot { margin-top: auto; border-top: 1px solid rgba(255,255,255,.08); padding-top: 18px; }
.account-mini { display: flex; align-items: center; gap: 10px; padding: 8px; min-width: 0; }
.avatar { width: 38px; height: 38px; border-radius: 12px; background: #2c465f; color: var(--accent); display: grid; place-items: center; font-weight: 850; flex: none; }
.account-mini strong, .account-mini span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-mini strong { font-size: 13px; }
.account-mini span { color: #899aac; font-size: 11px; margin-top: 3px; }
.logout-link { width: 100%; color: #aeb9c7; background: transparent; border: 0; text-align: left; padding: 10px 8px 0; font-size: 12px; }

.main { min-width: 0; padding: 32px clamp(24px, 4vw, 58px) 70px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 30px; }
.topbar h1 { margin: 4px 0 5px; font-size: 31px; letter-spacing: -.03em; }
.topbar p { margin: 0; color: var(--muted); }
.topbar-actions { display: flex; gap: 10px; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.metric, .panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.metric { padding: 20px; }
.metric-label { color: var(--muted); font-size: 12px; font-weight: 700; }
.metric-value { font-size: 32px; font-weight: 850; margin-top: 10px; letter-spacing: -.035em; }
.metric-note { font-size: 11px; color: var(--green); margin-top: 6px; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(280px, .7fr); gap: 18px; }
.panel { padding: 21px; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.panel-head h2 { font-size: 17px; margin: 0; }
.panel-head p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.status-list { display: grid; gap: 12px; }
.status-row { display: grid; grid-template-columns: 11px 1fr auto; gap: 11px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.status-row:last-child { border: 0; }
.status-dot { width: 9px; height: 9px; border-radius: 99px; background: var(--green); box-shadow: 0 0 0 4px rgba(45,156,107,.1); }
.status-row strong { font-size: 13px; display: block; }
.status-row span { font-size: 11px; color: var(--muted); }
.quick-actions { display: grid; gap: 9px; }
.quick-action { border: 1px solid var(--line); border-radius: 13px; padding: 14px; background: white; text-align: left; }
.quick-action:hover { border-color: #c9d3e4; box-shadow: 0 7px 22px rgba(21,36,55,.07); }
.quick-action strong { display: block; font-size: 13px; }
.quick-action span { color: var(--muted); font-size: 11px; display: block; margin-top: 4px; }

.table-panel { background: white; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 700px; }
th, td { padding: 15px 18px; text-align: left; border-bottom: 1px solid var(--line); font-size: 13px; }
th { color: var(--muted); background: #fafafb; font-size: 11px; text-transform: uppercase; letter-spacing: .045em; }
tbody tr:last-child td { border-bottom: 0; }
.identity-cell { display: flex; align-items: center; gap: 11px; }
.identity-cell .avatar { background: #edf1f6; color: #47627e; }
.identity-cell strong, .identity-cell span { display: block; }
.identity-cell span { color: var(--muted); font-size: 11px; margin-top: 3px; }
.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 0 9px; border-radius: 999px; font-size: 10px; font-weight: 800; letter-spacing: .035em; }
.badge-green { color: #187950; background: #e6f6ee; }
.badge-yellow { color: #986c12; background: #fff4d8; }
.badge-blue { color: #315cc1; background: #eaf0ff; }
.badge-gray { color: #5e6875; background: #eef0f3; }
.badge-red { color: #a83742; background: #fdebed; }
.empty-state { padding: 70px 25px; text-align: center; color: var(--muted); }
.empty-icon { width: 56px; height: 56px; border-radius: 18px; background: #f0f2f5; display: grid; place-items: center; margin: 0 auto 13px; font-size: 23px; }
.empty-state h3 { color: var(--ink); margin: 0 0 7px; }
.empty-state p { margin: 0 auto 20px; max-width: 430px; line-height: 1.55; }

dialog { width: min(540px, calc(100% - 32px)); border: 0; border-radius: 20px; padding: 0; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(10,20,31,.55); backdrop-filter: blur(3px); }
.dialog-head { padding: 22px 24px 16px; display: flex; align-items: flex-start; justify-content: space-between; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0 0 5px; font-size: 21px; }
.dialog-head p { margin: 0; color: var(--muted); font-size: 12px; }
.dialog-body { padding: 22px 24px; }
.dialog-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; padding: 15px 24px 22px; }

.mail-shell { grid-template-columns: 272px minmax(0, 1fr); background: #f7f8fa; }
.mail-sidebar { padding-bottom: 18px; }
.mail-admin-back { margin-top: 10px; width: 100%; }
.sidebar-caption { padding: 20px 9px 8px; color: #718397; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .09em; }
.sidebar-empty { color: #8fa0b4; font-size: 12px; padding: 0 9px; }
.mailbox-switcher { max-height: 214px; overflow-y: auto; }
.mailbox-switch { width: 100%; border: 0; border-radius: 11px; background: transparent; color: #b8c3cf; padding: 9px; text-align: left; }
.mailbox-switch:hover, .mailbox-switch.active { background: var(--nav-soft); color: white; }
.mailbox-switch span, .mailbox-switch small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mailbox-switch span { font-size: 12px; font-weight: 750; }
.mailbox-switch small { color: #8294a7; font-size: 10px; margin-top: 3px; }
.sidebar-folders { display: grid; gap: 3px; margin-top: 16px; }
.folder { width: 100%; display: flex; justify-content: space-between; border: 0; color: #aeb9c7; background: transparent; padding: 10px 11px; border-radius: 10px; font-size: 13px; text-align: left; }
.folder:hover { color: white; background: rgba(255,255,255,.05); }
.folder.active { background: var(--nav-soft); color: white; font-weight: 750; }
.mail-main { min-width: 0; padding: 24px; height: 100vh; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.mail-toolbar { min-height: 70px; display: flex; align-items: flex-start; justify-content: space-between; padding: 2px 4px 17px; }
.mail-toolbar h1 { margin: 4px 0 0; font-size: 27px; letter-spacing: -.025em; }
.mail-layout { display: grid; grid-template-columns: minmax(300px, 390px) minmax(0, 1fr); min-height: 0; background: white; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.message-list { border-right: 1px solid var(--line); overflow-y: auto; min-height: 0; }
.message-row { width: 100%; min-height: 92px; padding: 16px 52px 16px 18px; display: grid; gap: 6px; position: relative; border: 0; border-bottom: 1px solid var(--line); background: white; color: var(--ink); text-align: left; }
.message-row:hover { background: #fafbfd; }
.message-row.active { background: #eef3ff; box-shadow: inset 3px 0 var(--blue); }
.message-row.unread { background: #f5f8ff; }
.message-row.unread strong, .message-row.unread .message-from { font-weight: 850; }
.message-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 650; }
.message-from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--muted); }
.message-date { position: absolute; right: 14px; top: 17px; font-size: 10px; color: var(--muted); }
.paperclip { position: absolute; right: 16px; bottom: 17px; color: var(--muted); }
.message-reader { overflow-y: auto; min-width: 0; }
.message-placeholder { min-height: 100%; display: grid; place-items: center; text-align: center; padding: 40px; color: var(--muted); }
.reader-head { padding: 27px 30px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.reader-head h2 { margin: 0 0 15px; font-size: 23px; overflow-wrap: anywhere; }
.reader-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 15px; font-size: 12px; }
.reader-meta span, .reader-to { color: var(--muted); }
.reader-to { margin-top: 6px; font-size: 11px; }
.reader-actions { display: flex; gap: 8px; flex: none; }
.danger { color: var(--red); }
.reader-body { padding: 30px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; line-height: 1.75; overflow-wrap: anywhere; }
.attachment-list { margin: 0 30px 30px; padding-top: 18px; border-top: 1px solid var(--line); }
.attachment-list h3 { font-size: 13px; margin: 0 0 12px; }
.attachment { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; border: 1px solid var(--line); border-radius: 12px; padding: 10px 13px; margin: 0 7px 7px 0; }
.attachment:hover { background: #f7f8fa; }
.attachment > span { color: var(--blue); font-size: 19px; }
.attachment strong, .attachment small { display: block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment strong { font-size: 12px; }
.attachment small { color: var(--muted); font-size: 10px; margin-top: 2px; }
.mail-loading { min-height: 260px; display: flex; justify-content: center; align-items: center; gap: 6px; color: var(--muted); }
.mail-loading span { width: 7px; height: 7px; border-radius: 99px; background: var(--blue); animation: pulse 1s infinite alternate; }
.mail-loading span:nth-child(2) { animation-delay: .15s; }
.mail-loading span:nth-child(3) { animation-delay: .3s; }
.mail-loading p { margin-left: 6px; font-size: 12px; }
@keyframes pulse { to { opacity: .25; transform: translateY(-3px); } }
.compose-dialog { width: min(680px, calc(100% - 32px)); }
.compose-body details { margin: -5px 0 16px; }
.compose-body summary { color: var(--blue); font-size: 12px; cursor: pointer; }
.compose-copies { margin-top: 15px; }

.toast-region { position: fixed; right: 22px; bottom: 22px; z-index: 1000; display: grid; gap: 8px; }
.toast { background: var(--nav); color: white; padding: 13px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: 13px; animation: toast-in .2s ease-out; max-width: 360px; }
.toast.error { background: #9f3540; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 980px) {
    .metrics { grid-template-columns: 1fr 1fr; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .auth-page { grid-template-columns: 1fr; }
    .auth-story { display: none; }
    .mail-layout { grid-template-columns: minmax(280px, 42%) minmax(0, 1fr); }
}
@media (max-width: 720px) {
    .app-shell { grid-template-columns: 72px minmax(0, 1fr); }
    .sidebar { padding: 20px 10px; }
    .sidebar-brand > div:last-child, .nav-label, .account-mini > div:last-child, .logout-link { display: none; }
    .sidebar-brand { justify-content: center; padding-inline: 0; }
    .nav-btn { justify-content: center; padding: 12px; }
    .account-mini { justify-content: center; padding: 0; }
    .main { padding: 24px 16px 50px; }
    .topbar { display: block; }
    .topbar-actions { margin-top: 17px; }
    .metrics { grid-template-columns: 1fr 1fr; }
    .dialog-grid { grid-template-columns: 1fr; }
    .mail-shell { grid-template-columns: 72px minmax(0, 1fr); }
    .mail-main { padding: 15px; }
    .mailbox-switcher, .sidebar-folders .folder span:first-child, .sidebar-caption { display: none; }
    .sidebar-folders .folder { justify-content: center; }
    .mail-layout { grid-template-columns: 1fr; }
    .message-reader { display: none; }
    .message-list:has(.message-row.active) { display: none; }
    .message-list:has(.message-row.active) + .message-reader { display: block; }
    .reader-head { padding: 20px; display: block; }
    .reader-actions { margin-top: 16px; }
    .reader-body { padding: 20px; }
}
@media (max-width: 440px) {
    .metrics { grid-template-columns: 1fr; }
    .topbar-actions { display: grid; }
}
