/* ============================================
   TRƯỜNG SƠN — Internal Portal
   Brand: Tech Red #DC2626 · Slate Core #1E293B · Ice White #F8FAFC
   Type: Outfit (UI) · JetBrains Mono (codes/IDs)
   ============================================ */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  font-feature-settings: 'cv11', 'ss01';
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

/* ---------- TOKENS (light) ---------- */
:root {
  /* Brand */
  --tech-red: #DC2626;
  --tech-red-600: #B91C1C;
  --tech-red-700: #991B1B;
  --tech-red-50: #FEF2F2;
  --tech-red-100: #FEE2E2;
  --slate-core: #1E293B;
  --ice-white: #F8FAFC;

  /* Surfaces & text — light theme */
  --bg: #FAFBFC;
  --surface: #FFFFFF;
  --surface-2: #F4F5F7;
  --surface-hover: #EFF1F4;
  --border: #E5E7EB;
  --border-strong: #D1D5DB;
  --text: #0F172A;
  --text-2: #334155;
  --text-3: #64748B;
  --text-4: #94A3B8;
  --accent: var(--tech-red);
  --accent-fg: #FFFFFF;
  --accent-soft: var(--tech-red-50);
  --accent-soft-2: #FEE2E2;

  /* Status */
  --green: #16A34A;
  --green-soft: #DCFCE7;
  --amber: #D97706;
  --amber-soft: #FEF3C7;
  --blue: #2563EB;
  --blue-soft: #DBEAFE;
  --purple: #7C3AED;
  --purple-soft: #EDE9FE;

  /* Agent accents */
  --agent-quyche: #2563EB;
  --agent-sanpham: #7C3AED;
  --agent-kythuat: #0D9488;
  --agent-kinhdoanh: #DC2626;

  /* Shadows / radii */
  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 30px -10px rgba(15, 23, 42, 0.2), 0 4px 12px rgba(15,23,42,0.06);

  /* Layout */
  --sidebar-w: 224px;
  --topbar-h: 52px;
}

/* ---------- DARK THEME ---------- */
[data-theme="dark"] {
  --bg: #0B1220;
  --surface: #111827;
  --surface-2: #0F1626;
  --surface-hover: #1A2335;
  --border: #1F2A3D;
  --border-strong: #2D3A52;
  --text: #F1F5F9;
  --text-2: #CBD5E1;
  --text-3: #94A3B8;
  --text-4: #64748B;
  --accent-soft: rgba(220, 38, 38, 0.12);
  --accent-soft-2: rgba(220, 38, 38, 0.18);

  --green-soft: rgba(22,163,74,0.15);
  --amber-soft: rgba(217,119,6,0.15);
  --blue-soft: rgba(37,99,235,0.18);
  --purple-soft: rgba(124,58,237,0.18);

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow: 0 1px 3px rgba(0,0,0,0.5), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 30px -10px rgba(0,0,0,0.6), 0 4px 12px rgba(0,0,0,0.4);
}

/* ---------- BASE ---------- */
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; font-feature-settings: 'zero', 'ss01'; }

/* ---------- APP SHELL ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 100vh;
  height: 100vh;
  overflow: hidden;
}
.main {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr;
  min-height: 0;
  min-width: 0;
  background: var(--bg);
}
.main-body { overflow: auto; min-height: 0; }

/* ---------- SIDEBAR ---------- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  height: var(--topbar-h);
}
.sb-brand img { height: 22px; }
.sb-brand .badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--tech-red);
  letter-spacing: 0.04em;
}
.sb-section {
  padding: 12px 8px 4px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-4);
}
.sb-nav { padding: 4px 8px; display: flex; flex-direction: column; gap: 1px; }
.sb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-2);
  border-radius: var(--r-sm);
  cursor: pointer;
  position: relative;
  white-space: nowrap;
}
.sb-item > span:not(.kbd):not(.count) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.sb-item:hover { background: var(--surface-hover); color: var(--text); }
.sb-item.active {
  background: var(--accent-soft);
  color: var(--tech-red);
}
[data-theme="dark"] .sb-item.active { color: #FCA5A5; }
.sb-item .ico { width: 16px; height: 16px; opacity: 0.9; flex-shrink: 0; }
.sb-item .kbd {
  margin-left: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  color: var(--text-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 4px;
}
.sb-item.active .kbd { background: transparent; border-color: transparent; color: inherit; opacity: 0.7; }
.sb-item .count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-4);
  font-variant-numeric: tabular-nums;
}

.sb-user {
  margin-top: auto;
  padding: 10px;
  border-top: 1px solid var(--border);
}
.sb-user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r);
  cursor: pointer;
}
.sb-user-card:hover { background: var(--surface-hover); }
.sb-user-card .avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1E293B, #475569);
  color: #F1F5F9;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
}
.sb-user-card .name { font-size: 12.5px; font-weight: 600; line-height: 1.2; }
.sb-user-card .role { font-size: 11px; color: var(--text-3); line-height: 1.2; }

/* ---------- TOPBAR ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.tb-crumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  min-width: 0;
}
.tb-crumbs > span { overflow: hidden; text-overflow: ellipsis; }
.tb-crumbs .sep { color: var(--text-4); }
.tb-search {
  margin-left: auto;
  position: relative;
  width: 320px;
}
.tb-search input {
  width: 100%;
  height: 30px;
  padding: 0 10px 0 32px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--r-sm);
  font-size: 12.5px;
  outline: none;
}
.tb-search input:focus { border-color: var(--border-strong); background: var(--surface); }
.tb-search .ico { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-4); }
.tb-search .kbd {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  font-family: 'JetBrains Mono', monospace; font-size: 10.5px; color: var(--text-4);
  background: var(--surface); border: 1px solid var(--border);
  padding: 1px 5px; border-radius: 3px;
}
.tb-actions { display: flex; align-items: center; gap: 8px; }
.tb-iconbtn {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  color: var(--text-3);
}
.tb-iconbtn:hover { background: var(--surface-hover); color: var(--text); }
.tb-iconbtn.has-dot::after {
  content: ''; position: absolute; width: 6px; height: 6px;
  background: var(--tech-red); border-radius: 50%;
  transform: translate(8px, -8px);
}
.tb-iconbtn { position: relative; }

/* ---------- BUTTONS ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  transition: all 0.12s ease;
  white-space: nowrap;
}
.btn-primary {
  background: var(--slate-core);
  color: #fff;
}
.btn-primary:hover { background: #0F172A; }
[data-theme="dark"] .btn-primary { background: var(--tech-red); }
[data-theme="dark"] .btn-primary:hover { background: var(--tech-red-600); }
.btn-red {
  background: var(--tech-red);
  color: #fff;
}
.btn-red:hover { background: var(--tech-red-600); }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface-hover); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-sm { height: 26px; padding: 0 8px; font-size: 12px; }

/* ---------- CARDS / PANELS ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
}
.card-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: 13.5px; font-weight: 600; }
.card-body { padding: 16px; }

/* ---------- PAGE HEADER ---------- */
.page {
  padding: 24px 28px 40px;
  max-width: 1400px;
}
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
}
.page-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}
.page-sub {
  font-size: 13.5px;
  color: var(--text-3);
  margin-top: 4px;
}

/* ---------- BADGES / CHIPS ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
}
.chip.green { background: var(--green-soft); color: var(--green); border-color: transparent; }
.chip.amber { background: var(--amber-soft); color: var(--amber); border-color: transparent; }
.chip.blue { background: var(--blue-soft); color: var(--blue); border-color: transparent; }
.chip.red { background: var(--accent-soft); color: var(--tech-red); border-color: transparent; }
.chip.purple { background: var(--purple-soft); color: var(--purple); border-color: transparent; }
[data-theme="dark"] .chip.green { color: #4ADE80; }
[data-theme="dark"] .chip.amber { color: #FBBF24; }
[data-theme="dark"] .chip.blue { color: #60A5FA; }
[data-theme="dark"] .chip.red { color: #FCA5A5; }
[data-theme="dark"] .chip.purple { color: #C4B5FD; }

.dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-4);
}
.dot.green { background: var(--green); }
.dot.amber { background: var(--amber); }
.dot.red { background: var(--tech-red); }
.dot.blue { background: var(--blue); }

/* ---------- TABLES ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left;
  font-weight: 600;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-4);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  position: sticky; top: 0; z-index: 1;
}
.tbl td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.tbl tbody tr:hover { background: var(--surface-hover); cursor: pointer; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; }

/* ---------- LOGIN ---------- */
.login-screen {
  position: fixed; inset: 0;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  background: var(--bg);
  z-index: 10;
}
.login-left {
  background: var(--slate-core);
  color: #F1F5F9;
  padding: 48px;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}
.login-left::before {
  content: '';
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.04) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: radial-gradient(ellipse at 30% 50%, #000 0%, transparent 70%);
}
.login-left::after {
  content: '';
  position: absolute;
  width: 320px; height: 320px;
  background: radial-gradient(circle, var(--tech-red) 0%, transparent 60%);
  opacity: 0.25;
  filter: blur(40px);
  bottom: -80px; right: -80px;
}
.login-logo { height: 28px; position: relative; z-index: 1; }
.login-left h1 {
  font-size: 36px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1;
  margin: auto 0 16px; position: relative; z-index: 1;
}
.login-left h1 em { color: var(--tech-red); font-style: normal; }
.login-left p {
  font-size: 14px; color: #CBD5E1; max-width: 380px; line-height: 1.55;
  position: relative; z-index: 1;
}
.login-left .stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 16px; margin-top: 32px; position: relative; z-index: 1;
}
.login-left .stat { border-top: 1px solid rgba(255,255,255,0.12); padding-top: 12px; }
.login-left .stat-val { font-size: 20px; font-weight: 700; }
.login-left .stat-lbl { font-size: 11.5px; color: #94A3B8; letter-spacing: 0.04em; text-transform: uppercase; }

.login-right {
  display: flex; align-items: center; justify-content: center;
  padding: 48px;
}
.login-card { width: 100%; max-width: 380px; }
.login-card h2 { font-size: 24px; font-weight: 700; margin: 0 0 8px; letter-spacing: -0.01em; }
.login-card .muted { font-size: 13.5px; color: var(--text-3); margin-bottom: 28px; }
.google-btn {
  width: 100%;
  height: 44px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--r);
  font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all 0.15s;
}
.google-btn:hover { box-shadow: var(--shadow); }
.login-meta {
  margin-top: 24px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.55;
}
.login-meta b { color: var(--text); font-weight: 600; }
.login-footer { font-size: 11.5px; color: var(--text-4); margin-top: 24px; }

/* ---------- CHAT ---------- */
.chat-screen {
  display: grid;
  grid-template-columns: 252px 1fr;
  height: calc(100vh - var(--topbar-h));
  overflow: hidden;
}
.chat-history {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex; flex-direction: column;
  min-height: 0;
}
.chat-history-head {
  padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
  border-bottom: 1px solid var(--border);
}
.chat-new-btn {
  width: 100%;
  height: 32px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--slate-core); color: #fff;
  border-radius: var(--r-sm);
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
[data-theme="dark"] .chat-new-btn { background: var(--tech-red); }
.chat-history-search {
  position: relative;
}
.chat-history-search input {
  width: 100%; height: 30px;
  padding: 0 10px 0 30px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--r-sm);
  font-size: 12.5px;
  outline: none;
}
.chat-history-search .ico { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--text-4); }
.chat-history-list {
  flex: 1; overflow-y: auto; padding: 8px 8px 16px;
}
.chat-history-group {
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-4);
  padding: 10px 8px 4px;
}
.chat-history-item {
  display: flex; flex-direction: column; gap: 2px;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.chat-history-item:hover { background: var(--surface-hover); }
.chat-history-item.active { background: var(--accent-soft); }
.chat-history-item .ttl {
  font-size: 12.5px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text);
  max-width: 100%;
}
.chat-history-item.active .ttl { color: var(--tech-red); }
[data-theme="dark"] .chat-history-item.active .ttl { color: #FCA5A5; }
.chat-history-item .meta {
  display: flex; align-items: center; gap: 6px;
  font-size: 10.5px; color: var(--text-4);
  white-space: nowrap;
  overflow: hidden;
}
.chat-history-item .agent-tag {
  font-size: 10px; font-weight: 600;
}

.chat-main {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  background: var(--bg);
}
.chat-head {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.chat-head .agent-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12.5px; font-weight: 600;
  white-space: nowrap;
}
.chat-head .agent-pill .swatch { width: 8px; height: 8px; border-radius: 2px; }
.chat-head .ratelimit {
  margin-left: auto;
  font-size: 11.5px; color: var(--text-3);
  display: flex; align-items: center; gap: 6px;
}

.chat-body {
  flex: 1; overflow-y: auto; min-height: 0;
}
.chat-empty {
  max-width: 760px; margin: 0 auto; padding: 20px 24px 24px;
}
.chat-empty .hero {
  text-align: center; margin-bottom: 18px;
}
.chat-empty .hero h2 {
  font-size: 20px; font-weight: 700; margin: 0 0 6px; letter-spacing: -0.01em;
}
.chat-empty .hero p { font-size: 13px; color: var(--text-3); margin: 0; }
.agent-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.agent-card {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 12px 14px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
  overflow: hidden;
}
.agent-card::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--agent-color, var(--text-3));
}
.agent-card:hover {
  border-color: var(--agent-color);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}
.agent-card .hd { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.agent-card .ico {
  width: 36px; height: 36px;
  border-radius: var(--r);
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--agent-color) 12%, transparent);
  color: var(--agent-color);
  flex-shrink: 0;
}
.agent-card .ttl { font-size: 14px; font-weight: 700; line-height: 1.25; }
.agent-card .sub { font-size: 11.5px; color: var(--text-3); margin-top: 3px; line-height: 1.35; }
.agent-card .desc { font-size: 12.5px; color: var(--text-2); line-height: 1.5; margin-bottom: 10px; }
.agent-card .examples { display: flex; flex-direction: column; gap: 4px; }
.agent-card .example {
  font-size: 11.5px;
  color: var(--text-3);
  padding: 4px 8px;
  background: var(--surface-2);
  border-radius: 4px;
  cursor: pointer;
}
.agent-card .example:hover { background: var(--surface-hover); color: var(--text); }
.agent-card .example::before { content: '› '; color: var(--agent-color); font-weight: 700; }

.chat-thread {
  max-width: 780px; margin: 0 auto; padding: 24px 24px 32px;
  display: flex; flex-direction: column; gap: 20px;
}
.msg { display: flex; gap: 12px; }
.msg .avatar {
  width: 28px; height: 28px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 11.5px; font-weight: 700;
}
.msg.user .avatar {
  background: var(--slate-core); color: #F1F5F9;
}
.msg.assistant .avatar {
  background: color-mix(in srgb, var(--agent-color, var(--tech-red)) 14%, transparent);
  color: var(--agent-color, var(--tech-red));
}
.msg .bubble { flex: 1; min-width: 0; }
.msg .name {
  font-size: 12.5px; font-weight: 600; margin-bottom: 4px;
  display: flex; align-items: center; gap: 6px;
}
.msg .name .time { color: var(--text-4); font-weight: 400; font-size: 11px; }
.msg .content {
  font-size: 13.5px; line-height: 1.65; color: var(--text);
}
.msg .content p { margin: 0 0 10px; }
.msg .content p:last-child { margin: 0; }
.msg .content strong { font-weight: 600; }
.msg .content code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.msg .content ul, .msg .content ol { margin: 6px 0 10px; padding-left: 20px; }
.msg .content li { margin: 2px 0; }
.msg .content table {
  width: 100%; border-collapse: collapse; margin: 10px 0;
  font-size: 12.5px;
  border: 1px solid var(--border); border-radius: var(--r-sm); overflow: hidden;
}
.msg .content th, .msg .content td {
  padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left;
}
.msg .content th {
  background: var(--surface-2); font-weight: 600;
  text-transform: uppercase; font-size: 10.5px; letter-spacing: 0.04em;
  color: var(--text-3);
}
.msg .content tr:last-child td { border-bottom: none; }
.msg .content .source-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 500;
  padding: 1px 6px;
  background: var(--accent-soft);
  color: var(--tech-red);
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
}
[data-theme="dark"] .msg .content .source-tag { color: #FCA5A5; }
.msg .actions {
  display: flex; gap: 4px; margin-top: 8px;
  opacity: 0; transition: opacity 0.15s;
}
.msg:hover .actions { opacity: 1; }
.msg .actions button {
  font-size: 11px; color: var(--text-3);
  padding: 3px 7px; border-radius: 4px;
  display: flex; align-items: center; gap: 4px;
}
.msg .actions button:hover { background: var(--surface-hover); color: var(--text); }

.msg.streaming .content::after {
  content: ''; display: inline-block;
  width: 7px; height: 14px;
  background: var(--text); margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 1s infinite;
}
@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

.source-card {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  font-size: 12px;
}
.source-card .hd {
  padding: 8px 12px;
  background: var(--surface-2);
  font-weight: 600;
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
.source-card .items { display: flex; flex-direction: column; }
.source-card .item {
  padding: 8px 12px;
  display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--border);
}
.source-card .item:last-child { border-bottom: none; }
.source-card .item:hover { background: var(--surface-hover); cursor: pointer; }
.source-card .item .num {
  width: 18px; height: 18px;
  background: var(--accent-soft); color: var(--tech-red);
  font-family: 'JetBrains Mono', monospace; font-size: 11px;
  border-radius: 4px; display: flex; align-items: center; justify-content: center; font-weight: 700;
  flex-shrink: 0;
}
.source-card .item .ttl { font-weight: 500; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-card .item .ref { color: var(--text-4); font-family: 'JetBrains Mono', monospace; font-size: 11px; }

.chat-composer {
  border-top: 1px solid var(--border);
  padding: 12px 18px 16px;
  background: var(--surface);
}
.chat-composer-inner {
  max-width: 780px; margin: 0 auto;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 4px 4px 4px 14px;
  display: flex; align-items: flex-end; gap: 8px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chat-composer-inner:focus-within {
  border-color: var(--text-3);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.chat-composer textarea {
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  outline: none;
  font-size: 13.5px;
  line-height: 1.5;
  padding: 9px 0;
  min-height: 22px;
  max-height: 200px;
  font-family: inherit;
}
.chat-composer textarea::placeholder { color: var(--text-4); }
.composer-send {
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  background: var(--slate-core); color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: opacity 0.15s;
  flex-shrink: 0;
}
.composer-send:disabled { opacity: 0.3; cursor: not-allowed; }
[data-theme="dark"] .composer-send { background: var(--tech-red); }
.composer-toolbar {
  max-width: 780px; margin: 6px auto 0;
  display: flex; align-items: center; gap: 12px;
  font-size: 11px; color: var(--text-4);
}
.composer-toolbar .left { display: flex; align-items: center; gap: 10px; }
.composer-toolbar .chip-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 11px;
  cursor: pointer;
  color: var(--text-3);
}
.composer-toolbar .chip-btn:hover { color: var(--text); }
.composer-toolbar .right { margin-left: auto; font-variant-numeric: tabular-nums; }

/* ---------- DOCUMENTS ---------- */
.docs-grid {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 24px;
  align-items: start;
}
.doc-folders {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 8px;
  position: sticky; top: 20px;
}
.doc-folder {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
}
.doc-folder > span { overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.doc-folder:hover { background: var(--surface-hover); color: var(--text); }
.doc-folder.active { background: var(--accent-soft); color: var(--tech-red); }
[data-theme="dark"] .doc-folder.active { color: #FCA5A5; }
.doc-folder .count { margin-left: auto; font-size: 11px; color: var(--text-4); font-variant-numeric: tabular-nums; }
.doc-folder.active .count { color: inherit; opacity: 0.7; }

.doc-toolbar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 16px;
}
.doc-toolbar .filter {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12.5px; font-weight: 500;
  padding: 5px 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r-sm);
  cursor: pointer;
  color: var(--text-2);
}
.doc-toolbar .filter:hover { background: var(--surface-hover); }
.doc-toolbar .filter.active { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.doc-toolbar .search {
  margin-left: auto; position: relative; width: 240px;
}
.doc-toolbar .search input {
  width: 100%; height: 30px;
  padding: 0 10px 0 30px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r-sm);
  font-size: 12.5px; outline: none;
}
.doc-toolbar .search .ico { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--text-4); }

/* ---------- PRODUCTS ---------- */
.prod-filters {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.prod-img {
  width: 44px; height: 44px;
  border-radius: 8px;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
  color: var(--text-3);
  border: 1px solid var(--border);
}
.prod-img.ikg { background: linear-gradient(135deg, #1E293B, #334155); color: #fff; }
.prod-img.gtw { background: linear-gradient(135deg, #DC2626, #B91C1C); color: #fff; }
.prod-name { font-weight: 600; font-size: 13px; }
.prod-desc { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }

/* ---------- PROFILE ---------- */
.profile-head {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 24px;
}
.profile-avatar {
  width: 64px; height: 64px;
  border-radius: var(--r-lg);
  background: linear-gradient(135deg, #1E293B, #475569);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700;
}
.profile-info h2 { font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.profile-info .meta { font-size: 13px; color: var(--text-3); display: flex; gap: 12px; }
.kv-table { display: grid; grid-template-columns: 180px 1fr; gap: 0; }
.kv-table .k {
  font-size: 12.5px; color: var(--text-3); font-weight: 500;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.kv-table .v {
  font-size: 13px; padding: 12px 0; border-bottom: 1px solid var(--border);
}
.kv-table > div:nth-last-child(-n+2) { border-bottom: none; }
.kv-table > div:nth-last-child(-n+2) { border-bottom: none; }

/* ---------- ADMIN ---------- */
.stat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 16px;
}
.stat-card .lbl {
  font-size: 11px; color: var(--text-3); font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase;
}
.stat-card .val {
  font-size: 24px; font-weight: 700; margin-top: 6px; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat-card .delta {
  font-size: 11.5px; color: var(--green); margin-top: 4px;
  display: flex; align-items: center; gap: 4px;
}
.stat-card .delta.down { color: var(--tech-red); }

.bar-chart { display: flex; align-items: flex-end; gap: 2px; height: 120px; padding: 6px 0; }
.bar-chart .bar { flex: 1; background: var(--accent-soft-2); border-radius: 3px 3px 0 0; min-height: 4px; position: relative; }
.bar-chart .bar.active { background: var(--tech-red); }
.bar-chart .bar:hover { background: var(--tech-red-600); }

.tabs {
  display: flex; gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  padding: 8px 14px;
  font-size: 13px; font-weight: 500;
  color: var(--text-3);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--tech-red); border-bottom-color: var(--tech-red); font-weight: 600; }
[data-theme="dark"] .tab.active { color: #FCA5A5; border-bottom-color: #FCA5A5; }

/* ---------- INPUTS ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 500; color: var(--text-2); margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r-sm);
  font-size: 13px;
  outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--text-3);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea { resize: vertical; min-height: 80px; font-family: inherit; line-height: 1.5; }

/* ---------- SCROLLBARS ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-4); }

/* ---------- MISC ---------- */
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-3);
}
.empty-state .ico { margin-bottom: 12px; opacity: 0.5; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text); margin: 0 0 6px; }

/* highlight code */
pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  overflow-x: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  line-height: 1.5;
  margin: 8px 0;
}

/* ============================================
   MOBILE RESPONSIVE (Phase 3 Tuần 1)
   Brief §7.3: NV dùng tại công trường — cần mobile.
   ============================================ */

/* Hamburger button — ẩn ở desktop */
.menu-btn {
  display: none;
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  color: var(--text);
  align-items: center; justify-content: center;
  margin-right: 4px;
}
.menu-btn:hover { background: var(--surface-hover); }

/* Overlay phía sau sidebar khi mở trên mobile */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 998;
}

@media (max-width: 768px) {
  body { overflow: auto; }   /* cho phép scroll trang trên mobile */

  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 100vh;
  }

  /* Sidebar trở thành drawer */
  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: -100%;
    width: 280px;
    z-index: 1000;
    transition: left 0.22s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { left: 0; }
  .sidebar-overlay.open { display: block; }

  /* Topbar — bỏ crumbs + search trên mobile */
  .menu-btn { display: flex; }
  .tb-crumbs { font-size: 12.5px; }
  .tb-crumbs > span:not(:last-child),
  .tb-crumbs .sep { display: none; }   /* chỉ hiện title cuối */
  .tb-search { display: none; }

  /* Page padding nhỏ hơn */
  .page { padding: 14px 14px 28px; }
  .page-header { flex-direction: column; align-items: stretch; gap: 10px; }
  .page-title { font-size: 18px; }

  /* Chat: history sidebar cũng thành drawer */
  .chat-screen {
    grid-template-columns: 1fr;
    height: calc(100vh - var(--topbar-h));
  }
  .chat-history {
    position: fixed; top: var(--topbar-h); bottom: 0; left: -100%;
    width: 280px; z-index: 999;
    transition: left 0.22s ease;
  }
  .chat-history.open { left: 0; }

  /* Chat composer + thread */
  .chat-thread, .chat-empty, .chat-composer-inner, .composer-toolbar {
    max-width: 100%;
  }
  .chat-composer { padding: 10px 12px 14px; }

  /* Agent picker 1 cột */
  .agent-grid { grid-template-columns: 1fr; }

  /* Documents browser: gộp folders + list dọc */
  .docs-grid { grid-template-columns: 1fr; }
  .doc-folders {
    position: relative; top: auto;
    display: flex; gap: 4px; overflow-x: auto; padding: 6px;
  }
  .doc-folder { flex-shrink: 0; }

  /* Profile / KV table */
  .kv-table { grid-template-columns: 130px 1fr; }

  /* Stat grid 2 cột */
  .stat-grid { grid-template-columns: repeat(2, 1fr); }

  /* Login: stack dọc */
  .login-screen { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .login-left { padding: 24px; }
  .login-left h1 { font-size: 26px; }
  .login-left .stats { margin-top: 16px; }
  .login-right { padding: 24px; }

  /* Products table — scroll ngang */
  .tbl-wrap { overflow-x: auto; }
  .tbl { min-width: 700px; }
}

@media (max-width: 480px) {
  .login-left .stats { grid-template-columns: 1fr 1fr; }
  .login-left .stats .stat:last-child { display: none; }
  .stat-grid { grid-template-columns: 1fr; }
}
