:root {
  --pine: #173B36; --pine-2: #21504A; --pine-ink: #D8E6E2; --pine-dim: #9DB8B2;
  --marigold: #F0A81C; --ink: #18211F; --muted: #68736F; --line: #E4E8E6; --wash: #F4F6F5; --paper: #FFFFFF;
  --danger: #B42318;
  --font: "Avenir Next", Avenir, "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 16px/1.45 var(--font); color: var(--ink); background: var(--paper); -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: #0B5E8A; }
:focus-visible { outline: 2px solid var(--marigold); outline-offset: 2px; }
[hidden] { display: none !important; }

#app { display: grid; grid-template-columns: 280px minmax(0, 1fr) auto; height: 100dvh; }

/* ---- sidebar ---- */
#side { background: var(--pine); color: var(--pine-ink); display: flex; flex-direction: column; min-height: 0; padding-top: env(safe-area-inset-top); }
.brand { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 10px; }
.brand h1 { font-size: 28px; line-height: 1; margin: 0; font-weight: 700; letter-spacing: -0.02em; color: #fff; }
.brand .wordmark { display: block; height: 52px; width: auto; max-width: 180px; object-fit: contain; object-position: left center; }
.me { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--pine-ink); padding: 4px 6px; border-radius: 8px; }
.me:hover { background: var(--pine-2); }
.side-search { margin: 6px 14px 10px; }
.side-search input { width: 100%; border: 0; border-radius: 10px; padding: 9px 12px; background: var(--pine-2); color: #fff; }
.side-search input::placeholder { color: var(--pine-dim); }
.side-scroll { flex: 1; overflow-y: auto; padding: 0 8px 20px; -webkit-overflow-scrolling: touch; }
.side-h { display: flex; align-items: center; justify-content: space-between; padding: 16px 10px 4px; font-size: 13px; font-weight: 600; color: var(--pine-dim); }
.side-h button { color: var(--pine-dim); font-size: 20px; line-height: 1; width: 28px; height: 28px; border-radius: 8px; }
.side-h button:hover { background: var(--pine-2); color: #fff; }
.row { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 8px 10px; border-radius: 9px; color: var(--pine-ink); min-height: 40px; }
.row:hover { background: var(--pine-2); }
.row.on { background: var(--marigold); color: var(--ink); font-weight: 600; }
.row .glyph { width: 22px; text-align: center; opacity: .7; flex: none; }
.row .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.unread { color: #fff; font-weight: 700; }
.row.on.unread { color: var(--ink); }
.badge { background: var(--marigold); color: var(--ink); font-size: 12px; font-weight: 700; border-radius: 10px; padding: 1px 7px; }
.row.on .badge { background: var(--ink); color: #fff; }

/* ---- avatars ---- */
.av { width: 38px; height: 38px; border-radius: 12px; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px; object-fit: cover; }
.av.sm { width: 24px; height: 24px; border-radius: 8px; font-size: 11px; }
.av.lg { width: 54px; height: 54px; border-radius: 16px; font-size: 20px; }

/* ---- main ---- */
#main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--paper); }
.head { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--line); min-height: 60px; padding-top: calc(12px + env(safe-area-inset-top)); }
.head h2 { font-size: 19px; margin: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head .topic { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head .grow { flex: 1; min-width: 0; }
.back { display: none; font-size: 26px; width: 36px; height: 36px; margin-left: -8px; border-radius: 10px; }
.tool { height: 36px; padding: 0 12px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); white-space: nowrap; flex: none; }
.tool:hover { background: var(--wash); color: var(--ink); }
.tool.on { background: var(--pine); border-color: var(--pine); color: #fff; }
input.tool { width: 150px; background: #fff; }
.tool .slim { display: none; }

.scroll { flex: 1; overflow-y: auto; min-height: 0; padding: 8px 0 12px; -webkit-overflow-scrolling: touch; }
.day { display: flex; align-items: center; gap: 12px; margin: 18px 18px 8px; font-size: 13px; font-weight: 700; color: var(--muted); }
.day::before, .day::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.empty { color: var(--muted); padding: 40px 24px; text-align: center; max-width: 440px; margin: 0 auto; }
.empty b { display: block; color: var(--ink); font-size: 19px; margin-bottom: 6px; }
.more { display: block; margin: 8px auto; }

/* ---- messages ---- */
.msg { display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 0 12px; padding: 6px 18px; position: relative; }
.msg.cont { padding-top: 1px; }
.msg.cont .av, .msg.cont .meta { display: none; }
.msg:hover, .msg.sel { background: var(--wash); }
.msg.flash { animation: flash 2.2s ease-out; }
@keyframes flash { from { background: #FCE9BF; } to { background: transparent; } }
.msg .body { grid-column: 2; min-width: 0; }
.meta { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.meta b { font-weight: 700; }
.meta time, .meta .tag { font-size: 12.5px; color: var(--muted); }
.meta .tag { border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; background: #fff; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; }
.text code { background: var(--wash); border: 1px solid var(--line); border-radius: 5px; padding: 0 4px; font-size: .9em; }
.text pre { background: var(--wash); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; overflow-x: auto; margin: 4px 0; font-size: .88em; }
.mention { background: #FCE9BF; border-radius: 5px; padding: 0 3px; font-weight: 600; }
.edited { color: var(--muted); font-size: 12px; }
.files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.files .ph { border-radius: 12px; overflow: hidden; background: var(--wash); display: block; position: relative; }
.files .ph img { display: block; height: 180px; width: auto; max-width: 100%; object-fit: cover; }
.files.one .ph img { height: auto; max-height: 420px; max-width: min(100%, 520px); }
.files video { max-width: min(100%, 520px); max-height: 420px; border-radius: 12px; background: #000; display: block; }
.files audio { width: min(100%, 420px); }
.chip { display: inline-flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; text-decoration: none; color: var(--ink); max-width: 100%; background: #fff; }
.chip .ext { background: var(--pine); color: #fff; border-radius: 7px; font-size: 11px; font-weight: 700; padding: 3px 6px; }
.chip span.n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip small { color: var(--muted); white-space: nowrap; }
.chip.gone { color: var(--muted); border-style: dashed; }
.reacts { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.react { border: 1px solid var(--line); border-radius: 14px; padding: 1px 9px; font-size: 14px; background: #fff; }
.react.mine { border-color: var(--marigold); background: #FEF4DC; }
.react small { color: var(--muted); margin-left: 3px; font-weight: 600; }
.replies { margin-top: 5px; font-size: 14px; font-weight: 600; color: #0B5E8A; padding: 3px 8px; margin-left: -8px; border-radius: 8px; }
.replies:hover { background: #E3EFF5; }
.acts { position: absolute; right: 14px; top: -14px; display: none; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 4px 14px rgba(23, 59, 54, .12); z-index: 2; }
.msg:hover .acts, .msg.sel .acts { display: flex; }
.acts button { width: 36px; height: 34px; font-size: 16px; border-radius: 8px; }
.acts button:hover { background: var(--wash); }
.picker { position: absolute; right: 14px; top: 22px; z-index: 3; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(23, 59, 54, .18); padding: 6px; display: grid; grid-template-columns: repeat(5, 40px); }
.picker button { height: 40px; font-size: 21px; border-radius: 8px; }
.picker button:hover { background: var(--wash); }

/* ---- composer ---- */
.composer { border-top: 1px solid var(--line); padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); position: relative; background: #fff; }
.composer .box { display: flex; align-items: flex-end; gap: 6px; border: 1.5px solid var(--line); border-radius: 14px; padding: 5px 6px; background: #fff; }
.composer .box:focus-within { border-color: var(--pine); }
.composer textarea { flex: 1; border: 0; outline: 0; resize: none; padding: 7px 6px; max-height: 180px; background: transparent; min-width: 0; }
.composer .attach { width: 38px; height: 38px; border-radius: 10px; font-size: 22px; color: var(--muted); flex: none; }
.composer .attach:hover { background: var(--wash); }
.composer .send { height: 38px; padding: 0 16px; border-radius: 10px; background: var(--marigold); color: var(--ink); font-weight: 700; flex: none; }
.composer .send:disabled { background: var(--line); color: var(--muted); cursor: default; }
.pending { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.pending:empty { display: none; }
.pend { position: relative; border: 1px solid var(--line); border-radius: 10px; padding: 6px 30px 6px 10px; font-size: 14px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: linear-gradient(to right, #FEF4DC var(--p, 0%), #fff var(--p, 0%)); }
.pend.done { background: var(--wash); }
.pend.err { border-color: var(--danger); color: var(--danger); }
.pend button { position: absolute; right: 4px; top: 3px; width: 24px; height: 24px; color: var(--muted); }
.suggest { position: absolute; left: 14px; bottom: 100%; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(23, 59, 54, .18); padding: 4px; min-width: 200px; z-index: 5; }
.suggest button { display: flex; gap: 8px; align-items: center; width: 100%; text-align: left; padding: 7px 9px; border-radius: 8px; }
.suggest button.on, .suggest button:hover { background: var(--wash); }
.drop #main::after { content: "Drop to add to your message"; position: fixed; inset: 12px; border: 3px dashed var(--marigold); border-radius: 18px; background: rgba(255, 255, 255, .9); display: grid; place-items: center; font-size: 22px; font-weight: 700; z-index: 20; pointer-events: none; }

/* ---- thread panel ---- */
#thread { width: 400px; border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: #fff; }
#thread .head h2 { font-size: 17px; }
.thread-sep { margin: 6px 18px; font-size: 13px; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); padding-bottom: 6px; }

/* ---- memories ---- */
.mem-h { margin: 22px 18px 10px; font-size: 17px; font-weight: 700; }
.mem-h small { font-weight: 500; color: var(--muted); margin-left: 6px; font-size: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px; padding: 0 18px; }
.tile { position: relative; aspect-ratio: 1; background: var(--wash); border-radius: 6px; overflow: hidden; display: block; }
.tile img, .tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .play { position: absolute; left: 8px; bottom: 8px; background: rgba(0, 0, 0, .6); color: #fff; border-radius: 8px; font-size: 12px; padding: 2px 7px; font-weight: 600; }
.tile .yr { position: absolute; right: 6px; top: 6px; background: var(--marigold); color: var(--ink); border-radius: 7px; font-size: 12px; padding: 1px 7px; font-weight: 700; }
.strip { display: flex; gap: 6px; overflow-x: auto; padding: 0 18px 4px; }
.strip .tile { flex: 0 0 180px; }

/* ---- lightbox ---- */
.lb { position: fixed; inset: 0; background: rgba(10, 20, 18, .96); z-index: 50; display: flex; flex-direction: column; color: #fff; }
.lb .stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 8px; }
.lb .stage img, .lb .stage video { max-width: 100%; max-height: 100%; object-fit: contain; }
.lb .bar { display: flex; align-items: center; gap: 12px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); font-size: 14px; }
.lb .bar .cap { flex: 1; min-width: 0; }
.lb .bar .cap div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #C9D6D3; }
.lb button, .lb a.btn { color: #fff; border: 1px solid rgba(255, 255, 255, .3); border-radius: 10px; height: 38px; padding: 0 12px; text-decoration: none; display: inline-grid; place-items: center; font-weight: 600; font-size: 14px; white-space: nowrap; }
.lb .x { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 12px; width: 42px; font-size: 20px; background: rgba(0, 0, 0, .4); }
.lb .nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 60px; font-size: 26px; background: rgba(0, 0, 0, .4); }
.lb .prev { left: 8px; } .lb .next { right: 8px; }

/* ---- people + dialogs ---- */
.people { padding: 8px 18px 30px; max-width: 900px; }
.person { display: grid; grid-template-columns: 54px minmax(0, 1fr) auto; gap: 6px 14px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--line); }
.person .fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.person .btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
input.f, textarea.f { border: 1.5px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%; background: #fff; min-width: 0; }
input.f:focus { border-color: var(--pine); outline: 0; }
.hint { color: var(--muted); font-size: 14px; }
.btn { height: 40px; padding: 0 16px; border-radius: 10px; font-weight: 700; background: var(--marigold); color: var(--ink); white-space: nowrap; }
.btn.quiet { background: #fff; border: 1.5px solid var(--line); font-weight: 600; }
.btn.quiet:hover { background: var(--wash); }
dialog { border: 0; border-radius: 18px; padding: 24px; width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(23, 59, 54, .35); color: var(--ink); }
dialog::backdrop { background: rgba(23, 59, 54, .55); }
dialog h3 { margin: 0 0 4px; font-size: 21px; }
dialog p { margin: 0 0 14px; color: var(--muted); }
dialog .stack { display: grid; gap: 10px; }
dialog .end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.who { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; max-height: 46vh; overflow-y: auto; }
.who button { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px; border: 1.5px solid var(--line); border-radius: 14px; font-weight: 600; font-size: 14px; }
.who button:hover, .who button.on { border-color: var(--pine); background: var(--wash); }
.who button.on { box-shadow: inset 0 0 0 2px var(--pine); }

.hit { display: block; width: 100%; text-align: left; border-bottom: 1px solid var(--line); }
.hit .where { padding: 10px 18px 0; font-size: 13px; font-weight: 700; color: var(--muted); }
.hit .msg { pointer-events: none; }
mark { background: #FCE9BF; border-radius: 3px; }

#offline { position: fixed; left: 50%; top: calc(10px + env(safe-area-inset-top)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 8px 16px; border-radius: 20px; font-size: 14px; z-index: 60; }

@media (max-width: 1100px) { #thread { position: fixed; right: 0; top: 0; bottom: 0; z-index: 30; box-shadow: -10px 0 40px rgba(23, 59, 54, .2); width: min(400px, 100vw); } }
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  #side, #main { grid-column: 1; grid-row: 1; }
  body[data-pane="side"] #main, body[data-pane="main"] #side { display: none; }
  #thread { width: 100vw; border: 0; }
  .back { display: inline-grid; place-items: center; }
  .row { min-height: 46px; font-size: 17px; }
  .head { padding-left: 14px; padding-right: 12px; }
  .head .topic, input.tool, .tool .wide { display: none; }
  .tool { padding: 0 10px; }
  .tool .slim { display: inline; }
  .msg { padding-left: 14px; padding-right: 14px; }
  .grid { grid-template-columns: repeat(3, 1fr); padding: 0 4px; gap: 3px; }
  .strip { padding: 0 4px 4px; } .strip .tile { flex-basis: 132px; }
  .person { grid-template-columns: 54px minmax(0, 1fr); } .person .fields { grid-template-columns: 1fr; } .person .btns { grid-column: 1 / -1; justify-content: flex-start; }
  .files .ph img { height: 130px; }
  .acts { top: -10px; }
}
@media (prefers-reduced-motion: reduce) { .msg.flash { animation: none; background: #FCE9BF; } }

dialog .hero { display: block; width: 100%; max-height: 150px; object-fit: contain; background: var(--pine); border-radius: 14px; padding: 16px; margin-bottom: 14px; }
