:root, html[data-resolved="light"] {
  --bg: #f6f8fc;
  --surface: #ffffff;
  --ink: #1f1f1f;
  --muted: #444746;
  --line: #e1e3e1;
  --blue: #0b57d0;
  --blue-d: #0842a0;
  --blue-s: #d3e3fd;
  --red: #c5221f;
  --compose: #c2e7ff;
  --compose-h: #b3dffc;
  --row-unread: #ffffff;
  --row-read: #f2f6fc;
  --hover: #e9eef6;
  --chip: #e9eef6;
  --send: #0b57d0;
  --shadow: 0 1px 3px rgba(60,64,67,.3);
  --top: 64px;
  --side: 256px;
  --font: "Google Sans", "Segoe UI", Roboto, Arial, sans-serif;
  --compose-bar: #404547;
}
html[data-resolved="dark"] {
  --bg: #1f1f1f;
  --surface: #2d2e30;
  --ink: #e3e3e3;
  --muted: #c4c7c5;
  --line: #3c4043;
  --blue: #a8c7fa;
  --blue-d: #d3e3fd;
  --blue-s: #004a77;
  --red: #f28b82;
  --compose: #004a77;
  --compose-h: #0b57d0;
  --row-unread: #2d2e30;
  --row-read: #1f1f1f;
  --hover: #3c4043;
  --chip: #3c4043;
  --send: #a8c7fa;
  --shadow: 0 2px 8px rgba(0,0,0,.45);
  --compose-bar: #2d2e30;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--blue); text-decoration: none; }
button, input, select, textarea { font-family: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: currentColor; display: block; }

.app {
  min-height: 100%;
  display: grid;
  grid-template-columns: var(--side) 1fr;
  grid-template-rows: var(--top) 1fr;
  grid-template-areas: "top top" "side main";
}
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 40;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--ink); min-width: 160px; font-size: 22px; font-weight: 400;
}
.brand-mark { color: var(--red); }
.brand-img { height: 32px; max-width: 140px; object-fit: contain; }
.search {
  flex: 1; max-width: 720px; display: flex; align-items: center;
  background: var(--surface); border-radius: 24px; height: 48px; color: var(--muted);
}
.search:focus-within { box-shadow: var(--shadow); background: var(--surface); }
.search input {
  border: 0; background: transparent; flex: 1; outline: none; font-size: 16px; color: var(--ink);
}
.search-ico { width: 40px; height: 40px; color: var(--muted); background: transparent; border: 0; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 2px; }
.icon-btn {
  border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--hover); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600;
}
.avatar.lg { width: 40px; height: 40px; }
.userchip, .gearwrap { position: relative; }
.user-menu, .gear-menu {
  display: none; position: absolute; right: 0; top: 44px; width: 280px;
  background: var(--surface); border-radius: 12px; box-shadow: var(--shadow);
  padding: 8px; z-index: 50; border: 1px solid var(--line);
}
.userchip.open .user-menu, .gearwrap.open .gear-menu { display: block; }
.user-menu-h, .gear-h { padding: 10px 12px; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .04em; }
.user-menu a, .gear-menu a { display: block; padding: 10px 12px; color: var(--ink); border-radius: 8px; }
.user-menu a:hover, .gear-menu a:hover { background: var(--hover); }
.theme-picks { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; padding: 0 8px 10px; }
.theme-picks button {
  border: 1px solid var(--line); background: var(--bg); border-radius: 20px; padding: 8px 0; cursor: pointer; font-size: 12px;
}
.theme-picks button.on, .theme-picks button:hover { background: var(--blue-s); border-color: var(--blue); }

.sidebar { grid-area: side; padding: 8px 8px 24px; background: var(--bg); overflow: auto; }
.compose-btn {
  display: inline-flex; align-items: center; gap: 12px;
  background: var(--compose); color: var(--ink);
  border-radius: 16px; padding: 18px 24px; margin: 8px 0 16px 8px;
  font-weight: 500; box-shadow: 0 1px 2px rgba(0,0,0,.12);
}
.compose-btn:hover { background: var(--compose-h); }
.side-nav { display: flex; flex-direction: column; }
.side-link {
  display: flex; align-items: center; gap: 18px;
  padding: 0 12px 0 26px; height: 32px; border-radius: 0 16px 16px 0;
  color: var(--ink); margin-right: 12px; font-size: 14px;
}
.side-link .si { color: var(--muted); }
.side-link.active { background: var(--blue-s); font-weight: 700; }
.side-link:hover:not(.active) { background: var(--hover); }
.side-link.unread .sl { font-weight: 700; }
.sb { margin-left: auto; font-size: 12px; font-weight: 700; }
.side-sep { height: 1px; background: var(--line); margin: 10px 16px; }
.main {
  grid-area: main; min-width: 0; background: var(--surface);
  border-radius: 16px 0 0 0; overflow: auto;
}

.banner { margin: 12px 16px 0; padding: 10px 14px; border-radius: 8px; font-size: 14px; }
.banner-ok, .toast-ok { background: #c4eed0; color: #0d652d; }
.banner-err, .toast-err { background: #f9dedc; color: #c5221f; }
.toast { margin: 12px auto; max-width: 450px; padding: 10px 14px; border-radius: 8px; }

.page-pad { padding: 20px 24px 48px; }
.page-title { margin: 0 0 16px; font-weight: 400; font-size: 22px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--bg); border-radius: 16px; padding: 16px; }
.stat span { display: block; color: var(--muted); font-size: 13px; }
.stat strong { font-size: 26px; font-weight: 500; }
.card { background: var(--bg); border-radius: 16px; padding: 16px; overflow: auto; }
.split { display: grid; grid-template-columns: minmax(260px, 320px) 1fr; gap: 16px; align-items: start; }
.grow { flex: 1; min-width: 0; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form.narrow { max-width: 520px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.form input, .form select, .form textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 12px;
  font-size: 16px; background: var(--surface); color: var(--ink);
}
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid var(--blue-s); border-color: var(--blue); }
.form input:disabled { opacity: .7; }
.combo { display: flex; gap: 8px; }
.combo input { flex: 1; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 20px; padding: 10px 24px; cursor: pointer; font-weight: 500; font-size: 14px;
  background: var(--chip); color: var(--ink);
}
.btn.primary { background: var(--send); color: #fff; }
html[data-resolved="dark"] .btn.primary { color: #062e6f; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.danger { background: #f9dedc; color: var(--red); }
.btn.sm { padding: 6px 12px; font-size: 12px; }
.btn.wide { width: 100%; }
.data { width: 100%; border-collapse: collapse; font-size: 14px; }
.data th, .data td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 10px; background: var(--chip); font-size: 12px; }
.pill.ok { background: #c4eed0; color: #0d652d; }
.inline { display: inline; }
.row-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.muted { color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }
.check { flex-direction: row !important; align-items: center; gap: 10px !important; color: var(--ink) !important; font-size: 14px !important; }
.inline-search input { border: 1px solid var(--line); border-radius: 20px; padding: 8px 14px; background: var(--surface); }

.mail-toolbar {
  display: flex; align-items: center; gap: 2px; padding: 6px 8px;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 5;
}
.chk { width: 40px; display: flex; justify-content: center; }
.mail-list { min-height: 50vh; }
.mail-row {
  display: grid; grid-template-columns: 40px 40px 1fr auto; align-items: center;
  border-bottom: 1px solid var(--line); min-height: 42px;
}
.mail-row.unread { background: var(--row-unread); font-weight: 700; color: var(--ink); }
.mail-row:not(.unread) { background: var(--row-read); font-weight: 400; color: var(--muted); }
.mail-row:hover { box-shadow: inset 1px 0 0 var(--line), inset -1px 0 0 var(--line), 0 1px 2px rgba(0,0,0,.12); z-index: 1; }
.mail-row-main {
  display: grid; grid-template-columns: minmax(90px, 180px) 1fr auto auto; gap: 8px; align-items: center;
  min-width: 0; height: 42px; padding-right: 8px; color: inherit;
}
.from, .subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snip { font-weight: 400; color: var(--muted); }
.when { text-align: right; font-size: 12px; white-space: nowrap; min-width: 64px; }
.att-chip {
  display: inline-flex; align-items: center; gap: 4px; max-width: 140px;
  border: 1px solid var(--line); border-radius: 16px; padding: 2px 10px; font-size: 12px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink);
}
.row-quick { display: none; }
.mail-row:hover .row-quick { display: flex; }
.mail-row:hover .when { display: none; }
.star-btn { border: 0; background: transparent; color: #f4b400; cursor: pointer; }
.star-btn:not(.on) { color: #9aa0a6; }
.empty-mail { text-align: center; padding: 80px 20px; color: var(--muted); }
.pager { display: flex; gap: 6px; padding: 16px; flex-wrap: wrap; }
.pager a { padding: 6px 10px; border-radius: 8px; color: var(--ink); }
.pager a.on { background: var(--blue-s); }

.thread { padding: 8px 16px 40px; }
.thread-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.thread-sub { font-size: 22px; font-weight: 400; margin: 0; flex: 1; }
.msg { margin: 16px 8px 0; }
@media (min-width: 800px) { .msg { margin: 16px 48px 0; } }
.msg-h { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; }
.msg-meta { font-size: 13px; color: var(--muted); }
.msg-body { padding: 16px 0 8px; white-space: pre-wrap; line-height: 1.6; }
@media (min-width: 800px) { .msg-body, .msg-acts, .atts { padding-left: 52px; } }
.msg-acts { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 12px; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 8px; }
.att { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; color: var(--ink); min-width: 160px; }

.compose {
  display: flex; flex-direction: column;
  background: var(--surface); overflow: hidden;
}
.compose-h {
  display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 16px;
  background: var(--compose-bar); color: #fff;
}
.compose-h h2 { margin: 0; font-size: 14px; font-weight: 500; flex: 1; }
.compose-h .icon-btn { color: #fff; }
.field-row {
  display: grid; grid-template-columns: 56px 1fr auto; align-items: center;
  border-bottom: 1px solid var(--line); padding: 0 12px; min-height: 44px;
}
.field-row span { color: var(--muted); font-size: 13px; }
.field-row input { border: 0; outline: none; padding: 10px 0; font-size: 14px; background: transparent; }
.extra-cc { display: none; }
.extra-cc.show { display: grid; }
.linkish { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 13px; }
.compose-body { flex: 1; border: 0; outline: none; padding: 16px; resize: none; font-size: 14px; background: transparent; min-height: 180px; }
.compose-f { display: flex; align-items: center; gap: 8px; padding: 12px; flex-wrap: wrap; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.compose.min { height: 44px !important; width: 260px !important; }
.compose.min .field-row, .compose.min .compose-body, .compose.min .compose-f { display: none; }
.compose.max {
  position: fixed !important; inset: 24px !important; width: auto !important; height: auto !important;
  border-radius: 8px; z-index: 60;
}
.compose-contacts { padding: 16px 24px 32px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 16px; padding: 6px 12px; margin: 4px; cursor: pointer; }
.suggest {
  position: absolute; background: var(--surface); box-shadow: var(--shadow); border-radius: 8px;
  z-index: 70; max-height: 240px; overflow: auto; width: min(480px, 90vw);
}
.suggest button { display: block; width: 100%; text-align: left; border: 0; background: var(--surface); padding: 10px 12px; cursor: pointer; }
.people { display: flex; flex-direction: column; gap: 8px; }
.person { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 8px; color: var(--ink); }
.person:hover { background: var(--hover); }
.person em { display: block; color: var(--muted); font-style: normal; font-size: 13px; }

.auth-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; background: var(--bg); padding: 16px; }
.auth-top { display: flex; align-items: center; gap: 10px; width: min(450px, 100%); padding: 16px 0; font-size: 20px; }
.auth-top img { height: 32px; }
.auth-card {
  width: min(450px, 100%); background: var(--surface); border-radius: 28px;
  box-shadow: none; border: 1px solid var(--line); padding: 36px 28px 28px; text-align: left;
}
.auth-card h1 { font-weight: 400; font-size: 32px; margin: 8px 0 4px; text-align: left; }
.auth-card .muted { margin: 0 0 24px; }
.auth-logo { color: var(--red); }
.auth-brand-img { height: 40px; margin-bottom: 8px; }
.auth-extra { margin-top: 20px; }
.install-card { width: min(560px, 100%); }
.steps { display: flex; gap: 8px; list-style: none; padding: 0; }
.steps li { flex: 1; text-align: center; font-size: 12px; padding: 8px; border-bottom: 2px solid var(--line); color: var(--muted); }
.steps li.on { border-color: var(--blue); color: var(--blue); font-weight: 600; }
.steps li.done { border-color: #137333; color: #137333; }
table.plain { width: 100%; font-size: 14px; border-collapse: collapse; }
table.plain td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
.ok { color: #137333; } .bad { color: var(--red); }
.side-backdrop { display: none; position: fixed; inset: var(--top) 0 0 0; background: rgba(0,0,0,.4); z-index: 35; }
.side-backdrop.show { display: block; }
body.nav-open { overflow: hidden; }
.brand-preview { max-height: 48px; margin: 8px 0; display: block; }

@media (min-width: 961px) {
  .compose {
    position: fixed; right: 16px; bottom: 0; width: min(512px, calc(100vw - 32px));
    height: min(560px, calc(100vh - 72px)); z-index: 45;
    border-radius: 8px 8px 0 0; box-shadow: 0 8px 28px rgba(0,0,0,.3);
  }
}
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "top" "main"; }
  .sidebar {
    position: fixed; left: 0; top: var(--top); bottom: 0; width: min(280px, 88vw);
    z-index: 36; background: var(--bg); transform: translateX(-105%); transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .main { border-radius: 0; }
  .compose { margin: 0; height: calc(100dvh - var(--top)); border-radius: 0; }
  .search { max-width: none; height: 44px; }
  .split { grid-template-columns: 1fr; }
  .mail-row-main { grid-template-columns: 1fr auto; }
  .from { display: none; }
  .att-chip { display: none; }
  .page-pad { padding: 16px; }
}
@media (max-width: 720px) {
  .brand-text { display: none; }
  .brand { min-width: 0; }
  .topbar { padding: 6px 4px; }
  .search { height: 40px; }
}
@media (max-width: 480px) {
  .auth-card { border: 0; padding: 16px 8px; border-radius: 0; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .mail-row { grid-template-columns: 32px 28px 1fr; }
  .row-quick { display: none !important; }
  .when { display: block !important; }
}
