:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1e222b;
  --border: #2a2f3a;
  --text: #e8eaed;
  --muted: #9aa0aa;
  --gold: #f5b301;
  --gold2: #ffd24c;
  --user: #26303f;
  --asst: #1c2028;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
.hidden { display: none !important; }
.gold { color: var(--gold); }
.muted { color: var(--muted); }
.err { color: #ff6b6b; min-height: 1.2em; margin: 8px 0 0; font-size: 13px; }

/* ---- Login ---- */
.center { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  width: 360px;
  max-width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,.4);
}
.card h1 { margin: 0 0 4px; font-size: 24px; }
.card p { margin: 0 0 20px; }
.card input {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel2); color: var(--text);
  font-size: 15px; margin-bottom: 12px;
}
.card input:focus { outline: none; border-color: var(--gold); }
.card button {
  width: 100%; padding: 12px; border: none; border-radius: 10px;
  background: var(--gold); color: #1a1400; font-weight: 700; font-size: 15px; cursor: pointer;
}
.card button:hover { background: var(--gold2); }

/* ---- App layout ---- */
#app { display: flex; flex-direction: column; height: 100%; max-width: 900px; margin: 0 auto; }
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border); gap: 12px;
}
.hleft { display: flex; align-items: center; gap: 10px; }
.brand { font-weight: 700; font-size: 17px; }

/* ---- Ngăn kéo lịch sử ---- */
#overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20;
}
#overlay.open { opacity: 1; pointer-events: auto; }
#drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 290px; max-width: 82%;
  background: var(--panel); border-right: 1px solid var(--border);
  transform: translateX(-100%); transition: transform .22s ease; z-index: 21;
  display: flex; flex-direction: column;
}
#drawer.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.5); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px; border-bottom: 1px solid var(--border);
}
.drawer-title { font-weight: 700; }
.drawer-head button {
  background: var(--gold); color: #1a1400; border: none; border-radius: 8px;
  padding: 8px 12px; font-weight: 700; cursor: pointer; font-size: 13px;
}
.drawer-head button:hover { background: var(--gold2); }
.convo-list { flex: 1; overflow-y: auto; padding: 8px; }
.convo-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 24px 8px; }
.convo-item {
  position: relative; padding: 10px 32px 10px 12px; border-radius: 10px;
  cursor: pointer; margin-bottom: 4px; border: 1px solid transparent;
}
.convo-item:hover { background: var(--panel2); }
.convo-item.active { background: var(--panel2); border-color: var(--border); }
.convo-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.convo-del {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 13px; opacity: 0; transition: opacity .15s;
}
.convo-item:hover .convo-del { opacity: 1; }
.convo-del:hover { color: #ff6b6b; }
.controls { display: flex; gap: 8px; align-items: center; }
.controls select {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 13px;
}
.controls select:focus { outline: none; border-color: var(--gold); }
.ghost {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; width: 36px; height: 36px; font-size: 16px; cursor: pointer;
}
.ghost:hover { border-color: var(--gold); }

/* ---- Messages ---- */
#messages { flex: 1; overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 16px; }
.msg { display: flex; gap: 10px; align-items: flex-start; animation: msgIn .18s ease; }
.msg.user { justify-content: flex-end; }
@keyframes msgIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.avatar {
  width: 30px; height: 30px; border-radius: 9px; background: var(--panel2);
  border: 1px solid var(--border); display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}
.msg-main { max-width: 82%; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.msg.user .msg-main { align-items: flex-end; }
.bubble {
  padding: 11px 15px; border-radius: 14px; line-height: 1.6;
  word-wrap: break-word; overflow-wrap: anywhere; max-width: 100%;
}
.msg.user .bubble { background: var(--user); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.assistant .bubble { background: var(--asst); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
/* Dòng suy luận (mờ) hiện trong lúc CEO/Opus đang nghĩ — bị câu trả lời ghi đè khi có */
.thinking-live { opacity: .55; font-style: italic; white-space: pre-wrap; font-size: .94em; }

/* Markdown trong câu trả lời */
.msg.assistant .bubble > *:first-child { margin-top: 0; }
.msg.assistant .bubble > *:last-child { margin-bottom: 0; }
.bubble p { margin: 0 0 10px; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { margin: 14px 0 8px; line-height: 1.3; }
.bubble h1 { font-size: 1.35em; } .bubble h2 { font-size: 1.22em; } .bubble h3 { font-size: 1.08em; }
.bubble ul, .bubble ol { margin: 0 0 10px; padding-left: 22px; }
.bubble li { margin: 3px 0; }
.bubble li > ul, .bubble li > ol { margin: 3px 0; }
.bubble a { color: var(--gold2); }
.bubble strong { color: #fff; font-weight: 700; }
.bubble code { background: rgba(255,255,255,.08); padding: 1px 5px; border-radius: 5px; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .9em; }
.bubble pre { background: #0d1017; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; overflow-x: auto; margin: 0 0 10px; }
.bubble pre code { background: none; padding: 0; font-size: .88em; line-height: 1.5; }
.bubble blockquote { border-left: 3px solid var(--gold); margin: 0 0 10px; padding: 2px 0 2px 12px; color: var(--muted); }
.bubble table { border-collapse: collapse; margin: 0 0 10px; display: block; overflow-x: auto; max-width: 100%; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.bubble th { background: var(--panel2); }
.bubble hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

/* Hành động dưới câu trả lời */
.msg-actions { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.msg.assistant:hover .msg-actions { opacity: 1; }
.mini-btn { background: none; border: 1px solid transparent; border-radius: 7px; padding: 3px 7px; cursor: pointer; font-size: 13px; color: var(--muted); }
.mini-btn:hover { background: var(--panel2); border-color: var(--border); color: var(--text); }

/* Màn chào */
.welcome { margin: auto; text-align: center; max-width: 580px; padding: 24px 16px; }
.welcome-logo { height: 44px; margin-bottom: 6px; }
.welcome h2 { margin: 8px 0 4px; font-size: 1.5em; }
.suggest-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.suggest {
  text-align: left; background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; cursor: pointer; color: var(--text); font-size: 13.5px; line-height: 1.4;
  transition: border-color .15s, transform .1s;
}
.suggest:hover { border-color: var(--gold); transform: translateY(-1px); }
@media (max-width: 560px) { .suggest-grid { grid-template-columns: 1fr; } }

/* ---- Composer ---- */
footer {
  display: flex; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); align-items: flex-end;
}
#input {
  flex: 1; resize: none; border-radius: 12px; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text); padding: 12px 14px; font-size: 15px;
  font-family: inherit; max-height: 160px; line-height: 1.4;
}
#input:focus { outline: none; border-color: var(--gold); }
#send {
  padding: 12px 20px; border: none; border-radius: 12px; background: var(--gold);
  color: #1a1400; font-weight: 700; cursor: pointer; font-size: 15px;
}
#send:hover { background: var(--gold2); }
#send:disabled { opacity: .5; cursor: default; }
.usage { text-align: center; color: var(--muted); font-size: 12px; padding: 0 0 8px; min-height: 16px; }

/* ---- Chế độ Tạo bài MKT ---- */
.post-caption { white-space: pre-wrap; line-height: 1.5; margin-bottom: 10px; }
.post-img { max-width: 100%; border-radius: 10px; margin: 4px 0 10px; display: block; }
.post-imgerr { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }
.post-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.post-btn {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; font-size: 13px; cursor: pointer;
}
.post-btn:hover { border-color: var(--gold); }
.post-btn:disabled { opacity: .6; cursor: default; }

/* ---- Đính kèm file + web ---- */
.attach-chip { display: flex; align-items: center; gap: 8px; padding: 6px 16px; color: var(--muted); font-size: 13px; }
.attach-chip .chip-x { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 0 4px; }
.attach-chip .chip-x:hover { color: var(--gold); }
#webBtn.active { border-color: var(--gold); color: var(--gold); }

/* ---- Footer ngăn kéo + tài khoản ---- */
.drawer-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 14px; border-top: 1px solid var(--border);
}
.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px; text-decoration: underline; padding: 0; white-space: nowrap; }
.link-btn:hover { color: var(--gold); }

/* ---- Modal quản lý nhân viên ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 30; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; width: 480px; max-width: 100%; max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 700; }
.modal-body { padding: 14px 16px; overflow-y: auto; }
.add-user { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.add-user input, .add-user select {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 11px; font-size: 13px; width: 100%;
}
.add-user input:focus, .add-user select:focus { outline: none; border-color: var(--gold); }
.add-user button {
  grid-column: 1 / -1; background: var(--gold); color: #1a1400; border: none;
  border-radius: 8px; padding: 10px; font-weight: 700; cursor: pointer; font-size: 14px;
}
.add-user button:hover { background: var(--gold2); }
.user-list { display: flex; flex-direction: column; gap: 6px; }
.user-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; background: var(--panel2); border-radius: 10px; }
.user-nm { font-size: 14px; font-weight: 600; }
.user-rl { font-size: 12px; color: var(--muted); margin-top: 2px; }
.user-acts { display: flex; gap: 6px; flex-shrink: 0; }

/* ---- Pro polish: logo header, tìm/ghim hội thoại, nút Dừng ---- */
.brand { display: flex; align-items: center; gap: 7px; }
.brand-logo { height: 24px; width: auto; vertical-align: middle; }
.convo-search {
  margin: 0 12px 8px; padding: 8px 11px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text); font-size: 13px;
}
.convo-search:focus { outline: none; border-color: var(--gold); }
.convo-item { padding-right: 78px; }
.convo-acts {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  display: flex; gap: 1px; opacity: 0; transition: opacity .15s;
}
.convo-item:hover .convo-acts, .convo-item.active .convo-acts { opacity: 1; }
.convo-act { background: none; border: none; cursor: pointer; font-size: 12px; padding: 3px 4px; line-height: 1; border-radius: 6px; }
.convo-act:hover { background: var(--panel); }
.foot-links { display: flex; gap: 12px; flex-shrink: 0; }
#send.stop { background: #3a2222; color: #ffb0b0; }
#send.stop:hover { background: #4a2a2a; }

/* Responsive: không tràn ngang ở màn hẹp */
body { overflow-x: hidden; }
header { flex-wrap: wrap; row-gap: 8px; }
.controls { flex-wrap: wrap; justify-content: flex-end; }
.controls select { min-width: 0; max-width: 44vw; }
@media (max-width: 520px) {
  .brand { font-size: 15px; }
  .controls select { font-size: 12px; padding: 7px 8px; }
}
