/* Chirp stylesheet: design tokens, light/dark, 3-pane desktop, 2-screen mobile. */

:root {
  --bg: #ffffff;
  --bg-alt: #f6f7f9;
  --bg-hover: #eceef2;
  --bg-sidebar: #1f2330;
  --fg-sidebar: #c9cedb;
  --fg-sidebar-strong: #ffffff;
  --bg-sidebar-hover: #2b3042;
  --bg-sidebar-active: #3b5bdb;
  --fg: #1c1f26;
  --fg-muted: #5f6675;
  --border: #dfe2e8;
  --accent: #3b5bdb;
  --accent-fg: #ffffff;
  --accent-soft: #e7ecfd;
  --danger: #c92a2a;
  --danger-soft: #fdecec;
  --mention-bg: #fff6d6;
  --ok: #2b8a3e;
  --away: #e8a317;
  --shadow: 0 8px 28px rgba(15, 20, 40, 0.18);
  --radius: 8px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #15171d;
    --bg-alt: #1c1f27;
    --bg-hover: #262a35;
    --bg-sidebar: #0f1116;
    --bg-sidebar-hover: #1b1e27;
    --fg: #e7e9ee;
    --fg-muted: #9aa1b0;
    --border: #2b2f3b;
    --accent: #7b93ff;
    --accent-fg: #0b0e17;
    --accent-soft: #232a4a;
    --danger: #ff7b7b;
    --danger-soft: #3a1d1f;
    --mention-bg: #3a3320;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #15171d;
  --bg-alt: #1c1f27;
  --bg-hover: #262a35;
  --bg-sidebar: #0f1116;
  --bg-sidebar-hover: #1b1e27;
  --fg: #e7e9ee;
  --fg-muted: #9aa1b0;
  --border: #2b2f3b;
  --accent: #7b93ff;
  --accent-fg: #0b0e17;
  --accent-soft: #232a4a;
  --danger: #ff7b7b;
  --danger-soft: #3a1d1f;
  --mention-bg: #3a3320;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.45 var(--font); color: var(--fg); background: var(--bg); -webkit-text-size-adjust: 100%; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
a { color: var(--accent); }
kbd { font: 11px var(--mono); padding: 1px 5px; border: 1px solid var(--border); border-radius: 4px; background: var(--bg-alt); color: var(--fg-muted); }

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--fg-muted); }
.small { font-size: 12.5px; }
.pad { padding: 8px 16px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.spacer { flex: 1; }
.boot { display: grid; place-items: center; height: 100%; color: var(--fg-muted); }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); min-height: 36px; }
.btn:hover { background: var(--bg-hover); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-small { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn.wide { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 6px; background: transparent; color: inherit; flex: none; }
.icon-btn:hover { background: var(--bg-hover); }
.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; }
input[type='text'], input[type='password'], input[type='search'], input[type='number'], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); min-height: 38px;
}
input[type='checkbox'] { width: 16px; height: 16px; accent-color: var(--accent); }
textarea { resize: none; display: block; }
.field { margin: 0 0 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; font-size: 13.5px; }
.hint { color: var(--fg-muted); font-size: 12.5px; margin-top: 4px; }
.form-error { color: var(--danger); font-size: 13.5px; margin: 6px 0; min-height: 0; }
.form-error:empty { display: none; }
.check { display: flex; align-items: center; gap: 8px; margin: 12px 0; }
.tag { margin-left: 8px; padding: 1px 6px; font-size: 11px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.badge { background: var(--danger); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; padding: 0 5px; display: inline-grid; place-items: center; }
.badge.corner { position: absolute; top: -4px; right: -4px; }
.pip { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

.avatar { width: var(--size, 36px); height: var(--size, 36px); border-radius: 8px; display: inline-grid; place-items: center; flex: none; font-size: calc(var(--size, 36px) * 0.38); font-weight: 700; color: #fff; background: hsl(var(--hue) 45% 42%); user-select: none; }
.dot { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--fg-sidebar); display: inline-block; flex: none; }
.dot.online { background: var(--ok); border-color: var(--ok); }
.dot.away { background: var(--away); border-color: var(--away); }
.modal .dot { border-color: var(--fg-muted); }
.modal .dot.online { border-color: var(--ok); }
.modal .dot.away { border-color: var(--away); }

/* ---------- auth ---------- */
.auth-root { height: 100%; display: grid; place-items: center; padding: 16px; overflow: auto; background: var(--bg-alt); }
.auth-card { width: 100%; max-width: 400px; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 28px; box-shadow: var(--shadow); }
.auth-card .brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.auth-card h2 { font-size: 18px; margin-bottom: 14px; }
.auth-links { display: flex; justify-content: space-between; gap: 12px; margin: 16px 0 0; font-size: 14px; }

/* ---------- app shell ---------- */
.app { display: grid; grid-template-columns: 64px 260px minmax(0, 1fr); height: 100%; }
.rail { background: var(--bg-sidebar); display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px 0; overflow-y: auto; border-right: 1px solid rgba(255, 255, 255, 0.06); }
.rail .ws { position: relative; background: none; border: 2px solid transparent; border-radius: 12px; padding: 2px; color: var(--fg-sidebar); }
.rail .ws.active { border-color: var(--accent); }
.rail .ws.add { width: 40px; height: 40px; border: 1px dashed var(--fg-sidebar); border-radius: 10px; display: grid; place-items: center; }
.rail .ws:hover { background: var(--bg-sidebar-hover); }
.rail .pip { position: absolute; top: 2px; right: 2px; color: #fff; border: 2px solid var(--bg-sidebar); box-sizing: content-box; }

.sidebar { background: var(--bg-sidebar); color: var(--fg-sidebar); display: flex; flex-direction: column; min-height: 0; }
.ws-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 10px 10px 6px; padding: 8px 10px; background: transparent; border: 0; border-radius: 6px; color: var(--fg-sidebar-strong); font-weight: 700; font-size: 16px; text-align: left; }
.ws-title:hover { background: var(--bg-sidebar-hover); }
.search-btn { margin: 0 10px 8px; background: var(--bg-sidebar-hover); border-color: transparent; color: var(--fg-sidebar); justify-content: flex-start; }
.search-btn:hover { background: var(--bg-sidebar-hover); filter: brightness(1.15); }
.search-btn kbd { margin-left: auto; background: transparent; border-color: rgba(255, 255, 255, 0.2); color: var(--fg-sidebar); }
.side-scroll { flex: 1; overflow-y: auto; padding-bottom: 12px; }
.section-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 4px 16px; }
.section-head h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--fg-sidebar); opacity: 0.8; }
.section-head .icon-btn { width: 24px; height: 24px; color: var(--fg-sidebar); }
.section-head .icon-btn:hover { background: var(--bg-sidebar-hover); }
.sidebar .link { color: var(--fg-sidebar); opacity: 0.85; }
.rows { list-style: none; margin: 0; padding: 0 8px; }
.row-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 8px; border: 0; border-radius: 6px; background: transparent; color: var(--fg-sidebar); text-align: left; min-height: 32px; }
.row-item:hover { background: var(--bg-sidebar-hover); }
.row-item.active { background: var(--bg-sidebar-active); color: #fff; }
.row-item.unread { color: var(--fg-sidebar-strong); font-weight: 700; }
.row-item .lead { width: 16px; display: grid; place-items: center; flex: none; }
.row-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me { display: flex; align-items: center; gap: 4px; padding: 8px 10px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.me .icon-btn { color: var(--fg-sidebar); }
.me .icon-btn:hover { background: var(--bg-sidebar-hover); }
.me-btn { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 4px; border-radius: 6px; color: var(--fg-sidebar-strong); text-align: left; }
.me-btn:hover { background: var(--bg-sidebar-hover); }
.me-name { display: flex; flex-direction: column; min-width: 0; font-weight: 600; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-name .muted { color: var(--fg-sidebar); font-weight: 400; }

.content { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.banner { padding: 6px 16px; text-align: center; font-size: 13px; background: var(--mention-bg); border-bottom: 1px solid var(--border); }
.banner.offline { background: var(--danger-soft); color: var(--danger); }
.main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-header { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); min-height: 56px; }
.chat-header h2 { font-size: 16px; display: flex; align-items: center; gap: 2px; }
.chat-header .titles { min-width: 0; }
.chat-header .topic { max-width: 46ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: none; }

.list-wrap { position: relative; flex: 1; min-height: 0; display: flex; }
.messages { flex: 1; overflow-y: auto; padding: 8px 0 12px; overscroll-behavior: contain; }
.messages:focus-visible { outline-offset: -2px; }
.empty, .start { padding: 32px 20px; text-align: center; }
.older { text-align: center; padding: 8px; }
.jump { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); display: inline-flex; align-items: center; gap: 4px; background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 999px; padding: 6px 14px; box-shadow: var(--shadow); font-weight: 600; }
.day, .new-divider { display: flex; align-items: center; gap: 12px; margin: 14px 16px 6px; font-size: 12px; font-weight: 600; color: var(--fg-muted); }
.day::before, .day::after, .new-divider::before, .new-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.new-divider { color: var(--danger); }
.new-divider::before, .new-divider::after { background: var(--danger); opacity: 0.5; }

.msg { position: relative; display: flex; gap: 10px; padding: 3px 16px; }
.msg:hover { background: var(--bg-alt); }
.msg.mention { background: var(--mention-bg); box-shadow: inset 3px 0 0 var(--away); }
.msg.grouped { padding-top: 0; padding-bottom: 0; }
.msg.pending { opacity: 0.7; }
.msg.failed { opacity: 1; }
.gutter-time { width: 36px; flex: none; font-size: 10.5px; color: transparent; text-align: right; padding-top: 4px; }
.msg:hover .gutter-time { color: var(--fg-muted); }
.main-col { min-width: 0; flex: 1; }
.meta { line-height: 1.3; }
.meta time { color: var(--fg-muted); font-size: 12px; }
.body { overflow-wrap: anywhere; }
.body p { margin: 0; }
.body p + p, .body pre, .body ul, .body ol, .body blockquote { margin-top: 4px; }
.body ul, .body ol { margin-bottom: 0; padding-left: 22px; }
.body blockquote { margin-left: 0; padding-left: 10px; border-left: 3px solid var(--border); color: var(--fg-muted); }
.body code { font-family: var(--mono); font-size: 0.9em; background: var(--bg-hover); padding: 1px 5px; border-radius: 4px; }
.body pre { background: var(--bg-hover); padding: 10px 12px; border-radius: var(--radius); overflow-x: auto; }
.body pre code { background: none; padding: 0; }
.body .mention, .mention-chip { background: var(--accent-soft); color: var(--accent); border-radius: 4px; padding: 0 3px; font-weight: 600; }
.body .mention-all { background: var(--mention-bg); }
.body .mention.mention-me { background: var(--mention-bg); color: inherit; box-shadow: 0 0 0 1px var(--away); }
.att-img { display: block; max-width: min(360px, 100%); height: auto; border-radius: var(--radius); border: 1px solid var(--border); margin-top: 4px; background: var(--bg-alt); }
.att-file { display: inline-flex; align-items: center; gap: 8px; margin-top: 4px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); color: inherit; text-decoration: none; background: var(--bg); max-width: 100%; }
.att-file .fname { font-weight: 600; overflow-wrap: anywhere; }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction { border: 1px solid var(--border); background: var(--bg-alt); border-radius: 999px; padding: 1px 8px; font-size: 13px; }
.reaction.mine { background: var(--accent-soft); border-color: var(--accent); }
.toolbar { position: absolute; right: 16px; top: -14px; display: none; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 2px; box-shadow: var(--shadow); }
.msg:hover .toolbar, .msg:focus-within .toolbar { display: flex; }
.edit-box { min-height: 60px; }
.typing { height: 20px; padding: 0 16px; font-size: 12.5px; color: var(--fg-muted); }

/* ---------- composer ---------- */
.composer { padding: 0 16px 14px; }
.compose-row { display: flex; align-items: flex-end; gap: 4px; border: 1px solid var(--border); border-radius: 10px; padding: 4px; background: var(--bg); }
.compose-row:focus-within { border-color: var(--accent); }
.compose-field { position: relative; flex: 1; min-width: 0; }
.compose-input { border: 0; padding: 7px 6px; min-height: 36px; max-height: 200px; background: transparent; }
.compose-input:focus { outline: none; }
.send { padding: 0; width: 36px; min-height: 36px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 8px; border: 1px solid var(--border); border-radius: 999px; font-size: 13px; background: var(--bg-alt); }
.chip.err { border-color: var(--danger); color: var(--danger); }
.chip .icon-btn { width: 22px; height: 22px; }
.spin { width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.mention-box { position: absolute; bottom: calc(100% + 8px); left: 0; z-index: 20; list-style: none; margin: 0; padding: 4px; min-width: 260px; max-width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.mention-box li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.mention-box li.selected, .mention-box li:hover { background: var(--accent-soft); }

/* ---------- modals, toasts, popovers ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(10, 12, 20, 0.55); display: grid; place-items: center; padding: 16px; overflow: auto; }
.modal { width: 100%; max-width: 460px; max-height: calc(100dvh - 32px); display: flex; flex-direction: column; background: var(--bg); border-radius: 12px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.modal.wide { max-width: 640px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-body h3 { font-size: 14px; margin: 20px 0 8px; padding-top: 14px; border-top: 1px solid var(--border); }
.modal-body h3:first-child { margin-top: 0; padding-top: 0; border: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.list.pick { max-height: 320px; overflow-y: auto; margin-top: 8px; }
.list.pick li { padding: 6px 8px; border-radius: 6px; border: 0; cursor: pointer; }
.list.pick li.selected, .list.pick li:hover { background: var(--accent-soft); }
.recovery-code { font: 600 18px var(--mono); letter-spacing: 0.04em; text-align: center; padding: 14px 10px; margin: 14px 0; background: var(--bg-alt); border: 1px dashed var(--border); border-radius: var(--radius); user-select: all; overflow-wrap: anywhere; }
.recovery-code.small { font-size: 13px; text-align: left; }
.shortcuts { border-collapse: collapse; width: 100%; }
.shortcuts th { text-align: left; padding: 6px 12px 6px 0; white-space: nowrap; font-weight: 400; }
.shortcuts td { padding: 6px 0; }
#toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); font-size: 14px; }
.toast.error { background: var(--danger); color: #fff; }
.emoji-pop { position: fixed; z-index: 150; display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; padding: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); width: 296px; }
.emoji-btn { border: 0; background: none; font-size: 20px; padding: 4px; border-radius: 6px; line-height: 1; }
.emoji-btn:hover { background: var(--bg-hover); }

/* ---------- responsive ---------- */
@media (max-width: 1024px) {
  .app { grid-template-columns: 56px 230px minmax(0, 1fr); }
}
@media (max-width: 768px) {
  .app { grid-template-columns: 56px minmax(0, 1fr); }
  .sidebar { grid-column: 2; }
  .content { grid-column: 2; grid-row: 1; }
  .app[data-view='list'] .content { display: none; }
  .app[data-view='chat'] .sidebar, .app[data-view='chat'] .rail { display: none; }
  .app[data-view='chat'] { grid-template-columns: minmax(0, 1fr); }
  .app[data-view='chat'] .content { grid-column: 1; }
  .back { display: inline-grid; }
  .toolbar { display: flex; top: -16px; right: 8px; opacity: 0.9; }
  .msg:not(:hover):not(:focus-within) .toolbar { display: none; }
  .composer { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .chat-header .topic { display: none; }
  .modal-backdrop { align-items: end; padding: 0; }
  .modal { max-width: none; border-radius: 14px 14px 0 0; max-height: 92dvh; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; scroll-behavior: auto !important; } }
.sidebar .link.pad { padding: 4px 16px; display: block; }
