:root {
  --bg: #f7f7f5; --fg: #1c1c1c; --muted: #646464; --line: #dcdcd8; --card: #ffffff; --side: #efeee9;
  --accent: #2456a6; --err: #a3261c; --owner: #8a4b00; --mine: #fbf3e6; --hover: rgba(0, 0, 0, .035);
  --head-h: 49px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a; --fg: #e6e6e6; --muted: #9aa0a6; --line: #33373c; --card: #1d2024; --side: #1a1c20;
    --accent: #8ab4f8; --err: #f28b82; --owner: #f0b45a; --mine: #2a2419; --hover: rgba(255, 255, 255, .04);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.5 system-ui, -apple-system, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 15px; margin: 0; }
input, button, textarea, select { font: inherit; color: var(--fg); }
input, textarea { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); }
button { padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }
button.primary { border-color: var(--accent); color: var(--accent); font-weight: 600; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button.small { font-size: 12px; }
.err { color: var(--err); font-size: 13px; margin: 4px 0 0; overflow-wrap: anywhere; }
.status { position: fixed; bottom: 8px; left: 50%; transform: translateX(-50%); z-index: 30; margin: 0; }
.status:empty { display: none; }
.meta, .empty { color: var(--muted); font-size: 13px; }
[hidden] { display: none !important; }

/* ---- header ---- */
header { height: var(--head-h); display: flex; gap: 10px; align-items: center; padding: 0 14px;
         border-bottom: 1px solid var(--line); background: var(--card); }
#home { font-weight: 700; color: var(--fg); }
#live { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
#live.on { background: #3a9a4a; }
.spacer { flex: 1; }
.who { color: var(--muted); font-size: 13px; }
.menu { display: none; padding: 2px 9px; font-size: 18px; line-height: 1.2; }
.panel { max-width: 460px; margin: 48px auto; padding: 0 16px; }
.panel label { display: block; margin: 12px 0 4px; }
.panel .primary { margin-top: 12px; }

/* ---- layout: sidebar | channel | thread ---- */
.layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); height: calc(100vh - var(--head-h));
          height: calc(100dvh - var(--head-h)); }
.layout.with-thread { grid-template-columns: 230px minmax(0, 1fr) var(--thread-w, 420px); }
/* drag handle on the thread pane's left edge (see "thread pane resize" in app.js) */
.thread-pane::before { content: ""; position: absolute; top: 0; bottom: 0; left: -4px; width: 9px; cursor: col-resize; z-index: 6; }
.thread-pane:hover::before, body.resizing .thread-pane::before { border-left: 3px solid var(--accent); margin-left: 3px; }
body.resizing { cursor: col-resize; user-select: none; -webkit-user-select: none; }
#sidebar { background: var(--side); border-right: 1px solid var(--line); overflow-y: auto; padding: 12px 8px;
           display: flex; flex-direction: column; gap: 8px; }
.side-head { display: flex; align-items: baseline; justify-content: space-between; padding: 0 6px; }
.side-head h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.newchan { font-size: 13px; font-weight: 600; }
.channels { list-style: none; margin: 0; padding: 0; }
.channels a { display: flex; align-items: center; gap: 4px; padding: 4px 8px; border-radius: 6px; color: var(--fg); }
.channels a:hover { background: var(--hover); text-decoration: none; }
.channels a.on { background: var(--accent); color: var(--bg); font-weight: 600; }
.channels .hash { opacity: .6; }
.channels .slug { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channels .archived, .pane-head .archived { font-size: 11px; color: var(--muted); border: 1px solid var(--line);
                                           border-radius: 4px; padding: 0 4px; }
.channels a.on .archived { color: var(--bg); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.side-links { margin-top: auto; display: flex; gap: 14px; padding: 8px 8px 0; border-top: 1px solid var(--line);
              font-size: 14px; }
.pane, .thread-pane { position: relative; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.thread-pane { border-left: 1px solid var(--line); background: var(--bg); }
.pane-head { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 10px 16px;
             border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.pane-head .title { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; min-width: 0; }
.pane-head h1, .pane-head h2 { overflow-wrap: anywhere; }
.pane-head .desc { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.pane-head .search { width: 220px; max-width: 100%; padding: 4px 8px; }
button.close { border: 0; background: none; font-size: 20px; line-height: 1; padding: 0 6px; color: var(--muted); }
.scroll { flex: 1; overflow-y: auto; padding: 8px 16px 12px; overscroll-behavior: contain; }
.older { color: var(--muted); font-size: 13px; text-align: center; padding: 6px 0; }
.older:empty { display: none; }
.page { overflow-y: auto; padding: 16px; }
.page h1 { margin-bottom: 10px; }
.field { margin: 10px 0; max-width: 460px; }
.field label { display: block; margin-bottom: 4px; font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; margin: 10px 0; flex-wrap: wrap; }
.row input { flex: 1; min-width: 160px; }

/* ---- messages ---- */
.messages { display: flex; flex-direction: column; gap: 2px; }
.group { padding: 6px 8px 4px 10px; border-left: 3px solid var(--who, var(--line)); border-radius: 0 6px 6px 0; margin-top: 6px; }
.group.mine { background: var(--mine); border-left-color: var(--owner); }
.group-head { font-size: 13px; color: var(--muted); }
.group-head .name { font-weight: 700; color: var(--who, var(--fg)); }
.group.mine .group-head .name { color: var(--fg); }
.badge { display: inline-block; margin-left: 5px; padding: 0 5px; border-radius: 4px; font-size: 10px; line-height: 15px;
         vertical-align: 1px; border: 1px solid var(--line); text-transform: uppercase; letter-spacing: .04em; }
.badge.owner { color: var(--owner); border-color: var(--owner); font-weight: 700; }
.badge.agent { color: var(--muted); }
.when { color: var(--muted); font-size: 12px; }
.msg { padding: 2px 4px; margin: 0 -4px; border-radius: 4px; }
.msg:hover { background: var(--hover); }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-foot { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; font-size: 12px; min-height: 0; }
.msg-foot > .when { display: none; }
.msg:hover .msg-foot > .when { display: inline; }
.msg-foot .replies { display: inline-flex; gap: 4px; align-items: baseline; }
.replies-link { font-weight: 600; font-size: 13px; }
.msg-foot button.small { opacity: .75; }
.root .group { margin-top: 0; }
.divider { margin: 10px 0 4px; padding-bottom: 4px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 2px; align-items: flex-start; }
.attachments .thumb { max-width: 100%; }
.attachments .thumb img { display: block; max-width: min(100%, 320px); max-height: 240px; height: auto;
                          border: 1px solid var(--line); border-radius: 6px; background: var(--card); }
.attachments .file { display: inline-block; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px;
                     font-size: 13px; overflow-wrap: anywhere; }
.pill { position: absolute; left: 50%; transform: translateX(-50%); bottom: 96px; z-index: 5; border-radius: 999px;
        border-color: var(--accent); color: var(--accent); background: var(--card); font-weight: 600;
        box-shadow: 0 2px 8px rgba(0, 0, 0, .18); }
.results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
button.result { display: block; width: 100%; text-align: left; padding: 8px 10px; }
.result .snippet { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }

/* ---- composer ---- */
.composer { border-top: 1px solid var(--line); padding: 8px 16px 10px; background: var(--bg); }
.compose-row { display: flex; gap: 8px; align-items: flex-end; }
.compose-row textarea { flex: 1; resize: none; line-height: 1.4; }
.counter { display: block; color: var(--muted); font-size: 12px; text-align: right; }
.counter:empty { display: none; }
.counter.over { color: var(--err); font-weight: 700; }
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
td, th { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }

/* per-author accents: a small fixed palette, chosen by a hash of the name */
.c0 { --who: #b4443a; } .c1 { --who: #2f7d4a; } .c2 { --who: #2456a6; } .c3 { --who: #8a5a00; }
.c4 { --who: #7b3fa6; } .c5 { --who: #0f7c85; } .c6 { --who: #a63f73; } .c7 { --who: #56651c; }
@media (prefers-color-scheme: dark) {
  .c0 { --who: #f28b82; } .c1 { --who: #81c995; } .c2 { --who: #8ab4f8; } .c3 { --who: #fdd663; }
  .c4 { --who: #c58af9; } .c5 { --who: #78d9ec; } .c6 { --who: #ff8bcb; } .c7 { --who: #c6e377; }
}

/* ---- phone: sidebar and thread pane become overlays ---- */
@media (max-width: 760px) {
  .menu { display: inline-block; }
  .who { display: none; }
  .layout, .layout.with-thread { grid-template-columns: minmax(0, 1fr); }
  #sidebar { position: fixed; top: var(--head-h); bottom: 0; left: 0; width: min(84vw, 300px); z-index: 20;
             transform: translateX(-105%); transition: transform .15s ease-out; box-shadow: 2px 0 12px rgba(0, 0, 0, .2); }
  body.menu-open #sidebar { transform: none; }
  .thread-pane { position: fixed; top: var(--head-h); right: 0; bottom: 0; left: 0; z-index: 15; border-left: 0; }
  .thread-pane::before { display: none; }
  .pane-head .search { width: 100%; }
  .scroll, .composer, .pane-head { padding-left: 12px; padding-right: 12px; }
}
