/* tokens ------------------------------------------------------------------ */
:root {
  --bg: #ffffff;
  --bg-2: #f7f7f8;
  --bg-3: #efeff1;
  --fg: #141416;
  --fg-2: #5b5b63;
  --fg-3: #9a9aa3;
  --line: #e6e6ea;
  --accent: #2f6fed;
  --accent-fg: #ffffff;
  --sel: #eef3ff;
  --p2: #e5484d;
  --p1: #e5a13a;
  --p0: #6c6c74;
  --danger: #d33;
  --font: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  --sidebar-w: 224px;
  --list-w: 400px;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101012;
    --bg-2: #17171a;
    --bg-3: #202024;
    --fg: #ececee;
    --fg-2: #a3a3ab;
    --fg-3: #6c6c74;
    --line: #25252a;
    --accent: #5b8cff;
    --sel: #1b2438;
    --p0: #8f8f98;
    --danger: #ff6b6b;
  }
}

/* base -------------------------------------------------------------------- */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 var(--font);
  color: var(--fg);
  background: var(--bg);
  font-feature-settings: "tnum";
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, p { margin: 0; }
kbd {
  font: 11px/1 var(--font); padding: 2px 5px;
  border: 1px solid var(--line); border-radius: 4px; color: var(--fg-3); background: var(--bg);
}
[hidden] { display: none !important; }
.muted { color: var(--fg-2); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
.link:hover { text-decoration: underline; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); cursor: pointer; white-space: nowrap;
  transition: background .1s;
}
.btn:hover { background: var(--bg-2); }
.btn:disabled { opacity: .4; cursor: default; }
.btn-primary { background: var(--fg); color: var(--bg); border-color: var(--fg); justify-content: center; }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-quiet { border-color: transparent; background: transparent; padding: 5px 9px; }
.btn-quiet:hover { background: var(--bg-3); }
.btn-quiet.danger:hover { color: var(--danger); }
.btn-icon { padding: 2px 8px; }
.select { padding: 4px 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); max-width: 130px; }

.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; flex: none; }
.dot.p2 { background: var(--p2); }
.dot.p1 { background: var(--p1); }
.dot.p0 { background: var(--p0); }

/* layout ------------------------------------------------------------------ */
#app { display: grid; grid-template-columns: var(--sidebar-w) var(--list-w) minmax(0, 1fr); height: 100vh; }
#sidebar, #list-pane, #reader { min-height: 0; }
#sidebar { display: flex; flex-direction: column; padding: 16px 12px 12px; background: var(--bg-2); border-right: 1px solid var(--line); }
#list-pane { display: flex; flex-direction: column; border-right: 1px solid var(--line); }
#reader { display: flex; flex-direction: column; overflow: hidden; }

/* sidebar ----------------------------------------------------------------- */
#btn-compose { width: 100%; margin-bottom: 16px; padding: 8px 12px; }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav-item, .folder {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px; border-radius: 6px; border: 0; background: none; width: 100%;
  text-align: left; color: var(--fg-2); cursor: pointer;
}
.nav-item:hover, .folder:hover { background: var(--bg-3); color: var(--fg); }
.nav-item.active, .folder.active { background: var(--bg); color: var(--fg); box-shadow: 0 0 0 1px var(--line); font-weight: 500; }
.nav-item .count, .folder .count { margin-left: auto; font-size: 12px; color: var(--fg-3); }
.folder .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder.has-unread .count { color: var(--fg); font-weight: 600; }
.nav-label { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--fg-3); padding: 18px 10px 6px; }
#folder-list { flex: 1; overflow-y: auto; }

.sidebar-foot { padding-top: 12px; display: flex; flex-direction: column; gap: 8px; font-size: 12px; }
.sync { color: var(--fg-2); }
.sync-line { display: flex; justify-content: space-between; margin-bottom: 4px; }
.bar { height: 3px; background: var(--bg-3); border-radius: 2px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.sync-sub { margin-top: 4px; color: var(--fg-3); }
.me { color: var(--fg-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* list -------------------------------------------------------------------- */
.search-wrap { position: relative; padding: 12px 12px 8px; }
.search-icon { position: absolute; left: 24px; top: 23px; color: var(--fg-3); pointer-events: none; }
#search {
  width: 100%; padding: 9px 36px 9px 34px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg-2); outline: none;
}
#search:focus { border-color: var(--accent); background: var(--bg); }
.search-wrap kbd { position: absolute; right: 22px; top: 22px; }
.list-head { display: flex; align-items: baseline; gap: 10px; padding: 4px 16px 8px; font-weight: 600; }
.list-head .muted { font-weight: 400; font-size: 12px; }

.list { flex: 1; overflow-y: auto; border-top: 1px solid var(--line); }
.list-empty { padding: 40px 20px; color: var(--fg-3); text-align: center; }
.row {
  display: grid; grid-template-columns: 14px 1fr auto; grid-template-areas: "dot from date" "dot subject icons" "dot snippet snippet";
  column-gap: 8px; row-gap: 1px; padding: 9px 14px 9px 10px;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.row:hover { background: var(--bg-2); }
.row.selected { background: var(--sel); }
.row .dot { grid-area: dot; align-self: start; margin-top: 6px; width: 6px; height: 6px; background: transparent; }
.row.unread .dot { background: var(--fg); }
.row.p2 .dot { background: var(--p2); }
.row.p1 .dot { background: var(--p1); }
.row .from { grid-area: from; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg-2); }
.row.unread .from { color: var(--fg); font-weight: 600; }
.row .date { grid-area: date; font-size: 12px; color: var(--fg-3); }
.row .subject { grid-area: subject; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg-2); }
.row.unread .subject { color: var(--fg); font-weight: 500; }
.row .snippet { grid-area: snippet; font-size: 12px; color: var(--fg-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .icons { grid-area: icons; display: flex; gap: 6px; justify-content: flex-end; align-items: center; color: var(--fg-3); font-size: 12px; }
.row .folder-chip { font-size: 11px; color: var(--fg-3); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
.row.noise { opacity: .6; }
.row .star { color: var(--p1); }
.list-foot { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px 8px 16px; border-top: 1px solid var(--line); font-size: 12px; }
.pager .btn { padding: 2px 10px; font-size: 16px; line-height: 1; }
.loading { padding: 40px; color: var(--fg-3); text-align: center; }

/* reader ------------------------------------------------------------------ */
.reader-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--fg-2); }
#message { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.group { display: flex; gap: 2px; align-items: center; flex-wrap: wrap; }
.msg-head { padding: 22px 28px 16px; border-bottom: 1px solid var(--line); }
.msg-subject { font-size: 20px; font-weight: 600; line-height: 1.3; margin-bottom: 14px; overflow-wrap: anywhere; }
.msg-from-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.msg-from { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; min-width: 0; }
.msg-rcpts { margin-top: 6px; display: flex; flex-direction: column; gap: 2px; }
.msg-rcpts .k { display: inline-block; width: 22px; color: var(--fg-3); }
.msg-rcpts .addr { color: var(--fg-3); }
.remote-bar { display: flex; gap: 10px; padding: 6px 28px; background: var(--bg-2); border-bottom: 1px solid var(--line); }
.msg-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#msg-frame { flex: 1; width: 100%; border: 0; background: #fff; }
.msg-text { flex: 1; overflow-y: auto; padding: 22px 28px 40px; font-size: 15px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-text .quote { color: var(--fg-3); border-left: 2px solid var(--line); padding-left: 10px; display: inline-block; }
.msg-text a { color: var(--accent); }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 28px; border-top: 1px solid var(--line); }
.attachment { display: inline-flex; gap: 8px; padding: 5px 10px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--fg); text-decoration: none; font-size: 13px; }
.attachment:hover { border-color: var(--accent); }
.attachment .size { color: var(--fg-3); font-size: 12px; }

/* compose ----------------------------------------------------------------- */
.compose {
  position: fixed; right: 20px; bottom: 0; z-index: 20; width: min(620px, calc(100vw - 40px));
  display: flex; flex-direction: column; border: 1px solid var(--line); border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0; background: var(--bg);
  box-shadow: 0 12px 40px -12px rgba(0,0,0,.35);
}
.compose.min .compose-form { display: none; }
.compose-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--line); font-weight: 600; }
.compose-form { display: flex; flex-direction: column; }
.field { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.field span { width: 60px; padding-left: 14px; color: var(--fg-3); font-size: 13px; }
.field input { flex: 1; border: 0; background: transparent; padding: 9px 14px 9px 0; outline: none; }
.field-toggles { display: flex; gap: 12px; padding: 4px 14px 0; justify-content: flex-end; }
.compose textarea { border: 0; background: transparent; padding: 12px 14px; outline: none; resize: vertical; min-height: 180px; line-height: 1.55; }
.compose-foot { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--line); }
.spacer { flex: 1; }
.compose-form.sending { opacity: .6; pointer-events: none; }

/* toast ------------------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 30;
  padding: 8px 14px; background: var(--fg); color: var(--bg); border-radius: var(--radius); font-size: 13px; max-width: 70vw;
}
.toast.error { background: var(--danger); color: #fff; }

/* search chips ------------------------------------------------------------ */
.chips { display: flex; gap: 6px; align-items: center; padding: 0 12px 8px; }
.chip { font-size: 12px; padding: 3px 9px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); color: var(--fg-2); cursor: pointer; }
.chip:hover { background: var(--bg-2); }
.chip.active { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.row .scope { font-size: 11px; color: var(--fg-3); }

/* settings + new-mail banner ---------------------------------------------- */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; }
.modal-card { width: min(520px, calc(100vw - 40px)); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 20px 60px -20px rgba(0,0,0,.5); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 10px 12px 18px; border-bottom: 1px solid var(--line); }
.settings-section { padding: 14px 18px; border-bottom: 1px solid var(--line); }
.settings-section:last-child { border-bottom: 0; }
.settings-title { font-weight: 600; margin-bottom: 2px; }
.sound-rows { display: grid; grid-template-columns: 1fr auto auto; gap: 6px 10px; align-items: center; margin-top: 10px; }
.sound-rows .lbl { display: flex; align-items: center; gap: 8px; }
.newmail {
  position: fixed; right: 20px; top: 16px; z-index: 30; max-width: 360px;
  padding: 10px 14px; background: var(--bg); color: var(--fg); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: var(--radius); box-shadow: 0 12px 30px -12px rgba(0,0,0,.4);
  cursor: pointer; font-size: 13px;
}
.newmail.p2 { border-left-color: var(--p2); }
.newmail.p1 { border-left-color: var(--p1); }
.newmail .nm-from { font-weight: 600; }
.newmail .nm-subject { color: var(--fg-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* feeds, accounts, tabs --------------------------------------------------- */
.nav-item .fdot { width: 8px; height: 8px; border-radius: 2px; flex: none; background: var(--fg-3); }
.acct-row { display: flex; align-items: center; gap: 8px; padding: 6px 10px; color: var(--fg-2); font-size: 13px; }
.acct-row .adot, .row .adot, .msg-acct .adot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }
.acct-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-row .toggle { background: none; border: 0; color: var(--fg-3); cursor: pointer; padding: 0 2px; }
.acct-labels { padding-left: 14px; }
.acct-labels .folder { padding: 4px 10px; font-size: 13px; }
.row .adot { margin-left: 6px; vertical-align: middle; }
.modal-card.wide { width: min(720px, calc(100vw - 40px)); max-height: calc(100vh - 60px); display: flex; flex-direction: column; }
.tab-page { overflow-y: auto; padding: 14px 18px; }
.tabs { display: flex; gap: 4px; }
.tab { background: none; border: 0; padding: 4px 10px; border-radius: 6px; color: var(--fg-2); cursor: pointer; font-weight: 500; }
.tab.active { background: var(--bg-3); color: var(--fg); }
.feed-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-top: 10px; }
.feed-head { display: flex; gap: 8px; align-items: center; }
.feed-head input[type=text] { flex: 1; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); outline: none; }
.feed-head input[type=color] { width: 28px; height: 28px; border: 1px solid var(--line); border-radius: 6px; padding: 0; background: none; }
.rule-row { display: grid; grid-template-columns: 110px 110px 1fr auto; gap: 6px; margin-top: 6px; align-items: center; }
.rule-row select, .rule-row input { padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); outline: none; font-size: 13px; }
.settings-actions { display: flex; gap: 8px; align-items: center; margin-top: 14px; }
.select-plain { flex: 1; border: 0; background: transparent; padding: 9px 14px 9px 0; outline: none; }
.msg-acct { margin-left: 8px; font-size: 12px; color: var(--fg-3); }

/* account settings -------------------------------------------------------- */
.acct-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.acct-item:last-child { border-bottom: 0; }
.acct-item .adot { width: 10px; height: 10px; border-radius: 50%; }
.acct-item .info { flex: 1; min-width: 0; }
.acct-item .email { font-weight: 500; }
.acct-item .sub { font-size: 12px; color: var(--fg-3); }
.account-form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.af-row { display: flex; gap: 8px; }
.af-row input[type=text], .af-row input[type=email], .af-row input[type=password], .af-row input[type=number] {
  flex: 1; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg-2); outline: none; min-width: 0;
}
.af-row input:focus { border-color: var(--accent); background: var(--bg); }
.af-row input[type=color] { width: 36px; height: 34px; border: 1px solid var(--line); border-radius: 6px; padding: 0; background: none; }
.af-servers { display: flex; flex-direction: column; gap: 8px; padding: 8px 0 0; }
.af-check { display: flex; gap: 8px; align-items: flex-start; }

/* tasks ------------------------------------------------------------------- */
.task { display: grid; grid-template-columns: 18px 1fr auto; gap: 8px 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); align-items: start; }
.task input[type=checkbox] { margin: 3px 0 0; }
.task .t-title { overflow-wrap: anywhere; }
.task.done .t-title { text-decoration: line-through; color: var(--fg-3); }
.task .t-meta { grid-column: 2; font-size: 12px; color: var(--fg-3); display: flex; gap: 8px; flex-wrap: wrap; }
.task .t-meta .link { font-size: 12px; }
.task .t-due { font-size: 12px; color: var(--fg-2); white-space: nowrap; }
.task .t-due.overdue { color: var(--p2); }
.task-add { display: flex; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.task-add input { flex: 1; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg-2); outline: none; }

/* narrow ------------------------------------------------------------------ */
@media (max-width: 1100px) { :root { --sidebar-w: 200px; --list-w: 340px; } }
@media (max-width: 860px) {
  #app { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  #reader { display: none; }
  body.reading #list-pane { display: none; }
  body.reading #reader { display: flex; }
}
