:root {
  --bg: #f5f5f5; --panel: #ffffff; --text: #242424; --muted: #616161; --border: #e0e0e0;
  --brand: #4f52b2; --brand-dark: #3d3f99; --brand-soft: #e8ebfa; --accent: #0f6cbd;
  --unread: #4f52b2; --danger: #c4314b; --hover: #f0f0f0; --selected: #e8ebfa;
  font-family: 'Segoe UI', 'Segoe UI Web (West European)', system-ui, -apple-system, sans-serif;
  font-size: 14px; color: var(--text);
}
body.theme-dark { --bg: #1f1f1f; --panel: #292929; --text: #f0f0f0; --muted: #adadad; --border: #3d3d3d; --hover: #333; --selected: #2f2f4a; --brand-soft: #2f2f4a; }
body.theme-contrast { --bg: #000; --panel: #000; --text: #fff; --muted: #ffff00; --border: #fff; --hover: #1a1a1a; --selected: #1aebff33; --brand: #1aebff; --brand-soft: #000; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); }
a { color: var(--accent); }

.btn { font: inherit; border: 1px solid var(--border); background: var(--panel); color: var(--text); padding: 5px 12px; border-radius: 4px; cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.teams { border-color: var(--brand); color: var(--brand); }
.icon-btn { font: inherit; font-size: 18px; border: none; background: transparent; color: var(--text); cursor: pointer; padding: 4px 8px; border-radius: 4px; }
.icon-btn:hover { background: var(--hover); }
.link-btn { border: none; background: none; color: var(--accent); cursor: pointer; font: inherit; text-decoration: underline; }
kbd { border: 1px solid var(--border); border-radius: 3px; padding: 0 4px; font-size: 11px; background: var(--panel); }

.center-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; min-height: 60vh; padding: 24px; gap: 8px; }
.center-screen h1 { margin: 8px 0 0; font-size: 24px; }
.center-screen p { max-width: 460px; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--brand-soft); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* layout */
.layout { display: grid; height: 100vh; grid-template-columns: 220px minmax(280px, 380px) 1fr; grid-template-rows: 52px 1fr; grid-template-areas: "top top top" "folders list reader"; }
.topbar { grid-area: top; display: flex; align-items: center; gap: 10px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; min-width: 120px; }
.in-teams .brand { display: none; }
.search { display: flex; flex: 1; max-width: 560px; gap: 6px; }
.search select, .search input { font: inherit; padding: 5px 8px; border: 1px solid var(--border); border-radius: 4px; background: var(--panel); color: var(--text); }
.search input { flex: 1; min-width: 80px; }
.user { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }

.folders { grid-area: folders; overflow: auto; padding: 8px 4px; border-right: 1px solid var(--border); background: var(--bg); }
.folder { display: flex; align-items: center; gap: 6px; width: 100%; border: none; background: none; color: var(--text); font: inherit; text-align: left; padding: 6px 10px; border-radius: 4px; cursor: pointer; }
.folder:hover { background: var(--hover); }
.folder.active { background: var(--selected); font-weight: 600; }
.twisty { width: 12px; color: var(--muted); font-size: 11px; }
.f-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { color: var(--brand); font-weight: 700; font-size: 12px; }

.list-pane { grid-area: list; display: flex; flex-direction: column; overflow: hidden; background: var(--panel); border-right: 1px solid var(--border); }
.list-head { padding: 10px 12px 6px; border-bottom: 1px solid var(--border); }
.list-head h2 { margin: 0 0 6px; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.views { display: flex; gap: 4px; }
.view { font: inherit; font-size: 12px; border: 1px solid var(--border); background: var(--panel); color: var(--text); border-radius: 12px; padding: 2px 10px; cursor: pointer; }
.view.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.messages { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.msg { position: relative; padding: 9px 12px 9px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.msg:hover { background: var(--hover); }
.msg.selected { background: var(--selected); }
.msg.unread::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--unread); }
.msg.unread .msg-from, .msg.unread .msg-subject { font-weight: 700; }
.msg.unread .msg-subject { color: var(--brand); }
.msg-top { display: flex; justify-content: space-between; gap: 8px; }
.msg-from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.msg-subject, .msg-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-preview { color: var(--muted); font-size: 12px; padding-right: 36px; }
.msg-icons { position: absolute; right: 12px; bottom: 8px; display: flex; gap: 4px; font-size: 12px; }
.flagged { color: var(--danger); }
.imp { color: var(--danger); font-weight: 800; margin-right: 4px; }
.more { margin: 8px auto; }
.empty, .loading-row { padding: 16px; text-align: center; }

.reader { grid-area: reader; overflow: auto; background: var(--panel); }
#message { padding: 16px 20px; display: flex; flex-direction: column; min-height: 100%; }
#m-subject { margin: 0 0 12px; font-size: 20px; }
.m-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.m-from { font-weight: 600; }
.m-date { margin-left: auto; white-space: nowrap; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.actions .btn { font-size: 13px; padding: 4px 10px; }
.sep { width: 1px; background: var(--border); margin: 0 4px; }
.banner { background: #fff4ce; color: #3b2f00; border: 1px solid #f2dc8f; border-radius: 4px; padding: 6px 10px; margin-bottom: 8px; font-size: 13px; }
.attachments { list-style: none; padding: 0; margin: 0 0 8px; display: flex; flex-wrap: wrap; gap: 8px; }
.att { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); border-radius: 4px; padding: 6px 10px; cursor: pointer; font: inherit; }
.att:hover { border-color: var(--brand); }
.att-name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-body { flex: 1; width: 100%; min-height: 420px; border: none; background: #fff; border-radius: 4px; }
.hint { font-size: 12px; }

dialog { border: 1px solid var(--border); border-radius: 8px; background: var(--panel); color: var(--text); padding: 20px; width: min(640px, 94vw); box-shadow: 0 8px 32px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dialog h3 { margin: 16px 0 6px; font-size: 14px; }
dialog label { display: block; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
dialog input:not([type=checkbox]), dialog textarea { display: block; width: 100%; font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 4px; padding: 6px 8px; margin-top: 3px; }
dialog textarea { resize: vertical; min-height: 160px; }
.check { display: flex !important; gap: 8px; align-items: flex-start; color: var(--text) !important; font-size: 14px !important; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #333; color: #fff; padding: 8px 16px; border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.3); z-index: 10; }

.only-narrow { display: none; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-areas: "top" "list"; }
  .folders { display: none; }
  .reader { display: none; }
  body.show-folders .folders { display: block; position: fixed; top: 52px; left: 0; bottom: 0; width: 240px; z-index: 5; box-shadow: 4px 0 16px rgba(0,0,0,.2); }
  body.reading .list-pane { display: none; }
  body.reading .reader { display: block; grid-area: list; }
  .only-narrow { display: inline-flex; }
  #back-btn { align-self: flex-start; margin-bottom: 8px; }
  .search select { display: none; }
  .user, #compose-btn { display: none; }
}

/* public pages */
.page { max-width: 860px; margin: 0 auto; padding: 32px 20px 64px; line-height: 1.6; }
.page header { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.page header a { color: inherit; text-decoration: none; font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 10px; }
.page h1 { font-size: 30px; line-height: 1.2; }
.page h2 { margin-top: 32px; }
.hero { display: grid; grid-template-columns: 1.1fr 1fr; gap: 32px; align-items: center; }
.hero img.shot { width: 100%; border-radius: 8px; border: 1px solid var(--border); box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; padding: 0; list-style: none; }
.features li { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; }
.cta { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0; }
footer.site { margin-top: 48px; padding-top: 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
@media (max-width: 760px) { .hero { grid-template-columns: 1fr; } }
.pill { font-size: 12px; background: #fff4ce; color: #3b2f00; border: 1px solid #f2dc8f; border-radius: 12px; padding: 2px 10px; text-decoration: none; white-space: nowrap; }
