:root {
  --bg: #f4f2ed;
  --panel: #ffffff;
  --ink: #1c2226;
  --muted: #6b747a;
  --line: #e4e1d9;
  --accent: #1f6f5c;
  --accent-soft: #e3f1ec;
  --danger: #b4412f;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); font-size: 14px; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- login ---------- */
#login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
#login-form { width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 12px; }
#login-form h1 { margin: 0; font-size: 22px; }
#login-form p { margin: 0 0 6px; color: var(--muted); }
#login-form input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
#login-form button { padding: 10px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; }
#login-err { color: var(--danger); min-height: 18px; font-size: 13px; }

/* ---------- layout ---------- */
#app { height: 100vh; display: grid; grid-template-columns: 228px 380px minmax(0, 1fr); }
#side, #list, #thread { min-height: 0; overflow: auto; }
#side { padding: 16px 12px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
#list { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
#thread { background: var(--panel); display: flex; flex-direction: column; }

/* ---------- sidebar ---------- */
.brand { font-weight: 700; font-size: 16px; padding: 2px 8px 10px; display: flex; justify-content: space-between; align-items: center; }
.brand button { border: 0; background: none; color: var(--muted); font-size: 12px; }
.side-select { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; margin-bottom: 8px; }
.nav-h { margin: 14px 8px 4px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.nav { display: flex; justify-content: space-between; align-items: center; width: 100%; padding: 7px 10px; border: 0; border-radius: 8px; background: none; text-align: left; }
.nav:hover { background: rgba(0, 0, 0, .04); }
.nav.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .n { font-size: 12px; color: var(--muted); }
.nav.on .n { color: var(--accent); }
.sync { margin-top: auto; padding: 12px 8px 0; font-size: 12px; color: var(--muted); line-height: 1.5; }

.linkbtn { border: 0; background: none; padding: 0; margin-top: 4px; color: var(--accent); font-size: 12px; text-decoration: underline; }
.speed { margin-top: 6px; font-size: 11px; line-height: 1.5; }

/* ---------- list ---------- */
.list-head { padding: 12px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; position: sticky; top: 0; background: var(--panel); z-index: 2; }
.list-head input { flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.list-head button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 0 10px; }
.crumb { padding: 8px 14px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; }
.crumb button { border: 0; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 2px 8px; font-size: 12px; }
.row { display: grid; grid-template-columns: 34px 1fr auto; gap: 4px 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.row:hover { background: #faf9f6; }
.row.sel { background: var(--accent-soft); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: #e8e5dc; display: grid; place-items: center; font-weight: 600; color: #4a5258; grid-row: span 3; }
.row .top { display: flex; justify-content: space-between; gap: 8px; min-width: 0; }
.row .who { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.unread .who, .row.unread .subj { font-weight: 700; }
.row.unread .who::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-right: 6px; }
.row .time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.row .subj, .row .snip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; grid-column: 2 / 4; }
.row .snip { color: var(--muted); }
.row .meta { grid-column: 2 / 4; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--muted); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.more { margin: 14px; padding: 9px; border: 1px solid var(--line); background: #fff; border-radius: 8px; }

/* ---------- pills / chips ---------- */
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eee; color: #444; }
.s-lead { background: #ece6f7; color: #5b3f97; }
.s-int { background: #dff1e4; color: #1f6b3a; }
.s-book { background: #dbe9fb; color: #1f4f8f; }
.s-done { background: #d9f0ee; color: #17625a; }
.s-ooo { background: #e6e9ec; color: #4b5560; }
.s-wrong { background: #fbebcc; color: #8a5a00; }
.s-no { background: #eceae5; color: #6b6f73; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 6px; font-size: 12px; background: #f0eee8; color: #4a4f53; }
.tag button { border: 0; background: none; padding: 0; line-height: 1; color: var(--muted); }
.acct { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }

/* ---------- thread ---------- */
.t-empty { margin: auto; color: var(--muted); }
.t-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.t-head h2 { margin: 0; font-size: 18px; line-height: 1.3; }
.t-sub { color: var(--muted); font-size: 13px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.t-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.t-actions select, .t-actions button { padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.t-actions .primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.tags-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tags-row input { border: 1px dashed var(--line); border-radius: 6px; padding: 2px 8px; width: 130px; font-size: 12px; }
.note { width: 100%; min-height: 54px; resize: vertical; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fffdf6; font-size: 13px; }
.t-body { flex: 1 1 auto; min-height: 260px; overflow: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { flex: none; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.msg.out { background: #f6faf8; border-color: #d3e6df; }
.msg-h { padding: 8px 12px; display: flex; justify-content: space-between; gap: 10px; font-size: 13px; border-bottom: 1px solid var(--line); }
.msg-h .d { color: var(--muted); white-space: nowrap; }
.msg iframe { width: 100%; border: 0; display: block; height: 80px; background: transparent; }
.atts { padding: 8px 12px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }

.composer { border-top: 1px solid var(--line); padding: 12px 20px 16px; display: grid; gap: 8px; background: #fbfaf7; }
.composer .line { display: grid; grid-template-columns: 56px 1fr; align-items: center; gap: 8px; }
.composer label { color: var(--muted); font-size: 12px; }
.composer input, .composer textarea { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; width: 100%; }
.composer textarea { min-height: 120px; resize: vertical; }
.composer .bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.composer .send { padding: 9px 18px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; }
.composer .send[disabled] { opacity: .6; cursor: wait; }
.composer .hint { color: var(--muted); font-size: 12px; }
.back { display: none; border: 0; background: none; color: var(--accent); padding: 0; font-weight: 600; }

#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: #1c2226; color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; z-index: 20; }
#toast.on { opacity: 1; }
#toast.err { background: var(--danger); }

/* ---------- small screens ---------- */
.only-mobile { display: none; }
@media (max-width: 1100px) { #app { grid-template-columns: 200px 330px minmax(0, 1fr); } }
@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  #side { display: none; }
  #thread { display: none; }
  #app.show-thread #list { display: none; }
  #app.show-thread #thread { display: flex; }
  .back { display: inline-block; }
  .only-mobile { display: block; width: 100%; margin: 0; }
  #thread { overflow: auto; }
  .t-body { flex: none; overflow: visible; min-height: 0; }
  .msg-h { flex-wrap: wrap; }
  .composer { padding: 12px 14px 16px; }
  #list .list-head { flex-wrap: wrap; }
}

.s-custom { background: #e6e9f5; color: #34428a; }
.addst { font-size: 12px; margin: 2px 0 6px 12px; }
.ver { font-weight: 600; margin-right: 6px; }
