/* ===================================================================
   inbox.css — ib- namespace

   Containment, and why it's done this way
   ---------------------------------------
   The page must not scroll. The top bar stays put, and only the list
   column moves. Earlier attempts used height:calc(100vh - 190px), which
   guesses how much chrome sits above — get it wrong and the block
   overflows, so the page scrolls AND the panes scroll.

   Instead: lock .sh-scroll, then let flex measure the remainder. No
   arithmetic, nothing to get wrong.

     .sh-scroll.sh-locked   overflow hidden, no padding, flex column
       .sh-page.sh-wide     flex:1, min-height:0
         .tab-content       flex column, min-height:0
           .ib-app          flex column, min-height:0
             .ib-top        flex:0 0 auto   (never scrolls away)
             .ib-browse     flex:1, min-height:0
               panes        overflow-y:auto, min-height:0

   min-height:0 on every flex/grid child is load-bearing. The default is
   min-height:auto — "at least as tall as my content" — which stops a
   pane shrinking and pushes the page taller instead.

   Inside the detail pane the composer is a plain non-shrinking sibling,
   not position:sticky. A sticky element inside a scrolling flex parent
   resolves against the scroll height, which is what pushed the reply
   box off-screen last time.

   Needs from shell.js, in show():
     .sh-page   gets .sh-wide   when screen === 'inbox'
     .sh-scroll gets .sh-locked when screen === 'inbox'
   Needs from inbox.js, in render():
     the two views wrapped in <div class="ib-app">…</div>
   =================================================================== */

:root, [data-theme="light"] {
  --ib-bg:#F8F8F6; --ib-surface:#FFFFFF; --ib-surface2:#F0EDE5;
  --ib-ink:#1A1815; --ib-ink2:rgba(26,24,21,.74); --ib-ink3:rgba(26,24,21,.54);
  --ib-line:rgba(26,24,21,.11); --ib-line2:rgba(26,24,21,.2); --ib-sel:rgba(26,24,21,.05);
  --ib-ok:#3B6D33;   --ib-okbg:rgba(59,109,51,.10);
  --ib-warn:#8B5E14; --ib-warnbg:rgba(139,94,20,.10);
  --ib-bad:#8B2D2D;  --ib-badbg:rgba(139,45,45,.09);
  --ib-info:#2D4A7A; --ib-infobg:rgba(45,74,122,.09);
  --ib-star:#B8860B; --ib-btn:#1A1815; --ib-btntx:#F8F8F6;
}
[data-theme="dark"] {
  --ib-bg:#1C1A17; --ib-surface:#252320; --ib-surface2:#2E2B27;
  --ib-ink:#F4F1E8; --ib-ink2:rgba(244,241,232,.78); --ib-ink3:rgba(244,241,232,.56);
  --ib-line:rgba(244,241,232,.11); --ib-line2:rgba(244,241,232,.2); --ib-sel:rgba(244,241,232,.06);
  --ib-ok:#9CBF86;   --ib-okbg:rgba(143,173,122,.14);
  --ib-warn:#D4A155; --ib-warnbg:rgba(212,161,85,.14);
  --ib-bad:#D08383;  --ib-badbg:rgba(199,115,115,.13);
  --ib-info:#93B2DF; --ib-infobg:rgba(138,169,214,.13);
  --ib-star:#D4A155; --ib-btn:#F4F1E8; --ib-btntx:#1C1A17;
}

/* ---------- the height chain ---------- */
body.sh-body .sh-scroll.sh-locked {
  overflow:hidden; padding:0;
  display:flex; flex-direction:column; min-height:0;
}
body.sh-body .sh-scroll.sh-locked > .sh-page.sh-wide {
  max-width:none; width:100%; margin:0;
  flex:1 1 auto; min-height:0; display:flex; flex-direction:column;
}
body.sh-body .sh-scroll.sh-locked .tab-content.active {
  flex:1 1 auto; min-height:0; display:flex; flex-direction:column;
}
/* the footer links live inside .sh-scroll; hide them on this screen
   so they can't eat the height the panes need */
body.sh-body .sh-scroll.sh-locked > .social-links,
body.sh-body .sh-scroll.sh-locked > .footer-links { display:none; }

.ib-app { flex:1 1 auto; min-height:0; display:flex; flex-direction:column; }

#inbox {
  font-family:'Inter', system-ui, -apple-system, sans-serif;
  color:var(--ib-ink); font-size:15px; line-height:1.5;
}
#inbox * { box-sizing:border-box; }

/* ---------- states ---------- */
.ib-loading, .ib-empty {
  margin:24px; padding:56px 40px; text-align:center; color:var(--ib-ink3);
  background:var(--ib-surface); border:1px solid var(--ib-line); border-radius:10px;
}
.ib-empty h3 {
  font-family:'Newsreader',Georgia,serif; font-weight:500; font-size:21px;
  margin:0 0 8px; color:var(--ib-ink);
}
.ib-empty p { margin:0 auto; max-width:400px; font-size:14.5px; }
.ib-none { padding:48px 20px; text-align:center; font-size:13.5px; color:var(--ib-ink3); }

/* ---------- top bar: fixed, never scrolls away ---------- */
.ib-top {
  flex:0 0 auto;
  display:flex; align-items:center; justify-content:space-between;
  gap:16px; flex-wrap:wrap; padding:13px 20px;
  border-bottom:1px solid var(--ib-line); background:var(--ib-bg);
}
.ib-title { font-family:'Newsreader',Georgia,serif; font-weight:500; font-size:19px; }
.ib-sub { font-size:12.5px; color:var(--ib-ink3); margin-top:1px; }
.ib-topr { display:flex; align-items:center; gap:10px; }

.ib-seg { display:flex; gap:2px; padding:3px; background:var(--ib-surface2); border-radius:7px; }
.ib-seg button {
  padding:6px 13px; border:none; border-radius:5px; background:none; cursor:pointer;
  font-family:inherit; font-size:13px; font-weight:500; color:var(--ib-ink3);
}
.ib-seg button:hover { color:var(--ib-ink); }
.ib-seg button.on { background:var(--ib-surface); color:var(--ib-ink); }

/* ---------- three panes ---------- */
/* edge to edge: no border, no radius, meets the sidebar */
.ib-browse {
  flex:1 1 auto; min-height:0;
  display:grid; grid-template-columns:184px 350px minmax(400px, 1fr);
  background:var(--ib-surface);
}
.ib-rail, .ib-listcol, .ib-detail { min-height:0; }
.ib-rail, .ib-listcol { overflow-y:auto; }

.ib-rail { border-right:1px solid var(--ib-line); background:var(--ib-bg); padding:12px 8px; }
.ib-fitem, .ib-fsub {
  display:flex; align-items:center; justify-content:space-between; gap:8px;
  width:100%; padding:6px 10px; border:none; border-radius:6px; background:none;
  cursor:pointer; text-align:left; font-family:inherit; color:var(--ib-ink2);
}
.ib-fitem { font-size:13px; font-weight:500; }
.ib-fsub { font-size:12px; padding-left:22px; color:var(--ib-ink3); }
.ib-fitem:hover, .ib-fsub:hover { background:var(--ib-sel); color:var(--ib-ink); }
.ib-fitem.on, .ib-fsub.on { background:var(--ib-sel); color:var(--ib-ink); font-weight:600; }
.ib-fgrp { margin-top:8px; }
.ib-fhead {
  font-size:10px; font-weight:600; letter-spacing:.11em; text-transform:uppercase;
  color:var(--ib-ink3); padding:14px 10px 4px;
}
.ib-fn {
  font-size:11px; font-weight:600; padding:0 5px; border-radius:999px; min-width:20px;
  text-align:center; background:var(--ib-surface2); color:var(--ib-ink2); flex-shrink:0;
}
.ib-fitem.on .ib-fn, .ib-fsub.on .ib-fn { background:var(--ib-warnbg); color:var(--ib-warn); }

/* ---------- list: the one pane that really scrolls ---------- */
.ib-listcol { border-right:1px solid var(--ib-line); position:relative; }
.ib-lbar {
  position:sticky; top:0; z-index:2; display:flex; align-items:center; gap:10px;
  padding:8px 12px; background:var(--ib-surface); border-bottom:1px solid var(--ib-line);
  font-size:12px; color:var(--ib-ink3);
}
.ib-lbar .ib-lnk { margin-left:auto; }
.ib-lnk {
  background:none; border:none; cursor:pointer; padding:2px;
  font-family:inherit; font-size:12.5px; color:var(--ib-ink2);
  text-decoration:underline; text-underline-offset:3px;
}
.ib-lnk:hover { color:var(--ib-ink); }

.ib-ghead {
  position:sticky; top:33px; z-index:1; display:flex; align-items:center; gap:8px;
  padding:7px 12px; background:var(--ib-surface2); border-bottom:1px solid var(--ib-line);
  font-size:11.5px; color:var(--ib-ink3); cursor:pointer;
}
.ib-ghead b { color:var(--ib-ink2); font-weight:600; min-width:0;
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.ib-ghead .ib-fn { margin-left:auto; }
.ib-gcar { flex-shrink:0; }

.ib-row {
  display:grid; grid-template-columns:18px 26px 1fr; gap:9px; align-items:start;
  width:100%; padding:9px 12px; border:none; border-bottom:1px solid var(--ib-line);
  border-left:2px solid transparent; background:none; cursor:pointer;
  text-align:left; font-family:inherit; color:var(--ib-ink);
}
.ib-row:hover { background:var(--ib-sel); }
.ib-row.on { background:var(--ib-sel); border-left-color:var(--ib-ink); }
.ib-row.neg { border-left-color:var(--ib-bad); }
.ib-row.neg.on { background:var(--ib-badbg); }

.ib-chk {
  width:14px; height:14px; margin-top:3px; border:1px solid var(--ib-line2);
  border-radius:3px; background:var(--ib-surface); display:grid; place-items:center;
  font-size:9px; color:transparent;
}
.ib-row.picked .ib-chk { background:var(--ib-ink); border-color:var(--ib-ink); color:var(--ib-btntx); }

.ib-av {
  width:26px; height:26px; border-radius:50%; margin-top:1px; overflow:hidden; flex-shrink:0;
  background:var(--ib-surface2); color:var(--ib-ink3);
  display:grid; place-items:center; font-size:10px; font-weight:600;
}
.ib-av img { width:100%; height:100%; object-fit:cover; }
.ib-rmain { min-width:0; }
.ib-rtop { display:flex; align-items:baseline; gap:8px; }
.ib-nm { font-size:13px; font-weight:500; min-width:0;
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.ib-tm { margin-left:auto; font-size:11px; color:var(--ib-ink3); flex-shrink:0; }
.ib-pv { display:block; font-size:12.5px; color:var(--ib-ink3); margin-top:1px;
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.ib-marks { display:flex; gap:4px; flex-wrap:wrap; margin-top:3px; }
.ib-marks-lg { margin:0 0 14px; }
.ib-mk { font-size:10px; font-weight:600; padding:1px 5px; border-radius:3px; }
.ib-mk-neg { background:var(--ib-badbg); color:var(--ib-bad); }
.ib-mk-q { background:var(--ib-infobg); color:var(--ib-info); }
.ib-mk-draft { background:var(--ib-surface2); color:var(--ib-ink2); }
.ib-mk-fail { background:var(--ib-badbg); color:var(--ib-bad); }
.ib-mk-src { background:var(--ib-surface2); color:var(--ib-ink3); }
.ib-stars { color:var(--ib-star); font-size:11px; letter-spacing:.5px; }

.ib-bulk {
  position:sticky; bottom:0; display:flex; align-items:center; gap:10px;
  padding:10px 12px; background:var(--ib-ink); color:var(--ib-btntx); font-size:13px;
}
.ib-bulk button {
  margin-left:auto; padding:6px 12px; border:none; border-radius:6px; cursor:pointer;
  font-family:inherit; font-size:12.5px; font-weight:600;
  background:var(--ib-btntx); color:var(--ib-ink);
}
.ib-bulk .ib-x { margin-left:0; background:none; color:var(--ib-btntx);
  font-weight:400; text-decoration:underline; }

/* ---------- detail: body scrolls, composer sits at the bottom ---------- */
.ib-detail { display:flex; flex-direction:column; overflow:hidden; }
.ib-dbody {
  flex:1 1 auto; min-height:0; overflow-y:auto;
  padding:24px 28px; max-width:860px;
}
.ib-dhead { display:flex; align-items:flex-start; gap:12px; margin-bottom:16px; }
.ib-dav {
  width:40px; height:40px; border-radius:50%; overflow:hidden; flex-shrink:0;
  background:var(--ib-surface2); color:var(--ib-ink3);
  display:grid; place-items:center; font-size:13px; font-weight:600;
}
.ib-dav img { width:100%; height:100%; object-fit:cover; }
.ib-dwho { flex:1; min-width:0; }
.ib-dname { font-size:16px; font-weight:600; }
.ib-dmeta { font-size:12.5px; color:var(--ib-ink3); margin-top:1px; }

.ib-tag { margin-left:auto; padding:4px 10px; border-radius:5px;
  font-size:12px; font-weight:500; white-space:nowrap; flex-shrink:0; }
.ib-tag-todo { background:var(--ib-warnbg); color:var(--ib-warn); }
.ib-tag-draft { background:var(--ib-infobg); color:var(--ib-info); }
.ib-tag-done { background:var(--ib-okbg); color:var(--ib-ok); }
.ib-tag-fail { background:var(--ib-badbg); color:var(--ib-bad); }
.ib-tag-mute { background:var(--ib-surface2); color:var(--ib-ink3); }

.ib-said { font-size:16px; line-height:1.7; margin:0 0 18px; max-width:62ch; }
.ib-bigstars { color:var(--ib-star); font-size:18px; letter-spacing:2px; margin-bottom:10px; }
.ib-warnbox {
  padding:11px 14px; border-radius:8px; margin-bottom:18px; max-width:62ch;
  background:var(--ib-badbg); color:var(--ib-bad); font-size:13px; line-height:1.5;
}
.ib-parent { padding:11px 14px; border-radius:8px; background:var(--ib-surface2);
  margin-bottom:16px; max-width:62ch; }
.ib-parent p { margin:0; font-size:13px; color:var(--ib-ink3); line-height:1.5; }
.ib-ours { padding:12px 15px; border-radius:8px; background:var(--ib-okbg);
  margin-bottom:18px; max-width:62ch; }
.ib-ours p { margin:0; font-size:14px; line-height:1.6; color:var(--ib-ink2); }
.ib-lbl {
  font-size:10.5px; font-weight:700; letter-spacing:.08em; text-transform:uppercase;
  color:var(--ib-ink3); margin-bottom:5px;
}
.ib-ours .ib-lbl { color:var(--ib-ok); }

.ib-thread { display:flex; flex-direction:column; gap:7px; margin-bottom:18px; max-width:62ch; }
.ib-msg { padding:9px 13px; border-radius:12px; font-size:14.5px; line-height:1.5; max-width:80%; }
.ib-them { background:var(--ib-surface2); align-self:flex-start; border-bottom-left-radius:4px; }
.ib-us { background:var(--ib-ink); color:var(--ib-bg); align-self:flex-end; border-bottom-right-radius:4px; }

/* plain flex child, NOT position:sticky — sticky inside a scrolling
   flex parent resolves against scroll height and lands off-screen */
.ib-composer {
  flex:0 0 auto; position:static;
  padding:14px 28px 16px;
  border-top:1px solid var(--ib-line); background:var(--ib-surface);
}
.ib-area {
  width:100%; min-height:84px; resize:vertical; padding:11px 13px; border-radius:8px;
  background:var(--ib-bg); color:var(--ib-ink); border:1px solid var(--ib-line2);
  font-family:inherit; font-size:14.5px; line-height:1.6;
}
.ib-area:focus { outline:2px solid var(--ib-ink); outline-offset:-2px; }
.ib-cfoot { display:flex; align-items:center; justify-content:space-between;
  gap:12px; flex-wrap:wrap; margin-top:9px; }
.ib-hint { font-size:12px; color:var(--ib-ink3); }
.ib-cbtns { display:flex; gap:7px; }

/* ---------- queue ---------- */
.ib-queue { flex:1 1 auto; min-height:0; overflow-y:auto; padding:20px 20px 40px; }
.ib-qwrap { max-width:760px; margin:0 auto; }
.ib-qprog { display:flex; align-items:center; gap:14px; margin-bottom:14px;
  font-size:13px; color:var(--ib-ink3); }
.ib-qbar { flex:1; height:3px; border-radius:2px; background:var(--ib-surface2); overflow:hidden; }
.ib-qbar i { display:block; height:100%; background:var(--ib-ink); transition:width .25s ease; }
.ib-qcard { background:var(--ib-surface); border:1px solid var(--ib-line);
  border-radius:12px; padding:26px 28px; }
.ib-qdraft { border:1px solid var(--ib-line2); border-radius:10px; overflow:hidden; margin-top:4px; }
.ib-qdh {
  padding:9px 14px; background:var(--ib-infobg); color:var(--ib-info);
  font-size:10.5px; font-weight:700; letter-spacing:.08em; text-transform:uppercase;
}
.ib-qdraft .ib-area { border:none; border-radius:0; min-height:110px; background:var(--ib-surface); }
.ib-qacts { display:flex; align-items:center; justify-content:space-between;
  gap:12px; flex-wrap:wrap; margin-top:18px; }
.ib-keys { display:flex; gap:14px; font-size:12px; color:var(--ib-ink3); }
.ib-keys kbd {
  font-family:ui-monospace,Menlo,monospace; font-size:11px; padding:1px 5px;
  border:1px solid var(--ib-line2); border-radius:4px; background:var(--ib-surface2);
}
.ib-qdone { text-align:center; padding:70px 20px; }
.ib-qdone h2 { font-family:'Newsreader',Georgia,serif; font-weight:500; font-size:25px; margin:0 0 8px; }
.ib-qdone p { color:var(--ib-ink3); margin:0 0 20px; }

/* ---------- buttons ---------- */
.ib-btn {
  display:inline-flex; align-items:center; justify-content:center; gap:7px;
  padding:9px 16px; border-radius:7px; cursor:pointer; white-space:nowrap;
  font-family:inherit; font-size:13.5px; font-weight:500; line-height:1;
  border:1px solid transparent;
}
.ib-btn-p { background:var(--ib-btn); color:var(--ib-btntx); }
.ib-btn-p:hover { opacity:.88; }
.ib-btn-p:disabled { opacity:.45; cursor:default; }
.ib-btn-q { background:transparent; color:var(--ib-ink2); border-color:var(--ib-line2); }
.ib-btn-q:hover { background:var(--ib-surface2); color:var(--ib-ink); }

/* ---------- empty extras ---------- */
.ib-watch { margin:24px auto 0; padding-top:20px; max-width:320px;
  border-top:1px solid var(--ib-line); text-align:left; }
.ib-wrow { display:flex; align-items:center; gap:10px; padding:5px 0;
  font-size:13.5px; color:var(--ib-ink2); }
.ib-chip { padding:2px 8px; border-radius:4px; background:var(--ib-surface2);
  color:var(--ib-ink2); font-size:11.5px; font-weight:500; }
.ib-wnote { margin-top:12px; font-size:12.5px; color:var(--ib-ink3); line-height:1.5; }

/* ---------- sidebar badge ---------- */
.sh-navbadge {
  margin-left:auto; font-size:11px; font-weight:600; padding:2px 7px;
  border-radius:999px; background:var(--ib-warn); color:#FFF;
}
body.sh-mini .sh-navbadge { display:none; }

/* ===================================================================
   Responsive
   =================================================================== */

/* laptops — narrow the rail, keep three panes */
@media (max-width:1400px) {
  .ib-browse { grid-template-columns:164px 320px minmax(360px, 1fr); }
  .ib-dbody { padding:20px 22px; }
  .ib-composer { padding:12px 22px 14px; }
}

/* small laptops and landscape tablets — rail becomes a strip on top */
@media (max-width:1100px) {
  .ib-browse { grid-template-columns:300px minmax(320px, 1fr); grid-template-rows:auto 1fr; }
  .ib-rail {
    grid-column:1 / -1; display:flex; gap:6px;
    overflow-x:auto; overflow-y:hidden;
    padding:8px 12px; border-right:none; border-bottom:1px solid var(--ib-line);
  }
  .ib-fgrp { display:flex; gap:6px; margin-top:0; }
  .ib-fhead { display:none; }
  .ib-fitem, .ib-fsub { width:auto; white-space:nowrap; padding:6px 11px; }
}

/* phones and portrait tablets — give up on viewport locking and let
   the page scroll normally, which is the right behaviour there */
@media (max-width:820px) {
  body.sh-body .sh-scroll.sh-locked { overflow-y:auto; display:block; padding:0; }
  body.sh-body .sh-scroll.sh-locked > .social-links,
  body.sh-body .sh-scroll.sh-locked > .footer-links { display:flex; }
  body.sh-body .sh-scroll.sh-locked > .sh-page.sh-wide,
  body.sh-body .sh-scroll.sh-locked .tab-content.active { display:block; }
  .ib-app { display:block; }
  .ib-browse { display:block; }
  .ib-rail { display:flex; overflow-x:auto; padding:8px 12px;
    border-right:none; border-bottom:1px solid var(--ib-line); }
  .ib-listcol { border-right:none; border-bottom:1px solid var(--ib-line);
    max-height:340px; overflow-y:auto; }
  .ib-detail { display:block; overflow:visible; }
  .ib-dbody { overflow:visible; padding:18px 16px; }
  .ib-composer { padding:12px 16px 16px; }
  .ib-queue { overflow:visible; }
  .ib-qcard { padding:18px 16px; }
  .ib-cfoot { flex-direction:column; align-items:stretch; }
  .ib-cbtns .ib-btn { flex:1; }
  .ib-top { padding:12px 16px; }
}

/* count inside a segmented button */
.ib-segn {
  display:inline-block; margin-left:5px; padding:0 5px;
  border-radius:999px; font-size:11px; font-weight:600;
  background:var(--ib-line); color:var(--ib-ink2);
}
.ib-seg button.on .ib-segn { background:var(--ib-warnbg); color:var(--ib-warn); }

/* ===================================================================
   Filter bar — its own strip between the heading and the panes.
   Dark segments so it reads as the main control rather than an aside.
   =================================================================== */
.ib-filterbar {
  flex:0 0 auto;
  padding:10px 20px;
  border-bottom:1px solid var(--ib-line);
  background:var(--ib-bg);
}
.ib-filterbar .ib-seg {
  display:inline-flex; gap:3px; padding:3px;
  background:var(--ib-surface2); border-radius:8px;
}
.ib-filterbar .ib-seg button {
  padding:7px 15px; border:none; border-radius:6px; background:none;
  cursor:pointer; white-space:nowrap;
  font-family:inherit; font-size:13.5px; font-weight:500; color:var(--ib-ink2);
}
.ib-filterbar .ib-seg button:hover { color:var(--ib-ink); }
.ib-filterbar .ib-seg button.on {
  background:var(--ib-btn); color:var(--ib-btntx);
}
.ib-segn {
  display:inline-block; margin-left:5px; padding:0 6px;
  border-radius:999px; font-size:11px; font-weight:600;
  background:var(--ib-line); color:var(--ib-ink2);
}
.ib-filterbar .ib-seg button.on .ib-segn {
  background:rgba(255,255,255,.22); color:var(--ib-btntx);
}
[data-theme="dark"] .ib-filterbar .ib-seg button.on .ib-segn {
  background:rgba(0,0,0,.22);
}

.ib-top { padding:12px 20px; }
.ib-lbar { padding:8px 12px; }

@media (max-width:820px) {
  .ib-filterbar { padding:8px 16px; }
  .ib-filterbar .ib-seg { display:flex; width:100%; }
  .ib-filterbar .ib-seg button { flex:1; padding:7px 8px; font-size:12.5px; }
}