:root {
  --bg: #f5f5f9; --surface: #ffffff; --surface-2: #f0f0f6; --text: #16161d; --muted: #6a6a7a;
  --border: #e4e4ee; --accent: #6657f5; --accent-soft: #ecebff; --accent-text: #ffffff;
  --green: #12925a; --green-soft: #e2f6ec; --amber: #b26a00; --amber-soft: #fff1d6;
  --red: #d03a3a; --red-soft: #fde8e8; --gray-soft: #ececf2;
  --shadow: 0 1px 2px rgba(20, 20, 40, .05), 0 8px 24px rgba(20, 20, 40, .06);
  --radius: 14px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0d0d12; --surface: #16161e; --surface-2: #1e1e29; --text: #ececf4; --muted: #9797aa;
  --border: #292937; --accent: #8a7cff; --accent-soft: #24213f; --accent-text: #0d0d12;
  --green: #4fd093; --green-soft: #12301f; --amber: #f0b354; --amber-soft: #33270f;
  --red: #ff7b7b; --red-soft: #3a1717; --gray-soft: #24242f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14.5px/1.5 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
.ico { display: inline-flex; width: 18px; height: 18px; flex: none; }
.ico svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: "Cascadia Code", Consolas, ui-monospace, monospace; font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.right { margin-left: auto; }

/* ---------- nút & ô nhập ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 550; white-space: nowrap; transition: background .12s, border-color .12s, transform .05s; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.icon { width: 32px; height: 32px; padding: 0; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.input, select.input, textarea.input { width: 100%; height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); outline: none; transition: border-color .12s, box-shadow .12s; }
textarea.input { height: auto; padding: 10px 12px; resize: vertical; min-height: 84px; line-height: 1.5; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
label.field > small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 5px; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---------- đăng nhập ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; background: radial-gradient(900px 500px at 50% -10%, var(--accent-soft), transparent 70%); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 32px; box-shadow: var(--shadow); }
.logo { width: 44px; height: 44px; border-radius: 13px; background: var(--accent); color: #fff; display: grid; place-items: center; }
.logo .ico { width: 24px; height: 24px; }
.logo .ico svg { stroke-width: 2.4; }
.login-card h1 { font-size: 22px; margin: 18px 0 4px; }
.device { margin: 20px 0; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); display: flex; align-items: center; gap: 10px; }
.device b { font-family: Consolas, ui-monospace, monospace; letter-spacing: .04em; font-size: 14px; }
.err { color: var(--red); font-size: 13.5px; margin: 10px 0 0; min-height: 20px; }

/* ---------- khung chính ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; height: 100%; }
.side { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 16px 12px; min-height: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font-weight: 700; font-size: 16px; }
.brand .logo { width: 32px; height: 32px; border-radius: 10px; }
.brand .logo .ico { width: 18px; height: 18px; }
.nav { display: flex; flex-direction: column; gap: 2px; overflow: auto; }
.nav-title { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 16px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 520; }
.nav a:hover { background: var(--surface-2); }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.side-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.me { display: flex; align-items: center; gap: 10px; padding: 6px 6px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.main { min-width: 0; min-height: 0; overflow: auto; }
.page { max-width: 1120px; margin: 0 auto; padding: 28px 28px 60px; }
.page-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 23px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card h3 { font-size: 15px; margin-bottom: 12px; }
.grid { display: grid; gap: 14px; }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat .lbl { color: var(--muted); font-size: 13px; }
.stat .val { font-size: 27px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.stat .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.empty { text-align: center; color: var(--muted); padding: 44px 16px; }
.notice { padding: 12px 14px; border-radius: 12px; background: var(--amber-soft); color: var(--amber); font-size: 13.5px; }
.notice.info { background: var(--accent-soft); color: var(--accent); }

/* ---------- bảng ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface); }
td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; background: var(--gray-soft); color: var(--muted); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.bar { height: 7px; border-radius: 99px; background: var(--gray-soft); overflow: hidden; min-width: 90px; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.bar.warn > i { background: var(--amber); }
.bar.full > i { background: var(--red); }

/* ---------- biểu đồ cột ---------- */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 8px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; min-width: 0; }
.chart .col i { width: 100%; max-width: 34px; border-radius: 6px 6px 2px 2px; background: var(--accent); min-height: 2px; opacity: .9; }
.chart .col:hover i { opacity: 1; }
.chart .col span { font-size: 10.5px; color: var(--muted); white-space: nowrap; }

/* ---------- chat ---------- */
.chat { display: grid; grid-template-columns: 250px 1fr; height: 100%; }
.convs { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; padding: 14px 10px; gap: 10px; background: var(--bg); }
.conv-list { overflow: auto; display: flex; flex-direction: column; gap: 2px; }
.conv { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 9px; cursor: pointer; }
.conv:hover { background: var(--surface-2); }
.conv.on { background: var(--surface); box-shadow: inset 0 0 0 1px var(--border); font-weight: 600; }
.conv span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .btn { visibility: hidden; width: 24px; height: 24px; }
.conv:hover .btn { visibility: visible; }
.thread { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.thread-head { display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface); }
.thread-head select { width: auto; height: 34px; }
.msgs { flex: 1; overflow: auto; padding: 24px 20px; }
.msgs-inner { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.msg { display: flex; gap: 12px; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 100%; min-width: 0; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--accent); color: var(--accent-text); padding: 10px 14px; border-radius: 16px 16px 4px 16px; max-width: 80%; white-space: pre-wrap; }
.msg.assistant .bubble { padding-top: 4px; }
.msg .avatar { width: 30px; height: 30px; background: var(--accent); color: #fff; }
.msg .avatar .ico { width: 16px; height: 16px; }
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; overflow: auto; font: 13px/1.5 "Cascadia Code", Consolas, monospace; }
.bubble code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font: 13px "Cascadia Code", Consolas, monospace; }
.bubble pre code { background: none; padding: 0; }
.bubble ul, .bubble ol { margin: 0 0 10px; padding-left: 22px; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { font-size: 16px; margin: 14px 0 8px; }
.cursor::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }
.composer { padding: 12px 20px 20px; }
.composer-box { max-width: 780px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 8px 8px 8px 14px; box-shadow: var(--shadow); }
.composer-box:focus-within { border-color: var(--accent); }
.composer textarea { flex: 1; border: 0; outline: 0; background: transparent; resize: none; max-height: 200px; padding: 8px 0; line-height: 1.5; }
.welcome { text-align: center; margin: 12vh auto 0; max-width: 460px; }
.welcome h2 { font-size: 24px; margin: 16px 0 6px; }
.welcome .logo { margin: 0 auto; }

/* ---------- ảnh / video ---------- */
.studio { display: grid; grid-template-columns: 340px 1fr; gap: 18px; align-items: start; }
.studio .card { position: sticky; top: 0; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.job { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.job-media { aspect-ratio: 1; background: var(--surface-2); display: grid; place-items: center; position: relative; overflow: hidden; }
.job.video .job-media { aspect-ratio: 16 / 10; }
.job-media img, .job-media video { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.job-media video { cursor: default; object-fit: contain; background: #000; }
.job-media.multi { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; place-items: stretch; }
.job-body { padding: 10px 12px; }
.job-body p { margin: 0 0 8px; font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.spin { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: rot .8s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }
.pending { display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; padding: 12px; text-align: center; }
.thumb { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; border: 1px solid var(--border); }

/* ---------- hộp thoại & thông báo ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 10, 20, .5); display: grid; place-items: center; padding: 20px; z-index: 50; backdrop-filter: blur(2px); }
.modal { width: 100%; max-width: 480px; max-height: 90vh; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 22px; box-shadow: var(--shadow); }
.modal.wide { max-width: 900px; }
.modal h2 { font-size: 18px; margin-bottom: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.keybox { display: flex; align-items: center; gap: 8px; padding: 12px; border-radius: 12px; background: var(--surface-2); margin: 10px 0 14px; }
.keybox code { flex: 1; overflow-wrap: anywhere; font: 13px Consolas, monospace; }
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 99; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 12px; font-size: 13.5px; box-shadow: var(--shadow); max-width: 380px; animation: up .18s ease-out; }
.toast.bad { background: var(--red); color: #fff; }
@keyframes up { from { transform: translateY(8px); opacity: 0; } }

/* ---------- chuỗi chuyển tài khoản ---------- */
.chain { display: flex; align-items: stretch; gap: 8px; overflow: auto; padding-bottom: 4px; }
.chain .node { min-width: 150px; border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; background: var(--surface); }
.chain .node.on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chain .node.off { opacity: .55; }
.chain .node b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.chain .arrow { display: grid; place-items: center; color: var(--muted); }
pre.code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; overflow: auto; font: 12.5px/1.55 "Cascadia Code", Consolas, monospace; margin: 0; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side { flex-direction: row; align-items: center; padding: 8px 10px; border-right: 0; border-bottom: 1px solid var(--border); gap: 6px; overflow: auto; }
  .brand { padding: 0 6px 0 0; }
  .brand span, .nav-title, .me .grow { display: none; }
  .nav { flex-direction: row; }
  .nav a span:last-child { display: none; }
  .side-foot { margin: 0 0 0 auto; padding: 0; border: 0; }
  .chat { grid-template-columns: 1fr; }
  .convs { display: none; }
  .studio { grid-template-columns: 1fr; }
  .studio .card { position: static; }
  .cols-4, .cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-2 { grid-template-columns: 1fr; }
  .page { padding: 18px 14px 40px; }
}

td .mono, td.mono { white-space: nowrap; }
