/* Talk. Phone first, then two panes from 860px. Contrast is AA or better on the colors below.
   Text on white: #1a1f29 (16:1), muted #4b5563 (7.5:1). Buttons: white on #1d4ed8 (6.7:1). */
:root {
  --bg: #ffffff; --panel: #f4f6f9; --line: #d5dae3; --text: #1a1f29; --muted: #4b5563;
  --primary: #1d4ed8; --primary-dark: #1e3a8a; --danger: #b91c1c;
  --agent: #2563eb; --agent-bg: #eef4ff; --agent-ink: #1e3a8a; --agent-pill: #dbeafe;
  --bot: #7c3aed; --bot-bg: #f6f1ff; --bot-ink: #4c1d95; --bot-pill: #ede9fe;
  --imp: #6b7280; --imp-bg: #f3f4f6; --imp-ink: #374151;
  --warn-bg: #fff4d6; --warn-line: #b45309; --warn-ink: #5c3200;
  --tap: 44px; --radius: 10px;
}
* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 8px; top: -60px; z-index: 50; background: var(--text); color: #fff; padding: 10px 14px; border-radius: 8px; }
.skip:focus { top: 8px; }
a { color: var(--primary); }
:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 8px 16px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.ic { width: 18px; height: 18px; flex: none; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 8px; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 16px; }
p { margin: 0 0 10px; }

/* Buttons and inputs: every control is at least 44px high */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); min-width: var(--tap); padding: 8px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--panel); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.icon { padding: 8px; }
.btn.big { width: 100%; min-height: 52px; font-size: 17px; }
.linkbtn { min-height: var(--tap); padding: 6px 8px; border: 0; background: none; color: var(--primary); font: inherit; text-decoration: underline; cursor: pointer; }
input[type=text], input[type=email], input[type=search], select, textarea { width: 100%; min-height: var(--tap); padding: 9px 12px; border: 1px solid #8a93a3; border-radius: var(--radius); background: #fff; color: var(--text); font: inherit; }
textarea { resize: vertical; }
label { display: block; font-weight: 600; margin: 10px 0 4px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; min-height: var(--tap); padding: 8px 0; }
.check input { width: 22px; height: 22px; margin: 2px 0 0; flex: none; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); margin: 12px 0; padding: 8px 12px; }
legend { font-weight: 600; padding: 0 6px; }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.inline-form { display: grid; gap: 4px; margin: 10px 0; }
.stack-form { display: grid; gap: 2px; }
.notice { background: var(--warn-bg); border-left: 4px solid var(--warn-line); color: var(--warn-ink); padding: 8px 12px; border-radius: 6px; }
.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); }
.tag.ext { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-ink); }

/* Gate */
.gate { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: var(--panel); }
.gate-card { width: 100%; max-width: 440px; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 24px; }
.brand { font-size: 30px; letter-spacing: .5px; }
.fine { font-size: 13px; color: var(--muted); margin-top: 12px; }

/* Shell: phone shows one pane at a time */
.shell { height: 100vh; height: 100dvh; display: grid; grid-template-columns: 1fr; position: relative; }
.shell[data-pane="list"] .main { display: none; }
.shell[data-pane="main"] .side { display: none; }
.side { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-right: 1px solid var(--line); }
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 16px; }
.brand-link { font-size: 22px; font-weight: 800; color: var(--text); text-decoration: none; padding: 6px 0; }
.live { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; font-weight: 600; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--muted); }
.live-live { color: #14532d; border-color: #86c79b; }
.live-polling, .live-connecting, .live-off { color: var(--warn-ink); border-color: var(--warn-line); background: var(--warn-bg); }
.search { display: flex; gap: 6px; padding: 0 16px 8px; }
.side-title { display: flex; align-items: center; justify-content: space-between; padding: 4px 16px; }
.side-title h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.chnav { flex: 1; overflow-y: auto; min-height: 0; }
.chlist { list-style: none; margin: 0; padding: 0 8px; }
.chlink { display: flex; align-items: center; gap: 8px; min-height: var(--tap); padding: 6px 10px; border-radius: 8px; color: var(--text); text-decoration: none; }
.chlink:hover { background: #e8ecf3; }
.chlink.current { background: #dfe6f5; font-weight: 700; }
.chlink.has-unread .chname { font-weight: 800; }
.hash { color: var(--muted); font-weight: 700; }
.chname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread { min-width: 24px; padding: 1px 8px; border-radius: 999px; background: var(--primary); color: #fff; font-size: 13px; font-weight: 700; text-align: center; }
.side-foot { border-top: 1px solid var(--line); padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); }
.who-am-i { margin: 0 0 2px; }
.menu { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; }
.menu a { display: inline-flex; align-items: center; min-height: var(--tap); }

.main { display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden; }
.main:focus { outline: none; }
.page { padding: 16px; overflow-y: auto; max-width: 760px; width: 100%; flex: 1 1 auto; min-height: 0; }
.page.empty { display: none; }
.phead { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.phead h1 { margin: 0; }
.back { flex: none; }
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 14px 0; }
.plist { list-style: none; padding: 0; margin: 8px 0; }
.plist li { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--panel); }
.secret { border: 2px solid var(--primary); border-radius: var(--radius); padding: 12px; margin: 12px 0; background: #f5f8ff; }
.prose h2 { margin-top: 20px; }
.legend { padding-left: 20px; }

/* Channel screen */
.channel { display: flex; flex-direction: column; flex: 1; min-height: 0; position: relative; }
.chead { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.ctitle { flex: 1; min-width: 0; }
.ctitle h1 { font-size: 19px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topic { margin: 0; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 8px 14px; }
.banner p { margin: 0; }
.banner.outside { background: var(--warn-bg); border-bottom: 2px solid var(--warn-line); color: var(--warn-ink); }
.banner .ic { margin-top: 3px; }
.members { padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.msgs { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 0 12px; overscroll-behavior: contain; }
.older { text-align: center; padding: 8px; }
.day { text-align: center; margin: 14px 0 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
.day::before, .day::after { content: ""; display: inline-block; width: 18%; border-top: 1px solid var(--line); vertical-align: middle; margin: 0 10px; }

/* One message. The left bar and the badge show the source; the badge always has a word. */
.msg { display: flex; gap: 10px; padding: 8px 14px 8px 11px; border-left: 4px solid transparent; }
.msg:hover { background: #fafbfc; }
.msg.src-agent { background: var(--agent-bg); border-left-color: var(--agent); }
.msg.src-bot { background: var(--bot-bg); border-left-color: var(--bot); }
.msg.src-imported, .msg.src-system, .msg.src-unknown { background: var(--imp-bg); border-left-color: var(--imp); }
.msg.pending { opacity: .8; }
.msg.is-deleted .who { color: var(--muted); }
.av { width: 38px; height: 38px; flex: none; display: grid; place-items: center; font-size: 14px; font-weight: 800; background: #e3e8f2; color: #1f2937; margin-top: 2px; }
.av-round { border-radius: 50%; }
.av-square { border-radius: 8px; background: #e4daf8; color: var(--bot-ink); }
.av-none { display: none; }
.av-ring { background: #dbeafe; color: var(--agent-ink); outline: 2px dashed var(--agent); outline-offset: 2px; }
.src-imported .av, .src-unknown .av { background: #e5e7eb; color: var(--imp-ink); }
.mbody { flex: 1; min-width: 0; }
.mhead { display: flex; flex-wrap: wrap; gap: 2px 8px; align-items: baseline; }
.who { font-weight: 800; }
time { font-size: 13px; color: var(--muted); }
.note-imp { font-size: 13px; color: var(--imp-ink); font-weight: 600; }
.text { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.text a { color: var(--primary); word-break: break-all; }
.mention { font-weight: 700; color: var(--primary-dark); background: #e0e9ff; border-radius: 4px; padding: 0 3px; }
.tomb { margin: 2px 0 0; font-style: italic; color: var(--muted); }

/* The source pill: icon plus word, tooltip on hover and keyboard focus */
.pill { position: relative; display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; border: 1px solid transparent; cursor: help; }
.pill .ic { width: 14px; height: 14px; }
.pill::before { content: ""; position: absolute; inset: -12px -6px; }
.pill-human { background: #fff; border-color: #aab3c2; color: #1f2937; }
.pill-agent { background: var(--agent-pill); border-color: var(--agent); border-style: dashed; color: var(--agent-ink); }
.pill-bot { background: var(--bot-pill); border-color: var(--bot); color: var(--bot-ink); }
.pill-imported, .pill-system, .pill-unknown { background: #e5e7eb; border-color: var(--imp); color: var(--imp-ink); }
.pill .tip { display: none; position: absolute; left: 0; top: calc(100% + 6px); z-index: 20; width: max-content; max-width: min(300px, 80vw); padding: 8px 10px; border-radius: 8px; background: #111827; color: #fff; font-size: 13px; font-weight: 500; line-height: 1.35; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); white-space: normal; }
.pill:hover .tip, .pill:focus .tip { display: block; }

.actions { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
.actions .linkbtn { font-size: 14px; padding: 2px 10px; min-height: var(--tap); min-width: var(--tap); }
.msg { position: relative; }
@media (hover: hover) and (pointer: fine) {
  .msg .actions { position: absolute; right: 12px; top: -4px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 0 4px; opacity: 0; }
  .msg:hover .actions, .msg:focus-within .actions { opacity: 1; }
}
.confirm { display: inline-flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.editbox textarea { margin-top: 4px; }

.jump { position: absolute; left: 50%; transform: translateX(-50%); bottom: 90px; z-index: 5; box-shadow: 0 4px 14px rgba(0, 0, 0, .25); }
.composer { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #fff; }
.composer textarea { flex: 1; min-width: 0; max-height: 180px; resize: none; }
.composer .count { flex-basis: 100%; margin: 0; }

.results { list-style: none; padding: 0; }
.result { padding: 10px 0; border-bottom: 1px solid var(--line); }
.chlink-name, .result .chlink { display: inline; padding: 0; font-weight: 700; min-height: 0; }

.modal-bg { position: fixed; inset: 0; z-index: 40; background: rgba(15, 23, 42, .55); display: grid; place-items: center; padding: 16px; }
.modal { width: 100%; max-width: 460px; background: #fff; border-radius: 14px; padding: 18px; max-height: 90vh; overflow-y: auto; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 90px; z-index: 60; max-width: 90vw; background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; }

@media (min-width: 860px) {
  .shell { grid-template-columns: 320px 1fr; }
  .shell[data-pane="list"] .main, .shell[data-pane="main"] .side { display: flex; }
  .back { display: none; }
  .page.empty { display: block; }
  .page { padding: 24px 32px; }
  .msg { padding-left: 17px; padding-right: 24px; }
  .chead { padding: 10px 20px; }
  .composer { padding-left: 20px; padding-right: 20px; }
  .jump { bottom: 80px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }

/* The Sites shell adds its own skip link and <main>. This page has its own skip link. */
.skip-link { display: none; }
