:root {
  --brand: #1a56db;
  --brand-hover: #1546bd;
  --brand-soft: #e8effd;
  --brand-text: #ffffff;
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --hover: #f1f3f6;
  --border: #e4e7ec;
  --text: #1d2433;
  --muted: #667085;
  --danger: #d92d20;
  --danger-soft: #fdecea;
  --warn-bg: #fff8e6;
  --warn-border: #f6dfa3;
  --star: #f5a524;
  --shadow: 0 12px 40px rgba(16, 24, 40, 0.18);
  --compose-head: #1d2433;
  color-scheme: light;
}

:root[data-theme='dark'] {
  --brand: #4f86f7;
  --brand-hover: #6b9bff;
  --brand-soft: #1d2b4a;
  --bg: #0f1115;
  --panel: #16181d;
  --panel-2: #1b1e24;
  --hover: #20242c;
  --border: #2a2f39;
  --text: #e6e8eb;
  --muted: #9aa3b2;
  --danger: #ff6b5e;
  --danger-soft: #3a1d1b;
  --warn-bg: #2e2714;
  --warn-border: #5a4a1c;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  --compose-head: #262b35;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, 'Segoe UI', Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
.sprite { display: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.spacer { flex: 1; }
.error { color: var(--danger); margin: 0; }
kbd { display: inline-block; min-width: 20px; padding: 1px 6px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px;
  font: 12px ui-monospace, Consolas, monospace; text-align: center; background: var(--panel-2); }

/* ---------- icons & buttons ---------- */
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.ic.huge { width: 56px; height: 56px; stroke-width: 1.2; opacity: 0.35; }
button { cursor: pointer; border: 0; border-radius: 8px; padding: 8px 14px; background: none; display: inline-flex; align-items: center; gap: 6px; }
button:disabled { opacity: 0.55; cursor: default; }
.primary { background: var(--brand); color: var(--brand-text); font-weight: 600; }
.primary:hover:not(:disabled) { background: var(--brand-hover); }
.ghost { background: transparent; border: 1px solid var(--border); }
.ghost:hover { background: var(--hover); }
.pill { border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.pill:hover { background: var(--hover); }
.small-btn { padding: 5px 10px; font-size: 13px; }
.wide { width: 100%; padding: 12px; justify-content: center; }
.icon-btn { padding: 7px; border-radius: 50%; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.tiny { padding: 4px; }
.icon-btn.tiny .ic { width: 15px; height: 15px; }
.icon-btn.light { color: #fff; }
.icon-btn.light:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }
.danger-ic:hover { color: var(--danger); background: var(--danger-soft); }
.link-btn { padding: 0 4px; color: var(--brand); font-weight: 600; }
input, select, textarea { border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; background: var(--panel); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
select { cursor: pointer; }

.brand-mark { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; }
.brand-mark img { width: 34px; height: 34px; }
.brand-mark.small { font-size: 16px; }
.brand-mark.small img { width: 28px; height: 28px; }

.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--brand); color: #fff; display: flex; align-items: center;
  justify-content: center; font-weight: 700; flex: 0 0 auto; font-size: 15px; user-select: none; }
.avatar.sm { width: 32px; height: 32px; font-size: 13px; }
.avatar.xs { width: 34px; height: 34px; font-size: 13px; }
.avatar-btn { padding: 2px; border-radius: 50%; }

/* ---------- sign in ---------- */
.login { display: grid; grid-template-columns: 1.1fr 1fr; height: 100%; }
.login-brand { background: radial-gradient(circle at 15% 85%, #2f6ef0 0%, transparent 45%), linear-gradient(155deg, #1a56db 0%, #0d3489 100%);
  color: #fff; padding: 48px 56px; display: flex; flex-direction: column; justify-content: space-between; }
.login-brand .brand-mark img { background: #fff; border-radius: 9px; padding: 3px; }
.login-pitch h1 { font-size: 42px; line-height: 1.12; margin: 0 0 14px; letter-spacing: -0.5px; }
.login-pitch p { font-size: 17px; opacity: 0.88; margin: 0 0 22px; max-width: 480px; }
.login-points { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; opacity: 0.92; }
.login-points li::before { content: '✓'; display: inline-block; width: 22px; height: 22px; margin-right: 10px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.18); text-align: center; line-height: 22px; font-size: 12px; }
.login-panel { display: flex; align-items: center; justify-content: center; padding: 32px; background: var(--panel); }
.login-form { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px; }
.login-form h2 { margin: -10px 0 4px; font-size: 30px; letter-spacing: -0.3px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.login-form input { font-weight: 400; padding: 12px 14px; }

/* ---------- layout ---------- */
.mail { display: flex; flex-direction: column; height: 100%; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--border); }
.search { flex: 1; max-width: 680px; position: relative; display: flex; align-items: center; }
.search > .ic { position: absolute; left: 14px; color: var(--muted); pointer-events: none; }
.search input { width: 100%; background: var(--hover); border-color: transparent; padding: 11px 40px 11px 42px; border-radius: 12px; }
.search input:focus { background: var(--panel); }
.search .icon-btn { position: absolute; right: 6px; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 2px; }
.account { position: relative; margin-left: 6px; }
.menu { position: absolute; right: 0; top: calc(100% + 8px); background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); min-width: 240px; padding: 6px; z-index: 40; }
.menu-head { display: flex; flex-direction: column; padding: 10px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; word-break: break-all; }
.menu-item { width: 100%; padding: 9px 12px; border-radius: 8px; }
.menu-item:hover { background: var(--hover); }
.panes { flex: 1; display: grid; grid-template-columns: 240px minmax(320px, 420px) 1fr; min-height: 0; }

/* ---------- sidebar ---------- */
.sidebar { padding: 14px 10px; overflow-y: auto; display: flex; flex-direction: column; }
.compose { padding: 14px 20px; margin: 0 4px 16px; border-radius: 16px; font-size: 15px; box-shadow: 0 4px 14px rgba(26, 86, 219, 0.28); justify-content: center; }
.folders { list-style: none; margin: 0; padding: 0; }
.folders li { display: flex; align-items: center; gap: 12px; padding: 8px 12px 8px 14px; border-radius: 0 18px 18px 0; cursor: pointer; margin-right: 6px; color: var(--text); }
.folders li:hover { background: var(--hover); }
.folders li.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.folders li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folders .count { font-size: 12px; font-weight: 700; }
.folders li.drop-target { outline: 2px dashed var(--brand); }
.folder-tools { display: none; gap: 0; }
.folders li:hover .folder-tools { display: inline-flex; }
.folders li:hover .count { display: none; }
.folders-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 12px 6px 14px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.sidebar-foot { margin-top: auto; padding: 16px 14px 4px; }

/* ---------- list ---------- */
.list-pane { background: var(--panel); border-left: 1px solid var(--border); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.list-head { display: flex; align-items: center; gap: 10px; padding: 0 12px 0 16px; height: 52px; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.list-info { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.list-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.bulk-bar { display: flex; align-items: center; gap: 2px; flex: 1; }
.bulk-count { font-weight: 600; margin-right: auto; }
.bulk-bar select { padding: 5px 6px; font-size: 13px; max-width: 120px; }
.check { display: inline-flex; cursor: pointer; position: relative; }
.check input { position: absolute; opacity: 0; width: 0; height: 0; }
.check span { width: 18px; height: 18px; border: 2px solid var(--muted); border-radius: 5px; display: inline-block; transition: all 0.1s; }
.check input:checked + span { background: var(--brand); border-color: var(--brand); box-shadow: inset 0 0 0 2px var(--panel); }
.check input:indeterminate + span { background: linear-gradient(var(--brand), var(--brand)) center / 8px 2px no-repeat; border-color: var(--brand); }
.check input:focus-visible + span { box-shadow: 0 0 0 3px var(--brand-soft); }

.messages { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.msg { position: relative; display: grid; grid-template-columns: auto auto 1fr auto; grid-template-rows: auto auto auto; gap: 1px 10px;
  padding: 11px 14px 11px 16px; border-bottom: 1px solid var(--border); cursor: pointer; align-items: center; }
.msg:hover { background: var(--hover); }
.msg.active { background: var(--brand-soft); }
.msg.selected { background: var(--brand-soft); }
.msg.cursor { box-shadow: inset 3px 0 0 var(--muted); }
.msg.unread::before { content: ''; position: absolute; left: 4px; top: 50%; width: 7px; height: 7px; margin-top: -3px; border-radius: 50%; background: var(--brand); }
.msg .check { grid-row: 1 / 4; }
.msg .avatar { grid-row: 1 / 4; }
.m-from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.m-date { font-size: 12px; color: var(--muted); white-space: nowrap; text-align: right; }
.m-subject, .m-preview { grid-column: 3 / 5; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-subject { font-size: 13.5px; display: flex; align-items: center; gap: 6px; }
.m-subject .text { overflow: hidden; text-overflow: ellipsis; }
.m-preview { color: var(--muted); font-size: 13px; }
.msg.unread .m-from, .msg.unread .m-subject { font-weight: 700; }
.m-badges { display: inline-flex; gap: 4px; color: var(--muted); flex: 0 0 auto; }
.m-badges .ic { width: 14px; height: 14px; }
.m-badges .star { color: var(--star); fill: var(--star); }
.draft-tag { color: var(--danger); font-weight: 600; }
.row-actions { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); display: none; gap: 0; background: var(--hover); border-radius: 20px; padding: 0 2px; }
.msg:hover .row-actions { display: inline-flex; }
.msg.active .row-actions, .msg.selected .row-actions { background: var(--brand-soft); }
.row-actions .icon-btn { padding: 6px; }
.row-actions .icon-btn .ic { width: 16px; height: 16px; }
.row-actions .starred { color: var(--star); }
.row-actions .starred .ic { fill: var(--star); }
.list-empty { padding: 60px 16px; text-align: center; color: var(--muted); cursor: default; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.load-more { margin: 10px auto; }

/* ---------- reader ---------- */
.reader { background: var(--panel); overflow-y: auto; min-width: 0; }
.reader-empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--muted); }
.reader-empty p { margin: 0; }
#reader-content { display: flex; flex-direction: column; min-height: 100%; }
.reader-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 9px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--panel); z-index: 1; }
.reader-actions select { padding: 6px 8px; font-size: 13px; }
#star-btn.starred { color: var(--star); }
#star-btn.starred .ic { fill: var(--star); }
.r-subject { font-size: 22px; line-height: 1.3; margin: 20px 28px 14px; word-wrap: break-word; font-weight: 600; }
.r-meta { display: flex; align-items: flex-start; gap: 12px; padding: 0 28px 14px; }
.r-people { flex: 1; min-width: 0; word-wrap: break-word; }
.r-date { white-space: nowrap; }
.notice { margin: 0 28px 10px; padding: 9px 12px; background: var(--hover); border-radius: 8px; font-size: 13px; }
.notice.warn { background: var(--warn-bg); border: 1px solid var(--warn-border); }
#images-bar { background: var(--warn-bg); border: 1px solid var(--warn-border); }
.r-body { border: 0; width: 100%; flex: 1; min-height: 380px; background: var(--panel); }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 28px 16px; }
.attachments:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 13px;
  background: var(--panel-2); text-decoration: none; color: inherit; max-width: 280px; }
a.chip:hover { border-color: var(--brand); }
.chip .ic { color: var(--muted); }
.chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { padding: 2px; color: var(--muted); border-radius: 50%; }
.chip button:hover { background: var(--hover); color: var(--danger); }
.chip .ic.sm { width: 14px; height: 14px; }
.quick-reply { display: flex; gap: 10px; padding: 8px 28px 28px; }
.quick-reply button { border-radius: 999px; padding: 9px 18px; }

/* ---------- compose ---------- */
.compose-win { position: fixed; right: 24px; bottom: 0; width: min(580px, calc(100% - 32px)); height: min(640px, calc(100% - 40px));
  background: var(--panel); border-radius: 12px 12px 0 0; box-shadow: var(--shadow); display: flex; flex-direction: column; z-index: 20; border: 1px solid var(--border); }
.compose-win.minimized { height: auto; width: 320px; }
.compose-win.minimized .compose-form { display: none; }
.compose-win.maximized { right: 50%; bottom: 50%; transform: translate(50%, 50%); width: min(1000px, calc(100% - 48px)); height: calc(100% - 64px); border-radius: 12px; }
.compose-win.maximized .compose-head { border-radius: 12px 12px 0 0; }
.compose-head { display: flex; align-items: center; gap: 8px; background: var(--compose-head); color: #fff; padding: 6px 6px 6px 16px; border-radius: 12px 12px 0 0; cursor: pointer; }
.draft-status { font-size: 12px; opacity: 0.7; }
.compose-form { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.field-row { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); padding: 0 16px; }
.field-row label { color: var(--muted); min-width: 30px; }
.field-row input { flex: 1; border: 0; border-radius: 0; padding: 11px 0; box-shadow: none !important; background: transparent; }
.editor { flex: 1; overflow-y: auto; padding: 14px 16px; outline: none; line-height: 1.6; word-wrap: break-word; }
.editor:empty::before { content: attr(data-placeholder); color: var(--muted); }
.editor blockquote { margin: 6px 0; padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); }
.editor a { color: var(--brand); }
.editor .signature { color: var(--muted); }
.compose-form .attachments { padding: 6px 16px; }
.compose-form .error { padding: 0 16px 8px; }
.compose-foot { display: flex; align-items: center; gap: 4px; padding: 10px 12px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.send { border-radius: 999px; padding: 9px 20px; margin-right: 6px; }
.fmt-bar { display: flex; gap: 0; }
.fmt-bar button { padding: 6px; border-radius: 6px; color: var(--muted); }
.fmt-bar button:hover { background: var(--hover); color: var(--text); }
.fmt-bar .ic { width: 17px; height: 17px; }
.attach-label { cursor: pointer; }
.suggest { position: absolute; left: 16px; right: 16px; list-style: none; margin: 0; padding: 6px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); z-index: 25; max-height: 260px; overflow-y: auto; }
.suggest li { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; cursor: pointer; }
.suggest li.active, .suggest li:hover { background: var(--hover); }
.suggest .who { display: flex; flex-direction: column; min-width: 0; }
.suggest .who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- dialogs ---------- */
.modal { position: fixed; inset: 0; background: rgba(15, 17, 21, 0.5); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.dialog { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 22px 24px; width: 420px; max-width: 100%;
  display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); max-height: calc(100% - 32px); overflow-y: auto; }
.wide-dialog { width: 560px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog h2 { margin: 0; font-size: 19px; }
.dialog label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.dialog label .muted { font-weight: 400; }
.dialog textarea { resize: vertical; font-weight: 400; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; }
.shortcut-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; font-size: 13.5px; }

.toast { position: fixed; left: 24px; bottom: 24px; background: #1d2433; color: #fff; padding: 12px 16px; border-radius: 10px; z-index: 60;
  display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow); max-width: calc(100% - 48px); }
.toast .link-btn { color: #8ab4ff; }

.only-mobile { display: none; }

@media (max-width: 1100px) {
  .panes { grid-template-columns: 210px minmax(280px, 340px) 1fr; }
  .top-actions #shortcuts-btn { display: none; }
}

@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .panes { grid-template-columns: 1fr; position: relative; }
  .only-mobile { display: inline-flex; }
  .brand-mark.small span { display: none; }
  .sidebar { position: absolute; inset: 0 auto 0 0; width: 270px; background: var(--panel); z-index: 6; box-shadow: var(--shadow); display: none; }
  .sidebar.open { display: flex; }
  .reader { position: absolute; inset: 0; z-index: 5; display: none; }
  .reader.open { display: block; }
  .top-actions #theme-btn, .top-actions #settings-btn { display: none; }
  .compose-win, .compose-win.maximized { right: 0; bottom: 0; transform: none; width: 100%; height: 100%; border-radius: 0; }
  .compose-head { border-radius: 0 !important; }
  .row-actions { display: none !important; }
  .r-subject, .r-meta, .notice, .attachments, .quick-reply { margin-left: 16px; margin-right: 16px; padding-left: 0; padding-right: 0; }
  .shortcut-grid { grid-template-columns: 1fr; }
}
