:root {
  --bg: #212121;
  --bg-side: #171717;
  --bg-soft: #2f2f2f;
  --bg-hover: #2a2a2a;
  --bg-input: #303030;
  --line: #3a3a3a;
  --text: #ececec;
  --text-dim: #b4b4b4;
  --text-faint: #8f8f8f;
  --accent: #10a37f;
  --accent-2: #1a7f64;
  --user-bubble: #2f2f2f;
  --radius: 16px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Noto Sans Thai", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; height: 100vh; overflow: hidden; }

button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ============ Sidebar ============ */
#sidebar {
  width: 270px;
  background: var(--bg-side);
  display: flex;
  flex-direction: column;
  padding: 10px;
  gap: 8px;
  flex-shrink: 0;
  position: relative;
  transition: margin .2s ease;
}
/* ยุบแต่เหลือแถบดำบาง ๆ ไว้กดเปิดกลับ */
#sidebar.collapsed { margin-left: -256px; cursor: pointer; }
#sidebar.collapsed > * { visibility: hidden; }
#sidebar.collapsed::after {
  content: "›";
  position: absolute;
  right: 3px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  font-size: 17px;
  line-height: 1;
}
#sidebar.collapsed:hover { background: var(--bg-hover); }

.side-top { display: flex; gap: 6px; }
.side-btn {
  display: flex; align-items: center; gap: 9px;
  background: transparent; border: 1px solid transparent;
  color: var(--text-dim); padding: 10px 12px;
  border-radius: 10px; font-size: 14px; width: 100%;
  transition: background .15s;
}
.side-btn:hover { background: var(--bg-hover); color: var(--text); }
.side-btn.accent { flex: 1; border-color: var(--line); color: var(--text); }
.side-btn.accent:hover { background: var(--bg-soft); }

.icon-btn {
  background: transparent; border: none; color: var(--text-dim);
  width: 38px; height: 38px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background .15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.side-label {
  font-size: 11.5px; color: var(--text-faint);
  padding: 6px 10px 2px; text-transform: uppercase; letter-spacing: .6px;
}

#chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-item {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 10px; border-radius: 9px; cursor: pointer;
  color: var(--text-dim); font-size: 13.5px;
  border: 1px solid transparent; user-select: none;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: #2e2e2e; color: var(--text); border-color: var(--line); }
.chat-item .title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .del {
  opacity: 0; border: none; background: transparent; color: var(--text-faint);
  width: 24px; height: 24px; border-radius: 6px; font-size: 15px; line-height: 1;
}
.chat-item:hover .del { opacity: 1; }
.chat-item .del:hover { background: #453535; color: #ff8f8f; }

.side-bottom { display: flex; flex-direction: column; gap: 6px; }
.conn { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-faint); padding: 4px 12px; }
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: #6b6b6b; }
.conn.ok .dot { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.conn.ok .txt { color: #7fd9bd; }
.conn.err .dot { background: #e05252; }
.conn.err .txt { color: #ff9b9b; }

/* ============ Main ============ */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#topbar {
  height: 54px; display: flex; align-items: center; gap: 10px;
  padding: 0 14px; border-bottom: 1px solid var(--line);
  background: rgba(33, 33, 33, .9); backdrop-filter: blur(8px);
  z-index: 5;
}

.mode-switch { display: flex; background: var(--bg-input); border-radius: 999px; padding: 3px; gap: 2px; }
.mode-btn {
  display: flex; align-items: center; gap: 6px;
  border: none; background: transparent; color: var(--text-dim);
  padding: 6px 14px; border-radius: 999px; font-size: 13.5px; transition: .15s;
}
.mode-btn.active { background: var(--accent); color: #fff; }
.mode-btn:not(.active):hover { background: var(--bg-hover); color: var(--text); }

.model-pick { margin-left: auto; }
#model-select {
  background: var(--bg-input); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 7px 10px; font-size: 13px; max-width: 300px; outline: none;
}
#model-select:focus { border-color: var(--accent); }

/* ============ Chat area ============ */
#chat { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
#messages { max-width: 780px; margin: 0 auto; padding: 24px 16px 10px; }

#empty-state {
  max-width: 700px; margin: 0 auto; padding: 11vh 20px 0; text-align: center;
}
#empty-state .logo {
  font-size: 40px; color: var(--accent);
  animation: float 3s ease-in-out infinite;
}
@keyframes float { 50% { transform: translateY(-6px); } }
#empty-state h1 { font-size: 30px; margin: 14px 0 8px; font-weight: 600; }
#empty-state p { color: var(--text-dim); margin: 0 0 26px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.chip {
  background: var(--bg-side); border: 1px solid var(--line);
  color: var(--text-dim); padding: 10px 15px; border-radius: 12px;
  font-size: 13.5px; transition: .15s;
}
.chip:hover { background: var(--bg-soft); color: var(--text); border-color: #4c4c4c; }

.msg { display: flex; gap: 14px; margin-bottom: 26px; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(5px); } }

/* ข้อความเราอยู่ฝั่งขวา / AI อยู่ฝั่งซ้าย */
.msg.user { flex-direction: row-reverse; }
.msg.user .body { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .who { text-align: right; }
.msg.user .attach-row { justify-content: flex-end; }
.msg.user .content { text-align: left; }

.msg .avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700;
}
.msg.user .avatar { background: #5436da; color: #fff; }
.msg.assistant .avatar { background: var(--accent); color: #06281f; }
.msg.error .avatar { background: #b03a3a; color: #fff; }

.msg .body { min-width: 0; flex: 1; padding-top: 3px; }
.msg .who { font-size: 13px; font-weight: 600; margin-bottom: 3px; color: var(--text); }

.msg.user .content {
  background: var(--user-bubble); border-radius: var(--radius);
  padding: 11px 16px; display: inline-block; max-width: 100%;
}
.msg.assistant .content, .msg.error .content {
  background: transparent; padding: 2px 0;
}
.msg.error .content { color: #ff9b9b; }

/* attachments */
.attach-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.attach-row img {
  max-width: 220px; max-height: 160px; border-radius: 10px;
  border: 1px solid var(--line); object-fit: cover; cursor: zoom-in;
}
.attach-item { position: relative; display: inline-block; }
.attach-item img { display: block; }
.ref-btn {
  position: absolute; left: 6px; bottom: 6px;
  background: #000c; color: #fff; border: none; border-radius: 8px;
  font-size: 11.5px; padding: 4px 9px; cursor: pointer; opacity: 0;
  transition: opacity .15s; font-family: inherit;
}
.attach-item:hover .ref-btn { opacity: 1; }
.ref-btn:hover { background: var(--accent); }

/* markdown */
.content { line-height: 1.72; word-wrap: break-word; overflow-wrap: anywhere; }
.content p { margin: 0 0 12px; }
.content p:last-child { margin-bottom: 0; }
.content h1, .content h2, .content h3 { margin: 20px 0 10px; line-height: 1.35; }
.content h1 { font-size: 23px; } .content h2 { font-size: 20px; } .content h3 { font-size: 17px; }
.content ul, .content ol { margin: 0 0 12px; padding-left: 24px; }
.content li { margin: 4px 0; }
.content a { color: #6cb7ff; }
.content blockquote {
  margin: 12px 0; padding: 6px 14px; border-left: 3px solid var(--accent);
  background: var(--bg-soft); border-radius: 0 8px 8px 0; color: var(--text-dim);
}
.content code {
  background: var(--bg-soft); padding: 2px 6px; border-radius: 5px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13.5px;
}
.content pre {
  background: #0d0d0d; border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; overflow-x: auto; position: relative; margin: 0 0 14px;
}
.content pre code { background: none; padding: 0; font-size: 13.5px; line-height: 1.6; display: block; }
.copy-btn {
  position: absolute; top: 8px; right: 8px; font-size: 11.5px;
  background: #262626; color: var(--text-dim); border: 1px solid var(--line);
  border-radius: 7px; padding: 4px 9px; opacity: 0; transition: .15s;
}
.content pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--text); background: #333; }
.content table { border-collapse: collapse; width: 100%; margin: 0 0 14px; font-size: 14px; }
.content th, .content td { border: 1px solid var(--line); padding: 7px 11px; text-align: left; }
.content th { background: var(--bg-soft); }
.content hr { border: none; border-top: 1px solid var(--line); margin: 18px 0; }

/* generated / attached images in chat */
.img-card {
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 14px; overflow: hidden; max-width: 512px; margin-top: 8px;
}
.img-card img { width: 100%; display: block; }
.img-card .cap { padding: 9px 13px; font-size: 13px; color: var(--text-dim); border-top: 1px solid var(--line); }
.img-actions { display: flex; gap: 8px; padding: 9px 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.img-actions button {
  background: var(--bg-input); border: 1px solid var(--line); color: var(--text-dim);
  font-size: 12.5px; padding: 6px 12px; border-radius: 8px; transition: .15s;
}
.img-actions button:hover { background: #3c3c3c; color: var(--text); }

.msg-tools { margin-top: 8px; }
.msg-tools button {
  background: transparent; border: 1px solid var(--line); color: var(--text-faint);
  font-size: 12px; padding: 5px 11px; border-radius: 8px; transition: .15s;
}
.msg-tools button:hover { color: var(--text); background: var(--bg-soft); }

/* lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 80; background: rgba(0, 0, 0, .88);
  display: flex; align-items: center; justify-content: center; padding: 30px;
  cursor: zoom-out; animation: fade .15s ease;
}
.lightbox img {
  max-width: 100%; max-height: 100%; border-radius: 10px;
  box-shadow: var(--shadow); object-fit: contain;
}

/* loading */
.typing { display: inline-flex; gap: 5px; padding: 6px 0; }.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint);
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* สถานะ "กำลังทำงาน..." ระหว่าง AI ตอบ */
.working-status {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 8px; padding: 6px 13px;
  background: #16261f; border: 1px solid #2c4a3f;
  border-radius: 999px; color: #8fe0c6;
  font-size: 12.5px; font-weight: 500; letter-spacing: .2px;
}
.working-status .ws-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); animation: wsbounce 1s ease-in-out infinite;
}
@keyframes wsbounce {
  0%, 100% { opacity: .3; transform: scale(.75); }
  50% { opacity: 1; transform: scale(1.15); }
}

.gen-skeleton {
  width: 420px; max-width: 100%; height: 260px; border-radius: 14px;
  background: linear-gradient(100deg, #2a2a2a 30%, #343434 50%, #2a2a2a 70%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite; margin-top: 6px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ============ Composer ============ */
#composer-wrap { max-width: 780px; width: 100%; margin: 0 auto; padding: 0 16px 12px; }

#attach-preview {
  display: flex; gap: 8px; flex-wrap: wrap; padding: 8px 4px;
}
.thumb { position: relative; }
.thumb img {
  width: 62px; height: 62px; object-fit: cover;
  border-radius: 10px; border: 1px solid var(--line);
}
.thumb button {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px;
  border-radius: 50%; border: none; background: #000c; color: #fff;
  font-size: 12px; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.thumb button:hover { background: #e05252; }

.ref-hint {
  font-size: 12px; color: var(--text-dim); background: var(--bg-hover);
  border: 1px dashed var(--line); border-radius: 10px; padding: 6px 11px;
}
.ref-hint b { color: var(--text); }

/* ============ Video options ============ */
#video-opts {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--bg-hover); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px 12px; margin-bottom: 4px;
}
.vo-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.vo-group { display: flex; align-items: center; gap: 8px; }
.vo-label { font-size: 12.5px; color: var(--text-dim); white-space: nowrap; }
.vo-unit { font-size: 12.5px; color: var(--text-faint); }
.vo-toggle { display: flex; background: var(--bg-input); border-radius: 999px; padding: 3px; gap: 2px; }
.vo-chip {
  border: none; background: transparent; color: var(--text-dim);
  font-size: 12.5px; padding: 5px 12px; border-radius: 999px; cursor: pointer; transition: .15s;
}
.vo-chip.active { background: var(--accent); color: #fff; }
.vo-chip:disabled { opacity: .4; cursor: not-allowed; }
.vo-chip:not(.active):not(:disabled):hover { background: #3c3c3c; color: var(--text); }
#vo-duration, #vo-resolution {
  background: var(--bg-input); color: var(--text); border: 1px solid var(--line);
  border-radius: 9px; padding: 6px 9px; font-size: 13px; font-family: inherit;
}
#vo-resolution:disabled { opacity: .5; }
.vo-reset {
  margin-left: auto; background: transparent; border: 1px solid var(--line);
  color: var(--text-dim); border-radius: 9px; padding: 6px 13px;
  font-size: 12.5px; cursor: pointer; transition: .15s;
}
.vo-reset:hover { background: #3c3c3c; color: var(--text); }

.vo-frames { gap: 10px; }
.vo-slot {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; min-width: 118px; height: 66px; padding: 6px 10px;
  background: var(--bg-input); border: 1px dashed var(--line); border-radius: 12px;
  color: var(--text-dim); cursor: pointer; transition: .15s; overflow: hidden;
}
.vo-slot:hover { border-color: var(--accent); color: var(--text); }
.vo-slot.off { opacity: .4; cursor: not-allowed; }
.vo-slot.has { border-style: solid; padding: 0; }
.vo-slot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.vo-ico { font-size: 17px; }
.vo-txt { font-size: 11.5px; }
.vo-x {
  position: absolute; top: 4px; right: 4px; z-index: 2;
  width: 20px; height: 20px; border-radius: 50%; background: #000c; color: #fff;
  font-size: 12px; line-height: 20px; text-align: center;
}
.vo-x:hover { background: #e05252; }
.vo-hint { font-size: 11.5px; color: var(--text-faint); flex: 1; min-width: 180px; }

/* ช่อง Image ใบหน้า (สูงสุด 4 รูป) */
.vo-slot.face-slot { min-width: 150px; height: 74px; gap: 4px; }
.vo-slot.face-slot.has { flex-direction: column; padding: 7px 8px 5px; }
.face-strip { display: flex; gap: 4px; align-items: center; justify-content: center; flex-wrap: wrap; }
.face-th { position: relative; width: 30px; height: 38px; border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.face-th img { position: static; width: 100%; height: 100%; object-fit: cover; }
.face-th i {
  position: absolute; top: 0; right: 0; width: 14px; height: 14px;
  background: #000c; color: #fff; font-size: 9px; font-style: normal;
  line-height: 14px; text-align: center; cursor: pointer;
}
.face-th i:hover { background: #e05252; }
.face-add {
  width: 30px; height: 38px; border: 1px dashed var(--line); border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 15px; background: var(--bg-hover);
}
.face-add:hover { border-color: var(--accent); color: var(--accent); }
.face-count { font-size: 10.5px; color: var(--text-faint); letter-spacing: .3px; }

/* ============ Video card ============ */
.video-card {
  background: var(--bg-card, #1f1f1f); border: 1px solid var(--line);
  border-radius: 14px; overflow: hidden; margin-top: 6px; max-width: 520px;
}
.video-card video { width: 100%; display: block; max-height: 60vh; background: #000; }
.video-card .cap { padding: 8px 13px; font-size: 12.5px; color: var(--text-dim); border-top: 1px solid var(--line); }

#composer {
  display: flex; align-items: flex-end; gap: 6px;
  background: var(--bg-input); border: 1px solid var(--line);
  border-radius: 26px; padding: 8px 8px 8px 10px;
  box-shadow: var(--shadow); transition: border-color .15s;
}
#composer:focus-within { border-color: #565656; }
#input {
  flex: 1; background: transparent; border: none; outline: none; resize: none;
  color: var(--text); font-size: 15px; font-family: inherit;
  line-height: 1.55; max-height: 220px; padding: 9px 4px;
}
#input::placeholder { color: var(--text-faint); }

.send {
  width: 38px; height: 38px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; transition: .15s;
}
.send:hover { background: #0d8f6f; }
.send:disabled { background: #3d3d3d; color: #777; cursor: not-allowed; }
.send.stop { background: #d9d9d9; color: #111; }

.hint { text-align: center; font-size: 11.5px; color: var(--text-faint); padding-top: 9px; }

/* ============ Modal (ทุก popup เด้งกลางจอ) ============ */
#modal, #projects-modal, #usage-modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .62);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  backdrop-filter: blur(3px); animation: fade .15s ease;
  padding: 20px; box-sizing: border-box;
}
.modal-card {
  width: min(640px, calc(100vw - 32px)); max-height: 88vh;
  background: #1e1e1e; border: 1px solid var(--line);
  border-radius: 18px; display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 6px;
}
.modal-head h2 { margin: 0; font-size: 19px; }
.modal-body { padding: 12px 22px 4px; overflow-y: auto; }
.modal-foot { padding: 14px 22px 20px; display: flex; justify-content: flex-end; gap: 10px; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 13.5px; color: var(--text-dim); margin-bottom: 7px; }
.field small { display: block; color: var(--text-faint); font-size: 11.5px; margin-top: 6px; }
.field input[type="text"], .field input[type="password"], .field textarea, .field input[list] {
  width: 100%; background: var(--bg-input); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; color: var(--text);
  font-size: 14px; font-family: inherit; outline: none; resize: vertical;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.field input[type="range"] { width: 100%; accent-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

.ghost-btn {
  background: transparent; border: 1px solid var(--line); color: var(--text-dim);
  padding: 8px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 16px;
}
.ghost-btn:hover { background: var(--bg-soft); color: var(--text); }
.ghost-btn:disabled { opacity: .5; cursor: wait; }

.primary {
  background: var(--accent); border: none; color: #fff;
  padding: 10px 22px; border-radius: 10px; font-size: 14.5px; font-weight: 600;
}
.primary:hover { background: #0d8f6f; }
.settings-msg { font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.settings-msg.ok { color: #7fd9bd; }
.settings-msg.err { color: #ff9b9b; }

/* ============ Auth ============ */
#auth-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: radial-gradient(1200px 600px at 50% -10%, #2b2b2b, #131313);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.auth-card {
  width: min(400px, 100%); background: #1c1c1c;
  border: 1px solid var(--line); border-radius: 20px;
  padding: 32px 30px 26px; box-shadow: var(--shadow);
  animation: fade .25s ease;
}
.auth-logo { font-size: 36px; color: var(--accent); text-align: center; }
.auth-card h1 { font-size: 22px; margin: 10px 0 4px; text-align: center; }
.auth-card #auth-sub { font-size: 13px; color: var(--text-dim); text-align: center; margin: 0 0 6px; }
.auth-submit { width: 100%; margin-top: 4px; }

.auth-tabs {
  display: flex; background: var(--bg-input); border-radius: 11px;
  padding: 4px; gap: 4px; margin: 16px 0 4px;
}
.auth-tab {
  flex: 1; border: none; background: transparent; color: var(--text-dim);
  padding: 9px; border-radius: 8px; font-size: 14px; transition: .15s;
}
.auth-tab.active { background: var(--accent); color: #fff; font-weight: 600; }
.auth-tab:not(.active):hover { background: var(--bg-hover); color: var(--text); }

/* ============ Topbar: project + model ============ */
.topbar-right { margin-left: auto; display: flex; gap: 8px; align-items: center; min-width: 0; }
.project-select, #model-select {
  background: var(--bg-input); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 7px 10px; font-size: 13px; max-width: 190px; outline: none;
}
.project-select:focus, #model-select:focus { border-color: var(--accent); }
.project-select.has-project { border-color: var(--accent); color: #8fe0c6; }

#project-banner {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: #8fe0c6; background: #16261f;
  border: 1px solid #2c4a3f; border-bottom: none;
  padding: 8px 14px; border-radius: 12px 12px 0 0;
}
#project-banner .pb-path {
  font-family: ui-monospace, Consolas, monospace; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: left;
}
#project-banner button {
  margin-left: auto; background: transparent; border: 1px solid #2c4a3f;
  color: #8fe0c6; font-size: 11.5px; padding: 3px 9px; border-radius: 7px; flex-shrink: 0;
}
#project-banner button:hover { background: #1e372e; }

.hint-text { font-size: 13px; color: var(--text-dim); line-height: 1.6; margin: 0 0 6px; }

.settings-note {
  font-size: 12.8px; line-height: 1.6; color: var(--text-dim);
  background: var(--bg-input); border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  padding: 10px 13px; border-radius: 10px; margin-bottom: 18px;
}
.settings-note b { color: var(--text); }

.path-input-row { display: flex; gap: 8px; }
.path-input-row input { flex: 1; min-width: 0; }

/* ============ Usage popup ============ */
.usage-card { width: min(560px, calc(100vw - 32px)); }
.usage-total { text-align: center; padding: 8px 0 4px; }
.usage-usd { font-size: 42px; font-weight: 700; color: var(--accent); letter-spacing: -1px; }
.usage-sub { font-size: 13px; color: var(--text-faint); margin-top: 2px; }
.usage-stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 10px; margin: 16px 0 4px;
}
.usage-stat {
  background: var(--bg-input); border: 1px solid var(--line);
  border-radius: 11px; padding: 11px 12px; text-align: center;
}
.usage-stat .v { font-size: 17px; font-weight: 650; }
.usage-stat .k { font-size: 11.5px; color: var(--text-faint); margin-top: 3px; }

.usage-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.usage-table th, .usage-table td { padding: 8px 9px; border-bottom: 1px solid var(--line); text-align: left; }
.usage-table th { color: var(--text-faint); font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; }
.usage-table td.num, .usage-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.usage-table td.mdl { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usage-table .cost { color: var(--accent); font-weight: 650; }
.usage-empty { text-align: center; color: var(--text-faint); padding: 26px 10px; font-size: 14px; }

.danger-btn {
  background: #3a1f1f; border: 1px solid #6b3a3a; color: #ff9b9b;
  padding: 9px 16px; border-radius: 10px; font-size: 13.5px;
}
.danger-btn:hover { background: #4a2626; color: #ffbcbc; }
.modal-foot.spread { justify-content: space-between; }

/* ============ Auth ============ */
#auth-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: radial-gradient(1200px 600px at 50% -10%, #2b2b2b, #131313);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.auth-card {
  width: min(400px, 100%); background: #1c1c1c;
  border: 1px solid var(--line); border-radius: 20px;
  padding: 32px 30px 26px; box-shadow: var(--shadow);
  animation: fade .25s ease;
}
.auth-logo { font-size: 36px; color: var(--accent); text-align: center; }
.auth-card h1 { font-size: 22px; margin: 10px 0 4px; text-align: center; }
.auth-card #auth-sub { font-size: 13px; color: var(--text-dim); text-align: center; margin: 0 0 6px; }
.auth-submit { width: 100%; margin-top: 4px; }
.auth-switch { text-align: center; font-size: 13px; color: var(--text-faint); margin-top: 16px; }
.auth-switch a { color: var(--accent); text-decoration: none; }

/* ============ User bar ============ */
.user-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 11px; background: var(--bg-hover);
  border: 1px solid var(--line);
}
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent); color: #06281f;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; text-transform: uppercase;
}
.user-meta { flex: 1; min-width: 0; }
.user-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-id { font-size: 11.5px; color: var(--text-faint); }

/* ============ Settings extras ============ */
.section-title {
  font-size: 12.5px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-faint); margin: 22px 0 10px;
  padding-top: 14px; border-top: 1px solid var(--line);
}
.check-field { display: flex; gap: 9px; align-items: flex-start; margin-bottom: 6px; font-size: 13.5px; color: var(--text-dim); cursor: pointer; }
.check-field input { margin-top: 3px; accent-color: var(--accent); width: 16px; height: 16px; }
.ghost-btn.sm, .primary.sm { padding: 6px 12px; font-size: 12.5px; margin-bottom: 0; border-radius: 8px; }

.users-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.user-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-input); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px; font-size: 13.5px;
}
.user-row .tag {
  font-size: 11px; background: #26463d; color: #7fd9bd;
  padding: 2px 8px; border-radius: 99px;
}
.user-row .tag.admin { background: #463a26; color: #e8c27f; }
.user-row .grow { flex: 1; }
.user-row button {
  background: transparent; border: 1px solid var(--line); color: var(--text-faint);
  font-size: 12px; padding: 4px 10px; border-radius: 7px;
}
.user-row button:hover { color: #ff9b9b; border-color: #6b3a3a; }

/* ============ Files panel ============ */
.files-card { width: min(860px, calc(100vw - 32px)); height: min(78vh, 720px); }
.files-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 4px 22px 8px;
}
.crumbs { flex: 1; font-size: 13px; color: var(--text-dim); font-family: ui-monospace, Consolas, monospace; min-width: 150px; }
.crumbs button {
  background: none; border: none; color: var(--accent); font-size: 13px;
  font-family: inherit; padding: 0 3px; cursor: pointer;
}
.crumbs button:hover { text-decoration: underline; }
.files-actions { display: flex; gap: 8px; }
.files-root-path {
  padding: 0 22px 10px; font-size: 11.5px; color: var(--text-faint);
  font-family: ui-monospace, Consolas, monospace;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.files-body { flex: 1; overflow: auto; padding-top: 4px; }

.file-row {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: 9px; cursor: pointer;
  font-size: 14px; color: var(--text-dim);
}
.file-row:hover { background: var(--bg-hover); color: var(--text); }
.file-row .ic { width: 20px; text-align: center; flex-shrink: 0; }
.file-row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .sz { font-size: 12px; color: var(--text-faint); flex-shrink: 0; }
.file-row .act {
  opacity: 0; background: transparent; border: 1px solid var(--line);
  color: var(--text-faint); font-size: 11.5px; padding: 3px 9px; border-radius: 7px;
}
.file-row:hover .act { opacity: 1; }
.file-row .act:hover { color: #ff9b9b; border-color: #6b3a3a; }
.files-empty { color: var(--text-faint); text-align: center; padding: 40px 10px; font-size: 14px; }

#file-editor { display: flex; flex-direction: column; height: 100%; gap: 10px; }
.editor-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.editor-head span {
  font-family: ui-monospace, Consolas, monospace; font-size: 13.5px;
  color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.editor-head div { display: flex; gap: 8px; flex-shrink: 0; }
#editor-text {
  flex: 1; min-height: 320px; width: 100%; resize: vertical;
  background: #0d0d0d; border: 1px solid var(--line); border-radius: 12px;
  color: var(--text); font-family: ui-monospace, Consolas, monospace;
  font-size: 13.5px; line-height: 1.6; padding: 14px; outline: none;
}
#editor-text:focus { border-color: var(--accent); }

/* ============ Agent tool chip ============ */
.tool-chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: #16261f; border: 1px solid #2c4a3f; color: #8fe0c6;
  font-size: 12.5px; padding: 5px 11px; border-radius: 999px;
  margin: 3px 6px 3px 0; font-family: ui-monospace, Consolas, monospace;
}
.tool-chip.busy { color: #e8c27f; background: #26211a; border-color: #4a4131; }
.tool-chip.fail { color: #ff9b9b; background: #2a1b1b; border-color: #5a3535; }

/* ============ Toast ============ */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #000; color: #fff; border: 1px solid var(--line);
  padding: 11px 18px; border-radius: 11px; font-size: 13.5px;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
  z-index: 99; max-width: 90vw; box-shadow: var(--shadow);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }

/* ============ Scrollbar ============ */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #4a4a4a; border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #5c5c5c; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ============ Mobile ============ */
@media (max-width: 820px) {
  #sidebar { position: absolute; z-index: 30; height: 100%; box-shadow: var(--shadow); }
  #sidebar.collapsed { margin-left: -256px; }
  .model-pick select { max-width: 150px; }
  #empty-state { padding-top: 6vh; }
  #empty-state h1 { font-size: 24px; }
}

/* ============ Auth welcome (หัวหน้าหน้า Login) ============ */
#auth-overlay { flex-direction: column; gap: 22px; }
.auth-welcome { text-align: center; animation: fade .25s ease; }
.auth-welcome .aw-line { font-size: 15.5px; color: var(--text-dim); letter-spacing: .2px; }
.auth-welcome .aw-brand {
  font-size: 38px; font-weight: 700; color: var(--text);
  letter-spacing: -.5px; margin-top: 6px;
}

/* ============ PDF attachment chips ============ */
.thumb.doc {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-hover); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 26px 10px 12px;
  font-size: 13px; max-width: 230px;
}
.thumb.doc .doc-name {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 150px; color: var(--text);
}
.doc-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--bg-hover); border: 1px solid var(--line);
  border-radius: 10px; padding: 5px 11px; font-size: 13px;
  max-width: 260px; overflow: hidden;
}
.doc-chip i { font-style: normal; color: var(--text-faint); font-size: 11.5px; }
.msg.user .doc-chip { margin-left: auto; }


/* ============ App version badge (��������ҧ) ============ */
#version-badge {
  position: fixed;
  right: 12px;
  bottom: 10px;
  z-index: 30;
  font-size: 11px;
  font-family: ui-monospace, Consolas, monospace;
  color: var(--text-faint);
  background: rgba(20, 20, 20, .72);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  pointer-events: none;
  user-select: none;
  letter-spacing: .3px;
  opacity: .85;
}

/* ============ ʶҹ���������������� banner ============ */
#project-banner .pb-state {
  font-size: 11.5px;
  padding: 2px 9px;
  border-radius: 999px;
  flex-shrink: 0;
  border: 1px solid transparent;
  white-space: nowrap;
}
#project-banner .pb-state.on { color: #7ee7bd; background: #143527; border-color: #2c4a3f; }
#project-banner .pb-state.wait { color: #ffd479; background: #3a2f14; border-color: #5b4a1f; }
#project-banner .pb-state.off { color: #ff9d9d; background: #3a1a1a; border-color: #5b2626; }
#project-banner #pb-connect { margin-left: 0; }
#project-banner #pb-clear { margin-left: auto; }

#pj-root[readonly] { opacity: .75; cursor: default; }

/* กัน badge ทับข้อความ hint ตรงกลางล่างจอ (คอมโพเซอร์เต็มความกว้าง) */
@media (max-width: 820px) {
  .hint { padding-right: 74px; padding-left: 74px; }
}
