:root {
  --bg: #0d0e10;
  --panel: #141619;
  --panel-2: #1a1d21;
  --hover: #1f2327;
  --line: #262a30;
  --line-2: #30353c;
  --text: #ebe8e4;
  --muted: #8d939b;
  --faint: #5f656d;
  --accent: #ff7b00;
  --accent-2: #ff9a3d;
  --accent-soft: rgba(255, 123, 0, 0.12);
  --ok: #3fb950;
  --ok-soft: rgba(63, 185, 80, 0.12);
  --bad: #f85149;
  --bad-soft: rgba(248, 81, 73, 0.12);
  --warn: #d29922;
  --warn-soft: rgba(210, 153, 34, 0.12);
  --radius: 10px;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-2); }
[hidden] { display: none !important; }
::selection { background: rgba(255, 123, 0, 0.35); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2a2e34; border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: #3a3f46; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: 8px;
  background: var(--panel-2); cursor: pointer; white-space: nowrap; text-decoration: none; color: inherit;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--hover); border-color: #3b4148; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #140a00; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger { color: var(--bad); }
.btn.danger.armed { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 32px; padding: 0; justify-content: center; }
.btn.on { border-color: var(--accent); color: var(--accent-2); background: var(--accent-soft); }

.input, select.input, textarea.input {
  width: 100%; height: 36px; padding: 0 12px;
  background: var(--bg); border: 1px solid var(--line-2); border-radius: 8px; outline: none;
  transition: border-color .12s, box-shadow .12s;
}
textarea.input { height: auto; padding: 8px 12px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.affix { display: flex; align-items: stretch; }
.affix .input { border-radius: 8px 0 0 8px; }
.affix .input.right { border-radius: 0 8px 8px 0; }
.affix span {
  display: flex; align-items: center; padding: 0 10px;
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--muted); font-family: var(--mono); font-size: 13px;
}
.affix span:last-child { border-left: 0; border-radius: 0 8px 8px 0; }
.affix span:first-child { border-right: 0; border-radius: 8px 0 0 8px; }
label.field { display: grid; gap: 6px; margin-bottom: 14px; }
label.field > b { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.hint { color: var(--faint); font-size: 12px; }

.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch i { width: 36px; height: 20px; border-radius: 20px; background: var(--line-2); position: relative; transition: background .15s; flex: none; }
.switch i::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(16px); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 8px; border-radius: 6px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
}
.badge.ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.badge.bad { color: var(--bad); background: var(--bad-soft); border-color: transparent; }
.badge.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.badge.accent { color: var(--accent-2); background: var(--accent-soft); border-color: transparent; }
.count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; background: var(--accent); color: #140a00;
}
.count.muted { background: var(--line); color: var(--muted); }

.avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none; object-fit: cover;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff; background: #333;
}
.avatar.lg { width: 40px; height: 40px; font-size: 15px; }
.avatar.sm { width: 20px; height: 20px; font-size: 10px; }

/* ---------- login ---------- */
.login {
  height: 100%; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(600px 300px at 50% -10%, rgba(255, 123, 0, .18), transparent 70%),
    var(--bg);
}
.login form {
  width: min(360px, 100%); padding: 32px 28px; border-radius: 16px;
  background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
}
.login h1 { margin: 16px 0 4px; font-size: 20px; }
.login p { margin: 0 0 22px; color: var(--muted); }
.login .btn { width: 100%; height: 38px; justify-content: center; margin-top: 4px; }
.login .error { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 10px; }
.logo { width: 44px; height: 44px; border-radius: 12px; background: var(--accent); display: grid; place-items: center; }
.logo svg { width: 26px; height: 26px; }

/* ---------- shell ---------- */
.shell { height: 100%; display: grid; grid-template-rows: 56px 1fr; }
.top {
  display: flex; align-items: center; gap: 14px; padding: 0 16px;
  padding-top: env(safe-area-inset-top, 0px);
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; white-space: nowrap; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; }
.brand .logo svg { width: 18px; height: 18px; }
.brand small { font-weight: 500; color: var(--muted); }
.search { flex: 1; max-width: 520px; position: relative; }
.search .input { padding-left: 34px; background: var(--panel-2); border-color: var(--line); }
.search svg { position: absolute; left: 11px; top: 10px; width: 16px; height: 16px; color: var(--faint); }
.top .spacer { flex: 1; }
.live { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.live.on i { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.menu-btn { display: none; }

.panes { display: grid; grid-template-columns: 272px minmax(300px, 400px) 1fr; min-height: 0; }
.pane { min-height: 0; display: flex; flex-direction: column; }
.pane + .pane { border-left: 1px solid var(--line); }

/* ---------- sidebar ---------- */
.side { background: var(--panel); overflow-y: auto; padding: 12px 10px 24px; }
.side .new { width: 100%; justify-content: center; height: 36px; margin-bottom: 14px; }
.nav-title {
  display: flex; align-items: center; justify-content: space-between;
  margin: 18px 8px 6px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--faint);
}
.nav-item {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border: 0; border-radius: 8px; background: none; cursor: pointer; text-align: left;
  color: var(--text);
}
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--accent-soft); }
.nav-item.active .nav-label { color: var(--accent-2); }
.nav-item .ico { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--panel-2); flex: none; font-size: 14px; }
.nav-label { flex: 1; min-width: 0; }
.nav-label div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-label small { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item.paused .nav-label div { color: var(--muted); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 4px 0 6px; }
.stat { padding: 10px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); }
.stat b { display: block; font-size: 18px; }
.stat span { color: var(--muted); font-size: 12px; }
.sync { margin: 18px 8px 0; color: var(--faint); font-size: 12px; }

/* ---------- list ---------- */
.list { background: var(--bg); }
.list-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.list-head h2 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.list-head .sub { color: var(--muted); font-size: 12px; margin-top: 2px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.list-head .sub code { font-family: var(--mono); color: var(--text); cursor: pointer; }
.list-head .sub code:hover { color: var(--accent-2); }
.list-head .actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.items { flex: 1; overflow-y: auto; }
.item {
  display: block; width: 100%; padding: 12px 16px 12px 20px; border: 0; border-bottom: 1px solid var(--line);
  background: none; text-align: left; cursor: pointer; position: relative;
}
.item:hover { background: var(--panel); }
.item.active { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.item.unread::before { content: ''; position: absolute; left: 8px; top: 18px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.item .row1 { display: flex; align-items: baseline; gap: 8px; }
.item .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.item.unread .who { color: var(--text); font-weight: 600; }
.item time { color: var(--faint); font-size: 12px; flex: none; }
.item .subj { margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.unread .subj { font-weight: 600; }
.item .snip { margin-top: 2px; color: var(--faint); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .tags { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.item .tags .badge { height: 20px; font-size: 11px; }
.empty { padding: 48px 24px; text-align: center; color: var(--faint); }
.empty b { display: block; color: var(--muted); font-size: 15px; margin-bottom: 4px; }
.more { margin: 12px auto 20px; display: flex; }

/* ---------- reader ---------- */
.reader { background: var(--panel); min-width: 0; }
.reader-empty { flex: 1; display: grid; place-items: center; color: var(--faint); text-align: center; }
.reader-empty svg { width: 64px; height: 64px; opacity: .35; margin-bottom: 10px; }
.reader-head { padding: 18px 22px 14px; border-bottom: 1px solid var(--line); }
.reader-head h1 { margin: 0 0 14px; font-size: 20px; line-height: 1.3; word-break: break-word; }
.from { display: flex; gap: 12px; align-items: flex-start; }
.from .meta { flex: 1; min-width: 0; }
.from .name { font-weight: 600; word-break: break-word; }
.from .name span { color: var(--muted); font-weight: 400; font-family: var(--mono); font-size: 13px; }
.from .line { color: var(--muted); font-size: 13px; word-break: break-word; }
.from .line b { color: var(--faint); font-weight: 500; }
.from time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.chips { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; align-items: center; }
.toolbar { display: flex; gap: 6px; padding: 10px 22px; border-bottom: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.toolbar .spacer { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.seg button { height: 30px; padding: 0 12px; border: 0; background: var(--panel-2); cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button.on { background: var(--accent-soft); color: var(--accent-2); }
.body { flex: 1; min-height: 0; overflow: auto; position: relative; }
.body iframe { display: block; width: 100%; height: 100%; border: 0; background: #fff; }
.body pre {
  margin: 0; padding: 20px 22px; white-space: pre-wrap; word-break: break-word;
  font: 14px/1.6 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
.files { display: flex; gap: 8px; padding: 12px 22px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.file {
  display: inline-flex; align-items: center; gap: 8px; max-width: 280px;
  padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--panel-2);
  color: var(--text); text-decoration: none; font-size: 13px;
}
.file:hover { border-color: var(--accent); }
.file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file small { color: var(--muted); flex: none; }
.details { padding: 0 22px 12px; color: var(--muted); font-size: 12px; font-family: var(--mono); }
.details summary { cursor: pointer; font-family: system-ui, sans-serif; padding: 6px 0; }
.details dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 4px 0 0; }
.details dt { color: var(--faint); }
.details dd { margin: 0; word-break: break-all; color: var(--text); }
.back { display: none; }

/* ---------- modal ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .6);
  display: grid; place-items: center; padding: 16px; animation: fade .12s ease-out;
}
.modal {
  width: min(480px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .5); animation: pop .14s ease-out;
}
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal header h3 { margin: 0; font-size: 16px; }
.modal .content { padding: 18px 20px 6px; }
.modal footer { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px 16px; flex-wrap: wrap; }
.modal footer .left { margin-right: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; background: var(--bg); border-radius: 10px; margin-bottom: 18px; }
.tabs button { height: 34px; border: 0; border-radius: 7px; background: none; cursor: pointer; color: var(--muted); }
.tabs button.on { background: var(--panel-2); color: var(--text); box-shadow: 0 1px 0 var(--line-2); }
.picker { border: 1px solid var(--line-2); border-radius: 8px; max-height: 210px; overflow-y: auto; margin-top: 6px; }
.picker button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border: 0; background: none; cursor: pointer; text-align: left; }
.picker button:hover, .picker button.on { background: var(--accent-soft); }
.picker small { color: var(--muted); }
.picker .none { padding: 12px; color: var(--faint); font-size: 13px; }
.chosen { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; background: var(--accent-soft); border: 1px solid rgba(255, 123, 0, .35); }
.chosen div { flex: 1; min-width: 0; }
.chosen small { display: block; color: var(--muted); }
.form-error { color: var(--bad); font-size: 13px; min-height: 18px; }
.preview { font-family: var(--mono); font-size: 13px; color: var(--accent-2); word-break: break-all; }

/* ---------- toasts ---------- */
#toasts { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 60; display: grid; gap: 8px; max-width: calc(100vw - 32px); }
.toast {
  padding: 10px 14px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line-2);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4); animation: pop .15s ease-out; max-width: 380px;
}
.toast.ok { border-color: rgba(63, 185, 80, .45); }
.toast.bad { border-color: rgba(248, 81, 73, .5); }
.toast.accent { border-color: rgba(255, 123, 0, .55); }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .panes { grid-template-columns: 240px minmax(280px, 340px) 1fr; }
}
@media (max-width: 900px) {
  .menu-btn { display: inline-flex; }
  .brand > span, .live span { display: none; }
  .top { gap: 8px; padding: 0 10px; }
  .panes { grid-template-columns: 1fr; position: relative; }
  .pane + .pane { border-left: 0; }
  .side { position: absolute; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 20; transform: translateX(-102%); transition: transform .18s; box-shadow: 20px 0 40px rgba(0, 0, 0, .4); }
  .shell.menu .side { transform: none; }
  .reader { display: none; }
  .shell.reading .list { display: none; }
  .shell.reading .reader { display: flex; }
  .back { display: inline-flex; }
  .reader-head, .toolbar, .files, .details { padding-left: 16px; padding-right: 16px; }
  .body pre { padding: 16px; }
}
