/* ---------- tokens ---------- */
:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f1eee7;
  --surface-3: #e9e5dc;
  --border: #e2ddd2;
  --text: #22201c;
  --muted: #6e695f;
  --accent: #2e6b5b;
  --accent-strong: #245647;
  --accent-soft: #e1eee9;
  --on-accent: #ffffff;
  --claude: #c2643f;
  --claude-soft: #f8ece6;
  --claude-border: #efd3c6;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn-soft: #fff4dc;
  --mark: #fde68a;
  --mine: #2e6b5b;
  --on-mine: #ffffff;
  --shadow: 0 10px 30px rgba(40, 34, 20, .12), 0 2px 6px rgba(40, 34, 20, .06);
  --font: "Noto Sans Thai", "Sarabun", "Leelawadee UI", "Thonburi", "Tahoma", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --top-h: 56px;
  --tree-w: 310px;
  --chat-w: 430px;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1917; --surface: #22211e; --surface-2: #2a2926; --surface-3: #33312d; --border: #3a3833;
    --text: #ece8e1; --muted: #a39d92; --accent: #72b6a2; --accent-strong: #8fcab8; --accent-soft: #24372f;
    --on-accent: #0f1a16; --claude: #e38c69; --claude-soft: #352721; --claude-border: #5a3a2c;
    --danger: #f2877c; --danger-soft: #3a2220; --warn-soft: #3a3020; --mark: #6b5a17;
    --mine: #2f5d50; --on-mine: #eef7f3; --shadow: 0 10px 30px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1a1917; --surface: #22211e; --surface-2: #2a2926; --surface-3: #33312d; --border: #3a3833;
  --text: #ece8e1; --muted: #a39d92; --accent: #72b6a2; --accent-strong: #8fcab8; --accent-soft: #24372f;
  --on-accent: #0f1a16; --claude: #e38c69; --claude-soft: #352721; --claude-border: #5a3a2c;
  --danger: #f2877c; --danger-soft: #3a2220; --warn-soft: #3a3020; --mark: #6b5a17;
  --mine: #2f5d50; --on-mine: #eef7f3; --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.65 var(--font); -webkit-text-size-adjust: 100%;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.grow { flex: 1; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px;
  border: 0; background: transparent; color: var(--muted); flex: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 8px 14px;
}
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.small { padding: 3px 10px; font-size: 14px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 4px 10px 4px 8px; font-size: 14px; white-space: nowrap;
}
.pill svg { width: 16px; height: 16px; }

/* Claude's mark: an eight-point asterisk */
.claude-mark {
  display: inline-block; width: 18px; height: 18px; flex: none; background: var(--claude);
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g stroke="black" stroke-width="3.2" stroke-linecap="round"><path d="M12 2.5v19M2.5 12h19M5.3 5.3l13.4 13.4M18.7 5.3 5.3 18.7"/></g></svg>') center / contain no-repeat;
  mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g stroke="black" stroke-width="3.2" stroke-linecap="round"><path d="M12 2.5v19M2.5 12h19M5.3 5.3l13.4 13.4M18.7 5.3 5.3 18.7"/></g></svg>') center / contain no-repeat;
}
.claude-mark.spin { animation: spin 2.4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 55;
  height: calc(var(--top-h) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 12px 0;
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 700; font-size: 17px; min-width: 0; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-toggle { display: none; }
.chat-toggle {
  position: relative; display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px 0 12px;
  border-radius: 999px; border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent); font-weight: 600;
}
.chat-toggle:hover { background: var(--accent-strong); }
.chat-toggle.active { background: var(--surface); color: var(--accent); }
.badge {
  position: absolute; top: -6px; right: -6px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 12px; font-weight: 700; line-height: 22px; text-align: center;
  border: 2px solid var(--surface);
}
.avatar {
  --c: var(--accent);
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; flex: none;
  background: var(--c); color: #fff; font-weight: 700; font-size: 15px; border: 0; text-transform: uppercase;
}
.avatar.claude { background: var(--claude-soft); border: 1px solid var(--claude-border); }
.avatar.claude .claude-mark { width: 20px; height: 20px; }
.me-wrap, .claude-mode { position: relative; }
.menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 60; min-width: 250px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  padding: 6px; display: flex; flex-direction: column;
}
.menu-head { padding: 8px 10px; color: var(--muted); font-size: 14px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu button {
  text-align: left; border: 0; background: transparent; padding: 9px 10px; border-radius: 8px; display: flex; flex-direction: column;
}
.menu button:hover { background: var(--surface-2); }
.menu button small { color: var(--muted); font-size: 13px; line-height: 1.4; }
.menu button.on { background: var(--accent-soft); }
.menu button.on b::after { content: "  ✓"; color: var(--accent); }

/* ---------- layout ---------- */
.layout {
  /* absolute, not fixed: no stacking context, so drawers/scrim/top bar share one z-order */
  position: absolute; top: calc(var(--top-h) + env(safe-area-inset-top)); right: 0; bottom: 0; left: 0;
  display: grid; grid-template-columns: var(--tree-w) minmax(0, 1fr);
}
.layout.chat-open { grid-template-columns: var(--tree-w) minmax(0, 1fr) var(--chat-w); }
.tree-panel { min-height: 0; display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--border); }
.reader { min-height: 0; overflow: auto; scroll-behavior: smooth; -webkit-overflow-scrolling: touch; }
.scrim { position: fixed; inset: 0; background: rgba(20, 18, 14, .4); z-index: 40; }

/* ---------- tree ---------- */
.tree-search { position: relative; padding: 12px; border-bottom: 1px solid var(--border); }
.tree-search svg { position: absolute; left: 24px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); }
.tree-search input {
  width: 100%; height: 40px; padding: 0 12px 0 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); outline: none;
}
.tree-search input:focus { border-color: var(--accent); background: var(--surface); }
.tree { flex: 1; overflow: auto; padding: 8px 8px 40px; font-size: 15px; }
.tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul ul { margin-left: 15px; padding-left: 8px; border-left: 1px solid var(--border); }
.t-row { display: flex; align-items: flex-start; gap: 2px; border-radius: 8px; }
.t-row:hover { background: var(--surface-2); }
.t-row.active { background: var(--accent-soft); }
.t-row.active > a { color: var(--accent-strong); font-weight: 600; }
.t-caret {
  flex: none; width: 26px; height: 32px; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; border-radius: 6px;
}
.t-caret svg { width: 16px; height: 16px; transition: transform .15s; }
.t-caret.open svg { transform: rotate(90deg); }
.t-caret.none { visibility: hidden; }
.t-row a {
  flex: 1; min-width: 0; padding: 5px 8px 5px 2px; color: var(--text); text-decoration: none; line-height: 1.45;
}
.t-doc > .t-row a { font-weight: 700; }
.t-doc > .t-row .ico { margin-right: 6px; }
.t-row mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
.t-hit { display: block; font-size: 13px; color: var(--muted); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-empty { color: var(--muted); padding: 16px; font-size: 14px; }

/* ---------- reader ---------- */
.reader-inner { max-width: 900px; margin: 0 auto; padding: 22px 28px 120px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); text-decoration: underline; }
.reader-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.reader-head h1 { flex: 1; font-size: 26px; line-height: 1.35; margin: 0; }
.talk-btn {
  display: inline-flex; align-items: center; gap: 6px; flex: none; margin-top: 2px;
  border: 1px solid var(--accent); color: var(--accent); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 14px; font-weight: 600;
}
.talk-btn:hover { background: var(--accent-soft); }
.talk-btn svg { width: 17px; height: 17px; }
.md { overflow-wrap: anywhere; }
.md h2 { font-size: 21px; margin: 34px 0 10px; padding-top: 14px; border-top: 1px solid var(--border); scroll-margin-top: 12px; }
.md h3 { font-size: 18px; margin: 24px 0 8px; }
.md h4 { font-size: 16px; margin: 18px 0 6px; }
.md p, .md ul, .md ol { margin: 8px 0; }
.md li { margin: 3px 0; }
.md li > ul, .md li > ol { margin: 2px 0; }
.md strong { font-weight: 700; }
.md code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.md pre { background: var(--surface-2); padding: 12px; border-radius: 10px; overflow: auto; }
.md pre code { background: transparent; padding: 0; }
.md blockquote {
  margin: 12px 0; padding: 10px 16px; border-left: 4px solid var(--claude); background: var(--claude-soft); border-radius: 0 10px 10px 0;
}
.md blockquote p { margin: 4px 0; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 24px 0; }
.md img { max-width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--border); background: #fff; cursor: zoom-in; display: block; margin: 10px 0; }
.table-wrap { overflow-x: auto; margin: 12px 0; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); -webkit-overflow-scrolling: touch; }
.md table { border-collapse: collapse; width: 100%; font-size: 15px; line-height: 1.5; }
.md th, .md td { border-bottom: 1px solid var(--border); padding: 8px 10px; text-align: left; vertical-align: top; }
.md th + th, .md td + td { border-left: 1px solid var(--border); }
.md th { background: var(--surface-2); font-weight: 700; white-space: nowrap; }
.md tbody tr:last-child td { border-bottom: 0; }
.md tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
.sub-sec { margin-top: 8px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin: 18px 0; }
.card {
  display: block; padding: 14px 16px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface);
  text-decoration: none; color: var(--text);
}
.card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.card b { display: block; line-height: 1.4; }
.card small { color: var(--muted); }
.doc-title { font-size: 28px; line-height: 1.3; margin: 4px 0 12px; }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 40px; }
.pager a {
  display: block; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; text-decoration: none; color: var(--text); background: var(--surface);
}
.pager a:hover { border-color: var(--accent); }
.pager small { display: block; color: var(--muted); }
.pager .next { text-align: right; grid-column: 2; }

/* ---------- chat panel ---------- */
.chat-panel {
  position: relative; min-height: 0; display: flex; flex-direction: column;
  background: var(--bg); border-left: 1px solid var(--border);
}
.chat-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.chat-title { flex: 1; min-width: 0; line-height: 1.3; }
.chat-title b { font-size: 16px; }
.members { display: flex; gap: 6px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.members span { display: inline-flex; align-items: center; gap: 4px; }
.members i { width: 8px; height: 8px; border-radius: 50%; background: var(--surface-3); display: inline-block; }
.members .on i { background: #22a06b; }
.notify-banner {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--warn-soft); border-bottom: 1px solid var(--border); font-size: 14px; line-height: 1.45;
}
.notify-banner .grow { min-width: 0; }
.notify-banner .x { border: 0; background: transparent; color: var(--muted); font-size: 18px; }
.msgs { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 12px 6px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.msgs-top { text-align: center; font-size: 13px; color: var(--muted); padding: 6px; min-height: 8px; }
.day-sep { display: flex; justify-content: center; margin: 14px 0 8px; position: sticky; top: 0; z-index: 2; pointer-events: none; }
.day-sep span { background: var(--surface-3); color: var(--muted); font-size: 12.5px; padding: 2px 12px; border-radius: 999px; }
.msg { display: flex; gap: 8px; margin-top: 10px; align-items: flex-start; }
.msg.cont { margin-top: 2px; }
.msg.cont .avatar { visibility: hidden; height: 0; }
.msg .avatar { width: 32px; height: 32px; font-size: 13px; margin-top: 2px; }
.msg-body { min-width: 0; max-width: min(84%, 560px); display: flex; flex-direction: column; align-items: flex-start; }
.msg .name { font-size: 12.5px; color: var(--muted); margin: 0 4px 2px; font-weight: 600; }
.msg.cont .name { display: none; }
.bubble {
  position: relative; padding: 8px 12px; border-radius: 16px; border-top-left-radius: 6px;
  background: var(--surface); border: 1px solid var(--border); max-width: 100%; overflow-wrap: anywhere;
}
.msg.cont .bubble { border-top-left-radius: 16px; }
.bubble .text { white-space: pre-wrap; line-height: 1.55; }
.bubble .text a { color: inherit; text-decoration: underline; }
.msg.mine { flex-direction: row-reverse; }
.msg.mine .msg-body { align-items: flex-end; }
.msg.mine .avatar { display: none; }
.msg.mine .bubble { background: var(--mine); color: var(--on-mine); border-color: var(--mine); border-radius: 16px; border-top-right-radius: 6px; }
.msg.mine.cont .bubble { border-top-right-radius: 16px; }
.msg.claude .bubble { background: var(--claude-soft); border-color: var(--claude-border); }
.msg.claude .name { color: var(--claude); }
.msg.claude .bubble .md { white-space: normal; }
.bubble .md > :first-child { margin-top: 0; }
.bubble .md > :last-child { margin-bottom: 0; }
.bubble .md h1, .bubble .md h2, .bubble .md h3 { font-size: 16px; margin: 10px 0 4px; padding: 0; border: 0; }
.bubble .md table { font-size: 14px; }
.bubble .md .table-wrap { margin: 6px 0; }
.bubble .md blockquote { padding: 4px 10px; margin: 6px 0; }
.msg.pending .bubble { opacity: .65; }
.msg.failed .bubble { border-color: var(--danger); }
.msg.deleted .bubble { background: transparent; color: var(--muted); font-style: italic; border-style: dashed; }
.msg.mine.deleted .bubble { border-color: var(--border); }
.msg.flash .bubble { animation: flash 1.2s; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--claude); } 100% { box-shadow: none; } }
.meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin: 2px 6px 0; min-height: 18px; flex-wrap: wrap; }
.msg.mine .meta { flex-direction: row-reverse; }
.acts { display: inline-flex; gap: 2px; visibility: hidden; }
.acts button { border: 0; background: transparent; color: var(--muted); font-size: 12px; padding: 0 5px; border-radius: 6px; }
.acts button:hover { background: var(--surface-3); color: var(--text); }
@media (hover: hover) { .msg:hover .acts { visibility: visible; } }
.msg.show-acts .acts { visibility: visible; }
.seen { color: var(--accent); }
.quote {
  display: block; font-size: 13px; line-height: 1.4; padding: 4px 8px; margin: 0 0 6px; border-left: 3px solid var(--claude);
  background: color-mix(in srgb, var(--surface-3) 60%, transparent); border-radius: 6px; cursor: pointer; color: inherit; opacity: .9;
}
.msg.mine .quote { background: rgba(255, 255, 255, .14); border-left-color: rgba(255, 255, 255, .7); }
.refline {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 3px 9px; margin: 0 0 6px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-strong); text-decoration: none; font-weight: 600; max-width: 100%;
}
.msg.mine .refline { background: rgba(255, 255, 255, .16); color: var(--on-mine); }
.refline span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files { display: grid; gap: 4px; margin: 0 0 4px; }
.files.imgs { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); max-width: 340px; }
.files.imgs.one { grid-template-columns: 1fr; }
.files img { display: block; width: 100%; height: auto; aspect-ratio: 1; object-fit: cover; border-radius: 10px; cursor: zoom-in; background: var(--surface-2); }
.files.imgs.one img { width: auto; height: auto; aspect-ratio: auto; max-width: 100%; max-height: 340px; object-fit: contain; }
.file-chip {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; text-decoration: none; color: inherit;
  background: color-mix(in srgb, var(--surface-3) 55%, transparent); min-width: 200px; max-width: 320px;
}
.msg.mine .file-chip { background: rgba(255, 255, 255, .14); }
.file-chip .fi { flex: none; width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; background: var(--surface); color: var(--accent); font-size: 11px; font-weight: 700; }
.file-chip b { display: block; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip small { opacity: .75; }
.file-chip > div { min-width: 0; }
.msg.system { justify-content: center; }
.msg.system .sys { font-size: 13px; color: var(--muted); background: var(--surface-2); padding: 4px 12px; border-radius: 999px; text-align: center; max-width: 92%; }
.msg.system .sys time { opacity: .7; margin-left: 6px; }
.live-activity { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--claude); margin-top: 4px; }
.dots::after { content: "…"; animation: dots 1.2s steps(4, end) infinite; display: inline-block; width: 1.2em; overflow: hidden; vertical-align: bottom; }
@keyframes dots { 0% { width: 0; } 100% { width: 1.2em; } }
.jump {
  position: absolute; right: 16px; bottom: 150px; z-index: 5; border: 0; border-radius: 999px; padding: 6px 14px;
  background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow); font-size: 14px; font-weight: 600;
}
.claude-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 7px 12px; font-size: 14px;
  background: var(--claude-soft); border-top: 1px solid var(--claude-border); color: var(--text);
}
.claude-bar .grow { min-width: 140px; }
.claude-bar .btn { background: var(--surface); }
.typing { min-height: 0; padding: 0 16px; font-size: 13px; color: var(--muted); }
.typing:not(:empty) { padding: 2px 16px 4px; }
.composer {
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
}
.composer-row { display: flex; align-items: flex-end; gap: 4px; }
.composer textarea {
  flex: 1; min-width: 0; resize: none; max-height: 168px; min-height: 42px; padding: 9px 12px; line-height: 1.45;
  border: 1px solid var(--border); border-radius: 20px; background: var(--surface-2); outline: none;
}
.composer textarea:focus { border-color: var(--accent); background: var(--surface); }
.send {
  width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; flex: none;
}
.send:disabled { opacity: .45; cursor: default; }
.claude-call { width: 40px; height: 42px; }
.claude-call .claude-mark { width: 22px; height: 22px; }
.chip {
  display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 6px 8px 6px 10px; margin-bottom: 6px;
  background: var(--surface-2); border-left: 3px solid var(--claude); border-radius: 8px;
}
.chip.ref { border-left-color: var(--accent); }
.chip .grow { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .x { border: 0; background: transparent; color: var(--muted); font-size: 16px; padding: 0 4px; }
.pending { display: flex; gap: 8px; overflow-x: auto; }
.pending:not(:empty) { padding-bottom: 8px; }
.att {
  position: relative; flex: none; width: 76px; height: 76px; border-radius: 10px; overflow: hidden; background: var(--surface-2);
  border: 1px solid var(--border); display: grid; place-items: center; font-size: 11px; text-align: center; padding: 4px;
}
.att img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.att .nm { position: relative; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; word-break: break-all; }
.att .bar { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent); transition: width .2s; }
.att.error { border-color: var(--danger); }
.att.error::after { content: "ผิดพลาด"; position: absolute; inset: auto 0 0 0; background: var(--danger); color: #fff; font-size: 11px; }
.att .rm {
  position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .6); color: #fff; font-size: 13px; line-height: 22px; padding: 0;
}
.drop-overlay {
  position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 18%, transparent);
  border: 3px dashed var(--accent); border-radius: 12px; margin: 6px; pointer-events: none;
}
.drop-overlay div { background: var(--surface); padding: 12px 20px; border-radius: 12px; font-weight: 600; box-shadow: var(--shadow); }
.empty-chat { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 15px; }
.empty-chat .claude-mark { width: 36px; height: 36px; margin-bottom: 8px; }

/* ---------- lightbox / toast ---------- */
.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(10, 10, 10, .92); display: flex; flex-direction: column; }
.lb-bar { display: flex; justify-content: flex-end; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 12px 10px; }
.lb-btn { border: 1px solid rgba(255, 255, 255, .3); background: rgba(255, 255, 255, .08); color: #fff; border-radius: 10px; padding: 6px 14px; text-decoration: none; font-size: 15px; }
.lb-stage { flex: 1; overflow: auto; display: grid; place-items: center; padding: 8px; touch-action: pinch-zoom pan-x pan-y; }
.lb-stage img { max-width: 100%; max-height: calc(100vh - 90px); object-fit: contain; cursor: zoom-in; background: #fff; }
.lb-stage.zoom { place-items: start; }
.lb-stage.zoom img { max-width: none; max-height: none; cursor: zoom-out; }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 120;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; box-shadow: var(--shadow); font-size: 15px; max-width: calc(100% - 32px);
}

/* ---------- login ---------- */
.login-page { overflow: auto; display: grid; place-items: center; min-height: 100%; padding: 24px 16px; }
.login-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow);
  padding: 28px 24px; text-align: center;
}
.login-card h1 { margin: 10px 0 2px; font-size: 24px; }
.login-card form { text-align: left; margin-top: 20px; display: flex; flex-direction: column; gap: 16px; }
.who { border: 0; padding: 0; margin: 0; }
.who legend { font-weight: 600; margin-bottom: 8px; padding: 0; }
.who-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 10px; }
.who-list label { cursor: pointer; }
.who-list input { position: absolute; opacity: 0; pointer-events: none; }
.who-list .opt {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px; border-radius: 14px; border: 2px solid var(--border); background: var(--surface);
  font-weight: 600;
}
.who-list .opt .avatar { width: 44px; height: 44px; font-size: 18px; }
.who-list input:checked + .opt { border-color: var(--accent); background: var(--accent-soft); }
.who-list input:focus-visible + .opt { outline: 2px solid var(--accent); outline-offset: 2px; }
.pw span { display: block; font-weight: 600; margin-bottom: 6px; }
.pw input { width: 100%; height: 48px; padding: 0 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); font-size: 18px; letter-spacing: .1em; }
.pw input:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.login-error { color: var(--danger); background: var(--danger-soft); padding: 8px 12px; border-radius: 10px; margin: 0; font-size: 15px; }
.login-card .btn.primary { height: 48px; font-size: 17px; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .layout.chat-open { grid-template-columns: var(--tree-w) minmax(0, 1fr); }
  .chat-panel {
    position: fixed; top: calc(var(--top-h) + env(safe-area-inset-top)); right: 0; bottom: 0; z-index: 45;
    width: min(var(--chat-w), 100%); box-shadow: var(--shadow);
  }
}
@media (max-width: 820px) {
  :root { --top-h: 52px; }
  body { font-size: 16px; }
  .layout, .layout.chat-open { grid-template-columns: minmax(0, 1fr); }
  .tree-toggle { display: inline-grid; }
  .tree-panel {
    position: fixed; top: calc(var(--top-h) + env(safe-area-inset-top)); left: 0; bottom: 0; z-index: 46;
    width: min(340px, 88vw); transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow);
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.tree-open .tree-panel { transform: none; }
  .chat-toggle .lbl { display: none; }
  .chat-toggle { padding: 0 11px; }
  #btnTheme { display: none; }
  .brand { font-size: 16px; }
  .reader-inner { padding: 14px 16px 100px; }
  .reader-head { flex-direction: column; gap: 8px; }
  .reader-head h1 { font-size: 22px; }
  .doc-title { font-size: 23px; }
  .md table { font-size: 14px; }
  .md th, .md td { padding: 6px 8px; }
  .chat-panel { top: 0; width: 100%; z-index: 60; border-left: 0; padding-top: env(safe-area-inset-top); }
  .msg-body { max-width: 86%; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { grid-column: 1; }
  .jump { bottom: 140px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
