:root {
    color-scheme: light;
    --bg: #f5f6f5;
    --panel: #ffffff;
    --ink: #18201c;
    --muted: #657068;
    --line: #dfe5de;
    --soft-line: #eef2ee;
    --green: #18734a;
    --green-dark: #0f5d3b;
    --red: #b42318;
    --amber: #a15c07;
    --blue: #2457a6;
    --shadow: 0 12px 32px rgba(24, 32, 28, 0.06);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-panel {
    width: min(440px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 28px;
}

.auth-panel h1 {
    margin-bottom: 10px;
}

.auth-intro {
    color: var(--muted);
}

.auth-form {
    display: grid;
    gap: 14px;
    margin-top: 18px;
}

.auth-form label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.auth-form input {
    border: 1px solid var(--line);
    border-radius: 8px;
    min-height: 44px;
    padding: 0 12px;
    font: inherit;
    color: var(--ink);
}

.auth-form button {
    width: 100%;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 20px clamp(18px, 4vw, 52px);
    border-bottom: 1px solid var(--line);
    background: var(--panel);
    position: sticky;
    top: 0;
    z-index: 2;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--green);
    font-size: 13px;
    font-weight: 700;
}

h1, h2, p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: clamp(30px, 4vw, 52px);
    line-height: 1;
}

.app-shell {
    width: min(1280px, calc(100% - 32px));
    margin: 22px auto 56px;
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.actions,
.filters,
.mail-side {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.sidebar,
.workspace {
    min-width: 0;
}

.sidebar {
    position: sticky;
    top: 118px;
    max-height: calc(100vh - 140px);
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    box-shadow: var(--shadow);
    scrollbar-width: thin;
    scrollbar-color: #cbd6cd transparent;
}

.sidebar::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: #cbd6cd;
    border-radius: 999px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-section {
    display: grid;
    gap: 8px;
}

.sidebar-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 4px 10px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

.sidebar-title strong,
.sidebar-link strong,
.account-link em {
    color: var(--muted);
    font-style: normal;
    font-size: 12px;
}

.sidebar-link strong.has-unseen {
    color: var(--green-dark);
    background: #dff0e5;
    border-radius: 999px;
    min-width: 24px;
    min-height: 22px;
    display: inline-grid;
    place-items: center;
}

.sidebar-link,
.account-link {
    display: grid;
    align-items: center;
    gap: 9px;
    color: var(--ink);
    text-decoration: none;
    border-radius: 8px;
    min-height: 38px;
    padding: 8px 10px;
}

.sidebar-link {
    grid-template-columns: 22px minmax(0, 1fr) auto;
    font-weight: 750;
}

.account-link {
    grid-template-columns: minmax(0, 1fr) auto;
    margin-top: 8px;
    border-top: 1px solid var(--soft-line);
    border-radius: 0;
    padding-top: 14px;
}

.account-link span {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.account-link strong,
.account-link small,
.sidebar-link span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-link small {
    color: var(--muted);
    font-size: 12px;
}

.sidebar-link:hover,
.account-link:hover,
.sidebar-link.active,
.account-link.active {
    background: #edf4ef;
}

.sidebar-link.active,
.account-link.active {
    color: var(--green-dark);
}

.folder-list {
    display: grid;
    gap: 2px;
    margin: 2px 0 6px;
}

.folder-link {
    margin-left: 8px;
    min-height: 34px;
    font-size: 14px;
}

.folder-icon {
    display: inline-grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: #eef1ed;
    color: var(--green);
    font-size: 13px;
}

.folder-create {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 34px;
    gap: 8px;
    margin: 8px 0 4px 30px;
}

.folder-create input,
.folder-create button {
    border: 1px solid var(--line);
    background: var(--panel);
    border-radius: 8px;
    min-height: 34px;
    font: inherit;
    font-weight: 700;
}

.folder-create input {
    min-width: 0;
    padding: 0 10px;
}

.folder-create button {
    cursor: pointer;
    color: white;
    background: var(--green);
    border-color: var(--green);
    font-size: 18px;
    line-height: 1;
}

.folder-create button:hover {
    background: var(--green-dark);
    border-color: var(--green-dark);
}

.workspace {
    display: grid;
    gap: 14px;
}

.notice {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 14px;
    background: var(--panel);
    font-weight: 800;
}

.notice.error {
    border-color: #ffd2cc;
    background: #fff0ee;
    color: var(--red);
}

.button,
.icon-button,
.filters a,
.move-form select {
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--ink);
    text-decoration: none;
    border-radius: 8px;
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 14px;
    font-weight: 700;
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.button:hover,
.icon-button:hover,
.filters a:hover {
    border-color: #cbd6cd;
    box-shadow: 0 6px 18px rgba(24, 32, 28, 0.08);
    transform: translateY(-1px);
}

.icon-button {
    width: 42px;
    padding: 0;
}

.button.compact {
    min-height: 34px;
    padding: 0 10px;
    font-size: 13px;
}

.primary,
.filters a.active {
    background: var(--green);
    color: white;
    border-color: var(--green);
}

.primary:hover,
.filters a.active:hover {
    background: var(--green-dark);
    border-color: var(--green-dark);
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.stats div,
.briefing,
.mail-item,
.empty {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.stats div {
    padding: 16px 18px;
}

.stats span {
    display: block;
    font-size: 30px;
    font-weight: 800;
    line-height: 1;
}

.stats p,
.mail-meta,
.sender {
    color: var(--muted);
}

.briefing {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    padding: 16px 18px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.briefing h2 {
    font-size: 18px;
    margin-bottom: 4px;
}

.briefing p {
    margin-bottom: 0;
    color: var(--muted);
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.mail-toolbar {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 18px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px 18px;
}

.mail-toolbar h2 {
    margin-bottom: 0;
    font-size: 24px;
}

.filters {
    margin: 0;
}

.mail-list {
    display: grid;
    gap: 10px;
}

.mail-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(180px, auto);
    gap: 22px;
    padding: 18px 20px;
    box-shadow: 0 1px 0 rgba(24, 32, 28, 0.02);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    cursor: pointer;
}

.mail-item .move-form,
.mail-item a,
.mail-item details {
    cursor: auto;
}

.mail-item:hover {
    border-color: #ccd8d0;
    box-shadow: var(--shadow);
}

.mail-meta {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    font-size: 13px;
    margin-bottom: 8px;
}

.mail-item h2 {
    font-size: 20px;
    line-height: 1.25;
    margin-bottom: 6px;
    max-width: 820px;
}

.mail-item h2 a {
    color: var(--ink);
    text-decoration: none;
}

.mail-item h2 a:hover {
    color: var(--green-dark);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.mail-item p {
    line-height: 1.5;
    margin-bottom: 8px;
}

.sender {
    font-size: 15px;
    margin-bottom: 10px;
}

.summary {
    max-width: 920px;
    color: #2c342f;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.action-line {
    color: var(--blue);
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    background: #edf3ff;
    border-radius: 8px;
    padding: 7px 10px;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    border-radius: 999px;
    background: #eef1ed;
    padding: 0 10px;
    font-size: 13px;
    font-weight: 800;
    white-space: nowrap;
}

.badge-high {
    color: var(--red);
    background: #ffe8e6;
}

.badge-normal {
    color: var(--blue);
    background: #e8f0ff;
}

.badge-low {
    color: var(--amber);
    background: #fff2dd;
}

.draft {
    grid-column: 1 / -1;
    border-top: 1px solid var(--soft-line);
    padding-top: 12px;
}

.draft summary {
    cursor: pointer;
    font-weight: 800;
}

pre {
    white-space: pre-wrap;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    background: #f4f6f3;
    border-radius: 8px;
    padding: 12px;
    overflow: auto;
}

.empty {
    padding: 28px;
}

.mail-side {
    justify-content: flex-end;
}

.move-form {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    justify-content: flex-end;
    margin-top: 4px;
}

.move-form select {
    min-height: 34px;
    max-width: 170px;
    padding: 0 8px;
    font-weight: 700;
    font-size: 13px;
}

.move-form.stacked {
    display: grid;
    justify-content: stretch;
    gap: 12px;
}

.move-form.stacked label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.move-form.stacked select,
.move-form.stacked .button {
    max-width: none;
    width: 100%;
}

.message-layout {
    width: min(1180px, calc(100% - 32px));
    margin: 22px auto 56px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 18px;
    align-items: start;
}

.message-panel,
.message-actions {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.message-panel {
    padding: 24px;
}

.message-actions {
    padding: 18px;
    position: sticky;
    top: 118px;
}

.message-actions h2 {
    font-size: 18px;
    margin-bottom: 12px;
}

.message-head {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    border-bottom: 1px solid var(--soft-line);
    padding-bottom: 18px;
    margin-bottom: 18px;
}

.message-head h2 {
    font-size: clamp(26px, 4vw, 40px);
    line-height: 1.12;
    margin-bottom: 8px;
}

.message-badges {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-content: flex-start;
}

.message-meta {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin: 0 0 18px;
}

.message-meta div {
    border: 1px solid var(--soft-line);
    border-radius: 8px;
    padding: 12px;
}

.message-meta dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.message-meta dd {
    margin: 4px 0 0;
    font-weight: 750;
    overflow-wrap: anywhere;
}

.message-block {
    border-top: 1px solid var(--soft-line);
    padding-top: 18px;
    margin-top: 18px;
}

.message-block h3 {
    margin: 0 0 8px;
    font-size: 16px;
}

.message-block p {
    color: #2c342f;
    line-height: 1.65;
}

.message-body {
    white-space: normal;
    overflow-wrap: anywhere;
}

.action-block {
    background: #f4f8ff;
    border: 1px solid #d8e6ff;
    border-radius: 8px;
    padding: 14px;
}

@media (max-width: 980px) {
    .message-layout {
        display: flex;
        flex-direction: column;
    }

    .message-actions {
        position: static;
        width: 100%;
    }
}

@media (max-width: 720px) {
    .message-head,
    .message-meta {
        display: flex;
        flex-direction: column;
    }

    .move-form {
        justify-content: flex-start;
    }

    .app-shell {
        display: flex;
        flex-direction: column;
        width: min(100% - 24px, 1280px);
        margin-top: 14px;
    }

    .sidebar {
        position: static;
        width: 100%;
        max-height: none;
        overflow: visible;
    }

    .topbar,
    .briefing,
    .mail-toolbar,
    .mail-item {
        align-items: stretch;
        flex-direction: column;
        display: flex;
    }

    .stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .mail-side {
        justify-content: flex-start;
    }

    .button,
    .icon-button {
        width: 100%;
    }
}
