:root {
    color-scheme: light;
    --bg: #f5f6f8;
    --panel: #ffffff;
    --text: #202124;
    --muted: #6f747b;
    --line: #e4e6ea;
    --accent: #1769d2;
    --accent-dark: #0e4fa5;
    --hover: #edf4fd;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.topbar { height: 64px; display: flex; align-items: center; gap: 28px; padding: 0 24px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 600; white-space: nowrap; }
.brand-mark, .login-logo { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--accent); color: white; font-weight: 700; letter-spacing: -.5px; }
.search { display: flex; flex: 1; max-width: 760px; }
.search input { width: 100%; border: 1px solid var(--line); border-radius: 8px 0 0 8px; padding: 11px 14px; outline: none; background: #f7f8fa; }
.search input:focus { border-color: var(--accent); background: white; }
.search button { border: 0; border-radius: 0 8px 8px 0; padding: 0 18px; background: var(--accent); color: white; }
.account { margin-left: auto; display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.link-button { padding: 0; border: 0; background: none; color: var(--accent); }
.layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: calc(100vh - 64px); }
.sidebar { padding: 20px 14px; background: var(--panel); border-right: 1px solid var(--line); }
.compose { display: block; margin: 0 4px 22px; padding: 12px 18px; border-radius: 8px; background: var(--accent); color: white; text-align: center; font-weight: 600; }
.folder { display: flex; justify-content: space-between; gap: 12px; padding: 9px 12px; border-radius: 6px; color: #43474d; }
.folder:hover, .folder.active { background: var(--hover); color: var(--accent-dark); }
.folder.active { font-weight: 600; }
.count { color: var(--muted); font-size: 12px; }
.content { min-width: 0; padding: 24px 30px 50px; }
.thread-list-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
h1 { margin: 0 0 6px; font-size: 23px; font-weight: 600; }
.muted { color: var(--muted); }
.thread-list { overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.thread-row { display: grid; grid-template-columns: 220px minmax(0, 1fr) 100px; gap: 18px; align-items: center; min-height: 70px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.thread-row:last-child { border-bottom: 0; }
.thread-row:hover { background: var(--hover); }
.thread-row.unread { font-weight: 600; }
.thread-sender { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-main { display: flex; min-width: 0; gap: 10px; }
.thread-subject { max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-snippet { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-weight: 400; }
.thread-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; color: var(--muted); font-size: 12px; }
.pagination { display: flex; justify-content: center; gap: 20px; padding: 24px; }
.pagination a { color: var(--accent); }
.empty { padding: 60px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--muted); text-align: center; }
.thread-view { max-width: 1120px; margin: 0 auto; }
.thread-heading { margin-bottom: 18px; }
.back { display: inline-block; margin-bottom: 14px; color: var(--accent); }
.messages { display: flex; flex-direction: column; gap: 12px; }
.message { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); overflow: hidden; }
.message summary { display: flex; justify-content: space-between; gap: 20px; padding: 16px 20px; cursor: pointer; list-style: none; }
.message summary::-webkit-details-marker { display: none; }
.message-from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.message summary time { flex-shrink: 0; color: var(--muted); font-size: 12px; }
.message-details { padding: 0 20px 12px; color: var(--muted); font-size: 13px; }
.message-folder { margin-top: 6px; font-size: 12px; }
.message-body { padding: 20px; border-top: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 20px 16px; }
.attachment { padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fafafa; }
.message-actions { padding: 0 20px 16px; }
.message-actions a { color: var(--accent); font-size: 13px; }
.reply-box { margin-top: 22px; padding: 20px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.reply-box h2 { margin: 0; font-size: 18px; }
.reply-box p { color: var(--muted); }
.reply-box textarea { width: 100%; min-height: 130px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; resize: vertical; }
.primary { padding: 11px 20px; border: 0; border-radius: 8px; background: var(--accent); color: white; font-weight: 600; }
.primary:disabled { cursor: default; opacity: .5; }
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card { width: 100%; max-width: 410px; padding: 38px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: 0 8px 30px #20212412; }
.login-logo { margin-bottom: 18px; }
.login-card p { margin-bottom: 26px; color: var(--muted); }
.login-card label { display: block; margin: 16px 0; font-weight: 500; }
.login-card input { display: block; width: 100%; margin-top: 7px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; }
.login-card .primary { width: 100%; margin-top: 10px; }
.alert { padding: 10px 12px; border-radius: 6px; background: #fde9e7; color: #a33228; }

@media (max-width: 900px) {
    .topbar { gap: 14px; padding: 0 14px; }
    .account span { display: none; }
    .layout { grid-template-columns: 180px minmax(0, 1fr); }
    .content { padding: 18px 16px 40px; }
    .thread-row { grid-template-columns: 130px minmax(0, 1fr) 72px; gap: 10px; padding: 10px 12px; }
    .thread-main { display: block; }
    .thread-subject { display: block; max-width: 100%; }
}

@media (max-width: 620px) {
    .topbar { height: auto; min-height: 58px; flex-wrap: wrap; padding-top: 9px; padding-bottom: 9px; }
    .brand { font-size: 17px; }
    .brand-mark { width: 32px; height: 32px; font-size: 12px; }
    .search { order: 3; flex-basis: 100%; }
    .layout { display: block; }
    .sidebar { display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
    .compose { margin: 0; padding: 8px 14px; white-space: nowrap; }
    .sidebar nav { display: flex; gap: 6px; }
    .folder { white-space: nowrap; padding: 8px 10px; }
    .content { padding: 14px 10px 30px; }
    .thread-row { grid-template-columns: minmax(0, 1fr) 65px; }
    .thread-sender { grid-column: 1; }
    .thread-main { grid-column: 1; }
    .thread-meta { grid-column: 2; grid-row: 1 / span 2; }
    .thread-snippet { display: block; margin-top: 3px; }
    .message summary { display: block; }
    .message summary time { display: block; margin-top: 5px; }
}

.compose-page { max-width: 900px; margin: 0 auto; }
.compose-form { display: flex; flex-direction: column; gap: 16px; padding: 22px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.compose-form label { font-weight: 500; }
.compose-form input[type="text"], .compose-form input[type="email"], .compose-form textarea { display: block; width: 100%; margin-top: 6px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; }
.compose-form textarea { min-height: 300px; resize: vertical; white-space: pre-wrap; }
.compose-form .primary { align-self: flex-start; }
.cancel { margin-left: 14px; color: var(--accent); }
.success { margin-bottom: 16px; padding: 12px 14px; border-radius: 8px; background: #e5f4e8; color: #27632d; }
a.primary { display: inline-block; }
.ai-usage { margin: 14px 0; padding: 12px 14px; border-radius: 8px; background: #f3f6fa; font-size: 13px; }
.ai-usage div + div { margin-top: 4px; }
