/* Clamor — styled after Silent Clamor Press: warm paper tones, serif headings, quiet accents. */
:root {
  --accent: #7a2e2e;
  --accent-text: #ffffff;
  --bg: #f6f4ef;
  --panel: #ffffff;
  --side: #1d1b18;
  --side-text: #e9e5dc;
  --side-muted: #a7a092;
  --side-hover: #2c2925;
  --text: #1d1b18;
  --muted: #6b665c;
  --line: #e4e0d6;
  --hover: #f1eee7;
  --mention-bg: #f7ead2;
  --code-bg: #efece4;
  --danger: #a33a2a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #161513;
  --panel: #1d1c19;
  --side: #121110;
  --side-text: #e9e5dc;
  --side-muted: #8f897d;
  --side-hover: #24221f;
  --text: #ece8e0;
  --muted: #a39d91;
  --line: #33312c;
  --hover: #25231f;
  --mention-bg: #3a3022;
  --code-bg: #2a2824;
  --danger: #e0715e;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161513;
    --panel: #1d1c19;
    --side: #121110;
    --side-text: #e9e5dc;
    --side-muted: #8f897d;
    --side-hover: #24221f;
    --text: #ece8e0;
    --muted: #a39d91;
    --line: #33312c;
    --hover: #25231f;
    --mention-bg: #3a3022;
    --code-bg: #2a2824;
    --danger: #e0715e;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; overflow: hidden; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 9px 11px; width: 100%; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
a { color: var(--accent); }
:root[data-theme="dark"] a, .msg-body a { text-decoration-thickness: 1px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 500; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); }

.primary { background: var(--accent); color: var(--accent-text); border: 0; border-radius: 6px; padding: 9px 16px; }
.primary:disabled { opacity: .6; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 6px; padding: 7px 12px; }
.ghost.small, .primary.small { padding: 5px 10px; font-size: 13px; }
.danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); border-radius: 6px; padding: 7px 12px; }
.link { background: none; border: 0; color: var(--accent); padding: 0; text-decoration: underline; }
.icon { background: none; border: 0; padding: 4px 8px; border-radius: 4px; font-size: 16px; line-height: 1; }
.icon:hover { background: var(--hover); }

.boot { display: grid; place-items: center; height: 100%; color: var(--muted); }

/* login */
.login { display: grid; place-items: center; height: 100%; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 36px 32px; width: 100%; max-width: 380px; text-align: center; }
.login-card h1 { font-size: 30px; margin-bottom: 8px; }
.login-card form { display: grid; gap: 12px; }
.login-logo { max-height: 64px; max-width: 200px; margin: 0 auto 12px; display: block; }

/* layout */
.app { display: grid; grid-template-columns: 260px 1fr; height: 100%; }
.app.with-thread { grid-template-columns: 260px 1fr 380px; }
.sidebar { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; min-height: 0; padding-top: env(safe-area-inset-top); }
.ws { display: flex; align-items: center; gap: 10px; padding: 16px 16px 10px; }
.ws-logo { height: 28px; width: auto; max-width: 120px; border-radius: 4px; background: #fff; padding: 2px; }
.ws-name { font-family: var(--serif); font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search { padding: 0 12px 8px; }
.search input { background: var(--side-hover); border-color: transparent; color: var(--side-text); padding: 7px 10px; font-size: 14px; }
.search input::placeholder { color: var(--side-muted); }
.nav { flex: 1; overflow-y: auto; padding-bottom: 12px; }
.nav-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 4px; color: var(--side-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.nav-head .icon { color: var(--side-muted); font-size: 14px; }
.nav-head .icon:hover { background: var(--side-hover); color: var(--side-text); }
.nav-actions { display: flex; }
.list { list-style: none; margin: 0; padding: 0 8px; }
.list li button { width: 100%; text-align: left; background: none; border: 0; color: var(--side-muted); padding: 5px 10px; border-radius: 5px; display: flex; align-items: center; gap: 8px; }
.list li button:hover { background: var(--side-hover); color: var(--side-text); }
.list li button.active { background: var(--accent); color: var(--accent-text); }
.list li button.unread { color: var(--side-text); font-weight: 600; }
.list .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--accent); color: var(--accent-text); border-radius: 9px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.list li button.active .badge { background: var(--accent-text); color: var(--accent); }
.me { border-top: 1px solid var(--side-hover); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 8px; }
.me-btn { flex: 1; display: flex; align-items: center; gap: 8px; background: none; border: 0; color: var(--side-text); padding: 4px; border-radius: 6px; text-align: left; min-width: 0; }
.me-btn:hover { background: var(--side-hover); }
.me .ghost { color: var(--side-text); border-color: var(--side-hover); }
.avatar { width: 30px; height: 30px; border-radius: 6px; background: var(--accent); color: var(--accent-text); display: inline-grid; place-items: center; font-size: 13px; font-weight: 600; flex: none; }

.main, .thread { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--panel); }
.thread { border-left: 1px solid var(--line); }
.chan-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); padding-top: calc(12px + env(safe-area-inset-top)); }
.chan-title { flex: 1; min-width: 0; }
.chan-title h2 { font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chan-title div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { display: none; font-size: 26px; }
.join-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 16px; background: var(--hover); border-bottom: 1px solid var(--line); font-size: 14px; }
.empty { flex: 1; display: grid; place-items: center; color: var(--muted); }

/* messages */
.messages { flex: 1; overflow-y: auto; padding: 8px 0 12px; overscroll-behavior: contain; }
.day { text-align: center; margin: 14px 0 6px; font-size: 12px; color: var(--muted); }
.new-line { border-top: 1px solid var(--accent); margin: 6px 16px; position: relative; }
.new-line span { position: absolute; right: 0; top: -9px; background: var(--panel); color: var(--accent); font-size: 11px; padding: 0 6px; font-weight: 600; }
.msg { display: grid; grid-template-columns: 36px 1fr; gap: 10px; padding: 4px 16px; position: relative; }
.msg:hover { background: var(--hover); }
.msg.cont { padding-top: 1px; }
.msg.cont .avatar { visibility: hidden; height: 0; }
.msg.cont .msg-meta { display: none; }
.msg.flash { animation: flash 2s ease-out; }
@keyframes flash { from { background: var(--mention-bg); } to { background: transparent; } }
.msg .avatar { width: 36px; height: 36px; }
.msg-meta { display: flex; gap: 8px; align-items: baseline; }
.msg-author { font-weight: 600; }
.msg-time { color: var(--muted); font-size: 12px; }
.msg-body { word-wrap: break-word; overflow-wrap: anywhere; white-space: normal; }
.msg-body pre { background: var(--code-bg); padding: 8px 10px; border-radius: 6px; overflow-x: auto; font: 13px/1.45 var(--mono); white-space: pre-wrap; margin: 4px 0; }
.msg-body code { background: var(--code-bg); padding: 1px 4px; border-radius: 4px; font: 13px var(--mono); }
.msg-body .mention { background: var(--mention-bg); border-radius: 4px; padding: 0 3px; font-weight: 600; }
.msg-body .mention.me { background: var(--accent); color: var(--accent-text); }
.msg-deleted { color: var(--muted); font-style: italic; }
.edited { color: var(--muted); font-size: 12px; }
.msg-tools { position: absolute; right: 12px; top: -14px; display: none; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.msg:hover .msg-tools, .msg.tools-open .msg-tools { display: flex; }
.msg-tools button { background: none; border: 0; padding: 4px 8px; font-size: 14px; }
.msg-tools button:hover { background: var(--hover); }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction { border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 0 8px; font-size: 13px; line-height: 22px; }
.reaction.mine { border-color: var(--accent); background: var(--mention-bg); }
.thread-link { margin-top: 4px; background: none; border: 0; color: var(--accent); padding: 0; font-size: 13px; font-weight: 600; }
.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.file { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; text-decoration: none; color: var(--text); max-width: 340px; background: var(--panel); }
.file:hover { background: var(--hover); }
.file-icon { width: 34px; height: 34px; border-radius: 6px; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; background: #5b5850; flex: none; }
.file-icon.doc { background: #2b5797; }
.file-icon.pdf { background: #b3261e; }
.file-icon.xls { background: #1e7145; }
.file-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { font-size: 12px; color: var(--muted); }
.file-img { max-width: 320px; max-height: 240px; border-radius: 8px; border: 1px solid var(--line); display: block; }
.load-more { display: block; margin: 8px auto; }

/* composer */
.composer { border-top: 1px solid var(--line); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); position: relative; }
.composer .box { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.composer .box:focus-within { border-color: var(--accent); }
.composer textarea { border: 0; resize: none; max-height: 200px; min-height: 40px; background: transparent; outline: none; }
.composer .bar { display: flex; align-items: center; gap: 6px; padding: 4px 6px; }
.composer .bar .spacer { flex: 1; }
.composer .hint { font-size: 11px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 8px 0; }
.chip { font-size: 12px; background: var(--hover); border-radius: 12px; padding: 2px 4px 2px 10px; display: flex; align-items: center; gap: 4px; }
.chip button { background: none; border: 0; padding: 0 4px; }
.mention-pop { position: absolute; bottom: 100%; left: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.12); min-width: 240px; max-height: 240px; overflow-y: auto; z-index: 5; }
.mention-pop button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 7px 12px; }
.mention-pop button.sel, .mention-pop button:hover { background: var(--hover); }
.drop { outline: 2px dashed var(--accent); outline-offset: -6px; }

/* dialogs */
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; background: var(--panel); color: var(--text); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 48px); }
dialog::backdrop { background: rgba(20, 18, 15, .45); }
.modal { padding: 20px 22px; display: grid; gap: 14px; }
.modal h3 { font-size: 22px; }
.modal .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal label { display: grid; gap: 4px; font-size: 14px; }
.modal label.check { display: flex; align-items: center; gap: 8px; }
.modal label.check input { width: auto; }
.pick-list { max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.pick-list > div, .pick-list > label, .pick-list > button { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; }
.pick-list > :last-child { border-bottom: 0; }
.pick-list input[type="checkbox"] { width: auto; }
.pick-list .grow { flex: 1; min-width: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; padding: 8px 12px; border-bottom: 2px solid transparent; }
.tabs button.on { border-bottom-color: var(--accent); font-weight: 600; }
.tag { font-size: 11px; border: 1px solid var(--line); border-radius: 10px; padding: 0 7px; color: var(--muted); white-space: nowrap; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.emoji-grid button { font-size: 22px; background: none; border: 0; padding: 6px; border-radius: 6px; }
.emoji-grid button:hover { background: var(--hover); }
.result { text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 10px 4px; width: 100%; }
.result:hover { background: var(--hover); }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--side); color: var(--side-text); padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: calc(100vw - 32px); box-shadow: 0 4px 16px rgba(0,0,0,.2); }

/* phones */
@media (max-width: 760px) {
  .app, .app.with-thread { grid-template-columns: 1fr; }
  .app .main, .app .thread { display: none; }
  .app.show-main .sidebar { display: none; }
  .app.show-main .main { display: flex; }
  .app.show-thread .sidebar, .app.show-thread .main { display: none; }
  .app.show-thread .thread { display: flex; border-left: 0; }
  .back { display: inline-block; }
  .msg-tools { top: -18px; }
  .composer .hint { display: none; }
  input, textarea, select { font-size: 16px; } /* stops iPhone zooming in */
}
