/* AgentHub demo — khung và thành phần dùng chung. Màu khai báo bằng biến; tối / sáng đổi ở :root. */

:root {
  --bg: #f5f5fa;
  --surface: #ffffff;
  --surface-2: #f8f8fc;
  --ink: #16151f;
  --ink-2: #4b4a5c;
  --muted: #7d7b8f;
  --line: #e7e6f0;
  --line-strong: #d5d3e3;
  --sidebar: #15141f;
  --sidebar-2: #211f30;
  --sidebar-ink: #c7c5d8;
  --accent: #6d4aff;
  --accent-2: #8a6dff;
  --accent-soft: #efebff;
  --accent-ink: #ffffff;
  --good: #11795a; --good-bg: #e2f5ee;
  --warn: #a35d00; --warn-bg: #fdf1dc;
  --bad: #c0352b; --bad-bg: #fde8e6;
  --info: #1d5fd6; --info-bg: #e5eeff;
  --violet: #5b3bdb; --violet-bg: #ece7ff;
  --gray-bg: #efeff4;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(22, 21, 31, 0.05), 0 6px 18px rgba(22, 21, 31, 0.04);
  --sidebar-w: 232px;
  --bar-h: 40px;
  color-scheme: light;
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0e17; --surface: #181725; --surface-2: #1f1d2e; --ink: #ecebf5; --ink-2: #b9b7cc; --muted: #8b89a1;
    --line: #2a2840; --line-strong: #37354f; --sidebar: #0b0a12; --sidebar-2: #1a1828; --accent: #8a6dff; --accent-2: #a28cff;
    --accent-soft: #262044; --good: #4fd1a5; --good-bg: #123128; --warn: #f2b25b; --warn-bg: #3a2a10; --bad: #ff8a80; --bad-bg: #3d1a18;
    --info: #8fb4ff; --info-bg: #172544; --violet: #b7a6ff; --violet-bg: #2a2350; --gray-bg: #26243a; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f0e17; --surface: #181725; --surface-2: #1f1d2e; --ink: #ecebf5; --ink-2: #b9b7cc; --muted: #8b89a1;
  --line: #2a2840; --line-strong: #37354f; --sidebar: #0b0a12; --sidebar-2: #1a1828; --accent: #8a6dff; --accent-2: #a28cff;
  --accent-soft: #262044; --good: #4fd1a5; --good-bg: #123128; --warn: #f2b25b; --warn-bg: #3a2a10; --bad: #ff8a80; --bad-bg: #3d1a18;
  --info: #8fb4ff; --info-bg: #172544; --violet: #b7a6ff; --violet-bg: #2a2350; --gray-bg: #26243a; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); min-height: 100vh; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
pre { font: inherit; white-space: pre-wrap; margin: 0; }
code { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Thanh demo + bố cục ---------- */
.demo-bar {
  position: sticky; top: 0; z-index: 30; height: var(--bar-h); display: flex; align-items: center; gap: 12px;
  padding: 0 16px; background: var(--sidebar); color: var(--sidebar-ink); font-size: 12.5px; border-bottom: 1px solid var(--sidebar-2);
}
.demo-tag { white-space: nowrap; background: var(--accent); color: var(--accent-ink); padding: 2px 8px; border-radius: 6px; font-size: 11px; letter-spacing: 0.04em; }
.demo-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.demo-spacer { flex: 1; }
.demo-role { display: flex; align-items: center; gap: 6px; }
.demo-role select { background: var(--sidebar-2); border: 1px solid #34314a; color: #fff; border-radius: 7px; padding: 3px 6px; }
.demo-bar .icon-btn { color: var(--sidebar-ink); }
.demo-bar .btn-ghost-dark { background: transparent; border: 1px solid #45425e; color: #fff; }
.demo-bar .btn-ghost-dark:hover { background: var(--sidebar-2); }

.layout { display: flex; min-height: calc(100vh - var(--bar-h)); }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-ink); display: flex; flex-direction: column;
  position: sticky; top: var(--bar-h); height: calc(100vh - var(--bar-h)); overflow-y: auto; padding: 14px 10px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; color: #fff; }
.brand strong { display: block; font-size: 17px; }
.brand small { display: block; color: var(--sidebar-ink); font-size: 12px; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: linear-gradient(135deg, var(--accent), #b06dff); color: #fff; font-size: 17px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group { margin: 14px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: #807d98; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; font-size: 13.5px; }
.nav-item:hover { background: var(--sidebar-2); color: #fff; }
.nav-item.is-active { background: var(--sidebar-2); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav-icon { width: 18px; text-align: center; opacity: 0.85; }
.nav-item .pill { margin-left: auto; background: var(--accent); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 11.5px; font-weight: 600; }
.sidebar-foot { margin-top: auto; padding: 12px 8px 4px; border-top: 1px solid var(--sidebar-2); }
.user-card strong { display: block; color: #fff; font-size: 13px; }
.user-card span { font-size: 12px; }
.side-version { margin-top: 8px; font-size: 11px; color: #6f6c88; }
.sidebar-scrim { display: none; }
.nav-toggle { display: none; }

.main { flex: 1; min-width: 0; }
.view { padding: 24px 28px 48px; max-width: 1320px; margin: 0 auto; }

/* ---------- Khối ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; letter-spacing: -0.01em; }
.page-head p { margin: 4px 0 0; max-width: 760px; }
.page-actions { display: flex; gap: 8px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2 { font-size: 15px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-main { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); }
.kpi-label { color: var(--muted); font-size: 12.5px; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.kpi-sub { font-size: 12px; color: var(--ink-2); }
.kpi-good .kpi-value { color: var(--good); }
.kpi-warn .kpi-value { color: var(--warn); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.gap-xs { gap: 4px; } .gap-sm { gap: 8px; } .wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 2px; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
a.list-row:hover { background: var(--surface-2); }
.note { background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); padding: 10px 12px; color: var(--ink-2); }
.empty { padding: 24px; text-align: center; color: var(--muted); }
.empty-lg { padding: 64px 24px; }
.empty-lg strong { color: var(--ink); font-size: 16px; }
ul.plain { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.eyebrow { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 4px; }

/* ---------- Chữ ---------- */
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link { color: var(--accent); font-weight: 500; }

/* ---------- Nút, nhãn ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line-strong);
  background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-2); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger-ghost { color: var(--bad); border-color: transparent; background: transparent; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.icon-btn { background: transparent; border: 0; cursor: pointer; padding: 4px 6px; border-radius: 7px; font-size: 15px; }
.icon-btn:hover { background: var(--gray-bg); }
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge-green { background: var(--good-bg); color: var(--good); }
.badge-amber { background: var(--warn-bg); color: var(--warn); }
.badge-red { background: var(--bad-bg); color: var(--bad); }
.badge-blue { background: var(--info-bg); color: var(--info); }
.badge-violet { background: var(--violet-bg); color: var(--violet); }
.badge-gray { background: var(--gray-bg); color: var(--ink-2); }
.chip { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 999px; padding: 4px 11px; font-size: 12.5px; cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.tool-chip { display: inline-flex; align-items: center; gap: 3px; background: var(--accent-soft); color: var(--violet); border-radius: 6px; padding: 1px 7px; }
.avatar {
  --av: #334155; width: 32px; height: 32px; flex-shrink: 0; border-radius: 50%; display: grid; place-items: center;
  background: color-mix(in srgb, var(--av) 16%, var(--surface)); color: var(--av); font-size: 12px; font-weight: 700;
}
.avatar-agent { border-radius: 10px; background: var(--av); color: #fff; }
.avatar-xs { width: 22px; height: 22px; font-size: 10px; border-radius: 7px; }
.avatar-lg { width: 48px; height: 48px; font-size: 20px; border-radius: 14px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-live { background: var(--accent); box-shadow: 0 0 0 0 var(--accent); animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); } 100% { box-shadow: 0 0 0 8px transparent; } }

/* ---------- Bảng, form ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; }
.field input, .field textarea, .search { border: 1px solid var(--line-strong); border-radius: 9px; padding: 9px 11px; background: var(--surface); font-weight: 400; }
.field textarea { resize: vertical; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.form-error { color: var(--bad); margin: 0; min-height: 1em; font-size: 12.5px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; }
.toolbar .search { flex: 1; max-width: 420px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tab { background: none; border: 0; padding: 9px 14px; cursor: pointer; border-bottom: 2px solid transparent; font-weight: 500; color: var(--ink-2); white-space: nowrap; }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Modal, toast, tooltip ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(10, 9, 18, 0.5); display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: var(--radius); width: min(620px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 16px; }
.modal-body { padding: 16px 18px; }
#toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; }
.toast { background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); font-size: 13px; }
.toast-error { background: var(--bad); color: #fff; }
.toast-warn { background: var(--warn); color: #fff; }
[data-tip] { position: relative; }
[data-tip]:hover::after, [data-tip]:focus-visible::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); z-index: 5;
  background: var(--ink); color: var(--surface); font-size: 12px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; pointer-events: none;
}

/* ---------- Màn hình nhỏ ---------- */
@media (max-width: 1100px) {
  .grid-main { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .nav-toggle { display: inline-flex; }
  .demo-text, .demo-role span { display: none; }
  .sidebar { position: fixed; left: 0; top: var(--bar-h); z-index: 40; transform: translateX(-100%); transition: transform 0.2s; }
  .nav-open .sidebar { transform: none; }
  .nav-open .sidebar-scrim { display: block; position: fixed; inset: var(--bar-h) 0 0 0; z-index: 35; background: rgba(0, 0, 0, 0.4); }
  .view { padding: 16px 16px 40px; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi-value { font-size: 21px; }
  .page-head h1 { font-size: 20px; }
}
