/* Veda UI — tokens ตาม VEDA-UI-DESIGN.md ข้อ 3 */
:root {
  --bg: #F5F7FA; --surface: #FFFFFF; --surface-subtle: #F0F2F5; --border: #D9DEE7;
  --text: #18202B; --text-secondary: #667085; --text-muted: #98A2B3;
  --accent: #7C3AED; --accent-soft: #F3EEFF; --accent-text: #FFFFFF;
  --success: #10B981; --success-soft: #E6F7F0;
  --warning: #F59E0B; --warning-soft: #FEF3DC; --warning-text: #92400E;
  --error: #EF4444; --error-soft: #FDE8E8; --error-text: #991B1B;
  --info: #2563EB; --info-soft: #E8EFFD; --info-text: #1E40AF;
  --neutral: #667085; --neutral-soft: #EEF0F3;
  --success-text: #065F46;
  --scroll-thumb: #C4CBD6; --scroll-thumb-hover: #A9B2C0;
  --radius-card: 12px; --radius-btn: 8px; --radius-chip: 6px;
  --shadow-panel: 0 8px 24px rgba(24,32,43,.08);
  --sans: "Inter", "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --header-h: 52px; --nav-h: 56px;
  /* สีไฮไลต์โค้ด (แบบ MS Teams/VS light): คีย์แดง ค่าเขียว คำสั่งน้ำเงิน */
  --hl-key: #A31515; --hl-string: #0F7B3E; --hl-number: #1F2937; --hl-keyword: #1D4ED8; --hl-comment: #6B7280; --hl-title: #795E26; --hl-var: #C2410C;
}
[data-theme="dark"] {
  --bg: #0E1116; --surface: #161B22; --surface-subtle: #1D232C; --border: #2B3440;
  --text: #E8ECF2; --text-secondary: #A6B0BF; --text-muted: #727E8D;
  --scroll-thumb: #3A4451; --scroll-thumb-hover: #4B5665;
  --accent: #A78BFA; --accent-soft: #241B36; --accent-text: #0E1116;
  --success: #34D399; --success-soft: #12291F; --success-text: #6EE7B7;
  --warning: #FBBF24; --warning-soft: #2E2410; --warning-text: #FCD34D;
  --error: #F87171; --error-soft: #331A1A; --error-text: #FCA5A5;
  --info: #60A5FA; --info-soft: #15243A; --info-text: #93C5FD;
  --neutral: #A6B0BF; --neutral-soft: #1D232C;
  --shadow-panel: 0 8px 24px rgba(0,0,0,.4);
  --hl-key: #FF8B8B; --hl-string: #7EE787; --hl-number: #E8ECF2; --hl-keyword: #79B8FF; --hl-comment: #8B949E; --hl-title: #D2A8FF; --hl-var: #FFA657;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
/* iOS Safari: ตอนคีย์บอร์ดขึ้นจะเลื่อนทั้ง document เพื่อโชว์ช่องพิมพ์ แล้วค้างไว้ (header หลุด มีช่องว่างท้าย) → ตรึง body ไม่ให้เลื่อนเลย */
body.locked { position: fixed; inset: 0; width: 100%; overflow: hidden; overflow: clip; }
body { background: var(--bg); color: var(--text); font: 16px/1.5 var(--sans); -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--text-secondary); }
.small { font-size: 14px; }
.boot { padding: 40px; color: var(--text-secondary); text-align: center; }
::selection { background: var(--accent-soft); }

/* ---------- buttons / chips ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: var(--radius-btn); border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 500; font-size: 14px; line-height: 1.2; }
.btn:hover { background: var(--surface-subtle); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { background: var(--error); color: #fff; border-color: var(--error); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
.btn.ghost:hover { background: var(--surface-subtle); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.icon { padding: 6px 8px; }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* scrollbar เข้าธีม: บาง โปร่ง ไม่มีปุ่มลูกศร — Chromium/Firefox ใช้ scrollbar-width/color · Safari และ Chromium เก่าใช้ ::-webkit-scrollbar */
* { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); background-clip: padding-box; }
*::-webkit-scrollbar-button { width: 0; height: 0; display: none; }
*::-webkit-scrollbar-corner { background: transparent; }
textarea { scrollbar-gutter: auto; }
.chip { display: inline-block; font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: .04em; padding: 2px 7px; border-radius: var(--radius-chip); text-transform: uppercase; white-space: nowrap; }
.chip.neutral { background: var(--neutral-soft); color: var(--text-secondary); }
.chip.info { background: var(--info-soft); color: var(--info-text); }
.chip.warning { background: var(--warning-soft); color: var(--warning-text); }
.chip.success { background: var(--success-soft); color: var(--success-text); }
.chip.error { background: var(--error-soft); color: var(--error-text); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--neutral); }
.dot.ok { background: var(--success); } .dot.warn { background: var(--warning); } .dot.bad { background: var(--error); } .dot.info { background: var(--info); }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .9s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; border-top-color: var(--border); } }

/* ---------- shell ---------- */
/* แอปสูงเท่าหน้าจอเสมอ (iOS Safari: 100vh สูงเกินจอ → ใช้ 100dvh) แถวเนื้อหาเป็น minmax(0,1fr) ไม่งั้น grid จะยืดตามเนื้อหาแล้วทั้งหน้าเลื่อน header หลุด */
/* overflow:hidden ยังโดน Safari เลื่อนได้ตอน focus ช่องพิมพ์ (มันเลื่อน ancestor ทุกชั้นเพื่อโชว์ input แล้วค้าง) → clip = เลื่อนไม่ได้เลย */
.app { display: grid; grid-template-rows: var(--header-h) minmax(0, 1fr); height: 100vh; height: 100dvh; overflow: hidden; overflow: clip; }
/* คีย์บอร์ดขึ้น (มี input โฟกัส) → แอปหดเท่าพื้นที่ที่เห็นจริง ให้ช่องพิมพ์ลอยเหนือคีย์บอร์ด; ปิดคีย์บอร์ดแล้วกลับเป็นเต็มจอทันทีโดยไม่ต้องรอ event */
html.kb .app { height: var(--vvh, 100dvh); transform: translateY(var(--vvt, 0px)); } /* คีย์บอร์ดขึ้น: สูงเท่าที่มองเห็น + เลื่อนตาม visual viewport (iOS เลื่อน viewport เองตอน focus) */
.header { display: flex; align-items: center; gap: 12px; padding: 0 14px; border-bottom: 1px solid var(--border); background: var(--surface); }
.logo { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .04em; }
.logo-mark { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 14px; }
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary); }
.header .spacer { flex: 1; }
.stat { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 4px 10px; border-radius: 999px; color: var(--text-secondary); }
.stat.needs { background: var(--warning-soft); color: var(--warning-text); font-weight: 600; }
.stat.running { color: var(--info-text); }
.body { display: grid; min-height: 0; overflow: hidden; overflow: clip; }
.body.desktop { grid-template-columns: 250px 1fr; grid-template-rows: minmax(0, 1fr); }
.body.desktop.detail-open { grid-template-columns: 250px 1fr minmax(460px, 40%); }
.icon { display: inline-block; vertical-align: -3px; flex: none; }
.btn .icon { vertical-align: -3px; }
.btn.icon { padding: 6px; width: 34px; height: 34px; justify-content: center; }
.btn.icon.send { width: 40px; height: 40px; border-radius: 12px; }
.sidebar .nav-item .icon, .bottomnav .icon { vertical-align: -4px; }
.body.mobile { grid-template-rows: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); } /* ไม่มีแถบล่างแล้ว — เมนูอยู่ในลิ้นชัก ☰ · คอลัมน์ต้อง minmax(0,1fr) ไม่งั้น grid ขยายตามเนื้อหากว้างเกินจอ */
.sidebar { border-right: 1px solid var(--border); background: var(--surface); padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; overflow: auto; }
.sidebar .nav-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; border: 0; background: transparent; text-align: left; width: 100%; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar .section { font-family: var(--mono); font-size: 11px; letter-spacing: .1em; color: var(--text-muted); text-transform: uppercase; padding: 14px 10px 4px; }
.sidebar .bottom { margin-top: auto; }
.main { min-height: 0; overflow: hidden; overflow: clip; display: flex; flex-direction: column; }
.right { border-left: 1px solid var(--border); background: var(--surface); min-height: 0; overflow: auto; }
.bottomnav { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border-top: 1px solid var(--border); background: var(--surface); padding-bottom: env(safe-area-inset-bottom); }
.bottomnav button { border: 0; background: transparent; padding: 8px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; color: var(--text-secondary); position: relative; cursor: pointer; }
.bottomnav button.active { color: var(--accent); font-weight: 600; }
/* แยกฝั่ง: 6 ปุ่ม (Chat/Tasks/History × Company/Home) ป้ายบรรทัดล่างบอกฝั่ง คั่นกลุ่มด้วยเส้น */
.bottomnav.two button { padding: 6px 0 4px; font-size: 11px; gap: 1px; }
.bottomnav .lbl { line-height: 1.1; }
.bottomnav .side { font-size: 9.5px; line-height: 1.1; color: var(--text-muted); letter-spacing: .02em; }
.bottomnav button.active .side { color: var(--accent); }
.bottomnav .sep { width: 1px; background: var(--border); margin: 8px 0; }
.bottomnav.two { grid-auto-columns: auto; grid-template-columns: repeat(3, 1fr) 1px repeat(3, 1fr); }
.bottomnav.two .badge { right: calc(50% - 22px); top: 2px; }
.badge { position: absolute; top: 4px; right: calc(50% - 26px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--warning); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; min-height: 0; flex: 1; overflow: hidden; overflow: clip; }
.timeline { flex: 1; min-height: 0; overflow: auto; -webkit-overflow-scrolling: touch; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: min(720px, 92%); }
.msg.user { align-self: flex-end; }
.msg.user .bubble { background: var(--accent-soft); border-radius: 14px 14px 4px 14px; padding: 10px 14px; white-space: pre-wrap; word-break: break-word; }
.msg.veda { align-self: flex-start; display: grid; grid-template-columns: 28px 1fr; gap: 10px; }
.avatar { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-weight: 700; font-size: 13px; margin-top: 2px; }
.msg.veda .bubble { background: var(--surface); border: 1px solid var(--border); border-radius: 4px 14px 14px 14px; padding: 10px 14px; }
.msg.head { align-self: flex-start; margin-left: 38px; }
.msg.head .bubble { border: 1px dashed var(--border); border-radius: 10px; padding: 8px 12px; font-size: 14.5px; background: var(--surface-subtle); }
.msg.head .who { font-family: var(--mono); font-size: 11px; color: var(--text-secondary); margin-bottom: 4px; }
.msg.system { align-self: center; text-align: center; font-size: 13px; color: var(--text-secondary); padding: 2px 10px; max-width: 100%; }
.msg.system.err { color: var(--error-text); }
.msg .time { font-family: var(--mono); font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.msg.user .time { text-align: right; }
.md p { margin: 0 0 8px; } .md p:last-child { margin-bottom: 0; }
.md ul, .md ol { margin: 4px 0 8px; padding-left: 20px; }
.md code { font-family: var(--mono); font-size: 13px; background: var(--surface-subtle); padding: 1px 5px; border-radius: 4px; }
.md pre { background: var(--surface-subtle); padding: 10px 12px; border-radius: 8px; overflow: auto; font-size: 13px; }
.md h1, .md h2, .md h3 { font-size: 15px; margin: 10px 0 4px; }
.md a[data-veda], .md button[data-veda] { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--accent); color: var(--accent); background: var(--accent-soft); text-decoration: none; font-size: 13px; cursor: pointer; }
.msg.veda.streaming .time { display: inline-flex; align-items: center; gap: 6px; }
.proposal.perm .cmd-pre { margin: 6px 0 0; white-space: pre-wrap; word-break: break-all; font-size: 12.5px; color: var(--text-secondary); }
.proposal.perm .perm-title { font-weight: 600; font-size: 15px; line-height: 1.4; }
.proposal.perm .perm-raw summary { cursor: pointer; margin-top: 4px; }
.proposal.perm .perm-raw summary::marker { color: var(--text-muted); }
.secbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 6px 14px; font-size: 13px; color: var(--text-secondary); border-bottom: 1px solid var(--border); background: var(--surface); }
.secbar .dot.ok { box-shadow: 0 0 0 3px var(--success-soft); }
.model-select { padding: 2px 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); font-size: 12px; font-family: var(--mono, ui-monospace, monospace); color: var(--text); }
.secbar .model-select { margin-left: auto; }
.sidebar .nav-item .dot { width: 8px; height: 8px; margin-left: auto; flex: none; }
.bottomnav .dot { width: 7px; height: 7px; margin-left: 4px; }
.proposal.perm .head { background: var(--warn-soft, var(--accent-soft)); color: var(--warn-text, var(--accent)); }
.progress { align-self: flex-start; display: inline-flex; align-items: center; gap: 8px; color: var(--text-secondary); font-size: 14px; margin-left: 38px; }
.files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.files img { max-width: 160px; max-height: 120px; border-radius: 8px; border: 1px solid var(--border); }
.files .file { font-family: var(--mono); font-size: 12px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; }

.composer { border-top: 1px solid var(--border); background: var(--surface); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
/* กล่องพิมพ์แบบ Claude: textarea ด้านบน แถวเครื่องมือด้านล่างในกล่องเดียว (แนบ · @ · โมเดล … โหมด · ส่ง) */
.composer .box { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 10px 10px 8px; border: 1px solid var(--border); border-radius: 16px; background: var(--bg); box-shadow: 0 1px 2px rgba(24,32,43,.04); }
.composer .box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea { resize: none; min-height: 28px; max-height: 160px; padding: 4px 6px; border: 0; background: transparent; font-size: 15px; line-height: 1.45; outline: none; }
.composer textarea:focus-visible { outline: none; }
.composer .bar { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.composer .bar .spacer { flex: 1; }
.composer .bar .btn.icon { width: 32px; height: 32px; padding: 0; justify-content: center; flex: none; } /* ไอคอนอยู่กลางปุ่มกลมพอดี (padding ซ้าย-ขวาเดิมทำให้เบี้ยว) */
.composer .bar .model-select { max-width: 42vw; }
.composer .bar .resolved { font-family: var(--mono); font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text-secondary); font-size: 12.5px; cursor: pointer; white-space: nowrap; }
.pill:hover { background: var(--surface-subtle); }
.pill.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }
.composer .send { width: 34px; height: 34px; border-radius: 50%; padding: 0; justify-content: center; }
.composer .stop { width: 34px; height: 34px; border-radius: 50%; padding: 0; justify-content: center; color: var(--error); border-color: var(--error-soft); background: var(--error-soft); }
.composer .attach { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.composer .attach .thumb { position: relative; }
.composer .attach img { height: 56px; border-radius: 8px; border: 1px solid var(--border); }
.composer .attach .x { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: var(--error); color: #fff; font-size: 12px; cursor: pointer; }
.composer .hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.popover { position: absolute; bottom: 100%; left: 0; margin-bottom: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-panel); padding: 6px; z-index: 5; }
.popover button { display: block; width: 100%; text-align: left; padding: 6px 10px; border: 0; background: transparent; border-radius: 6px; cursor: pointer; }
.popover button:hover { background: var(--surface-subtle); }

/* ---------- proposal card ---------- */
.proposal { margin-top: 10px; border: 1px solid var(--accent); border-radius: var(--radius-card); background: var(--surface); overflow: hidden; }
.proposal.done, .proposal.dead { border-color: var(--border); }
.proposal.dead { opacity: .65; }
.proposal .head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 14px; }
.proposal.done .head { background: var(--success-soft); color: var(--success-text); }
.proposal.dead .head { background: var(--neutral-soft); color: var(--text-secondary); }
.proposal .item { display: grid; grid-template-columns: 22px 1fr; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); align-items: start; }
.proposal .item input[type=checkbox] { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); }
.proposal .item .t { font-weight: 500; }
.proposal .item .d { font-size: 13.5px; color: var(--text-secondary); white-space: pre-wrap; word-break: break-word; }
.proposal .item .res { font-family: var(--mono); font-size: 12px; margin-top: 4px; }
.proposal .item .res.ok { color: var(--success-text); } .proposal .item .res.bad { color: var(--error-text); } .proposal .item .res.stale { color: var(--warning-text); }
.proposal .edit { display: grid; gap: 6px; margin-top: 6px; }
.proposal .edit input, .proposal .edit textarea, .proposal .edit select { padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); font-size: 14px; }
.proposal .edit textarea { min-height: 90px; resize: vertical; }
.proposal .actions { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); }

/* ---------- task card ---------- */
.task { border: 1px solid var(--border); border-left: 3px solid var(--neutral); border-radius: var(--radius-card); background: var(--surface); padding: 10px 12px; display: grid; gap: 6px; }
.task.needs { border-left-color: var(--warning); } .task.needs.bad { border-left-color: var(--error); }
.task.working { border-left-color: var(--info); }
.task .top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; row-gap: 4px; } /* จอแคบ: รหัสงานไม่หักกลางคำ ป้าย/สถานะตกบรรทัดใหม่ทั้งชิ้น */
.task .top .id { white-space: nowrap; }
.task .top .spinner { flex: none; width: 12px; height: 12px; }
.task .top .proj { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task .id { font-family: var(--mono); font-size: 12px; color: var(--text-secondary); }
.task .title { font-weight: 500; }
.task .line { font-size: 13px; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }
.task .btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.task.clickable { cursor: pointer; }
.task.clickable:hover { background: var(--surface-subtle); }
.task .revise { display: flex; gap: 6px; margin-top: 4px; }
.task .revise input { flex: 1; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); }
.msg.card { align-self: stretch; max-width: 100%; }

/* ---------- board ---------- */
.board { padding: 12px 14px 20px; overflow: auto; min-height: 0; flex: 1; display: grid; gap: 14px; align-content: start; }
.board h3 { margin: 6px 0 0; font-size: 13px; font-family: var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--text-secondary); display: flex; align-items: center; gap: 8px; }
.board h3 .n { background: var(--neutral-soft); border-radius: 999px; padding: 0 8px; font-size: 12px; }
.board h3.needs .n { background: var(--warning-soft); color: var(--warning-text); }
.board .group { display: grid; gap: 8px; }
.board .empty { font-size: 13px; color: var(--text-muted); padding: 4px 2px; }
.segment { display: flex; gap: 4px; padding: 10px 14px 0; }
.segment button { flex: 1; padding: 7px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); font-size: 13px; cursor: pointer; }
.segment button.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 600; }
.board-title { font-size: 15px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chipbtn { flex: none; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: 13px; cursor: pointer; }
.chipbtn.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 600; }
.sidebar .nav-item.sub { padding-left: 22px; font-size: 14.5px; }

/* ---------- detail ---------- */
.detail { display: flex; flex-direction: column; min-height: 0; height: 100%; background: var(--surface); }
.detail .dh { padding: 12px 14px 8px; border-bottom: 1px solid var(--border); display: grid; gap: 4px; }
.detail .dh .row1 { display: flex; align-items: center; gap: 8px; }
.detail .dh .close { margin-left: auto; }
.detail .tabs { display: flex; gap: 2px; padding: 0 10px; border-bottom: 1px solid var(--border); }
.detail .tabs button { padding: 10px 10px; border: 0; background: transparent; border-bottom: 2px solid transparent; cursor: pointer; color: var(--text-secondary); font-size: 14px; }
.detail .tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.detail .content { flex: 1; overflow: auto; padding: 12px 14px 20px; }
.detail .foot { display: flex; gap: 8px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 10px; font-size: 14px; }
.kv .k { color: var(--text-secondary); }
.kv .v.mono { word-break: break-all; }
.evi { display: grid; gap: 14px; }
.evi h4 { margin: 0 0 6px; font-size: 13px; color: var(--text-secondary); font-family: var(--mono); letter-spacing: .06em; text-transform: uppercase; }
.evi pre { background: var(--surface-subtle); padding: 10px; border-radius: 8px; font-size: 12.5px; overflow: auto; max-height: 260px; margin: 0; }
.evi .warnbox { background: var(--warning-soft); color: var(--warning-text); padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.act { display: grid; gap: 6px; }
.act .ev { display: grid; grid-template-columns: 52px 1fr; gap: 8px; font-size: 13.5px; }
.act .ev .t { font-family: var(--mono); font-size: 11px; color: var(--text-muted); padding-top: 2px; }
.act .ev .k { font-family: var(--mono); font-size: 11px; color: var(--text-secondary); }
.diffwrap { overflow: auto; }
.cmd { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.cmd code { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; font-family: var(--mono); font-size: 12.5px; background: var(--surface-subtle); padding: 6px 8px; border-radius: 6px; }
.diffwrap .d2h-wrapper { font-size: 12px; }
.sheet { position: fixed; inset: 0; z-index: 20; background: var(--surface); display: flex; flex-direction: column; }
.overlay { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; }
/* กล่องยืนยัน/กรอกค่าแบบเข้าธีม (dialog.js) แทน window.confirm/prompt */
.dialog-overlay { align-items: center; justify-content: center; padding: 20px; z-index: 40; backdrop-filter: blur(2px); }
.dialog { width: min(420px, 100%); background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: var(--shadow-panel); padding: 18px 18px 14px; display: flex; flex-direction: column; gap: 12px; }
.dialog .dlg-head { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.dialog .dlg-head .icon { color: var(--warning); flex: none; }
.dialog.danger .dlg-head .icon { color: var(--error); }
.dialog .dlg-body { color: var(--text-secondary); font-size: 14px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.dialog .dlg-input { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); font-size: 14px; font-family: var(--mono); }
.dialog .dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 2px; }
.overlay .panel { width: 100%; max-width: 520px; margin: 0 auto; background: var(--surface); border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: grid; gap: 12px; box-shadow: var(--shadow-panel); }
@media (min-width: 1024px) { .overlay { align-items: center; } .overlay .panel { border-radius: 16px; } }
.settings .opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.settings select { padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); }
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 999px; font-size: 13px; z-index: 40; box-shadow: var(--shadow-panel); }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; min-height: 100dvh; }
.login { width: min(360px, 90vw); display: grid; gap: 16px; }
.login .logo { font-size: 22px; justify-content: center; }
.login form { display: grid; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 18px; }
.login input { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); }
.login label { font-size: 13px; color: var(--text-secondary); }

/* ---------- board: rows ---------- */
.board.rows { gap: 0; padding: 0 0 24px; }
.board.rows .chips { padding: 10px 14px 0; }
.toolbar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg); z-index: 3; flex-wrap: wrap; }
.toolbar .search { flex: 1; min-width: 180px; display: flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 8px; padding: 0 8px; background: var(--surface); color: var(--text-muted); }
.toolbar .search input { flex: 1; border: 0; background: transparent; padding: 7px 0; font-size: 14px; color: var(--text); outline: none; }
.toolbar .opt-inline { display: flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; color: var(--text-secondary); }
.toolbar .count { white-space: nowrap; }
.grp h3 { position: sticky; top: 46px; z-index: 2; margin: 0; padding: 8px 14px; background: var(--bg); border-bottom: 1px solid var(--border); cursor: pointer; user-select: none; }
.grp h3 .icon { vertical-align: -2px; color: var(--text-muted); }
.grp .empty { padding: 10px 14px; }
.grp .more { margin: 6px 14px; }
.row { display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto auto; align-items: center; gap: 10px; padding: 7px 14px; border-bottom: 1px solid var(--border); border-left: 3px solid transparent; cursor: pointer; background: var(--surface); }
.row:hover, .row:focus-visible { background: var(--surface-subtle); outline: none; }
.row.selected { background: var(--accent-soft); }
.row.needs { border-left-color: var(--warning); } .row.needs.bad { border-left-color: var(--error); } .row.working { border-left-color: var(--info); }
.row .chip { min-width: 96px; text-align: center; }
.row .id { font-family: var(--mono); font-size: 12px; color: var(--text-secondary); white-space: nowrap; }
.row .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--text-secondary); white-space: nowrap; max-width: 380px; overflow: hidden; }
/* ป้ายชื่อโปรเจกต์บนหัวงาน (แถวกระดาน การ์ดในแชท หัว Task Detail) */
.proj { display: inline-block; font-family: var(--mono); font-size: 11.5px; line-height: 1.5; padding: 0 6px; margin-left: 6px; border-radius: 4px; background: var(--neutral-soft); color: var(--text-secondary); white-space: nowrap; vertical-align: 1px; }
.row .meta .line { display: flex; align-items: center; gap: 6px; overflow: hidden; text-overflow: ellipsis; }
.row .acts { display: flex; gap: 6px; min-width: 0; }
.row .acts:empty { display: none; }
@media (max-width: 1023px) {
  .row { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-rows: auto auto; padding: 8px 12px; row-gap: 3px; }
  .row .chip { grid-row: 1; min-width: 0; }
  .row .id { grid-row: 1; grid-column: 2; }
  .row .acts { grid-row: 1; grid-column: 3; }
  .row .title { grid-row: 2; grid-column: 1 / 3; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .row .meta { grid-row: 3; grid-column: 1 / 4; max-width: none; }
  .toolbar { top: 0; }
  .grp h3 { position: static; } /* มือถือ toolbar สูงไม่คงที่ → หัวกลุ่มไม่ต้องติด */
}

.delivery { margin-top: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--surface-subtle); }
.delivery h4 { margin: 0 0 4px; display: flex; align-items: center; gap: 8px; }
.delivery .kv { margin-top: 6px; }
.sidebar .nav-item .badge { position: static; margin-left: 6px; flex: none; }

.md .md-diff { margin: 8px 0; border: 1px solid var(--border); border-radius: 8px; overflow: auto; }
.md .md-diff .d2h-wrapper { font-size: 12px; }
.md .md-diff .d2h-file-wrapper { border: 0; margin: 0; }
.md .md-diff .d2h-file-header { padding: 4px 8px; font-family: var(--mono); font-size: 11.5px; }

/* ปุ่มคัดลอกข้อความในแชท (บนบรรทัดเวลาใต้ข้อความ) — จางไว้ โผล่ชัดตอนชี้/แตะ */
.msg .cp { display: inline-flex; align-items: center; gap: 3px; margin-left: 8px; padding: 1px 6px; border: 0; border-radius: 4px; background: transparent; color: var(--text-muted); font: inherit; font-size: 11px; cursor: pointer; vertical-align: middle; opacity: 0.55; }
.msg:hover .cp, .msg .cp:focus-visible { opacity: 1; }
.msg .cp:hover { background: var(--surface-subtle); color: var(--text); }
@media (hover: none) { .msg .cp { opacity: 0.85; padding: 3px 8px; } }

/* กล่องโค้ดในแชท (แบบแชท MS Teams): หัว = ไอคอน+ชื่อภาษา(+ไฟล์) ปุ่มคัดลอกขวา · ตัว = เลขบรรทัด + สีตามภาษา · ใช้ทั้งข้อความเลขาและผู้ใช้ */
.md .codeblock, .bubble .codeblock { margin: 8px 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); text-align: left; }
.msg.user .bubble .codeblock { background: var(--surface); }
.codeblock .codehead { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 6px 6px 10px; border-bottom: 1px solid var(--border); background: var(--surface-subtle); font-size: 12.5px; color: var(--text-secondary); font-family: var(--sans); }
.codeblock .codehead .lang { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.codeblock .codehead .lang svg { width: 15px; height: 15px; flex: none; }
.codeblock .codehead .fname { font-family: var(--mono); font-size: 11.5px; color: var(--text-muted); margin-left: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.codeblock .codehead .cpb { border: 0; background: transparent; color: var(--text-secondary); padding: 3px 5px; border-radius: 4px; cursor: pointer; display: inline-flex; flex: none; }
.codeblock .codehead .cpb svg { width: 15px; height: 15px; }
.codeblock .codehead .cpb:hover { background: var(--surface); color: var(--text); }
.codeblock .codebody { display: flex; overflow: auto; max-height: 520px; }
.codeblock .codebody pre { margin: 0; padding: 8px 0; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; background: transparent; border-radius: 0; overflow: visible; white-space: pre; }
.codeblock .codebody .gutter { flex: none; text-align: right; padding: 8px 10px 8px 12px; color: var(--text-muted); user-select: none; position: sticky; left: 0; background: var(--surface); }
.codeblock .codebody pre.code { flex: 1; padding-left: 10px; padding-right: 14px; }
.codeblock .codebody code.hljs { background: none; padding: 0; font-size: inherit; display: block; white-space: pre; color: var(--text); }
.msg.user .bubble .txt { white-space: pre-wrap; }
/* สี token ของ highlight.js ตามธีม */
.hljs-attr, .hljs-property, .hljs-name { color: var(--hl-key); }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-quote { color: var(--hl-string); }
.hljs-number { color: var(--hl-number); }
.hljs-literal, .hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-type, .hljs-tag { color: var(--hl-keyword); }
.hljs-comment, .hljs-meta { color: var(--hl-comment); font-style: italic; }
.hljs-title, .hljs-title.function_, .hljs-title.class_, .hljs-section, .hljs-attribute, .hljs-selector-class, .hljs-selector-id { color: var(--hl-title); }
.hljs-variable, .hljs-template-variable, .hljs-symbol, .hljs-bullet, .hljs-params { color: var(--hl-var); }
.hljs-deletion { color: var(--error-text); background: var(--error-soft); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 600; }

/* กันกล่องโค้ด/บรรทัดยาวดันความกว้างของข้อความและหน้าเกินจอ — grid/flex item ต้อง min-width:0 ถึงจะเลื่อนในตัวเองแทนการขยาย */
.msg, .msg > div, .msg .bubble, .msg .md, .proposal, .proposal .item > div, .codeblock, .md-diff { min-width: 0; max-width: 100%; }
.msg.veda > div { min-width: 0; }
.chat, .chat .list, .chat .msgs { min-width: 0; }
.md .codeblock, .bubble .codeblock { box-sizing: border-box; }

/* รายละเอียดงาน: ห้ามเลื่อนซ้ายขวา — ข้อความ/path/โค้ด inline ต้องตัดบรรทัดในกรอบ กล่องโค้ดเลื่อนในตัวเอง */
.detail .content { overflow-x: hidden; overflow-y: auto; overflow-wrap: anywhere; min-width: 0; }
.detail .content .md code, .detail .content code { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.detail .content .md p, .detail .content .md li, .detail .content .md td, .detail .content .md h1, .detail .content .md h2, .detail .content .md h3, .detail .content .md h4 { overflow-wrap: anywhere; }
.detail .kv .v, .detail .kv .k { overflow-wrap: anywhere; min-width: 0; }
.detail .content .codeblock code.hljs, .detail .content .codebody pre { white-space: pre; }
.evi pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.detail .content .diffwrap { max-width: 100%; }
.evi, .evi div, .evi h4, .evi span, .evi .kv, .evi .kv .v { min-width: 0; max-width: 100%; overflow-wrap: anywhere; word-break: break-word; }
.evi .mono, .detail .content .mono { white-space: pre-wrap; word-break: break-all; }
.evi h4 { white-space: normal; }

/* มือถือ: ลิ้นชักเมนูจากปุ่ม ☰ (แทนแถบล่างที่กินที่) */
.drawer { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.4); display: flex; }
.drawer-panel { width: min(300px, 84vw); height: 100%; background: var(--surface); display: flex; flex-direction: column; box-shadow: var(--shadow-panel); animation: drawer-in .18s ease-out; }
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 10px 8px 6px 14px; border-bottom: 1px solid var(--border); }
.drawer-panel .sidebar { border-right: 0; flex: 1; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
@keyframes drawer-in { from { transform: translateX(-24px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .drawer-panel { animation: none; } }
.header .where { font-size: 14px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.header .stat.needs { white-space: nowrap; }

/* มือถือ: แถบสถานะเลขาบรรทัดเดียว (ชื่อเครื่องสั้น + สถานะ) รายละเอียด session อยู่ใน title · กล่องพิมพ์ไม่โชว์ชื่อรุ่นซ้ำ */
@media (max-width: 1023px) {
  .secbar { flex-wrap: nowrap; white-space: nowrap; overflow: hidden; gap: 5px; padding: 5px 10px; font-size: 12.5px; }
  .secbar .sess { display: none; }
  .secbar .chip { max-width: 44vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .secbar .st { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .composer .bar .resolved { display: none; }
  .composer .bar .model-select { max-width: 30vw; } /* ให้ปุ่มส่งอยู่แถวเดียวกันบนจอ 400px */
  .composer .bar { flex-wrap: nowrap; }
}
/* code inline ยาว (path/ชื่อไฟล์) ต้องตัดบรรทัดในกรอบข้อความ ไม่ล้นขวา (โค้ดในกล่อง pre เลื่อนในตัวเองอยู่แล้ว) */
.md :not(pre) > code { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }

/* ป้าย "VEDA" เหนือกล่องข้อความ: desktop ใช้วงกลม V (ซ่อนป้าย) · มือถือซ่อนวงกลม ใช้ป้ายเล็กๆ แทน ข้อความกว้างเต็มจอ */
.msg.veda .from { display: none; font-family: var(--mono); font-size: 10.5px; letter-spacing: .08em; color: var(--text-muted); margin: 0 0 3px 4px; }
@media (max-width: 1023px) {
  .msg.veda { grid-template-columns: 1fr; gap: 0; max-width: 96%; }
  .msg.veda .avatar { display: none; }
  .msg.veda .from { display: block; }
  .msg.head { margin-left: 0; max-width: 96%; }
  .msg.user { max-width: 92%; }
}

/* มือถือ: ลดขนาดแชท+ช่องพิมพ์ 20% (ผู้ใช้ขอ 2026-09-06) — คอมคงเดิม */
@media (max-width: 1023px) {
  .msg .bubble { font-size: 13px; line-height: 1.5; }
  .msg.veda .bubble, .msg.user .bubble { padding: 8px 11px; }
  .msg.head .bubble { font-size: 12px; padding: 6px 10px; }
  .msg.system { font-size: 11px; }
  .msg .time { font-size: 10px; }
  .md code { font-size: 11px; }
  .md h1, .md h2, .md h3 { font-size: 13px; }
  .codeblock .codebody pre { font-size: 10.5px; }
  .codeblock .codehead { font-size: 10.5px; padding: 4px 4px 4px 8px; }
  .md .md-diff .d2h-wrapper { font-size: 10px; }
  .composer { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
  .composer .box { padding: 8px 8px 6px; border-radius: 13px; gap: 2px; }
  .composer textarea { font-size: 13px; min-height: 22px; line-height: 1.4; }
  .composer .bar .btn.icon { width: 27px; height: 27px; }
  .composer .send, .composer .stop { width: 28px; height: 28px; }
  .composer .bar .pill { font-size: 11px; padding: 3px 7px; }
  .composer .bar .model-select { font-size: 11px; height: 26px; }
}

/* มือถือ: รายละเอียดงานเล็กลง 20% + แถวข้อมูล (kv) เป็นแนวตั้ง หัวข้อบน ค่าล่าง (จอแคบ ซ้าย-ขวาอ่านยาก) */
@media (max-width: 1023px) {
  .detail { font-size: 13px; }
  .detail .dh { padding: 9px 12px 6px; gap: 3px; font-size: 13px; }
  .detail .dh .row1 { font-size: 12px; }
  .detail .dh > div[style*="font-weight"] { font-size: 14px; }
  .detail .tabs button { padding: 8px 8px; font-size: 12px; }
  .detail .content { padding: 10px 12px 16px; font-size: 13px; }
  .detail .content .md { font-size: 13px; }
  .detail .content .md h1, .detail .content .md h2, .detail .content .md h3 { font-size: 13px; }
  .detail .content .md code, .detail .content code { font-size: 11px; }
  .detail .content .codeblock .codebody pre { font-size: 10.5px; }
  .detail .kv { display: flex; flex-direction: column; gap: 2px 0; font-size: 12.5px; }
  .detail .kv .k { font-family: var(--mono); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); margin-top: 9px; }
  .detail .kv .k:first-child { margin-top: 0; }
  .detail .kv .v { padding-left: 0; }
  .evi { gap: 11px; }
  .evi h4 { font-size: 11px; }
  .evi pre { font-size: 10.5px; padding: 8px; }
  .evi .warnbox { font-size: 12px; }
  .detail .foot { padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); gap: 6px; }
  .detail .foot .btn { font-size: 12.5px; padding: 6px 10px; }
  .delivery { padding: 8px 10px; font-size: 12.5px; }
  .delivery .cmd code { font-size: 11px; }
}
/* มือถือ: รหัสงานบนหัวรายละเอียดห้ามหักกลางคำ — แถวแรกตัดขึ้นบรรทัดใหม่ทั้งชิ้น (ป้ายโฟลเดอร์ลงมาบรรทัดล่าง) */
@media (max-width: 1023px) {
  .detail .dh .row1 { flex-wrap: wrap; row-gap: 4px; }
  .detail .dh .row1 > .mono { white-space: nowrap; }
  .detail .dh .row1 .proj { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
