:root {
  --bg: #0e1116; --panel: #151a22; --panel2: #1b212b; --line: #262e3b; --text: #e8ebf0; --muted: #8a93a4;
  --acc: #3ec7a1; --acc2: #2a9e7f; --me: #1f6f5c; --them: #222a36; --warn: #e8b04a; --bad: #e5646b; --ok: #3ec7a1;
  --r: 14px; --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-text-size-adjust: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 16px; }
.grow { flex: 1; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
#app { height: 100%; }

/* nút */
.btn { border: 1px solid var(--line); background: var(--panel2); padding: 9px 14px; border-radius: 10px; cursor: pointer; transition: background .15s, border-color .15s; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: #36404f; background: #222a36; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--acc); border-color: var(--acc); color: #06221a; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #52d6b1; }
.btn.warn { border-color: #6b5326; color: var(--warn); }
.btn.danger { border-color: #6b2f33; color: var(--bad); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.icon { border: 0; background: transparent; width: 36px; height: 36px; border-radius: 10px; cursor: pointer; font-size: 18px; color: var(--muted); }
.icon:hover { background: var(--panel2); color: var(--text); }

/* form */
.form { display: flex; flex-direction: column; gap: 10px; }
.form label { font-size: 13px; color: var(--muted); margin-top: 4px; }
input, textarea, select { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--acc2); }
textarea { resize: vertical; }
select { cursor: pointer; }
hr { border: 0; border-top: 1px solid var(--line); margin: 8px 0; width: 100%; }
.row2 { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row2 > select, .row2 > input { flex: 1 1 160px; width: auto; }
.keybox { font-family: var(--mono); font-size: 13px; word-break: break-all; color: var(--acc); resize: none; }
.warnbox { background: #2a2214; border: 1px solid #5b4720; color: #f0cd85; padding: 10px 12px; border-radius: 10px; margin: 0; }
.okbox { background: #12291f; border: 1px solid #1f5a45; color: #9fe8cf; padding: 10px 12px; border-radius: 10px; }
.stat { padding: 9px 12px; border-radius: 10px; background: var(--panel2); border-left: 3px solid var(--muted); }
.stat.ok { border-color: var(--ok); } .stat.warn { border-color: var(--warn); } .stat.bad { border-color: var(--bad); }

/* màn hình đăng nhập / nhập key */
.landing { min-height: 100%; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 50% -10%, #17302a 0%, transparent 60%); }
.card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px 24px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 20px 60px #0008; }
.card h1 { margin: 0; font-size: 24px; }
.card p { margin: 0; }
.card .logo { width: 52px; height: 52px; }
.logo { width: 28px; height: 28px; border-radius: 8px; flex: none; }

/* khung chính */
.shell { display: grid; grid-template-columns: 320px 1fr; height: 100%; height: 100dvh; }
.side { border-right: 1px solid var(--line); background: var(--panel); min-height: 0; display: flex; }
.side-in { display: flex; flex-direction: column; width: 100%; min-height: 0; }
.side-h { display: flex; align-items: center; gap: 8px; padding: 14px 14px 10px; }
.side-act { padding: 0 14px 10px; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 99px; background: #1d3a31; color: var(--acc); }
.list { overflow-y: auto; flex: 1; padding: 4px 8px 12px; }
.item { width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; background: transparent; border: 0; border-radius: 12px; padding: 10px; cursor: pointer; }
.item:hover { background: var(--panel2); }
.item.active { background: #1c2733; }
.i-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.i-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.i-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.i-end { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.i-time { font-size: 12px; color: var(--muted); }
.badge { background: var(--acc); color: #06221a; font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 5px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px #3ec7a122; } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.main { min-width: 0; min-height: 0; display: flex; }
.placeholder { flex: 1; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 20px; }
.ph-icon { font-size: 44px; }

/* chat */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.c-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.c-head .back { display: none; font-size: 26px; line-height: 1; }
.c-info { flex: 1; min-width: 0; }
.c-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-sub.ok { color: var(--ok); } .c-sub.warn { color: var(--warn); } .c-sub.bad { color: var(--bad); }
.banner { padding: 10px 14px 0; }
.lockbar { background: #2a1719; border: 1px solid #5a2a2f; color: #f3b9bd; border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.lockbar.soft { background: var(--panel2); border-color: var(--line); color: var(--muted); flex-direction: row; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.lb-f { display: flex; gap: 8px; }
.lb-f input { font-family: var(--mono); font-size: 13px; }
.msgs { flex: 1; overflow-y: auto; padding: 14px 14px 8px; display: flex; flex-direction: column; gap: 4px; overscroll-behavior: contain; }
.empty { margin: auto; color: var(--muted); }
.day { text-align: center; margin: 10px 0 6px; }
.day span { font-size: 12px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); padding: 2px 10px; border-radius: 99px; }
.row { display: flex; }
.row.me { justify-content: flex-end; }
.bubble { max-width: min(78%, 620px); padding: 7px 11px 5px; border-radius: 16px; background: var(--them); border-bottom-left-radius: 5px; }
.row.me .bubble { background: var(--me); border-bottom-left-radius: 16px; border-bottom-right-radius: 5px; }
.bubble.locked { background: #1a1d24; border: 1px dashed #343c4a; }
.row.me .bubble.locked { background: #17211e; border-color: #2b4a40; }
.who { font-size: 12px; font-weight: 600; color: var(--acc); margin-bottom: 1px; }
.txt { white-space: pre-wrap; word-break: break-word; }
.txt.garbled { font-family: var(--mono); font-size: 13px; color: #6f7a8c; letter-spacing: .5px; word-break: break-all; user-select: none; }
.meta { font-size: 11px; color: #9fb0c3a8; text-align: right; margin-top: 2px; }
.composer { display: flex; gap: 8px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); align-items: flex-end; }
.composer textarea { resize: none; max-height: 160px; border-radius: 20px; padding: 10px 14px; line-height: 1.4; }
.composer textarea:disabled { opacity: .6; }
.send { width: 42px; height: 42px; flex: none; border-radius: 50%; border: 0; background: var(--acc); color: #06221a; font-size: 17px; cursor: pointer; }
.send:disabled { background: var(--line); color: var(--muted); cursor: default; }

/* dialog */
dialog { padding: 0; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); color: var(--text); width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-shadow: 0 30px 80px #000a; }
dialog::backdrop { background: #05080cbb; backdrop-filter: blur(2px); }
.dlg { display: flex; flex-direction: column; max-height: calc(100dvh - 26px); }
.dlg-h { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; gap: 8px; }
.dlg-h b { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlg-b { padding: 8px 16px 16px; overflow-y: auto; }
.dlg-b p { margin: 0; }
.dlg-f { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.devs { display: flex; flex-direction: column; gap: 8px; }
.dev { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--panel2); border-radius: 10px; padding: 8px 10px; }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 20px); background: #222b37; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 99; max-width: calc(100vw - 30px); text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { border-color: #6b2f33; color: #f3b9bd; }

/* điện thoại */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .shell.in-chat .side { display: none; }
  .shell:not(.in-chat) .main { display: none; }
  .c-head .back { display: block; }
  .c-head { padding: 8px 10px; }
  .bubble { max-width: 86%; }
  .lb-f { flex-direction: column; }
}
