/* =====================================================================
   NEON Desktop v1 — หน้าต่างหลัก (เทอร์มินัลแชท)
   ===================================================================== */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: clip; }   /* clip: focus()/scrollIntoView เลื่อนหน้าไม่ได้ */
body {
  background: var(--bg-solid); color: var(--text);
  font-family: var(--ui-font, var(--sans)); font-size: var(--ui-size, 14.5px); line-height: var(--ui-lh, 1.65);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  display: flex; flex-direction: column;
  transition: background-color .25s, color .25s;
  --tb-h: 40px; --sb-h: 30px; --side-w: 320px; --hist-w: 260px; --measure: var(--ui-measure, 860px); --tab-h: 0px;
}
/* ความหนาแน่น (ตั้งค่า → การแสดงผล) */
html[data-density="compact"] body { --tb-h: 34px; --sb-h: 26px; --side-w: 290px; --hist-w: 230px; }
html[data-density="compact"] .msg { margin-bottom: 14px; }
html[data-density="compact"] #log { padding-top: 16px; }
html[data-density="compact"] .item { padding: 6px 8px; }
html[data-density="compact"] .conv { padding: 5px 8px 5px 10px; }
html[data-density="comfy"] body { --tb-h: 46px; --sb-h: 32px; --side-w: 350px; --hist-w: 290px; }
html[data-density="comfy"] .msg { margin-bottom: 30px; }
html[data-density="comfy"] #log { padding-top: 36px; }
html[data-density="comfy"] .item { padding: 12px 10px; }
html[data-density="comfy"] .conv { padding: 9px 8px 9px 10px; }
html[data-density="comfy"] .prompt { padding: 11px 10px 11px 16px; }
/* ปิดเอฟเฟกต์ / ลดความโปร่งใส */
html.no-fx body::after { display: none; }
html.no-fx *, html.no-fx *::before, html.no-fx *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; }
html.no-fx .cursor { animation: none !important; }
html.no-fx .brand .logo, html.no-fx .boot-logo .logo, html.no-fx .welcome .big .logo { filter: none; }
html.solid .overlay, html.solid #scrim { backdrop-filter: none; background: color-mix(in srgb, var(--bg-solid) 86%, transparent); }
html.solid #dropZone { background: var(--bg-solid); }
html.solid .dot { box-shadow: none; }
/* เส้นสแกนบางๆ (เฉพาะธีมที่กำหนด --scan) */
body::after { content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 999; mix-blend-mode: screen;
  background: repeating-linear-gradient(0deg, rgba(255, 255, 255, var(--scan)) 0 1px, transparent 1px 3px); }
.light body::after, html.light body::after { display: none; }
:focus-visible { outline: 1.5px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
button { font-family: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
svg { width: 16px; height: 16px; display: block; }
kbd { font-family: var(--mono); font-size: 10.5px; padding: 1px 5px; border: 1px solid var(--line2); border-bottom-width: 2px; border-radius: 4px; color: var(--text2); background: var(--bg2); }
.hidden { display: none !important; }
.mono { font-family: var(--mono); }
::-webkit-scrollbar { width: 10px; height: 10px; } ::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 8px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); border: 3px solid transparent; background-clip: padding-box; }
::selection { background: var(--tint2); color: var(--text); }

/* ---------- ปุ่มพื้นฐาน ---------- */
.ibtn { width: 30px; height: 30px; display: grid; place-items: center; border: 0; background: none; color: var(--text2); border-radius: 7px; transition: background .15s, color .15s; -webkit-app-region: no-drag; }
.ibtn:hover { background: var(--tint); color: var(--text); }
.ibtn.on { color: var(--accent); background: var(--tint2); }
.ibtn:disabled { opacity: .35; pointer-events: none; }
.tbtn { font-family: var(--mono); font-size: 11.5px; letter-spacing: .3px; padding: 5px 11px; border: 1px solid var(--line); background: none; color: var(--text2); border-radius: 6px; transition: all .15s; white-space: nowrap; }
.tbtn:hover { color: var(--text); border-color: var(--line2); background: var(--tint); }
.tbtn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); box-shadow: 0 0 6px var(--good); display: inline-block; flex: none; }
.dot.off { background: var(--text3); box-shadow: none; }
.dot.warn { background: var(--warn); box-shadow: 0 0 6px var(--warn); }
.dot.bad { background: var(--bad); box-shadow: 0 0 6px var(--bad); }
.grow { flex: 1; }

/* ---------- หน้าบูต ---------- */
#boot { position: fixed; inset: 0; z-index: 1000; background: var(--bg-solid); display: grid; place-items: center; transition: opacity .45s ease, visibility .45s; }
#boot.out { opacity: 0; visibility: hidden; }
.boot-inner { width: min(560px, 80vw); font-family: var(--mono); }
.boot-logo { font-size: 44px; font-weight: 600; letter-spacing: 10px; color: var(--text); display: flex; align-items: center; gap: 14px; }
.boot-logo .mark { color: var(--accent); font-size: 30px; letter-spacing: 0; text-shadow: 0 0 18px var(--glow); }
.logo { color: var(--accent); filter: drop-shadow(0 0 6px var(--glow)) drop-shadow(0 0 14px var(--glow)); flex: none; }
.boot-logo .logo { width: 48px; height: 48px; }
.boot-sub { color: var(--text3); font-size: 11.5px; letter-spacing: 3px; margin: 2px 0 26px 48px; min-height: 18px; }
.boot-lines { font-size: 12.5px; color: var(--text2); min-height: 118px; line-height: 1.8; }
.boot-lines div { display: flex; gap: 10px; white-space: pre; }
.boot-lines .k { color: var(--text3); }
.boot-lines .ok { color: var(--good); } .boot-lines .warn { color: var(--warn); }
.boot-bar { height: 2px; background: var(--line); margin-top: 18px; border-radius: 2px; overflow: hidden; }
.boot-bar i { display: block; height: 100%; width: 0; background: var(--accent); box-shadow: 0 0 10px var(--glow); transition: width .35s ease; }

/* ---------- แถบหัวหน้าต่าง ---------- */
#titlebar { height: var(--tb-h); flex: none; display: flex; align-items: center; padding: 0 8px 0 14px; gap: 10px;
  border-bottom: 1px solid var(--line); background: var(--bg2); -webkit-app-region: drag; user-select: none; position: relative; z-index: 20; }
body.mac #titlebar { padding-left: 82px; }
body.mac #winBtns { display: none; }
body.fullscreen #titlebar { padding-left: 14px; }
.brand { font-family: var(--mono); font-weight: 600; font-size: 13px; letter-spacing: 3px; display: flex; align-items: center; gap: 8px; color: var(--text); }
.brand .mark { color: var(--accent); text-shadow: 0 0 12px var(--glow); }
.brand .logo { width: 22px; height: 22px; }
.brand .ver { font-weight: 400; font-size: 10px; color: var(--text3); letter-spacing: 1px; }
.tb-center { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; justify-content: center; }
.tb-center .sep { width: 1px; height: 16px; background: var(--line2); margin: 0 4px; }
#convTitle { font-size: 13px; color: var(--text2); max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 3px 8px; border-radius: 6px; -webkit-app-region: no-drag; cursor: text; }
#convTitle:hover { color: var(--text); background: var(--tint); }
.tb-right { display: flex; align-items: center; gap: 2px; -webkit-app-region: no-drag; }
.chip { display: flex; align-items: center; gap: 8px; height: 28px; padding: 0 6px 0 10px; border: 1px solid var(--line); background: var(--bg3); border-radius: 7px; font-family: var(--mono); font-size: 12px; color: var(--text); margin-right: 6px; max-width: 260px; transition: border-color .15s, background .15s; }
.chip:hover { border-color: var(--line2); background: var(--bg4); }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip kbd { margin-left: 2px; }
.win { display: flex; margin-left: 8px; }
.win button { width: 40px; height: 30px; border: 0; background: none; color: var(--text2); display: grid; place-items: center; border-radius: 6px; transition: background .15s, color .15s; }
.win button:hover { background: var(--tint); color: var(--text); }
.win button.close:hover { background: var(--bad); color: #fff; }
.win svg { width: 14px; height: 14px; }

/* ---------- โครง ---------- */
#body { flex: 1; min-height: 0; display: flex; position: relative; overflow: clip; }
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; overflow: clip; }

/* ---------- ประวัติแชท ---------- */
#sidebar { width: var(--hist-w); flex: none; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--bg2); transition: margin-left .22s ease; }
#sidebar.closed { margin-left: calc(-1 * var(--hist-w)); }
.sb-head { display: flex; gap: 6px; padding: 10px 10px 6px; align-items: center; }
.search { flex: 1; display: flex; align-items: center; gap: 7px; height: 30px; padding: 0 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg3); color: var(--text3); }
.search:focus-within { border-color: var(--line2); }
.search svg { width: 14px; height: 14px; }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: var(--text); font-family: inherit; font-size: 13px; }
.search input::placeholder { color: var(--text3); }
#convList { flex: 1; overflow-y: auto; padding: 4px 8px 10px; }
.conv-group { font-family: var(--mono); font-size: 10px; letter-spacing: 2px; color: var(--text3); text-transform: uppercase; padding: 12px 8px 4px; }
.conv { display: flex; align-items: center; gap: 6px; padding: 7px 8px 7px 10px; border-radius: 7px; cursor: pointer; color: var(--text2); font-size: 13.2px; position: relative; transition: background .12s, color .12s; }
.conv::before { content: "›"; font-family: var(--mono); color: var(--text3); opacity: 0; width: 8px; transition: opacity .12s; }
.conv .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .del { opacity: 0; width: 22px; height: 22px; }
.conv:hover { background: var(--tint); color: var(--text); }
.conv:hover .del, .conv:hover::before { opacity: 1; }
.conv.on { background: var(--tint2); color: var(--text); }
.conv.on::before { opacity: 1; color: var(--accent); }
.sb-foot { display: flex; justify-content: space-between; padding: 8px 14px; border-top: 1px solid var(--line); font-family: var(--mono); font-size: 10px; letter-spacing: 2px; color: var(--text3); }

/* ---------- ล็อกแชท ---------- */
#log { flex: 1; overflow-y: auto; padding: 28px 0 24px; scroll-behavior: auto; }
#log > * { width: min(var(--measure), calc(100% - 64px)); margin-left: auto; margin-right: auto; }
.msg { display: grid; grid-template-columns: 30px 1fr; gap: 0 12px; margin-bottom: 22px; animation: msgIn .22s ease-out; }
@keyframes msgIn { from { opacity: 0; transform: translateY(5px); } }
.msg .body { min-width: 0; }
.msg .gutter { font-family: var(--mono); font-size: 15px; color: var(--accent); text-align: right; padding-top: 1px; user-select: none; }
.msg.me .gutter { color: var(--text3); }
.msg.me .txt { color: var(--me-text); white-space: pre-wrap; word-break: break-word; font-weight: 500; }
.msg.bot .who { font-family: var(--mono); font-size: 11px; letter-spacing: 1.5px; color: var(--text3); display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.msg.bot .who b { color: var(--accent); font-weight: 600; }
.msg.bot .who small { letter-spacing: .3px; font-size: 10.5px; }
.msg.bot .who .ok { color: var(--good); }
.msg.bot.err .md { color: var(--bad); }
.msg.bot .foot { font-family: var(--mono); font-size: 10.5px; color: var(--text3); display: flex; gap: 14px; align-items: center; margin-top: 8px; min-height: 22px; letter-spacing: .3px; }
.msg.bot .foot .acts { display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.msg.bot:hover .foot .acts, .msg.bot.last .foot .acts { opacity: 1; }
.msg.bot .foot .acts button { display: flex; align-items: center; gap: 5px; padding: 3px 8px; border: 0; background: none; border-radius: 5px; color: var(--text3); font-family: var(--mono); font-size: 10.5px; transition: all .12s; }
.msg.bot .foot .acts button:hover { color: var(--text); background: var(--tint); }
.msg.bot .foot .acts svg { width: 12px; height: 12px; }

/* เครื่องมือที่ AI เรียก — แสดงเหมือนบรรทัดล็อก */
.toolrun { font-family: var(--mono); font-size: 12px; margin: 2px 0 10px; display: grid; gap: 3px; }
.toolrun .t { display: flex; gap: 9px; align-items: baseline; color: var(--text2); padding: 2px 0; }
.toolrun .t i { font-style: normal; width: 12px; flex: none; text-align: center; }
.toolrun .t.run i { color: var(--accent); animation: blink .9s steps(2) infinite; }
.toolrun .t.ok i { color: var(--good); } .toolrun .t.bad i { color: var(--bad); }
.toolrun .t.bad { color: var(--bad); }
.toolrun .t .nm { color: var(--text); }
.toolrun .t .sm { color: var(--text3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@keyframes blink { 50% { opacity: .25; } }

/* คำตอบ (Markdown) */
.md { word-break: break-word; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md h2, .md h3, .md h4 { margin: 18px 0 8px; font-weight: 600; letter-spacing: -.01em; }
.md h2 { font-size: 18px; } .md h3 { font-size: 16px; } .md h4 { font-size: 14.5px; color: var(--text2); }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; } .md li { margin: 3px 0; }
.md li::marker { color: var(--text3); font-family: var(--mono); }
.md a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--line2); } .md a:hover { border-color: var(--accent); }
.md code { font-family: var(--mono); font-size: .88em; background: var(--bg4); border: 1px solid var(--line); padding: 1px 6px; border-radius: 5px; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.md blockquote { margin: 8px 0; padding: 4px 14px; border-left: 2px solid var(--accent); color: var(--text2); }
.md strong { font-weight: 600; color: var(--text); }
.codeblock { margin: 10px 0 12px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--bg3); }
.codehead { display: flex; align-items: center; justify-content: space-between; padding: 5px 8px 5px 12px; font-family: var(--mono); font-size: 10.5px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--text3); border-bottom: 1px solid var(--line); background: var(--bg2); }
.codehead button { background: none; border: 1px solid var(--line); color: var(--text2); font-family: var(--mono); font-size: 10.5px; padding: 2px 8px; border-radius: 4px; letter-spacing: 0; text-transform: none; transition: all .12s; }
.codehead button:hover { color: var(--text); border-color: var(--line2); }
.codeblock pre { margin: 0; padding: 12px 14px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; }
.codeblock code { background: none; border: 0; padding: 0; font-size: inherit; }
.tablewrap { overflow-x: auto; margin: 10px 0 12px; border: 1px solid var(--line); border-radius: 8px; }
.md table { border-collapse: collapse; width: 100%; min-width: 100%; font-size: 13.5px; }
.md td code, .md th code { white-space: nowrap; }
.md th, .md td { word-break: normal; overflow-wrap: anywhere; }
.md th, .md td { padding: 7px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.md th { font-family: var(--mono); font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: var(--text2); background: var(--bg2); font-weight: 500; }
.md tr:last-child td { border-bottom: 0; }
.cursor { display: inline-block; width: 8px; height: 1.05em; background: var(--accent); vertical-align: -2px; margin-left: 2px; animation: blink 1s steps(2) infinite; box-shadow: 0 0 8px var(--glow); }
.cursor.live { animation: none; }

/* ส่วนเสริม: แหล่งอ้างอิง / รูป / ผลคำสั่ง / คำเตือน */
.extra:empty { display: none; }
.sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.sources a { font-family: var(--mono); font-size: 11px; color: var(--text2); text-decoration: none; border: 1px solid var(--line); border-radius: 5px; padding: 2px 8px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; transition: all .12s; }
.sources a:hover { color: var(--accent); border-color: var(--line2); }
.results { font-family: var(--mono); font-size: 12px; color: var(--text2); margin-top: 8px; display: grid; gap: 2px; }
.results .bad { color: var(--bad); }
.warn { font-family: var(--mono); font-size: 12px; color: var(--warn); margin-top: 6px; }
.genimgs { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.genimgs figure { margin: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--bg3); max-width: 360px; }
.genimgs img { display: block; max-width: 100%; cursor: zoom-in; }
.genimgs figcaption { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 4px 10px; font-family: var(--mono); font-size: 10.5px; color: var(--text3); }
.genimgs figcaption button { background: none; border: 0; color: var(--text2); font-family: var(--mono); font-size: 10.5px; }
.atts { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.atts img { max-height: 160px; max-width: 260px; border-radius: 6px; border: 1px solid var(--line); }
.filechip { font-family: var(--mono); font-size: 11.5px; padding: 3px 9px; border: 1px solid var(--line); border-radius: 5px; color: var(--text2); }

/* หน้าต้อนรับ */
.welcome { padding: 10vh 30px 40px; animation: msgIn .3s ease-out; }
.welcome .big { font-family: var(--mono); font-size: 30px; font-weight: 600; letter-spacing: 6px; color: var(--text); margin-bottom: 4px; }
.welcome .big .mark { color: var(--accent); margin-right: 12px; text-shadow: 0 0 16px var(--glow); }
.welcome .big { display: flex; align-items: center; gap: 12px; } .welcome .big .logo { width: 40px; height: 40px; }
.welcome .line { font-family: var(--mono); font-size: 12px; letter-spacing: 2px; color: var(--text3); margin-bottom: 36px; }
.welcome .sugs { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.welcome .sugs button { text-align: left; border: 1px solid var(--line); background: var(--bg2); border-radius: 8px; padding: 11px 14px; color: var(--text2); font-size: 13px; line-height: 1.5; transition: all .15s; }
.welcome .sugs button b { display: block; font-family: var(--mono); font-size: 11px; letter-spacing: 1px; color: var(--accent); font-weight: 500; margin-bottom: 2px; }
.welcome .sugs button:hover { border-color: var(--line2); color: var(--text); background: var(--bg4); transform: translateY(-1px); }
.welcome .tips { margin-top: 28px; font-family: var(--mono); font-size: 11px; color: var(--text3); line-height: 2; }
.welcome .tips kbd { margin-right: 2px; }

/* ---------- ช่องพิมพ์ ---------- */
#composer { flex: none; padding: 0 32px 10px; position: relative; }
#composer > * { width: min(var(--measure), 100%); margin-left: auto; margin-right: auto; }
.prompt { display: flex; align-items: flex-end; gap: 10px; padding: 8px 8px 8px 14px; border: 1px solid var(--line2); border-radius: 10px; background: var(--bg3); transition: border-color .15s, box-shadow .15s; position: relative; }
.prompt:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--tint); }
.prompt .ps { font-family: var(--mono); font-size: 13.5px; font-weight: 600; color: var(--accent); padding-bottom: 7px; user-select: none; white-space: nowrap; letter-spacing: .5px; }
body.busy .prompt .ps { color: var(--text3); }
#input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; resize: none; color: var(--text); font-family: inherit; font-size: var(--ui-size, 14.5px); line-height: var(--ui-lh, 1.65); padding: 5px 0; max-height: 220px; caret-color: var(--accent); }
#input::placeholder { color: var(--text3); }
.prompt .tools { display: flex; gap: 2px; align-items: center; }
.send { width: 32px; height: 32px; border: 0; border-radius: 7px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; transition: filter .15s, transform .1s, background .15s; }
.send:hover { filter: brightness(1.08); } .send:active { transform: scale(.95); }
.send.stop { background: var(--bad); color: #fff; }
.hint { display: flex; justify-content: space-between; align-items: center; font-family: var(--mono); font-size: 10.5px; color: var(--text3); padding: 6px 4px 0; min-height: 24px; gap: 12px; }
.hint #statusLine { color: var(--text2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 1em; }
.hint #statusLine:not(:empty)::before { content: "▸ "; color: var(--accent); }
.hint .keys { white-space: nowrap; flex: none; }
#attachBar { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 0 8px; }
.att { display: flex; align-items: center; gap: 7px; padding: 4px 6px 4px 4px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg2); font-size: 12px; max-width: 240px; }
.att img { width: 30px; height: 30px; object-fit: cover; border-radius: 4px; }
.att .ic { width: 30px; height: 30px; border-radius: 4px; background: var(--bg4); display: grid; place-items: center; font-family: var(--mono); font-size: 9.5px; color: var(--text2); }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att button { background: none; border: 0; color: var(--text3); padding: 0 2px; } .att button:hover { color: var(--bad); }
/* เมนูคำสั่ง / */
#slashMenu { position: absolute; left: -1px; right: -1px; bottom: calc(100% + 8px); max-height: 300px; overflow-y: auto; background: var(--bg2); border: 1px solid var(--line2); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; z-index: 30; animation: popIn .12s ease-out; }
@keyframes popIn { from { opacity: 0; transform: translateY(4px); } }
#slashMenu .it { display: grid; grid-template-columns: 120px 1fr auto; gap: 12px; align-items: center; padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--text2); }
#slashMenu .it .c { font-family: var(--mono); color: var(--text); font-size: 12.5px; }
#slashMenu .it .c b { color: var(--accent); font-weight: 600; }
#slashMenu .it .a { font-family: var(--mono); font-size: 10.5px; color: var(--text3); }
#slashMenu .it.on, #slashMenu .it:hover { background: var(--tint2); color: var(--text); }
#dropZone { position: absolute; inset: 10px; z-index: 40; border: 1.5px dashed var(--accent); border-radius: 12px; background: color-mix(in srgb, var(--bg-solid) 88%, transparent); display: grid; place-items: center; font-family: var(--mono); font-size: 16px; letter-spacing: 2px; color: var(--accent); text-align: center; pointer-events: none; }
#dropZone small { display: block; font-size: 11px; color: var(--text2); letter-spacing: 1px; margin-top: 6px; }

/* ---------- แผงงาน (ขวา) ---------- */
#side { width: var(--side-w); flex: none; display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--bg2); transition: margin-right .22s ease; }
#side.closed { margin-right: calc(-1 * var(--side-w)); }
#sideTabs { display: flex; align-items: center; gap: 2px; padding: 8px 8px 0; border-bottom: 1px solid var(--line); }
#sideTabs button:not(.ibtn) { background: none; border: 0; border-bottom: 2px solid transparent; padding: 7px 7px 9px; font-family: var(--mono); font-size: 11px; letter-spacing: .3px; color: var(--text3); display: flex; gap: 6px; align-items: center; margin-bottom: -1px; transition: color .15s; white-space: nowrap; }
#sideTabs button:not(.ibtn):hover { color: var(--text); }
#sideTabs button.on { color: var(--text); border-bottom-color: var(--accent); }
#sideTabs b { font-size: 10px; min-width: 16px; padding: 0 5px; border-radius: 8px; background: var(--bg4); color: var(--text2); text-align: center; line-height: 16px; font-weight: 500; }
#sideTabs b:empty { display: none; }
#sideTabs b.hot { background: var(--bad); color: #fff; }
#sideTabs .x { margin-left: auto; width: 24px; height: 24px; margin-bottom: 4px; }
.view { display: none; flex: 1; min-height: 0; flex-direction: column; }
.view.on { display: flex; }
.addrow { display: flex; gap: 4px; align-items: center; padding: 10px 10px 6px; }
.addrow input[type=text] { flex: 1; min-width: 0; height: 30px; padding: 0 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg3); color: var(--text); font-family: inherit; font-size: 13px; outline: 0; }
.addrow input[type=text]:focus { border-color: var(--line2); }
.addrow input[type=datetime-local] { width: 34px; height: 30px; padding: 0; overflow: hidden; color: transparent; border: 1px solid var(--line); border-radius: 7px; background: var(--bg3); color: var(--text2); font-family: var(--mono); font-size: 11px; outline: 0; color-scheme: var(--scheme); cursor: pointer; }
.addrow input[type=datetime-local]::-webkit-calendar-picker-indicator { margin: 0; padding: 0 8px; filter: var(--pick-filter, invert(.6)); cursor: pointer; }
.addrow input[type=datetime-local].has { color: var(--text2); }
html.light .addrow input[type=datetime-local]::-webkit-calendar-picker-indicator { filter: invert(.3); }
.addrow input[type=datetime-local].has { width: 150px; padding: 0 8px; }
.addrow input::placeholder { color: var(--text3); }
.addrow.bar { padding: 10px 10px 6px; }
.addrow .path { flex: 1; min-width: 0; font-family: var(--mono); font-size: 11px; color: var(--text3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: left; }
.list { flex: 1; overflow-y: auto; padding: 2px 6px 12px; }
.item { display: flex; gap: 10px; align-items: flex-start; padding: 9px 8px; border-radius: 7px; transition: background .12s; position: relative; }
.item:hover { background: var(--tint); }
.item .chk { width: 16px; height: 16px; border: 1.5px solid var(--line2); border-radius: 4px; flex: none; margin-top: 3px; cursor: pointer; display: grid; place-items: center; color: var(--accent-ink); transition: all .12s; }
.item .chk svg { width: 11px; height: 11px; opacity: 0; }
.item .chk:hover { border-color: var(--accent); }
.item.done .chk { background: var(--accent); border-color: var(--accent); } .item.done .chk svg { opacity: 1; }
.item.done .title { text-decoration: line-through; color: var(--text3); }
.item .body { flex: 1; min-width: 0; }
.item .title { font-size: 13.2px; line-height: 1.5; word-break: break-word; }
.item .meta { font-family: var(--mono); font-size: 10.5px; color: var(--text3); margin-top: 2px; }
.item.late .meta { color: var(--bad); } .item.soon .meta { color: var(--warn); }
.item .del { opacity: 0; width: 24px; height: 24px; flex: none; }
.item:hover .del { opacity: 1; }
.item .del:hover { color: var(--bad); }
.item .tag { font-family: var(--mono); font-size: 10.5px; color: var(--accent); margin-right: 6px; }
.item .fic { font-family: var(--mono); font-size: 9.5px; width: 34px; height: 24px; border: 1px solid var(--line); border-radius: 4px; display: grid; place-items: center; color: var(--text2); flex: none; text-transform: uppercase; letter-spacing: .5px; }
.item.dir .fic { color: var(--accent); }
.item.file { cursor: pointer; }
#view-files.dropping { outline: 1.5px dashed var(--accent); outline-offset: -6px; border-radius: 10px; background: var(--tint); }
.section { font-family: var(--mono); font-size: 10px; letter-spacing: 2px; text-transform: uppercase; color: var(--text3); padding: 12px 8px 4px; }
.empty { padding: 40px 20px; text-align: center; color: var(--text3); font-size: 12.5px; line-height: 1.8; }
.empty b { display: block; font-family: var(--mono); letter-spacing: 2px; font-size: 11px; color: var(--text2); margin-bottom: 4px; }
.rt { padding: 10px 8px; border-radius: 7px; }
.rt:hover { background: var(--tint); }
.rt .top { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.rt .top b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.rt .when { font-family: var(--mono); font-size: 10.5px; color: var(--accent); white-space: nowrap; }
.rt.off { opacity: .5; }
.rt .p { color: var(--text2); font-size: 12px; margin: 3px 0; line-height: 1.5; max-height: 3em; overflow: hidden; }
.rt .meta { font-family: var(--mono); font-size: 10.5px; color: var(--text3); display: flex; gap: 8px; align-items: center; }
.rt .meta .ibtn { width: 22px; height: 22px; margin-left: auto; }
.rt .meta .ibtn svg { width: 12px; height: 12px; }
.sw { width: 28px; height: 16px; border-radius: 8px; background: var(--line2); position: relative; cursor: pointer; flex: none; transition: background .15s; }
.sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--bg-solid); transition: left .15s; }
.sw.on { background: var(--accent); } .sw.on::after { left: 14px; }

/* ---------- แถบสถานะ ---------- */
#statusbar { height: var(--sb-h); flex: none; display: flex; align-items: stretch; border-top: 1px solid var(--line); background: var(--bg2); font-family: var(--mono); font-size: 11px; color: var(--text2); user-select: none; position: relative; z-index: 20; }
.st-prov { display: flex; align-items: center; gap: 8px; padding: 0 14px; border: 0; border-right: 1px solid var(--line); background: none; color: var(--text); font-family: var(--mono); font-size: 11.5px; transition: background .15s; max-width: 340px; }
.st-prov:hover { background: var(--tint); }
.st-prov .st-model { color: var(--text3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-prov .st-model:not(:empty)::before { content: "· "; }
.st-stats { display: flex; align-items: stretch; overflow: hidden; }
.st { display: flex; align-items: center; gap: 6px; padding: 0 12px; border-right: 1px solid var(--line); white-space: nowrap; }
.st em { font-style: normal; font-size: 9.5px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--text3); }
.st b { font-weight: 500; color: var(--text); font-variant-numeric: tabular-nums; }
.st b s { text-decoration: none; color: var(--text3); margin: 0 3px; }
.st .bar { width: 48px; height: 3px; background: var(--line2); border-radius: 2px; overflow: hidden; display: block; }
.st .bar u { display: block; height: 100%; width: 0; background: var(--good); transition: width .4s; }
.st .bar u.warn { background: var(--warn); } .st .bar u.bad { background: var(--bad); }
.st.pulse b { animation: pulse .5s ease; }
@keyframes pulse { 30% { color: var(--accent); } }
.st-right { margin-left: auto; display: flex; align-items: center; gap: 14px; padding: 0 14px; color: var(--text3); white-space: nowrap; }
.st-busy { color: var(--accent); }
.st-busy:not(:empty)::before { content: "◌ "; display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.st-clock { color: var(--text2); font-variant-numeric: tabular-nums; }

/* ---------- Overlay ทั่วไป ---------- */
.overlay { position: fixed; inset: 0; z-index: 100; background: color-mix(in srgb, var(--bg-solid) 55%, transparent); backdrop-filter: blur(4px); display: grid; place-items: start center; padding-top: 12vh; animation: fade .15s ease-out; }
@keyframes fade { from { opacity: 0; } }
.pal, .usage { width: min(640px, calc(100% - 40px)); background: var(--bg2); border: 1px solid var(--line2); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; animation: rise .18s cubic-bezier(.2, .8, .3, 1.1); }
@keyframes rise { from { opacity: 0; transform: translateY(-8px) scale(.985); } }
.pal-in { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.pal-in .ps { font-family: var(--mono); color: var(--accent); font-size: 16px; }
.pal-in input { flex: 1; background: none; border: 0; outline: 0; color: var(--text); font-family: inherit; font-size: 15px; }
.pal-in input::placeholder { color: var(--text3); }
.pal-list { max-height: 52vh; overflow-y: auto; padding: 6px; }
.pal-list .g { font-family: var(--mono); font-size: 10px; letter-spacing: 2px; text-transform: uppercase; color: var(--text3); padding: 10px 10px 4px; }
.pal-list .it { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px; cursor: pointer; color: var(--text2); font-size: 13.5px; }
.pal-list .it .nm { color: var(--text); font-weight: 500; }
.pal-list .it .md2 { font-family: var(--mono); font-size: 11px; color: var(--text3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.pal-list .it .tg { font-family: var(--mono); font-size: 10px; padding: 1px 7px; border-radius: 4px; border: 1px solid var(--line2); color: var(--text2); }
.pal-list .it .tg.free { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.pal-list .it .tg.act { color: var(--accent); border-color: var(--accent); }
.pal-list .it .k { font-family: var(--mono); font-size: 10.5px; color: var(--text3); }
.pal-list .it.on { background: var(--tint2); color: var(--text); }
.pal-list .it.dim { opacity: .5; }
.pal-list .it .c { font-family: var(--mono); font-size: 12.5px; color: var(--text); } .pal-list .it .c b { color: var(--accent); font-weight: 600; }
.pal-foot { padding: 8px 16px; border-top: 1px solid var(--line); font-family: var(--mono); font-size: 10.5px; color: var(--text3); display: flex; gap: 10px; }

/* แผงการใช้งาน */
.usage { width: min(900px, calc(100% - 40px)); }
.u-head { display: flex; align-items: center; gap: 12px; padding: 12px 10px 12px 18px; border-bottom: 1px solid var(--line); font-family: var(--mono); }
.u-head b { font-size: 13px; letter-spacing: 2px; }
.u-head span { font-size: 11px; color: var(--text3); }
.u-body { max-height: 60vh; overflow-y: auto; padding: 8px 12px; }
.u-foot { padding: 10px 18px; border-top: 1px solid var(--line); font-family: var(--mono); font-size: 10.5px; color: var(--text3); line-height: 1.6; }
.u-row { display: grid; grid-template-columns: 1.4fr 70px 150px 80px 70px 1.2fr 100px; gap: 10px; align-items: center; padding: 10px 8px; border-radius: 8px; font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; }
.u-row.head { font-size: 9.5px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--text3); padding: 6px 8px 2px; }
.u-row:not(.head):hover { background: var(--tint); }
.u-row.act { background: var(--tint); box-shadow: inset 2px 0 0 var(--accent); }
.u-row .nm { display: flex; align-items: center; gap: 8px; font-family: var(--ui-font, var(--sans)); font-size: 13.5px; font-weight: 500; }
.u-row .nm small { font-family: var(--mono); font-size: 10.5px; color: var(--text3); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.u-row .dim { color: var(--text3); }
.u-row .spark { display: flex; align-items: flex-end; gap: 2px; height: 18px; }
.u-row .spark i { flex: 1; min-width: 2px; background: var(--line2); border-radius: 1px; }
.u-row .spark i.hot { background: var(--accent); }
.u-row .lim { display: flex; flex-direction: column; gap: 3px; }
.u-row .lim .bar { height: 3px; background: var(--line2); border-radius: 2px; overflow: hidden; } .u-row .lim .bar u { display: block; height: 100%; background: var(--good); }
.u-row .lim .bar u.warn { background: var(--warn); } .u-row .lim .bar u.bad { background: var(--bad); }
.u-row .last { display: flex; flex-direction: column; font-size: 11px; }
.u-row .last .bad { color: var(--bad); }
.u-sum { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 6px 8px 10px; }
.u-sum div { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--bg3); }
.u-sum em { display: block; font-style: normal; font-family: var(--mono); font-size: 9.5px; letter-spacing: 2px; text-transform: uppercase; color: var(--text3); }
.u-sum b { font-family: var(--mono); font-size: 20px; font-weight: 500; color: var(--text); font-variant-numeric: tabular-nums; }
.u-sum small { font-family: var(--mono); font-size: 10.5px; color: var(--text3); margin-left: 6px; }
.u-body .acts { display: flex; justify-content: flex-end; gap: 6px; padding: 8px; }

/* ---------- Toast ---------- */
#toast { position: fixed; bottom: calc(var(--sb-h) + 16px); left: 50%; transform: translateX(-50%); z-index: 200; background: var(--bg2); color: var(--text); border: 1px solid var(--line2); border-radius: 8px; padding: 8px 14px; font-family: var(--mono); font-size: 12px; box-shadow: var(--shadow); animation: rise .18s ease-out; max-width: 80vw; }

/* ---------- โหมดเว็บ (เปิดในเบราว์เซอร์): ไม่มีปุ่มหน้าต่าง / ไม่มีพื้นที่ลาก ---------- */
.web-only { display: none !important; }
body.web .web-only { display: grid !important; }
body.web #titlebar { -webkit-app-region: no-drag; padding-left: 14px; }
body.web #winBtns { display: none; }
body.web .st-key { display: none; }
body.web.fullscreen #titlebar { --tb-h: 36px; }
body.web #btnFull svg { width: 15px; height: 15px; }

/* ---------- ข้อความ: ใช้แนวทางเดิม / ทางเลือกอื่น / ปุ่มบันทึกแนวทาง ---------- */
.recalled { font-family: var(--mono); font-size: 11px; color: var(--text3); margin: -2px 0 8px; letter-spacing: .2px; }
.recalled::first-letter { color: var(--accent); }
.alts { margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg2); font-size: 13px; }
.alts summary { cursor: pointer; padding: 6px 12px; font-family: var(--mono); font-size: 11px; letter-spacing: .5px; color: var(--text2); list-style: none; user-select: none; display: flex; gap: 8px; align-items: center; }
.alts summary::-webkit-details-marker { display: none; }
.alts summary::before { content: '›'; color: var(--accent); font-weight: 600; transition: transform .15s; display: inline-block; }
.alts[open] summary::before { transform: rotate(90deg); }
.alts summary b { font-weight: 500; min-width: 16px; padding: 0 5px; border-radius: 8px; background: var(--bg4); color: var(--text2); text-align: center; font-size: 10px; line-height: 16px; }
.alts ol { margin: 0; padding: 2px 14px 10px 30px; color: var(--text2); } .alts li { margin: 4px 0; } .alts li p { margin: 0; }
.msg.bot .foot .acts button.pb { color: var(--text3); }
.msg.bot .foot .acts button.pb:hover { color: var(--accent); }
.msg.bot .foot .acts button:disabled { opacity: .7; color: var(--good); }
.hint .tok { font-family: var(--mono); color: var(--text3); white-space: nowrap; flex: none; cursor: help; margin-left: auto; }
.hint .tok:not(:empty)::before { content: "⌁ "; color: var(--accent); }
.hint .tok.hi { color: var(--warn); }
.hint .tok:not(:empty) + .keys { margin-left: 10px; }
.hint #statusLine { flex: 1; }

/* ---------- แถบสถานะ: โหมดประหยัดโทเคน / Discord ---------- */
.st-eco { display: flex; align-items: center; gap: 6px; padding: 0 10px; border-right: 1px solid var(--line); white-space: nowrap; }
.st-eco em { font-style: normal; font-size: 9.5px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--text3); }
.st-eco button { border: 0; background: none; color: var(--text3); font-family: var(--mono); font-size: 10.5px; padding: 2px 7px; border-radius: 4px; transition: all .12s; }
.st-eco button:hover { color: var(--text); background: var(--tint); }
.st-eco button.on { color: var(--accent-ink); background: var(--accent); font-weight: 600; }
.st-eco[data-mode="saver"] button.on { background: var(--good); color: #052e16; }
.st-eco[data-mode="full"] button.on { background: var(--warn); color: #3b2300; }
.st-dc { display: flex; align-items: center; gap: 6px; cursor: pointer; color: var(--text3); }
.st-dc:hover { color: var(--text); }

/* ---------- แผงสกิล / งานที่เคยทำ ---------- */
#sideTabs { overflow-x: auto; scrollbar-width: none; } #sideTabs::-webkit-scrollbar { display: none; }
#sideTabs button:not(.ibtn) { padding-left: 6px; padding-right: 6px; flex: none; }
.addrow.seg2 { gap: 2px; }
.addrow .seg { flex: 1; display: inline-flex; gap: 2px; padding: 2px; border-radius: 7px; background: var(--bg3); border: 1px solid var(--line); }
.addrow .seg button { flex: 1; border: 0; background: none; color: var(--text3); font-family: var(--mono); font-size: 11px; padding: 4px 6px; border-radius: 5px; display: flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; transition: all .12s; }
.addrow .seg button:hover { color: var(--text); }
.addrow .seg button.on { background: var(--bg2); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .25); }
.addrow .seg button b { font-size: 9.5px; min-width: 14px; padding: 0 4px; border-radius: 7px; background: var(--bg4); color: var(--text2); line-height: 14px; font-weight: 500; } .addrow .seg button b:empty { display: none; }
.search.sk { flex: none; margin: 0 10px 6px; }
.skform { display: grid; gap: 6px; margin: 2px 10px 8px; padding: 10px; border: 1px solid var(--line2); border-radius: 9px; background: var(--bg3); animation: popIn .15s ease-out; }
.skform input, .skform textarea { width: 100%; background: var(--bg-solid); border: 1px solid var(--line); border-radius: 6px; color: var(--text); font-family: inherit; font-size: 13px; padding: 6px 10px; outline: 0; resize: vertical; line-height: 1.55; }
.skform textarea { font-family: var(--mono); font-size: 12px; min-height: 90px; }
.skform input:focus, .skform textarea:focus { border-color: var(--accent); }
.skform input::placeholder, .skform textarea::placeholder { color: var(--text3); }
.skbtns { display: flex; justify-content: flex-end; gap: 6px; }
.sk { border-radius: 8px; margin-bottom: 2px; transition: background .12s; }
.sk:hover, .sk.open { background: var(--tint); }
.sk .top { display: flex; gap: 10px; align-items: flex-start; padding: 9px 8px; cursor: pointer; }
.sk .ic { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line); display: grid; place-items: center; color: var(--accent); flex: none; background: var(--bg3); }
.sk .ic svg { width: 14px; height: 14px; }
.sk.exp .ic { color: var(--good); }
.sk .body { flex: 1; min-width: 0; }
.sk .title { font-size: 13.2px; line-height: 1.45; word-break: break-word; font-weight: 500; }
.sk .meta { font-family: var(--mono); font-size: 10.5px; color: var(--text3); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sk .top .del, .sk .top .edit, .sk .top .pin { opacity: 0; width: 24px; height: 24px; flex: none; }
.sk:hover .top .del, .sk:hover .top .edit, .sk:hover .top .pin, .sk.open .top .del, .sk.open .top .edit, .sk.open .top .pin, .sk .top .pin.on { opacity: 1; }
.sk .top .pin.on { color: var(--accent); }
.sk .top .edit:hover { color: var(--accent); }
.sk .steps { display: none; padding: 0 12px 12px 44px; font-size: 13px; color: var(--text2); line-height: 1.6; }
.sk.open .steps { display: block; animation: msgIn .18s ease-out; }
.sk .steps ol, .sk .steps ul { margin: 0 0 8px; padding-left: 18px; } .sk .steps li { margin: 2px 0; } .sk .steps p { margin: 0 0 6px; }
.sk .steps code { font-family: var(--mono); font-size: 11px; background: var(--bg4); border: 1px solid var(--line); padding: 1px 6px; border-radius: 4px; margin: 0 4px 4px 0; display: inline-block; }
.sk .steps .req { font-size: 12.5px; color: var(--text); margin-bottom: 6px; white-space: pre-wrap; word-break: break-word; max-height: 4.8em; overflow: hidden; }
.sk .steps .out { font-family: var(--mono); font-size: 11.5px; color: var(--good); margin-top: 4px; }
.sk .steps .tools:not(:empty) { margin-top: 6px; }
.sk .steps .use { margin-top: 8px; color: var(--accent); border-color: var(--line2); }
.sk .steps .use:hover { background: var(--tint2); }
.sk.pinned .title::before { content: '📌 '; font-size: 11px; }

/* ---------- ตั้งค่าในหน้าเดียวกัน (iframe เลื่อนเข้าจากขวา) ---------- */
#settingsOverlay { position: fixed; inset: 0; z-index: 150; background: color-mix(in srgb, var(--bg-solid) 55%, transparent); backdrop-filter: blur(3px); opacity: 0; transition: opacity .2s ease; }
#settingsOverlay.in { opacity: 1; }
.so-panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(1100px, 100%); background: var(--bg-solid); border-left: 1px solid var(--line2); box-shadow: var(--shadow); transform: translateX(28px); opacity: 0; transition: transform .24s cubic-bezier(.2, .8, .3, 1), opacity .2s ease; }
#settingsOverlay.in .so-panel { transform: none; opacity: 1; }
#settingsFrame { width: 100%; height: 100%; border: 0; display: block; background: var(--bg-solid); }
body.settings-open { overflow: hidden; }

/* ---------- การแสดงผล (ป็อปโอเวอร์ Aa) ---------- */
#display { position: fixed; inset: 0; z-index: 120; }
.dp { position: absolute; top: calc(var(--tb-h) + 6px); right: 12px; width: min(380px, calc(100% - 24px)); background: var(--bg2); border: 1px solid var(--line2); border-radius: 12px; box-shadow: var(--shadow); animation: rise .18s ease-out; max-height: calc(100vh - var(--tb-h) - 24px); display: flex; flex-direction: column; overflow: hidden; }
.dp-head { display: flex; align-items: center; gap: 10px; padding: 10px 8px 10px 16px; border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: 12px; letter-spacing: 2px; }
.dp-body { padding: 6px 16px 14px; overflow-y: auto; }
.dp-row { margin-top: 12px; }
.dp-row label { display: block; font-family: var(--mono); font-size: 10.5px; letter-spacing: 1px; text-transform: uppercase; color: var(--text3); margin-bottom: 6px; }
.dp-row label code { color: var(--text2); text-transform: none; letter-spacing: 0; margin-left: 6px; }
.dp-range { display: flex; align-items: center; gap: 10px; }
.dp-range input[type=range] { flex: 1; accent-color: var(--accent); }
.dp-range .a { font-size: 11px; color: var(--text3); } .dp-range .b { font-size: 18px; color: var(--text2); }
.dp-seg { display: flex; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg3); }
.dp-seg button { flex: 1; border: 0; background: none; color: var(--text3); font-family: inherit; font-size: 12.5px; padding: 6px 4px; border-radius: 5px; transition: all .12s; }
.dp-seg button:hover { color: var(--text); } .dp-seg button.on { background: var(--bg2); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .25); font-weight: 600; }
.dp-row select, .dp-custom { width: 100%; background: var(--bg3); border: 1px solid var(--line); color: var(--text); font-family: inherit; font-size: 13px; padding: 7px 10px; border-radius: 7px; outline: 0; color-scheme: var(--scheme); }
.dp-row select:focus, .dp-custom:focus { border-color: var(--accent); }
.dp-custom { display: none; margin-top: 6px; } .dp-custom.show { display: block; }
.dp-prev { margin-top: 6px; padding: 8px 10px; border: 1px dashed var(--line2); border-radius: 7px; color: var(--text2); font-size: 14px; line-height: 1.5; }
.dp-check { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 13px; cursor: pointer; flex-wrap: wrap; }
.dp-check input { accent-color: var(--accent); width: 15px; height: 15px; }
.dp-check small { flex-basis: 100%; color: var(--text3); font-size: 11px; padding-left: 23px; margin-top: -4px; }
.dp-more { margin-top: 12px; width: 100%; font-family: var(--mono); font-size: 11.5px; padding: 7px; border: 1px solid var(--line); border-radius: 7px; background: none; color: var(--accent); }
.dp-more:hover { background: var(--tint); }

/* ---------- มือถือ: แถบแท็บล่าง / เมนูเพิ่มเติม / สถานะย่อ ---------- */
.mobile-only { display: none !important; }
#tabbar { position: fixed; left: 0; right: 0; bottom: 0; height: var(--tab-h); z-index: 60; background: var(--bg2); border-top: 1px solid var(--line); display: flex; align-items: stretch; padding-bottom: env(safe-area-inset-bottom); user-select: none; }
#tabbar button { flex: 1; border: 0; background: none; color: var(--text3); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-family: inherit; font-size: 10.5px; position: relative; min-height: 44px; -webkit-tap-highlight-color: transparent; }
#tabbar button svg { width: 22px; height: 22px; }
#tabbar button.on { color: var(--accent); }
#tabbar button b { position: absolute; top: 6px; left: calc(50% + 6px); font-size: 9.5px; min-width: 15px; padding: 0 4px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); line-height: 15px; font-weight: 600; }
#tabbar button b:empty { display: none; }
#scrim { position: fixed; inset: 0; z-index: 14; background: color-mix(in srgb, var(--bg-solid) 55%, transparent); backdrop-filter: blur(2px); animation: fade .15s ease-out; }
.pill { display: flex; align-items: center; gap: 7px; height: 32px; padding: 0 11px; border: 1px solid var(--line); background: var(--bg3); border-radius: 999px; font-family: var(--mono); font-size: 11.5px; color: var(--text); max-width: 150px; }
.pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.more { width: min(640px, 100%); background: var(--bg2); border: 1px solid var(--line2); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; animation: rise .18s cubic-bezier(.2, .8, .3, 1.1); }
.more-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 12px; max-height: 70vh; overflow-y: auto; }
.more-grid button { border: 1px solid var(--line); background: var(--bg3); color: var(--text2); border-radius: 10px; padding: 12px 6px 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-family: inherit; font-size: 11.5px; min-height: 72px; -webkit-tap-highlight-color: transparent; }
.more-grid button svg { width: 22px; height: 22px; color: var(--accent); }
.more-grid button.on { border-color: var(--accent); color: var(--text); background: var(--tint); }
.more-grid button:active { background: var(--tint2); }
.overlay.sheet { place-items: end center; padding: 0; }
.u-acts-m { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  body { --side-w: 300px; }
  #side { position: absolute; right: 0; top: 0; bottom: 0; z-index: 15; box-shadow: var(--shadow); }
  #side.closed { margin-right: 0; transform: translateX(100%); box-shadow: none; }
  #side { transition: transform .22s ease; }
}
@media (max-width: 960px) {
  #sidebar { position: absolute; left: 0; top: 0; bottom: 0; z-index: 15; box-shadow: var(--shadow); transition: transform .22s ease; }
  #sidebar.closed { margin-left: 0; transform: translateX(-100%); box-shadow: none; }
  #log > * { width: calc(100% - 40px); }
  #composer { padding: 0 20px 8px; }
  .hint .keys { display: none; }
  #stHint { display: none; }
  .st-eco em { display: none; }
  .st-dc { display: none; }
  .chip kbd { display: none; }
  .st-prov { max-width: 220px; }
  .st.lim { display: none; }
}
@media (max-width: 820px) { .st-stats .st:nth-child(3), .st-stats .st:nth-child(2) { display: none; } #convTitle { max-width: 30vw; } }

/* =====================================================================
   มือถือ (≤760px หรือหน้าจอสัมผัส ≤900px): แถบบน + แชทเต็มจอ + แถบแท็บล่าง + แผงเป็นชีตเต็มจอ
   ===================================================================== */
@media (max-width: 760px), ((pointer: coarse) and (max-width: 900px)) {
  html, body { height: 100%; }
  body { height: var(--vvh, 100dvh); --tab-h: calc(56px + env(safe-area-inset-bottom)); --side-w: 100vw; --hist-w: min(86vw, 340px); --tb-h: calc(52px + env(safe-area-inset-top)); }
  body.kb { --tab-h: 0px; }
  .mobile-only { display: flex !important; }
  body.kb #tabbar { display: none !important; }
  /* แถบบน */
  #titlebar { padding: env(safe-area-inset-top) 6px 0 6px; gap: 2px; }
  #titlebar .ibtn { width: 44px; height: 44px; }
  .brand { gap: 0; flex: none; padding: 0 2px; } .brand #brandText, .brand .ver { display: none; } .brand .logo { width: 26px; height: 26px; }
  .tb-center { justify-content: flex-start; gap: 0; } .tb-center .sep, #btnHistory { display: none; }
  #convTitle { max-width: none; flex: 1; font-size: 15px; font-weight: 500; padding: 8px 6px; color: var(--text); }
  #btnNew { flex: none; }
  .tb-right { gap: 0; }
  #modelChip, #btnSearch, #btnChar, #btnPanel, #btnSettings, #btnDisplay, #btnFull, #winBtns { display: none !important; }
  /* แชท */
  #body { padding-bottom: var(--tab-h); }
  #log { padding: 14px 0 12px; }
  #log > * { width: calc(100% - 24px); }
  .msg { grid-template-columns: 16px 1fr; gap: 0 8px; margin-bottom: 18px; }
  .msg .gutter { font-size: 13px; }
  .msg.bot .foot .acts { opacity: 1; }
  .msg.bot .foot .acts button { padding: 6px 8px; min-height: 32px; }
  .welcome { padding: 4vh 6px 24px; } .welcome .big { font-size: 24px; letter-spacing: 4px; } .welcome .sugs { grid-template-columns: 1fr; } .welcome .tips { display: none; }
  .welcome .sugs button { padding: 12px 14px; min-height: 44px; }
  .genimgs figure { max-width: 100%; } .atts img { max-width: 100%; }
  .md table { width: max-content; min-width: 100%; } .md th, .md td { overflow-wrap: normal; word-break: normal; max-width: 70vw; } .md th { white-space: nowrap; }
  /* ช่องพิมพ์ */
  #composer { padding: 0 10px calc(8px + env(safe-area-inset-bottom)); }
  body.kb #composer { padding-bottom: 8px; }
  .prompt { padding: 6px 6px 6px 12px; border-radius: 14px; gap: 6px; }
  .prompt .ps { display: none; }
  #input { font-size: 16px; padding: 8px 0; max-height: 160px; }
  .prompt .tools .ibtn { width: 40px; height: 40px; } .send { width: 40px; height: 40px; border-radius: 10px; }
  .hint { padding: 4px 4px 0; min-height: 18px; font-size: 10px; } .hint .keys { display: none; }
  #slashMenu { max-height: 42vh; } #slashMenu .it { grid-template-columns: 96px 1fr; padding: 11px 10px; min-height: 44px; } #slashMenu .it .a { display: none; }
  #dropZone { inset: 6px; font-size: 14px; }
  /* ประวัติแชท: ลิ้นชักซ้าย */
  #sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 70; width: var(--hist-w); box-shadow: var(--shadow); transition: transform .22s ease; margin: 0; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
  #sidebar.closed { margin-left: 0; transform: translateX(-100%); box-shadow: none; }
  .sb-head { padding: 12px 10px 8px; } .search { height: 40px; } .search input { font-size: 16px; }
  #btnNew2 { width: 40px; height: 40px; }
  .conv { padding: 11px 8px 11px 12px; font-size: 14.5px; min-height: 44px; } .conv .del { opacity: 1; width: 32px; height: 32px; }
  /* แผงงาน: ชีตเต็มจอ (เหนือแถบแท็บ) */
  #side { position: fixed; left: 0; right: 0; top: 0; bottom: var(--tab-h); z-index: 50; width: 100%; box-shadow: none; transition: transform .24s cubic-bezier(.2, .8, .3, 1), opacity .2s; margin: 0; border: 0; }
  #side.closed { margin: 0; transform: translateY(14px); opacity: 0; pointer-events: none; }
  #sideTabs { padding: calc(6px + env(safe-area-inset-top)) 8px 0; gap: 0; position: sticky; top: 0; background: var(--bg2); }
  #sideTabs button:not(.ibtn) { font-size: 12.5px; padding: 11px 9px 12px; min-height: 44px; }
  #sideTabs .x { width: 40px; height: 40px; margin-bottom: 2px; }
  .addrow { padding: 10px 10px 6px; gap: 6px; }
  .addrow input[type=text] { height: 42px; font-size: 16px; } .addrow .ibtn { width: 42px; height: 42px; } .addrow input[type=datetime-local] { height: 42px; width: 42px; font-size: 16px; }
  .addrow input[type=datetime-local].has { width: 150px; }
  .item { padding: 11px 8px; } .item .title { font-size: 14.5px; } .item .del { opacity: 1; width: 32px; height: 32px; } .item .chk { width: 20px; height: 20px; margin-top: 2px; }
  .sk .top .del, .sk .top .edit, .sk .top .pin { opacity: 1; width: 32px; height: 32px; }
  .rt .meta .ibtn { width: 32px; height: 32px; }
  .skform input, .skform textarea { font-size: 16px; }
  .search.sk input { font-size: 16px; }
  /* แถบสถานะ: ซ่อน ใช้ pill ด้านบนแทน */
  #statusbar { display: none; }
  #toast { bottom: calc(var(--tab-h) + 72px); max-width: 92vw; font-size: 13px; }
  /* overlay ทุกตัวเป็นชีตจากด้านล่าง */
  .overlay { place-items: end center; padding: 0; }
  .pal, .usage, .more { width: 100%; border-radius: 16px 16px 0 0; border-bottom: 0; animation: up .2s cubic-bezier(.2, .8, .3, 1); max-height: 88vh; display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }
  @keyframes up { from { transform: translateY(24px); opacity: 0; } }
  .pal-in input { font-size: 16px; } .pal-list { max-height: none; flex: 1; overflow-y: auto; } .pal-list .it { padding: 12px 10px; min-height: 44px; } .pal-foot { display: none; }
  .u-body { max-height: none; flex: 1; overflow-y: auto; padding: 8px; }
  .u-sum { grid-template-columns: repeat(2, 1fr); } .u-row { grid-template-columns: 1.4fr 60px 1fr; font-size: 11.5px; }
  .u-row > :nth-child(4), .u-row > :nth-child(5), .u-row > :nth-child(6), .u-row > :nth-child(7) { display: none; }
  .u-acts-m { display: flex; gap: 6px; padding: 8px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
  .u-acts-m .tbtn { flex: 1; padding: 9px 8px; font-size: 12px; min-height: 40px; }
  .u-acts-m .tbtn.on { color: var(--accent); border-color: var(--accent); }
  .u-foot { display: none; }
  .more-grid { grid-template-columns: repeat(3, 1fr); }
  /* ป็อปโอเวอร์การแสดงผล → ชีต */
  .dp { top: auto; right: 0; left: 0; bottom: 0; width: 100%; border-radius: 16px 16px 0 0; max-height: 88vh; animation: up .2s cubic-bezier(.2, .8, .3, 1); padding-bottom: env(safe-area-inset-bottom); }
  .dp-row select, .dp-custom { font-size: 16px; } .dp-seg button { min-height: 40px; }
  /* ตั้งค่า: เต็มจอ */
  .so-panel { width: 100%; border-left: 0; transform: translateY(100%); opacity: 1; transition: transform .26s cubic-bezier(.2, .8, .3, 1); }
}
@media (hover: none) and (pointer: coarse) {
  .msg.bot .foot .acts { opacity: 1; } .item .del, .conv .del { opacity: 1; }
  .sk .top .del, .sk .top .edit, .sk .top .pin { opacity: 1; }
}
@media (min-width: 1700px) { body { --measure: 960px; font-size: 15px; } }
@media (min-width: 2400px) { body { --measure: 1100px; font-size: 16px; --side-w: 380px; --hist-w: 300px; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition-duration: .001s !important; }
  .cursor { animation: none !important; }
}
