/* ============================================================
   JULE Room · web2 — OpenRouter-style shell (light theme)
   tokens → base → nav → sidebar → main → cards → composer → modal
   ============================================================ */

:root {
  --bg: #ffffff;
  --bg-soft: #f7f7f9;
  --bg-sunk: #f2f2f5;
  --surface: #ffffff;
  --line: #e6e6ea;
  --line-strong: #d4d4dc;
  --ink: #14161c;
  --ink-2: #4b5563;
  --ink-3: #8a90a0;
  --accent: #7c3aed;
  --accent-2: #8b5cf6;
  --accent-soft: #f1ecfe;
  --ok: #16a34a;
  --ok-soft: #e8f7ee;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-pill: 999px;

  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;

  --font: "Inter", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-md: 0 10px 30px rgba(16, 24, 40, .10);
  --shadow-lg: 0 24px 60px rgba(16, 24, 40, .18);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1, h2, p { margin: 0; }
button { font: inherit; }
kbd {
  font-family: var(--font);
  font-size: 11px;
  color: var(--ink-3);
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 6px;
}
.dim { color: var(--ink-3); }
.build { font-style: normal; font-size: 10px; color: var(--ink-3); background: var(--bg-sunk); border-radius: 4px; padding: 0 5px; margin-left: 4px; vertical-align: middle; }
#errbar {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%);
  z-index: 99; max-width: 90vw; padding: 10px 16px;
  background: #7f1d1d; color: #fee2e2; border-radius: 10px;
  font-size: 13px; box-shadow: var(--shadow-lg);
}

/* ---------------- nav ---------------- */
.nav {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  height: 56px;
  padding: 0 var(--s-4);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 30;
}
.nav-left { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.logo {
  display: grid; place-items: center;
  width: 28px; height: 28px;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: #fff; font-size: 15px;
}
.logo-text { font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.nav-search {
  display: flex; align-items: center; gap: 6px;
  margin-left: var(--s-2);
  padding: 0 10px;
  height: 34px; width: 260px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg-soft);
}
.nav-search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font: inherit; color: var(--ink); }
.nav-search .mag { color: var(--ink-3); }

.nav-menu { display: flex; align-items: center; gap: var(--s-1); margin-left: var(--s-2); }
.nav-item {
  border: 0; background: transparent; color: var(--ink-2);
  padding: 7px 12px; border-radius: var(--r-md); cursor: pointer;
}
.nav-item:hover { background: var(--bg-soft); color: var(--ink); }
.nav-item.is-active { background: var(--bg-sunk); color: var(--ink); font-weight: 600; }
.nav-item.is-muted { color: var(--ink-3); cursor: default; }

.nav-right { margin-left: auto; display: flex; align-items: center; gap: var(--s-3); }
.ws-chip {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); background: var(--bg);
  padding: 5px 10px 5px 6px; border-radius: var(--r-pill); cursor: pointer;
}
.ws-chip:hover { background: var(--bg-soft); }
.ws-dot, .ws-badge {
  display: grid; place-items: center;
  width: 22px; height: 22px; border-radius: 7px;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 12px;
}
.nav-avatar {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 50%;
  background: #111827; color: #fff; font-weight: 700; font-size: 13px;
}

/* ---------------- shell ---------------- */
.shell { display: grid; grid-template-columns: 272px minmax(0, 1fr); height: calc(100vh - 56px); }

/* ---------------- rooms sidebar ---------------- */
.rooms {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--bg);
  min-height: 0;
}
.rooms-head { display: flex; align-items: center; justify-content: space-between; padding: var(--s-4) var(--s-4) var(--s-2); }
.rooms-title { font-weight: 700; }
.icon-btn {
  border: 0; background: transparent; color: var(--ink-3);
  width: 30px; height: 30px; border-radius: var(--r-sm); cursor: pointer;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--ink); }

.new-chat {
  display: flex; align-items: center; gap: var(--s-2);
  margin: 0 var(--s-4) var(--s-3);
  padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--bg); color: var(--ink); cursor: pointer;
}
.new-chat:hover { background: var(--bg-soft); }
.new-chat .pen { color: var(--accent); }
.new-chat kbd { margin-left: auto; }

.rooms-search {
  display: flex; align-items: center; gap: 6px;
  margin: 0 var(--s-4) var(--s-2);
  padding: 0 10px; height: 32px;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg-soft);
}
.rooms-search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font: inherit; color: var(--ink); }
.rooms-search .mag { color: var(--ink-3); }

.rooms-meta { display: flex; align-items: center; justify-content: space-between; padding: var(--s-2) var(--s-4); color: var(--ink-3); font-size: 12px; }
.link-btn { border: 0; background: transparent; color: var(--ink-3); cursor: pointer; }
.link-btn:hover { color: var(--accent); }

.rooms-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 0 var(--s-2) var(--s-3); }
.rooms-group { padding: var(--s-2) var(--s-3) 4px; color: var(--ink-3); font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.room-row { display: flex; align-items: center; gap: var(--s-1); border-radius: var(--r-md); }
.room-item {
  flex: 1 1 auto; min-width: 0; text-align: left;
  border: 0; background: transparent; color: var(--ink);
  padding: 9px 11px; border-radius: var(--r-md); cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.room-item:hover { background: var(--bg-soft); }
.room-item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.room-del {
  flex: 0 0 28px; width: 28px; height: 28px;
  border: 0; background: transparent; color: var(--ink-3);
  border-radius: var(--r-sm); cursor: pointer; opacity: 0;
}
.room-row:hover .room-del { opacity: 1; }
.room-del:hover { background: #fdecec; color: #dc2626; }
.room-rename {
  flex: 0 0 28px; width: 28px; height: 28px;
  border: 0; background: transparent; color: var(--ink-3);
  border-radius: var(--r-sm); cursor: pointer; opacity: 0;
}
.room-row:hover .room-rename { opacity: 1; }
.room-rename:hover { background: var(--bg-soft); color: var(--ink); }

.rooms-foot {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-top: 1px solid var(--line);
}

/* ---- collapsible sidebar: icon rail (แบบ A) ---- */
.shell.rail { grid-template-columns: 60px minmax(0, 1fr); }
.shell.rail .rooms { align-items: center; }
.shell.rail .rooms-head { justify-content: center; width: 100%; padding: var(--s-3) 0; }
.shell.rail .rooms-title { display: none; }
.shell.rail .new-chat { justify-content: center; width: 40px; height: 40px; margin: 0 0 var(--s-2); padding: 0; }
.shell.rail .new-chat kbd,
.shell.rail .new-chat span:not(.pen) { display: none; }
.shell.rail .rooms-search,
.shell.rail .rooms-meta,
.shell.rail .rooms-list,
.shell.rail .rooms-foot { display: none; }
.ws-copy { display: flex; flex-direction: column; line-height: 1.2; flex: 1; }
.ws-copy span { color: var(--ink-3); font-size: 12px; }

/* ---------------- main ---------------- */
.main { display: flex; flex-direction: column; min-height: 0; }
.main-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-3) var(--s-5);
  border-bottom: 1px solid var(--line);
}
.btn-add {
  display: inline-flex; align-items: center; gap: var(--s-2);
  border: 1px solid var(--line); background: var(--bg);
  padding: 8px 14px; border-radius: var(--r-md); cursor: pointer; font-weight: 600;
}
.btn-add:hover { background: var(--bg-soft); }
.view-select {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 7px 12px; color: var(--ink-2); cursor: default;
}

.stage { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }

/* ---------------- empty state: categories ---------------- */
.cats { flex: 1 1 auto; display: flex; flex-direction: column; justify-content: center; gap: var(--s-5); padding: var(--s-6) var(--s-5); }
.cats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); max-width: 720px; width: 100%; margin: 0 auto; }
.cat-card {
  display: flex; flex-direction: column; gap: var(--s-4);
  min-height: 132px; padding: var(--s-4);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface); cursor: pointer; text-align: left;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s ease, box-shadow .15s ease, transform .1s ease;
}
.cat-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.cat-title { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.cat-count { font-size: 11px; font-weight: 700; color: var(--ink-2); background: var(--bg-sunk); border-radius: var(--r-pill); padding: 1px 8px; }
.cat-sub { color: var(--ink-3); font-size: 12.5px; }
.cat-card.is-empty { cursor: default; opacity: .6; }
.cat-card.is-empty:hover { box-shadow: var(--shadow-sm); transform: none; border-color: var(--line); }
.cat-icons { margin-top: auto; display: flex; }
.cat-ico {
  display: grid; place-items: center;
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--surface); margin-left: -8px;
  color: #fff; font-size: 13px;
}
.cat-ico:first-child { margin-left: 0; }
.cat-more {
  display: grid; place-items: center;
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--surface); margin-left: -8px;
  background: var(--bg-sunk); color: var(--ink-2); font-size: 11px; font-weight: 700;
}

.examples { display: flex; flex-wrap: wrap; gap: var(--s-3); max-width: 720px; width: 100%; margin: 0 auto; }
.example {
  flex: 1 1 150px; min-width: 150px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--surface); padding: 10px 12px; cursor: pointer; text-align: left;
  box-shadow: var(--shadow-sm);
}
.example:hover { border-color: var(--line-strong); }
.example strong { display: block; font-size: 13px; }
.example span { color: var(--ink-3); font-size: 12px; }

/* ---------------- thread ---------------- */
.thread { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.thread-models {
  display: flex; flex-wrap: wrap; gap: var(--s-2);
  padding: var(--s-3) var(--s-5);
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
}
.model-pill {
  display: inline-flex; align-items: center; gap: var(--s-2);
  padding: 5px 10px; border-radius: var(--r-pill);
  border: 1px solid var(--line); background: var(--surface); font-size: 13px;
  cursor: pointer; user-select: none;
}
.model-pill:hover { border-color: var(--line-strong); }
.model-pill b { font-weight: 600; }
.model-pill .dot { width: 8px; height: 8px; border-radius: 50%; }
.model-pill .api { color: var(--ink-3); font-size: 12px; }
.model-pill.is-paused { opacity: .55; background: var(--bg-soft); border-style: dashed; }
.model-pill.is-paused .dot { opacity: .4; }
.model-pill .pill-state { font-size: 12px; color: var(--ink-2); }
.pill-x {
  display: grid; place-items: center; width: 18px; height: 18px;
  border: 0; border-radius: 50%; background: transparent; color: var(--ink-3);
  font-size: 14px; line-height: 1; cursor: pointer; padding: 0;
}
.pill-x:hover { background: #fdecec; color: #dc2626; }
.thread-models .pills-count { margin-left: auto; color: var(--ink-3); font-size: 12px; white-space: nowrap; }
.thread-models .pills-empty { color: var(--ink-3); font-size: 13px; }

.messages { flex: 1 1 auto; min-height: 320px; overflow-y: auto; padding: var(--s-5); display: flex; flex-direction: column; gap: var(--s-4); }
.empty { margin: auto; display: flex; flex-direction: column; align-items: center; gap: var(--s-1); color: var(--ink-3); text-align: center; }
.empty strong { color: var(--ink-2); }

/* ---------------- identities catalog (view) ---------------- */
.catalog { flex: 1 1 auto; overflow-y: auto; padding: var(--s-5) var(--s-5) var(--s-6); }
.catalog-head { max-width: 860px; margin: 0 auto var(--s-4); }
.catalog-head h2 { font-size: 18px; }
.catalog-head p { color: var(--ink-3); font-size: 13px; margin-top: 4px; }
.catalog-grid { max-width: 860px; margin: 0 auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--s-4); }
.catalog-card { display: flex; flex-direction: column; gap: var(--s-3); padding: var(--s-4); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-sm); }
.catalog-top { display: flex; align-items: center; gap: var(--s-3); }
.catalog-ico { display: grid; place-items: center; width: 34px; height: 34px; flex: 0 0 34px; border-radius: var(--r-sm); color: #fff; font-size: 16px; }
.catalog-name { font-weight: 700; }
.catalog-role { color: var(--ink-2); font-size: 12px; }
.catalog-desc { color: var(--ink-2); font-size: 13px; }
.catalog-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.catalog-tag { font-size: 11px; color: var(--ink-2); background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--r-pill); padding: 2px 8px; }
.catalog-tag.is-ready { color: var(--ok); background: var(--ok-soft); border-color: #bfe6cd; }
.catalog-add { align-self: flex-start; border: 1px solid var(--line-strong); background: var(--bg); border-radius: var(--r-md); padding: 6px 12px; cursor: pointer; font-weight: 600; font-size: 12px; }
.catalog-add:hover { background: var(--bg-soft); }
.catalog-tools { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; margin-top: var(--s-3); }
.catalog-search { display: flex; align-items: center; gap: 6px; padding: 0 10px; height: 34px; width: 240px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg-soft); }
.catalog-search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font: inherit; color: var(--ink); }
.catalog-search .mag { color: var(--ink-3); }
.catalog-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip { border: 1px solid var(--line); background: var(--bg); color: var(--ink-2); border-radius: var(--r-pill); padding: 4px 12px; cursor: pointer; font-size: 12px; }
.tag-chip:hover { background: var(--bg-soft); }
.tag-chip.is-on { background: var(--accent-soft); border-color: #ddd0fb; color: var(--accent); font-weight: 600; }
.catalog-empty { grid-column: 1 / -1; color: var(--ink-3); font-size: 13px; padding: var(--s-4); text-align: center; }

/* ---------------- status (usage overview) ---------------- */
.status { flex: 1 1 auto; overflow-y: auto; padding: var(--s-5) var(--s-5) var(--s-6); }
.status-head { max-width: 860px; margin: 0 auto var(--s-4); }
.status-head h2 { font-size: 18px; }
.status-head p { color: var(--ink-3); font-size: 13px; margin-top: 4px; }
.status-tiles { max-width: 860px; margin: 0 auto var(--s-5); display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--s-3); }
.status-tile { display: flex; flex-direction: column; gap: 4px; padding: var(--s-4); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-sm); }
.status-tile .st-label { color: var(--ink-3); font-size: 12px; }
.status-tile .st-value { font-size: 18px; font-variant-numeric: tabular-nums; }
.status-cols { max-width: 860px; margin: 0 auto; display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: var(--s-5); }
.status-block h3 { font-size: 14px; margin-bottom: var(--s-3); }
.status-row { margin-bottom: var(--s-3); }
.status-row .sr-top { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-2); font-size: 13px; }
.status-row .sr-name { font-weight: 600; }
.status-row .sr-val { color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.status-row .sr-bar { height: 8px; margin-top: 6px; border-radius: var(--r-pill); background: var(--bg-sunk); overflow: hidden; }
.status-row .sr-bar i { display: block; height: 100%; background: var(--accent-2); border-radius: var(--r-pill); }
.status-empty { color: var(--ink-3); font-size: 13px; padding: var(--s-3) 0; }
.status-chart { max-width: 860px; margin: 0 auto var(--s-5); padding: var(--s-4); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-sm); }
.status-chart .daychart { width: 100%; height: auto; display: block; }
.chart-legend { display: flex; gap: var(--s-4); margin-top: var(--s-3); color: var(--ink-3); font-size: 12px; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }
.status-note { max-width: 860px; margin: 0 auto var(--s-4); color: var(--ink-3); font-size: 12px; }

/* ปุ่มเลือกช่วงเวลา (สถานะการใช้งาน) — โทนเดียวกับหน้า */
.status-range { max-width: 860px; margin: 0 auto var(--s-4); display: flex; gap: 8px; flex-wrap: wrap; }
.status-range-btn { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-3); font-size: 13px; cursor: pointer; }
.status-range-btn:hover { background: var(--bg-soft); color: var(--ink); }
.status-range-btn.is-active { background: var(--bg-sunk); color: var(--ink); font-weight: 600; border-color: #8b5cf6; }

/* ปฏิทินเลือกช่วงเอง (กำหนดเอง 📅) — card โทนเดิม */
.status-datepicker { max-width: 860px; margin: 0 auto var(--s-4); padding: var(--s-4); border: 1px solid var(--line);
  border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-sm); }
.status-datepicker[hidden] { display: none; }
.status-datepicker .sd-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.status-datepicker .sd-row label { color: var(--ink-3); font-size: 12px; min-width: 48px; }
.status-datepicker input[type="date"] { background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--r-md, 8px); color: var(--ink); padding: 5px 8px; font-size: 13px; }
.status-datepicker .sd-err { color: #f87171; font-size: 12px; margin-bottom: 8px; }
.status-datepicker .sd-actions { display: flex; gap: 8px; }
.status-datepicker .sd-actions #sd-apply { background: #8b5cf6; border: 1px solid #8b5cf6; color: #fff;
  border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer; }
.status-datepicker .sd-actions #sd-cancel { background: transparent; border: 1px solid var(--line);
  color: var(--ink-3); border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer; }
.status-datepicker .sd-actions button:hover { filter: brightness(1.1); }

.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: min(760px, 90%); padding: var(--s-3) var(--s-4); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--bg-soft); }
.msg.user .bubble { background: var(--accent-soft); border-color: #ddd0fb; }
.msg.bot .bubble { background: var(--surface); }
.bubble-head { display: flex; align-items: baseline; gap: var(--s-2); margin-bottom: 4px; }
.bubble-sender { font-weight: 700; font-size: 13px; }
.bubble-time { color: var(--ink-3); font-size: 11px; }
.bubble-text { white-space: pre-wrap; overflow-wrap: anywhere; }

.typing { display: flex; gap: 4px; padding: 3px 1px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: .95; } }

/* ---------------- composer ---------------- */
.composer-area { padding: var(--s-3) var(--s-5) var(--s-4); }
.composer {
  max-width: 860px; margin: 0 auto;
  border: 1px solid var(--line-strong); border-radius: var(--r-lg);
  background: var(--surface); box-shadow: var(--shadow-sm);
  padding: var(--s-3) var(--s-3) var(--s-2);
}
.composer textarea {
  width: 100%; min-height: 40px; max-height: 180px; resize: none;
  border: 0; outline: none; background: transparent; color: var(--ink); font: inherit; font-size: 15px;
}
.composer-tools { display: flex; align-items: center; gap: var(--s-2); padding-top: var(--s-2); }
.ctool {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--bg); color: var(--ink-2); cursor: pointer;
}
.ctool:hover { background: var(--bg-soft); }
.ctool:disabled { opacity: .5; cursor: not-allowed; }
.ctools-spacer { flex: 1; }
.note { color: var(--ink-3); font-size: 12px; }
.send {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: var(--accent); color: #fff; font-size: 16px; cursor: pointer;
}
.send:disabled { background: #cbc7e6; cursor: not-allowed; }
.disclaimer { max-width: 860px; margin: 10px auto 0; text-align: center; color: var(--ink-3); font-size: 11px; }

/* ---------------- modal (picker) ---------------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(16, 24, 40, .34); }
.modal-panel {
  position: relative; width: min(560px, calc(100vw - 32px));
  max-height: min(680px, 86vh); display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); overflow: hidden;
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-4); padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 16px; }
.modal-head p { color: var(--ink-3); font-size: 12px; }
.modal-body { padding: var(--s-3) var(--s-4); min-height: 132px; overflow-y: auto; display: flex; flex-direction: column; gap: var(--s-3); }
.modal-empty { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--ink-3); text-align: center; }
.modal-empty strong { color: var(--ink-2); }
.picker-group { color: var(--ink-3); font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; padding: var(--s-2) var(--s-1) 0; }

.identity-row {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3); border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--surface); cursor: pointer;
}
.identity-row:hover { border-color: var(--line-strong); background: var(--bg-soft); }
.identity-row.is-selected { border-color: var(--accent); background: var(--accent-soft); }
.identity-block { display: flex; flex-direction: column; }
.identity-row.is-selected .id-glyph { box-shadow: 0 0 0 2px rgba(124, 58, 237, .35); }

/* model chip (locked default, scroll to change) */
.model-chip {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 8px; padding: 5px 10px;
  border: 1px solid var(--line-strong); border-radius: var(--r-pill);
  background: var(--bg-soft); color: var(--ink); font-size: 12px;
  cursor: pointer; max-width: 100%;
}
.model-chip:hover { border-color: var(--accent); color: var(--accent); }
.model-chip.is-locked { background: #eef7f0; border-color: #cfe8d8; color: #14532d; }
.model-chip .mc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 190px; }
.model-chip .mc-caret { color: var(--ink-3); }

/* model panel — vertical list, ~10 rows visible */
.model-panel { margin: 6px 0 2px 0; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); box-shadow: var(--shadow-sm); }
.mp-head { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--line); }
.mp-search { flex: 1; display: flex; align-items: center; gap: 6px; padding: 0 8px; height: 32px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--bg-soft); }
.mp-search .mag { color: var(--ink-3); }
.mp-search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font: inherit; font-size: 13px; color: var(--ink); }
.mp-count { color: var(--ink-3); font-size: 11px; white-space: nowrap; }
.mp-filter, .mp-reset { display: grid; place-items: center; height: 32px; padding: 0 9px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--bg); color: var(--ink-2); cursor: pointer; font-size: 12px; }
.mp-filter:hover, .mp-reset:hover { background: var(--bg-soft); }
.mp-filter.is-on { background: var(--accent-soft); border-color: #ddd0fb; color: var(--accent); }

.mp-list { max-height: 466px; overflow-y: auto; padding: 4px 0; }
.mp-group { padding: 8px 12px 4px; color: var(--ink-3); font-size: 11px; font-weight: 600; letter-spacing: .03em; text-transform: capitalize; position: sticky; top: 0; background: var(--surface); }
.mp-row { display: flex; align-items: center; gap: var(--s-2); padding: 8px 12px; cursor: pointer; }
.mp-row:hover { background: var(--bg-soft); }
.mp-row.is-current { background: var(--accent-soft); }
.mp-ico { width: 20px; text-align: center; font-size: 14px; }
.mp-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mp-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-sub { color: var(--ink-3); font-size: 11px; }
.mp-lock { font-size: 12px; }
.mp-cur { color: var(--accent); font-weight: 700; }
.mp-star { border: 0; background: transparent; color: var(--ink-3); font-size: 15px; cursor: pointer; padding: 0 4px; }
.mp-star:hover, .mp-star.is-on { color: #f59e0b; }
.mp-more { display: block; width: calc(100% - 24px); margin: 6px 12px 8px; padding: 7px; border: 1px dashed var(--line-strong); border-radius: var(--r-sm); background: transparent; color: var(--ink-2); cursor: pointer; font-size: 12px; }
.mp-more:hover { background: var(--bg-soft); }
.mp-empty { padding: 16px; text-align: center; color: var(--ink-3); font-size: 13px; }

.id-glyph { display: grid; place-items: center; width: 38px; height: 38px; border-radius: var(--r-md); color: #fff; font-size: 17px; flex: 0 0 38px; }
.id-copy { flex: 1; min-width: 0; }
.id-copy strong { display: block; }
.id-copy span { color: var(--ink-3); font-size: 12px; }
.id-api { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--ink-3); }
.id-api select {
  border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--bg);
  padding: 6px 8px; font: inherit; font-size: 12px; color: var(--ink); max-width: 190px;
}
.id-check { color: var(--accent); font-size: 18px; width: 20px; text-align: center; }

.modal-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); padding: var(--s-3) var(--s-5); border-top: 1px solid var(--line); background: var(--bg-soft); }
.picker-count { color: var(--ink-3); font-size: 12px; }
.modal-actions { display: flex; gap: var(--s-2); }

.btn { border: 1px solid transparent; border-radius: var(--r-md); padding: 9px 16px; font-weight: 600; cursor: pointer; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #6d28d9; }
.btn-primary:disabled { background: #cbc7e6; cursor: not-allowed; }
.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--ink); }
.btn-ghost:hover { background: var(--bg-soft); }
.btn-danger { background: #dc2626; color: #fff; border-color: #dc2626; }
.btn-danger:hover { background: #b91c1c; color: #fff; }
.modal-head p { white-space: pre-line; }

/* ---------------- responsive ---------------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; height: auto; min-height: calc(100vh - 56px); }
  .rooms { display: none; }
  .cats-grid { grid-template-columns: 1fr; }
  .nav-menu { display: none; }
  .nav-search { width: 160px; }
}

/* ---- attachments (web2) ---- */
.attach-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 8px; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 6px 4px 10px; border: 1px solid var(--line);
  border-radius: var(--r-pill); background: var(--bg-soft);
  font-size: 12px; color: var(--ink-2); max-width: 100%;
}
.attach-chip .ac-name { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip .ac-x {
  border: 0; background: transparent; cursor: pointer; color: var(--ink-3);
  font-size: 14px; line-height: 1; padding: 0 2px;
}
.attach-chip .ac-x:hover { color: var(--ink); }
.ctool.is-off { opacity: .45; cursor: not-allowed; }

/* ---- token chip + card (จุดรวม · ยอดสะสมของห้อง) ---- */
.main-head { position: relative; }
.head-right { display: inline-flex; align-items: center; gap: var(--s-2); }
.token-chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--bg); padding: 7px 12px; cursor: pointer;
  color: var(--ink-2); font-size: 13px;
}
.token-chip:hover { background: var(--bg-soft); }
.token-chip .tc-icon { opacity: .7; }
.token-chip b { color: var(--ink); font-variant-numeric: tabular-nums; }
.token-card {
  position: absolute; z-index: 40; top: calc(100% + 6px); right: var(--s-5);
  width: 330px; padding: var(--s-3);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface); box-shadow: 0 18px 40px rgba(0,0,0,.12);
}
.token-card .tc-head { font-size: 12px; color: var(--ink-3); margin-bottom: 6px; }
.token-card .tc-row { display: grid; grid-template-columns: 1fr auto auto auto; gap: 8px; padding: 4px 0; font-size: 12px; color: var(--ink-2); }
.token-card .tc-name { color: var(--ink); font-weight: 600; }
.token-card .tc-stat { color: var(--ink-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.token-card .tc-sum { color: var(--ink); font-weight: 600; }
.token-card .tc-foot { display: flex; justify-content: space-between; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; font-size: 13px; }
.token-card .tc-foot b { font-variant-numeric: tabular-nums; }
.token-card .tc-note { margin-top: 4px; font-size: 11px; color: var(--ink-3); }

/* ---- token card: ค่าใช้จ่ายต่อบอท (21:05) ---- */
.token-card { width: 400px; }
.token-card .tc-row { grid-template-columns: 1fr auto auto auto auto; gap: 10px; }
.token-card .tc-cost { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- token card: แถวแบบย่อ 16,860/129 · 16,989 · ($0.0147) ---- */
.token-card { width: 360px; }
.token-card .tc-row { grid-template-columns: 1fr auto auto auto; gap: 10px; }
.token-card .tc-row.tc-labels { padding-bottom: 4px; margin-bottom: 2px; border-bottom: 1px dashed var(--line); font-size: 10.5px; }
.token-card .tc-row.tc-labels .tc-stat { color: var(--ink-3); }
.token-card .tc-io { color: var(--ink-3); }
.token-card .tc-cost { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- ท้ายคำตอบ: $0.002 · 123 tok (แบบเรฟ) ---- */
.bubble-usage {
  margin-top: 6px; text-align: right;
  font-size: 11px; color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
