:root {
  --bg: #fff; --fg: #1f2328; --mut: #667085; --line: #e4e7eb; --hover: #f0f3f6;
  --sel: #dfeaff; --acc: #1a5fd0; --read: #f6f8fa; --nav: #f6f8fa; --warn: #fff4d6; --star: #e8a400;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191d; --fg: #e4e6ea; --mut: #98a2b3; --line: #2b3038; --hover: #22262d;
    --sel: #1c3157; --acc: #82b1ff; --read: #121417; --nav: #121417; --warn: #4a3b10;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--fg); background: var(--bg);
  display: grid; grid-template: 52px 1fr / 220px 1fr; grid-template-areas: "top top" "nav main"; overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--acc); }
[hidden] { display: none !important; }
.mut { color: var(--mut); }
.grow { flex: 1; }

.btn, .ico, .link { background: none; border: 1px solid transparent; border-radius: 6px; padding: 5px 10px; }
.btn { border-color: var(--line); }
.btn:hover, .ico:hover { background: var(--hover); }
.ico { padding: 4px 8px; font-size: 16px; line-height: 1; }
.link { color: var(--acc); padding: 2px 4px; }
.primary { background: var(--acc); color: #fff; border: 0; border-radius: 6px; padding: 7px 18px; font-weight: 600; }
@media (prefers-color-scheme: dark) { .primary { color: #0b1220; } }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 1px; }

#top { grid-area: top; display: flex; align-items: center; gap: 12px; padding: 0 12px; border-bottom: 1px solid var(--line); }
#menu-btn { display: none; }
.logo { font-weight: 700; font-size: 18px; text-decoration: none; color: var(--fg); width: 196px; }
#search { flex: 1; max-width: 640px; }
#q { width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--read); }
#who { margin-left: auto; display: flex; align-items: center; gap: 6px; min-width: 0; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; background: none; white-space: nowrap; font-size: 13px; }
.chip.on { background: var(--sel); border-color: var(--acc); }
.chip.bad { border-color: #d33; color: #d33; }
.tag.bad { color: #b3261e; border-color: currentColor; }
.tag.meh { color: #8a5a00; border-color: currentColor; }
.tag { font-size: 11px; border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; color: var(--mut); margin-left: 6px; font-weight: 400; }

#nav { grid-area: nav; background: var(--nav); padding: 12px 8px; overflow-y: auto; border-right: 1px solid var(--line); }
#compose-btn { width: 100%; padding: 10px; border: 0; border-radius: 8px; background: var(--acc); color: #fff; font-weight: 600; margin-bottom: 10px; }
@media (prefers-color-scheme: dark) { #compose-btn { color: #0b1220; } }
#nav a { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 6px; color: var(--fg); text-decoration: none; }
#nav a:hover { background: var(--hover); }
#nav a.on { background: var(--sel); font-weight: 600; }
#nav a span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#nav a b { font-size: 12px; }
#nav h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--mut); margin: 14px 10px 4px; font-weight: 600; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }

#main { grid-area: main; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#bar { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-bottom: 1px solid var(--line); min-height: 44px; flex: none; }
#bar .count { margin-left: auto; color: var(--mut); font-size: 13px; white-space: nowrap; }
#list, #thread, #settings { flex: 1; overflow-y: auto; outline: none; }

.row {
  display: grid; grid-template-columns: 30px 26px 190px 1fr auto 74px; align-items: center; height: 38px; padding: 0 12px 0 9px;
  border-bottom: 1px solid var(--line); border-left: 3px solid transparent; cursor: pointer; background: var(--read); position: relative;
}
.row.unread { background: var(--bg); }
.row.unread .subj, .row.unread .date { font-weight: 600; }
.row.sel { background: var(--sel); }
.row.cur { border-left-color: var(--acc); }
.row:hover { box-shadow: inset 0 0 0 1px var(--line); z-index: 1; }
.row > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .from i { font-style: normal; color: var(--mut); font-size: 12px; }
.row .subj { padding-right: 8px; }
.row .date { text-align: right; font-size: 12px; color: var(--mut); }
.row.unread .date { color: var(--fg); }
.row .clip { font-size: 12px; padding: 0 4px; }
.row .acts { display: none; position: absolute; right: 8px; top: 3px; background: inherit; padding-left: 8px; }
.star { background: none; border: 0; padding: 0 2px; font-size: 16px; color: var(--mut); line-height: 1; }
.star.on { color: var(--star); }
.empty { padding: 60px 20px; text-align: center; color: var(--mut); }
.more { display: block; margin: 14px auto; }
@media (hover: hover) { .row:hover .acts { display: flex; gap: 2px; } }

#thread { padding: 0 20px 40px; }
#thread h2 { font-size: 20px; font-weight: 500; margin: 16px 0 12px; overflow-wrap: anywhere; }
.msg { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; }
.msg > header { display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer; }
.msg .av { width: 32px; height: 32px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-weight: 600; flex: none; }
.msg .hd { flex: 1; min-width: 0; }
.msg .hd div { color: var(--mut); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .em { color: var(--mut); font-size: 12px; }
.msg time { color: var(--mut); font-size: 12px; white-space: nowrap; }
.msg .body { display: none; padding: 4px 14px 14px 54px; }
.msg.open .body { display: block; }
.msg:not(.open) .tools, .msg:not(.open) .em, .msg:not(.open) .chk { display: none; }
.vchip { border: 1px solid currentColor; border-radius: 10px; background: none; font-size: 11px; padding: 0 7px; line-height: 17px; vertical-align: 1px; }
.vchip.ok, .res.ok { color: #1a7f37; } .vchip.bad, .res.bad { color: #d33; } .vchip.meh, .res.meh { color: #8a6d1f; }
.inspect { border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; margin-bottom: 12px; font-size: 13px; background: var(--read); }
.inspect table { border-collapse: collapse; width: 100%; }
.inspect th { text-align: left; font-weight: 600; padding: 4px 12px 4px 0; vertical-align: top; white-space: nowrap; width: 1%; }
.inspect td { padding: 4px 0; }
.inspect .res { font-weight: 600; }
.inspect .why { color: var(--mut); font-size: 12px; }
.inspect .conn { margin-top: 6px; font-size: 12px; overflow-wrap: anywhere; }
.inspect .link { padding-left: 0; font-size: 12px; }
.msg.unread .hd b::after { content: " •"; color: var(--acc); }
.text { white-space: pre-wrap; overflow-wrap: anywhere; }
.quote { color: var(--mut); border-left: 2px solid var(--line); padding-left: 10px; margin-top: 6px; }
.fold { border: 0; background: var(--hover); border-radius: 6px; padding: 0 8px; margin-top: 6px; line-height: 14px; }
.note { background: var(--warn); border-radius: 6px; padding: 6px 10px; margin-bottom: 10px; font-size: 13px; }
iframe.html { width: 100%; border: 0; background: #fff; border-radius: 4px; display: block; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.atts a, .cfile { border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; text-decoration: none; color: var(--fg); font-size: 13px; }
.atts a:hover { background: var(--hover); }
.replybar { display: flex; gap: 8px; padding: 8px 0 0 54px; }

#composer {
  position: fixed; right: 20px; bottom: 0; width: min(560px, 100vw); height: min(600px, calc(100vh - 60px)); z-index: 20;
  background: var(--bg); border: 1px solid var(--line); border-bottom: 0; border-radius: 10px 10px 0 0;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .25); display: flex; flex-direction: column;
}
.c-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 14px; background: var(--nav); border-radius: 10px 10px 0 0; font-weight: 600; }
.c-row { display: flex; align-items: center; gap: 8px; padding: 0 14px; border-bottom: 1px solid var(--line); }
.c-row span { color: var(--mut); width: 52px; flex: none; font-size: 13px; }
.c-row input, .c-row select { flex: 1; border: 0; background: none; padding: 8px 0; outline: none; min-width: 0; }
#c-text { flex: 1; border: 0; resize: none; padding: 12px 14px; outline: none; background: none; line-height: 1.5; }
#c-files { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px; }
.cfile button { border: 0; background: none; padding: 0 0 0 6px; color: var(--mut); }
.c-foot { display: flex; align-items: center; gap: 8px; padding: 10px 14px; }

#toast {
  position: fixed; left: 20px; bottom: 20px; background: #24292f; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 30;
  display: flex; gap: 14px; align-items: center; box-shadow: 0 4px 16px rgba(0, 0, 0, .3);
}
#toast button { background: none; border: 0; color: #8ab4ff; font-weight: 600; padding: 0; }
#pop {
  position: fixed; z-index: 40; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 4px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .2); max-height: 60vh; overflow-y: auto; min-width: 180px;
}
#pop button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 7px 12px; border-radius: 5px; }
#pop button:hover { background: var(--hover); }
#pop hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

dialog { border: 1px solid var(--line); border-radius: 12px; padding: 22px; background: var(--bg); color: var(--fg); max-width: min(92vw, 640px); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { margin: 0 0 8px; font-size: 18px; }
#login { width: 360px; }
#login label { display: block; margin-top: 12px; font-size: 13px; color: var(--mut); }
#login input { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
#login .wide { display: block; width: 100%; margin-top: 12px; padding: 9px 18px; }
#login .or { text-align: center; margin: 14px 0 0; font-size: 13px; }
.err { color: #d33; min-height: 1.4em; margin: 8px 0 0; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
#help td { padding: 4px 10px 4px 0; vertical-align: top; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font: 12px ui-monospace, monospace; background: var(--read); }

@media (max-width: 760px) {
  body { grid-template-columns: 1fr; grid-template-areas: "top" "main"; }
  #menu-btn { display: block; }
  .logo { display: none; }
  #nav { display: none; position: fixed; top: 52px; bottom: 0; left: 0; width: 250px; z-index: 15; box-shadow: 0 0 40px rgba(0, 0, 0, .4); }
  body.nav-open #nav { display: block; }
  .row { grid-template-columns: 30px 26px 1fr auto 60px; grid-template-rows: 20px 20px; height: 52px; }
  .row .from { grid-column: 3; grid-row: 1; }
  .row .subj { grid-column: 3 / 5; grid-row: 2; }
  .row .clip { grid-column: 4; grid-row: 1; }
  .row .date { grid-column: 5; grid-row: 1; }
  #who .chip:not(.on):not(.all) { display: none; }
  #thread { padding: 0 10px 40px; }
  .msg .body, .replybar { padding-left: 14px; }
  #composer { right: 0; height: calc(100vh - 52px); }
}

/* settings and admin */
#nav a.settings-link { margin-top: 14px; border-top: 1px solid var(--line); border-radius: 0 0 6px 6px; }
#bar .tab { padding: 5px 12px; border-radius: 6px; color: var(--fg); text-decoration: none; }
#bar .tab:hover { background: var(--hover); }
#bar .tab.on { background: var(--sel); font-weight: 600; }
#settings { padding: 4px 20px 60px; }
#settings section { max-width: 900px; border-bottom: 1px solid var(--line); padding: 4px 0 18px; }
#settings section:last-child { border-bottom: 0; }
#settings h2 { font-size: 16px; margin: 18px 0 8px; }
#settings p { margin: 6px 0; }
#settings table { border-collapse: collapse; width: 100%; margin: 8px 0; }
#settings th, #settings td { text-align: left; padding: 6px 10px 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
#settings th { font-size: 12px; font-weight: 600; color: var(--mut); }
#settings tr:last-child td { border-bottom: 0; }
#settings td.acts { white-space: nowrap; }
#settings code { font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
#settings input:not([type=checkbox]), #settings select { padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); min-width: 0; }
#settings input.num { width: 70px; }
#settings .stack { display: grid; gap: 6px; max-width: 560px; margin-top: 10px; }
#settings .stack label { display: grid; gap: 2px; }
#settings .stack .btn { justify-self: start; }
#settings .frow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; }
#settings .check { display: inline-flex; align-items: center; gap: 6px; }
#settings .small { font-size: 12.5px; }
#settings ul.plain { list-style: none; padding: 0; margin: 6px 0; }
#settings ul.plain li { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
#settings details.domain { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
#settings details.domain summary { cursor: pointer; }
.danger { color: #d33; }
.btn.danger { border-color: #d33; }
.newpw { background: var(--warn); border-radius: 8px; padding: 10px 14px; margin: 10px 0; }
.newpw code#newpw { font-size: 16px; letter-spacing: .04em; }
.st-ok { color: #1a7f37; } .st-missing { color: #d33; } .st-wrong, .st-split { color: #b7791f; }
#settings details.quoted { margin-top: 6px; }
#settings details.quoted summary { cursor: pointer; color: var(--acc); font-size: 12.5px; }
@media (prefers-color-scheme: dark) { .vchip.ok, .res.ok { color: #56d364; } .vchip.meh, .res.meh { color: #e3b341; } .st-ok { color: #56d364; } .st-wrong, .st-split { color: #e3b341; } }
@media (max-width: 760px) { #settings { padding: 4px 10px 60px; } #settings table { display: block; overflow-x: auto; } }

#settings .sigs label { display: block; font-weight: 600; margin-bottom: 6px; }
#settings .sigs textarea { display: block; width: 100%; max-width: 520px; margin-top: 4px; font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
#settings .sigs details { margin: 6px 0; }
#settings .sigs summary { cursor: pointer; color: var(--acc); }

#folders a.drop { background: var(--sel); outline: 2px dashed var(--acc); outline-offset: -2px; }
.drag-ghost { position: fixed; top: -100px; left: 0; padding: 6px 12px; border-radius: 6px; background: var(--acc); color: #fff; font-weight: 600; max-width: 300px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#composer.drop { outline: 3px dashed var(--acc); outline-offset: -3px; }
body.drop-files::after { content: "Drop files to start a new message with them attached"; position: fixed; inset: 12px; display: grid; place-items: center; border: 3px dashed var(--acc); border-radius: 12px; background: color-mix(in srgb, var(--bg) 85%, transparent); font-size: 18px; font-weight: 600; pointer-events: none; z-index: 50; }
