:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #eef0f3;
  --text: #15181d;
  --muted: #6b7280;
  --line: #e2e5ea;
  --accent: #2f6fed;
  --accent-soft: #e7eefc;
  --danger: #d94040;
  --unread-bg: #ffffff;
  --read-bg: #f9fafb;
  --radius: 10px;
  --sidebar-w: 240px;
  --list-w: 380px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --panel: #171a21;
    --panel-2: #1f232c;
    --text: #e8eaef;
    --muted: #8b93a1;
    --line: #262b35;
    --accent: #5b8cff;
    --accent-soft: #1d2a4a;
    --danger: #ff6b6b;
    --unread-bg: #171a21;
    --read-bg: #13161c;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.error { color: var(--danger); min-height: 1.2em; font-size: 13px; }

/* ---------- login ---------- */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); padding: 20px; }
.login-card {
  width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px; display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.login-card h1 { margin: 0; font-size: 28px; }
.login-card p { margin: 0 0 8px; color: var(--muted); }
.login-card input, .login-card button {
  padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); font-size: 16px;
}
.login-card button { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) var(--list-w) 1fr; height: 100%; height: 100dvh; }
.sidebar, .list, .reader { min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); }
.list { background: var(--panel); border-right: 1px solid var(--line); }
.reader { background: var(--bg); }

.icon-btn {
  width: 36px; height: 36px; border-radius: 9px; display: inline-grid; place-items: center; font-size: 18px; color: var(--muted);
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn.active { color: #f5b301; }
.link-btn { color: var(--muted); font-size: 13px; padding: 6px 8px; }
.link-btn:hover { color: var(--text); }
.mobile-only { display: none; }

/* ---------- sidebar ---------- */
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 8px 16px; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: -0.2px; }
.accounts, .views { display: flex; flex-direction: column; padding: 6px 8px; gap: 2px; }
.views { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; }
.acct, .view {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; text-align: left; width: 100%;
}
.acct:hover, .view:hover { background: var(--panel-2); }
.acct.active, .view.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.acct .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 10px; }
.acct .all-dot { background: conic-gradient(#4f8cff, #ff7a59, #2fbf71, #b06cff, #4f8cff); }
.acct .label, .view span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct .sub { display: block; font-size: 11px; color: var(--muted); font-weight: 400; overflow: hidden; text-overflow: ellipsis; }
.acct .count, .view .count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.acct.active .count { color: var(--accent); }
.acct .warn { color: var(--danger); font-size: 12px; }
.acct .spin { width: 10px; height: 10px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.sidebar-foot { margin-top: auto; padding: 10px 12px 14px; display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--line); }
.add-account { text-decoration: none; font-weight: 600; font-size: 14px; padding: 8px; border-radius: 9px; }
.add-account:hover { background: var(--panel-2); }

/* ---------- list ---------- */
.list-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 6px; }
.search { position: relative; flex: 1; }
.search input {
  width: 100%; padding: 9px 32px 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); font-size: 15px;
  -webkit-appearance: none; appearance: none;
}
.search input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.search .clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 26px; height: 26px; border-radius: 50%; color: var(--muted); font-size: 18px; }
.list-title { padding: 4px 16px 8px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }
.threads { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.thread {
  display: grid; grid-template-columns: 4px 1fr auto; gap: 0 10px; padding: 10px 14px 10px 10px;
  border-bottom: 1px solid var(--line); cursor: pointer; background: var(--read-bg); width: 100%; text-align: left;
}
.thread .bar { grid-row: 1 / span 3; border-radius: 2px; background: transparent; }
.thread.unread { background: var(--unread-bg); }
.thread.unread .from, .thread.unread .subject { font-weight: 700; }
.thread:hover { background: var(--panel-2); }
.thread.active { background: var(--accent-soft); }
.thread .from { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.thread .from .n { color: var(--muted); font-weight: 400; font-size: 12px; }
.thread .date { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.thread .subject { grid-column: 2 / span 2; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread .snippet { grid-column: 2 / span 2; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread .icons { display: inline-flex; gap: 4px; font-size: 12px; color: var(--muted); }
.thread .star { color: #f5b301; }
.thread .acct-tag { font-size: 11px; padding: 1px 6px; border-radius: 999px; color: #fff; font-weight: 600; margin-left: auto; }
.list-foot { padding: 10px; text-align: center; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); }
.list-foot button { color: var(--accent); font-weight: 600; padding: 6px 10px; border-radius: 8px; }
.list-foot button:hover { background: var(--panel-2); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty a { font-weight: 600; }

/* ---------- reader ---------- */
.reader-empty { margin: auto; color: var(--muted); }
.reader-body { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.reader-head { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.reader-actions { display: flex; gap: 2px; margin-left: auto; }
.reader-subject { font-size: 20px; margin: 16px 20px 8px; font-weight: 650; letter-spacing: -0.2px; }
.messages { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 16px 40px; }
.msg { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; margin: 10px 0; overflow: hidden; }
.msg-head { display: grid; grid-template-columns: 36px 1fr auto; gap: 10px; padding: 12px 14px; cursor: pointer; align-items: center; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px; }
.msg-head .who { min-width: 0; }
.msg-head .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-head .meta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-head .date { font-size: 12px; color: var(--muted); white-space: nowrap; }
.msg.collapsed .msg-content { display: none; }
.msg.collapsed .msg-head .meta { white-space: nowrap; }
.msg-content { border-top: 1px solid var(--line); }
.msg-tools { display: flex; gap: 8px; padding: 6px 14px; font-size: 12px; color: var(--muted); align-items: center; flex-wrap: wrap; }
.msg-tools button { color: var(--accent); font-weight: 600; padding: 4px 6px; border-radius: 6px; }
.msg-tools button:hover { background: var(--panel-2); }
.msg-frame { width: 100%; border: 0; display: block; background: #fff; min-height: 60px; }
.msg-text { white-space: pre-wrap; padding: 14px; font-size: 15px; line-height: 1.5; word-wrap: break-word; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 14px 14px; border-top: 1px solid var(--line); }
.attachment {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 9px; background: var(--panel-2);
  text-decoration: none; color: var(--text); font-size: 13px; max-width: 100%;
}
.attachment .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.attachment .size { color: var(--muted); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 50; box-shadow: 0 6px 24px rgba(0,0,0,0.25);
}

/* ---------- phone / narrow ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .mobile-only { display: inline-grid; }
  .sidebar, .list, .reader { display: none; border-right: 0; }
  body[data-pane="sidebar"] .sidebar { display: flex; }
  body[data-pane="list"] .list { display: flex; }
  body[data-pane="reader"] .reader { display: flex; }
  .list-head { padding-top: calc(10px + env(safe-area-inset-top)); }
  .sidebar-head { padding-top: calc(14px + env(safe-area-inset-top)); }
  .reader-head { padding-top: calc(8px + env(safe-area-inset-top)); }
  .sidebar-foot { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .messages { padding: 0 10px 60px; }
  .reader-subject { margin: 12px 14px 4px; font-size: 18px; }
  .thread { padding: 12px 14px 12px 10px; }
  .acct, .view { padding: 12px 10px; font-size: 16px; }
}
