/* UpRouter — hệ thống giao diện theo 9router (palette cam #E56A4A, nền ấm trung tính, Inter + Material Symbols).
   Bố cục & token màu tham chiếu 9router (github.com/decolua/9router, MIT). */

/* ============ tokens ============ */
:root, [data-theme="light"] {
  --brand-50: #fdf1ed; --brand-100: #fadccf; --brand-200: #f4b59c; --brand-300: #ee8d6a; --brand-400: #ea7855;
  --brand-500: #E56A4A; --brand-600: #cc5236; --brand-700: #a64027; --brand-800: #7a2f1d; --brand-900: #4d1e12;
  --primary: var(--brand-500); --primary-hover: var(--brand-600);
  --primary-soft: rgba(229, 106, 74, .10); --primary-text: var(--brand-600);

  --bg: #FDFAF6; --bg-alt: #F7F3EE;
  --surface: #ffffff; --surface-2: #f4f4f5; --surface-3: #e7e7e9;
  --vibrancy: rgba(255, 255, 255, .72);
  --border: #e5e7eb; --border-subtle: #f1f1f3;
  --text: #0a0a0a; --text-muted: #6B7280; --text-subtle: #9CA3AF;
  --hover: rgba(0, 0, 0, .05);

  --danger: #cf222e; --success: #10B981; --warning: #F59E0B; --info: #3B82F6;
  --c-green: #16a34a; --c-red: #dc2626; --c-yellow: #ca8a04; --c-blue: #2563eb; --c-amber: #d97706;
  --c-orange: #f97316; --c-pink: #db2777; --c-purple: #9333ea;

  --radius: 10px; --radius-lg: 14px;
  --shadow-soft: 0 1px 2px 0 rgba(0, 0, 0, .04);
  --shadow-warm: 0 2px 12px -2px rgba(229, 106, 74, .18);
  --shadow-elev: inset 0 1px 0 0 rgba(255, 255, 255, .8), 0 1px 2px rgba(15, 23, 42, .04), 0 12px 36px -8px rgba(15, 23, 42, .10);
  --focus: 0 0 0 3px rgba(229, 106, 74, .18);
  --grid-opacity: .08;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, monospace;

  /* bí danh cho các trang cũ */
  --panel: var(--surface); --panel-2: var(--surface-2); --bg-2: var(--surface-2); --line: var(--border);
  --muted: var(--text-muted); --faint: var(--text-subtle);
  --accent: var(--primary); --accent-2: var(--primary-text); --accent-soft: var(--primary-soft);
  --ok: var(--c-green); --warn: var(--c-yellow); --bad: var(--c-red);
  --ok-soft: rgba(34, 197, 94, .10); --warn-soft: rgba(234, 179, 8, .10); --bad-soft: rgba(239, 68, 68, .10);
  --info-soft: rgba(59, 130, 246, .10);
  --shadow: var(--shadow-elev);
  color-scheme: light;
}
[data-theme="dark"] {
  --primary: #E56A4A; --primary-hover: #cc5236; --primary-text: var(--brand-300);
  --bg: #1a1a1a; --bg-alt: #1F1F1E;
  --surface: #262626; --surface-2: #303030; --surface-3: #3a3a3a;
  --vibrancy: rgba(38, 38, 38, .72);
  --border: #333333; --border-subtle: #2a2a2a;
  --text: #ededed; --text-muted: #9ca3af; --text-subtle: #6b7280;
  --hover: rgba(255, 255, 255, .05);
  --danger: #ef4444; --success: #22c55e; --warning: #fbbf24; --info: #60a5fa;
  --c-green: #4ade80; --c-red: #f87171; --c-yellow: #facc15; --c-blue: #60a5fa; --c-amber: #fbbf24;
  --c-orange: #fb923c; --c-pink: #f472b6; --c-purple: #c084fc;
  --shadow-soft: 0 1px 2px 0 rgba(0, 0, 0, .3);
  --shadow-warm: 0 2px 12px -2px rgba(229, 106, 74, .25);
  --shadow-elev: inset 0 1px 0 0 rgba(255, 255, 255, .06), 0 1px 2px rgba(0, 0, 0, .4), 0 16px 48px -8px rgba(0, 0, 0, .55);
  --grid-opacity: .04;
  color-scheme: dark;
}

/* ============ base ============ */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
a { color: var(--primary); text-decoration: none; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
h1, h2, h3, h4, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { user-select: none; }
button:not(:disabled), [role="button"], label[for], summary, select { cursor: pointer; }
button:disabled { cursor: not-allowed; }
::selection { background: rgba(229, 106, 74, .3); color: var(--primary-text); }
input, textarea { accent-color: var(--primary); }
* { scrollbar-width: thin; scrollbar-color: rgba(120, 120, 120, .35) transparent; }
[data-theme="dark"] * { scrollbar-color: rgba(180, 180, 180, .3) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background-color: rgba(150, 150, 150, .35); border-radius: 9999px; border: 2px solid transparent; background-clip: padding-box; }
:focus-visible { outline: 2px solid rgba(229, 106, 74, .6); outline-offset: 2px; }

/* Material Symbols (font ligature) */
.ms { font-family: "Material Symbols Outlined"; font-weight: normal; font-style: normal; font-size: 18px; line-height: 1;
  letter-spacing: normal; text-transform: none; display: inline-block; white-space: nowrap; word-wrap: normal; direction: ltr;
  font-feature-settings: "liga"; -webkit-font-smoothing: antialiased; flex: none; user-select: none;
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24; opacity: 0; width: 1em; overflow: hidden; }
.fonts-loaded .ms { opacity: 1; transition: opacity .12s ease-out; }
.ms.fill { font-variation-settings: "FILL" 1, "wght" 400, "GRAD" 0, "opsz" 24; }
.ms.spin { animation: spin 1s linear infinite; }

/* ============ shell (sidebar + header + main) ============ */
.shell { display: flex; height: 100vh; width: 100%; overflow: hidden; background: var(--bg); }
.sidebar { width: 288px; flex: none; display: flex; flex-direction: column; min-height: 100%;
  border-right: 1px solid var(--border-subtle); background: var(--vibrancy); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px); }
.traffic { display: flex; align-items: center; gap: 8px; padding: 20px 24px 8px; }
.traffic i { width: 12px; height: 12px; border-radius: 50%; display: block; }
.traffic i:nth-child(1) { background: #FF5F56; } .traffic i:nth-child(2) { background: #FFBD2E; } .traffic i:nth-child(3) { background: #27C93F; }
.brand { padding: 16px 24px; display: flex; align-items: center; gap: 12px; color: var(--text); }
.brand .logo { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700)); box-shadow: var(--shadow-warm); flex: none; }
.brand .logo .ms { font-size: 20px; }
.brand-name { font-size: 18px; line-height: 28px; font-weight: 600; letter-spacing: -.025em; }
.brand-ver { font-size: 12px; line-height: 16px; color: var(--text-muted); }
.nav { flex: 1; padding: 8px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 4px 12px; min-height: 32px; border-radius: 8px;
  color: var(--text-muted); font-size: 13px; font-weight: 500; transition: background-color .15s, color .15s; }
.nav a .ms { font-size: 18px; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a:hover .ms { color: var(--primary); }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav a.active .ms { font-variation-settings: "FILL" 1, "wght" 400, "GRAD" 0, "opsz" 24; color: var(--primary); }
.nav .sep { padding: 12px 16px 0; margin: 8px 0 8px; font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-muted); opacity: .6; }
.nav .new { margin-left: auto; font-size: 10px; font-weight: 600; padding: 2px 6px; border-radius: 3px; background: rgba(34, 197, 94, .15); color: #4ade80; }

.main { position: relative; isolation: isolate; flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; }
.main::before { content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none; opacity: var(--grid-opacity);
  background-image: linear-gradient(to right, var(--primary) 1px, transparent 1px), linear-gradient(to bottom, var(--primary) 1px, transparent 1px);
  background-size: 40px 40px; }
.header { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 32px 8px;
  border-bottom: 1px solid var(--border-subtle); z-index: 20; }
.header .menu-btn { display: none; }
.head-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.head-title .t { display: flex; align-items: center; gap: 8px; }
.head-title .t .ms { color: var(--primary); font-size: 24px; }
.head-title h1 { font-size: 24px; line-height: 32px; font-weight: 600; letter-spacing: -.025em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-title p { font-size: 14px; line-height: 20px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.round-btn { width: 40px; height: 40px; border-radius: 9999px; border: 0; background: transparent; color: var(--text-muted);
  display: grid; place-items: center; transition: .15s; }
.round-btn:hover { background: var(--surface-2); color: var(--text); }
.round-btn .ms { font-size: 22px; }
.menu-wrap { position: relative; }
.dropdown { position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; background: var(--surface); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-elev); padding: 6px; z-index: 60; animation: slide-top .18s cubic-bezier(.22, 1, .36, 1); }
.dropdown button, .dropdown a { width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; border: 0;
  background: transparent; color: var(--text); font-size: 13px; text-align: left; }
.dropdown button:hover, .dropdown a:hover { background: var(--surface-2); }
.dropdown .ms { font-size: 18px; color: var(--text-muted); }
.content { flex: 1; overflow-y: auto; padding: 40px; }
.content.full { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.page { max-width: 1280px; margin-inline: auto; }
.content.full .page { max-width: none; flex: 1; width: 100%; height: 100%; }
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .2); z-index: 40; display: none; }

/* thanh công cụ của trang (pageHead cũ): tiêu đề nằm trên header chung */
.page-toolbar { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 24px; }
.stack { display: flex; flex-direction: column; gap: 32px; }
.stack > .card + .card { margin-top: 0; }

/* ============ components ============ */
.card { background: var(--surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); box-shadow: var(--shadow-soft); padding: 24px; min-width: 0; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card.elev { box-shadow: var(--shadow-elev); }
.card.hover { transition: box-shadow .15s, border-color .15s; cursor: pointer; }
.card.hover:hover { box-shadow: var(--shadow-warm); border-color: rgba(229, 106, 74, .3); }
.card.p-sm { padding: 16px; } .card.p-xs { padding: 12px; } .card.p-0 { padding: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head h2, .card-title { font-size: 18px; line-height: 28px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card-head h2 .ms, .card-title .ms { color: var(--primary); font-size: 24px; }
.card-head .sub { color: var(--text-muted); font-size: 13px; }
.section { padding: 16px; border-radius: var(--radius); background: var(--bg); border: 1px solid var(--border-subtle); }
.divider { border-top: 1px solid var(--border); margin: 16px 0; }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.two { grid-template-columns: 1.4fr 1fr; }
.stat .k { color: var(--text-muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.stat .v { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .s { color: var(--text-subtle); font-size: 12px; margin-top: 2px; }
.stat.accent { border-color: rgba(229, 106, 74, .4); }

/* nút: primary | secondary(mặc định) | outline | ghost | danger | success ; cỡ sm | md | lg */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 16px; border-radius: var(--radius);
  font-size: 14px; font-weight: 600; white-space: nowrap; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  transition: background-color .15s, border-color .15s, color .15s, transform .15s ease-out; }
.btn:hover { background: var(--surface-3); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn .ms { font-size: 18px; }
.btn.primary { background: var(--brand-500); border-color: transparent; color: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .1); }
.btn.primary:hover { background: var(--brand-600); }
.btn.outline { background: transparent; }
.btn.outline:hover { background: var(--surface-2); border-color: rgba(229, 106, 74, .4); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.white { background: #fff; color: #000; border-color: transparent; }
.btn.white:hover { background: #f3f4f6; }
.btn.danger { background: transparent; border-color: transparent; color: var(--danger); }
.btn.danger:hover { background: rgba(239, 68, 68, .1); }
.btn.primary.danger, .btn.solid-danger { background: #ef4444; color: #fff; border-color: transparent; }
.btn.primary.danger:hover, .btn.solid-danger:hover { background: #dc2626; }
.btn.success { background: #16a34a; color: #fff; border-color: transparent; }
.btn.success:hover { background: #15803d; }
.btn.sm { height: 28px; padding: 0 12px; font-size: 12px; border-radius: 8px; gap: 6px; }
.btn.sm .ms { font-size: 16px; }
.btn.lg { height: 44px; padding: 0 24px; }
.btn.icon { width: 36px; padding: 0; }
.btn.sm.icon { width: 28px; }
.btn.full { width: 100%; }
/* nút icon trơn (copy / xoá / ẩn hiện) */
.icon-btn { display: inline-grid; place-items: center; padding: 8px; border: 0; border-radius: 6px; background: transparent; color: var(--text-muted); transition: .15s; flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--primary); }
.icon-btn.xs { padding: 4px; } .icon-btn.xs .ms { font-size: 14px; }
.icon-btn.red { color: var(--danger); } .icon-btn.red:hover { background: rgba(239, 68, 68, .1); color: var(--danger); }

/* badge / pill */
.badge, .pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 9999px; font-weight: 600; white-space: nowrap;
  padding: 4px 10px; font-size: 12px; line-height: 16px; background: var(--surface-2); color: var(--text-muted); }
.badge.sm, .pill { padding: 2px 8px; font-size: 11px; }
.badge .dot, .pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge .dot { content: none; }
.pill.nodot::before { display: none; }
.badge.success, .pill.ok { background: rgba(34, 197, 94, .10); color: var(--c-green); }
.badge.warning, .pill.warn { background: rgba(234, 179, 8, .10); color: var(--c-yellow); }
.badge.error, .pill.bad { background: rgba(239, 68, 68, .10); color: var(--c-red); }
.badge.info, .pill.info { background: rgba(59, 130, 246, .10); color: var(--c-blue); }
.badge.primary, .pill.accent { background: var(--primary-soft); color: var(--primary-text); }
.badge.success .dot { background: #22c55e; } .badge.warning .dot { background: #eab308; } .badge.error .dot { background: #ef4444; }
.badge.info .dot { background: #3b82f6; } .badge.primary .dot { background: var(--brand-500); } .badge .dot { background: #6b7280; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); font-family: var(--mono); font-size: 12px;
  color: var(--text); max-width: 100%; overflow-wrap: anywhere; white-space: normal; }
.chip { display: inline-block; font-family: var(--mono); font-size: 12px; line-height: 16px; padding: 2px 6px; border-radius: 4px;
  background: var(--surface-2); color: var(--text-muted); text-align: center; flex: none; }
.chip.primary { background: var(--primary-soft); color: var(--primary); }

/* form */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; min-width: 0; }
.field label { font-size: 14px; font-weight: 500; color: var(--text); }
.field .hint { font-size: 12px; color: var(--text-muted); }
.input, select.input, textarea.input { width: 100%; padding: 10px 12px; font-size: 14px; line-height: 20px; color: var(--text); background: var(--surface-2);
  border: 1px solid transparent; border-radius: var(--radius); outline: none; transition: box-shadow .15s ease-out, border-color .15s ease-out; }
.input::placeholder { color: var(--text-muted); opacity: .7; }
.input:focus { border-color: rgba(229, 106, 74, .4); box-shadow: 0 0 0 2px rgba(229, 106, 74, .3); }
.input:disabled { opacity: .5; }
.input[readonly] { cursor: text; }
select.input { appearance: none; -webkit-appearance: none; padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px; }
[data-theme="dark"] select option { background: var(--surface); color: var(--text); }
textarea.input { resize: vertical; min-height: 80px; }
.input.mono { font-family: var(--mono); font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-subtle); }
.small { font-size: 12px; }
.right { text-align: right; }
.err-text { color: var(--c-red); }
.warn-text { color: var(--c-yellow); overflow-wrap: anywhere; }
.ok-text { color: var(--c-green); }

/* toggle (role=switch) — md: 44x24 thumb 20 ; sm: 32x16 thumb 12 */
.toggle { position: relative; display: inline-flex; flex: none; width: 44px; height: 24px; border-radius: 9999px; border: 0; padding: 0;
  background: var(--surface-3); transition: background-color .2s ease-in-out; }
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .15); transition: transform .2s ease-in-out; }
.toggle[aria-checked="true"] { background: var(--brand-500); }
.toggle[aria-checked="true"]::after { transform: translateX(20px); }
.toggle:focus-visible { outline: none; box-shadow: 0 0 0 2px rgba(229, 106, 74, .3); }
.toggle:disabled { opacity: .5; }
.toggle.sm { width: 32px; height: 16px; }
.toggle.sm::after { width: 12px; height: 12px; }
.toggle.sm[aria-checked="true"]::after { transform: translateX(16px); }
.toggle.lg { width: 56px; height: 28px; }
.toggle.lg::after { width: 24px; height: 24px; }
.toggle.lg[aria-checked="true"]::after { transform: translateX(28px); }
.switch-row { display: flex; align-items: center; gap: 12px; }

/* segmented control / tabs */
.seg, .tabs { display: inline-flex; align-items: center; padding: 4px; border-radius: var(--radius); background: var(--surface-2); overflow-x: auto; max-width: 100%; gap: 0; }
.seg button, .tabs button { flex: none; height: 36px; padding: 0 16px; border-radius: 8px; border: 0; background: transparent; color: var(--text-muted);
  font-size: 14px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; transition: .15s; }
.seg.sm button, .tabs button { height: 28px; font-size: 12px; padding: 0 12px; }
.seg button:hover, .tabs button:hover { color: var(--text); }
.seg button.active, .tabs button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .15); }
.seg button .ms { font-size: 16px; }

/* bảng */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em;
  padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--border-subtle); vertical-align: middle; }
.tbl tbody tr:hover td { background: rgba(127, 127, 127, .04); }
.tbl tr:last-child td { border-bottom: none; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl-wrap { overflow-x: auto; }
.empty { padding: 32px; text-align: center; color: var(--text-muted); }
.empty-state { text-align: center; padding: 48px 16px; }
.empty-state .ring { display: inline-grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); margin-bottom: 16px; }
.empty-state .ring .ms { font-size: 32px; }
.empty-state b { display: block; font-weight: 500; margin-bottom: 4px; }
.empty-state p { font-size: 14px; color: var(--text-muted); margin-bottom: 16px; }
.dashed { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 8px; border: 1px dashed var(--border); border-radius: 12px;
  color: var(--text-muted); font-size: 14px; }

.copy { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: var(--radius); padding: 6px 6px 6px 12px; min-width: 0; }
.copy code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
pre.code { background: var(--surface-2); border: 1px solid var(--border-subtle); border-radius: var(--radius); padding: 14px; overflow-x: auto;
  font: 12.5px/1.6 var(--mono); margin: 0; }
.callout { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); font-size: 13px; }
.callout.warn { border-color: rgba(245, 158, 11, .4); background: rgba(245, 158, 11, .06); color: var(--c-amber); }
.callout.bad { border-color: rgba(239, 68, 68, .4); background: rgba(239, 68, 68, .06); color: var(--c-red); }
.callout.info { border-color: rgba(59, 130, 246, .4); background: rgba(59, 130, 246, .06); color: var(--c-blue); }
.spin { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes slide-top { from { transform: translateY(-10px); opacity: 0; } }
.tip { position: relative; display: inline-flex; align-items: center; }
.tip > .ms { font-size: 14px; color: var(--text-muted); cursor: help; }
.tip .tip-text { pointer-events: none; position: absolute; left: 20px; top: 50%; transform: translateY(-50%); z-index: 50; width: 256px;
  border-radius: 4px; background: #1f2937; color: #fff; font-size: 12px; line-height: 1.4; padding: 6px 10px; opacity: 0; transition: opacity .15s; box-shadow: var(--shadow-elev); }
.tip:hover .tip-text { opacity: 1; }
.progress { height: 6px; border-radius: 9999px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 9999px; background: #22c55e; transition: width .3s; }
.progress > i.warn { background: #eab308; } .progress > i.bad { background: #ef4444; }

/* ============ modal (có đèn giao thông kiểu macOS) / toast / login ============ */
.overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.overlay::before { content: ""; position: absolute; inset: 0; background: rgba(0, 0, 0, .5); backdrop-filter: blur(2px); animation: fade .2s ease-out; }
.modal { position: relative; width: 100%; max-width: 520px; max-height: calc(100dvh - 32px); display: flex; flex-direction: column; background: var(--surface);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); box-shadow: var(--shadow-elev); animation: fade .2s ease-out; }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 8px; border-bottom: 1px solid var(--border-subtle); }
.modal-head .lights { display: flex; align-items: center; gap: 8px; margin: 0 16px 0 8px; }
.modal-head .lights button, .modal-head .lights i { width: 16px; height: 16px; border-radius: 50%; border: 0; padding: 0; display: grid; place-items: center; }
.modal-head .lights button { background: #FF5F56; color: #fff; font-size: 9px; font-weight: 700; line-height: 1; }
.modal-head .lights button span { opacity: 0; transition: opacity .15s; }
.modal-head .lights button:hover span { opacity: 1; }
.modal-head .lights i { background: rgba(255, 255, 255, .15); }
[data-theme="light"] .modal-head .lights i { background: rgba(58, 58, 58, .2); }
.modal-head h3 { font-size: 18px; line-height: 28px; font-weight: 600; }
.modal-head .x { display: none; }
.modal-body { padding: 24px; overflow-y: auto; min-width: 0; overflow-wrap: anywhere; }
.modal-foot { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 16px 24px; border-top: 1px solid var(--border-subtle); flex-wrap: wrap; }
#toasts { position: fixed; top: 16px; right: 16px; z-index: 80; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 380px); }
.toast { display: flex; align-items: flex-start; gap: 8px; border-radius: 8px; border: 1px solid rgba(34, 197, 94, .3); background: rgba(34, 197, 94, .1);
  color: var(--c-green); padding: 8px 12px; box-shadow: 0 10px 15px -3px rgba(0, 0, 0, .2); backdrop-filter: blur(6px); font-size: 12px; line-height: 16px;
  animation: slide-top .18s cubic-bezier(.22, 1, .36, 1); white-space: pre-wrap; word-break: break-word; }
.toast .ms { font-size: 18px; line-height: 20px; }
.toast.error { border-color: rgba(239, 68, 68, .3); background: rgba(239, 68, 68, .1); color: var(--c-red); }
.toast.warning { border-color: rgba(245, 158, 11, .3); background: rgba(245, 158, 11, .1); color: var(--c-amber); }
.toast.info { border-color: rgba(59, 130, 246, .3); background: rgba(59, 130, 246, .1); color: var(--c-blue); }
[data-theme="dark"] .toast { background-color: rgba(38, 38, 38, .85); background-image: linear-gradient(rgba(34, 197, 94, .1), rgba(34, 197, 94, .1)); }
[data-theme="dark"] .toast.error { background-image: linear-gradient(rgba(239, 68, 68, .1), rgba(239, 68, 68, .1)); }
[data-theme="dark"] .toast.warning { background-image: linear-gradient(rgba(245, 158, 11, .1), rgba(245, 158, 11, .1)); }
[data-theme="dark"] .toast.info { background-image: linear-gradient(rgba(59, 130, 246, .1), rgba(59, 130, 246, .1)); }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--bg);
  background-image: radial-gradient(circle at 15% 20%, rgba(229, 106, 74, .18) 0%, transparent 40%), radial-gradient(circle at 85% 80%, rgba(229, 106, 74, .10) 0%, transparent 40%); }
.login .card { width: min(400px, 100%); padding: 32px; box-shadow: var(--shadow-elev); }
.login .brand { padding: 0 0 20px; }
.login h1 { font-size: 22px; font-weight: 600; letter-spacing: -.02em; margin-bottom: 4px; }
.steps { counter-reset: s; display: grid; gap: 12px; padding: 0; margin: 0; list-style: none; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 28px 1fr; gap: 10px; }
.steps li::before { content: counter(s); width: 24px; height: 24px; border-radius: 7px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 12px; }

/* ============ trang cũ giữ lại: combo / chart / flow / chat / test API ============ */
.chain { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chain .arrow { color: var(--text-subtle); }
.chain-edit { display: grid; gap: 8px; }
.chain-item { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: var(--radius); padding: 6px 8px 6px 12px; }
.chain-item .idx { width: 20px; height: 20px; border-radius: 6px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.chart { width: 100%; height: 220px; display: block; }
.chart .bar { fill: var(--primary); opacity: .85; }
.chart .bar:hover { opacity: 1; }
.chart .bar2 { fill: #60a5fa; opacity: .7; }
.chart .axis { fill: var(--text-subtle); font-size: 10.5px; font-family: var(--font); }
.chart .gridline { stroke: var(--border); stroke-dasharray: 3 3; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 180px) 1fr 70px; gap: 10px; align-items: center; font-size: 12.5px; padding: 5px 0; }
.hbar .track { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--primary); border-radius: 99px; }
.hbar .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flow { width: 100%; height: auto; display: block; }
.fg-edge { fill: none; stroke: var(--border); stroke-width: 2; stroke-dasharray: 5 7; opacity: .7; }
.fg-edge.active { stroke: var(--primary); stroke-width: 2.6; opacity: 1; animation: fg-flow .6s linear infinite; }
@keyframes fg-flow { to { stroke-dashoffset: -24; } }
.fg-box { fill: var(--surface-2); stroke: var(--border); stroke-width: 1.5; }
.fg-label { fill: var(--text); font: 600 12px var(--font); }
.fg-sub { fill: var(--text-muted); font: 10px var(--font); }
.fg-node.core .fg-box { fill: var(--surface); stroke: var(--text-subtle); }
.fg-node.on .fg-box { stroke: var(--primary); }
.fg-node.core.on .fg-box { stroke: var(--primary); stroke-width: 2.5; }
.fg-node.on .fg-label { fill: var(--primary); }

.chat { display: grid; grid-template-columns: 270px 1fr; height: 100%; min-height: 0; }
.chat-side { border-right: 1px solid var(--border-subtle); background: var(--vibrancy); display: flex; flex-direction: column; min-height: 0; }
.chat-side .top { padding: 16px 12px 10px; display: grid; gap: 10px; }
.chat-list { overflow-y: auto; padding: 4px 8px 16px; flex: 1; }
.chat-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--text-muted); }
.chat-item:hover, .chat-item.active { background: var(--surface-2); color: var(--text); }
.chat-item .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.chat-item .src { font-size: 13px; }
.chat-item .del { opacity: 0; }
.chat-item:hover .del { opacity: 1; }
.chat-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-bottom: 1px solid var(--border-subtle); }
.chat-head .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msgs { flex: 1; overflow-y: auto; padding: 24px 0; }
.msg { max-width: 820px; margin: 0 auto 18px; padding: 0 24px; display: flex; gap: 12px; }
.msg .av { width: 30px; height: 30px; border-radius: 8px; flex: none; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.msg.user .av { background: var(--surface-2); color: var(--text-muted); }
.msg.assistant .av { background: linear-gradient(135deg, var(--brand-500), var(--brand-700)); color: #fff; }
.msg .body { min-width: 0; flex: 1; }
.msg .meta { font-size: 11.5px; color: var(--text-subtle); margin-top: 6px; display: flex; gap: 10px; flex-wrap: wrap; }
.msg.user .bubble { background: var(--surface); border: 1px solid var(--border-subtle); border-radius: 12px; padding: 10px 14px; display: inline-block; white-space: pre-wrap; word-break: break-word; }
.md { word-break: break-word; }
.md p { margin: 0 0 10px; } .md p:last-child { margin-bottom: 0; }
.md pre { background: var(--surface-2); border-radius: var(--radius); padding: 12px; overflow-x: auto; }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; } .md td, .md th { border: 1px solid var(--border); padding: 5px 9px; }
.md ul, .md ol { padding-left: 22px; margin: 0 0 10px; }
.md a { text-decoration: underline; }
.cursor::after { content: "▌"; color: var(--primary); animation: blink 1s steps(2) infinite; margin-left: 2px; }
@keyframes blink { 50% { opacity: 0; } }
.composer { padding: 12px 24px 20px; }
.composer .box { max-width: 820px; margin: 0 auto; background: var(--surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); padding: 10px 10px 10px 14px; display: flex; gap: 10px; align-items: flex-end; box-shadow: var(--shadow-soft); }
.composer .box:focus-within { border-color: rgba(229, 106, 74, .4); box-shadow: var(--focus); }
.composer textarea { flex: 1; border: 0; outline: 0; background: transparent; resize: none; max-height: 220px; min-height: 24px; padding: 6px 0; }
.composer .note { max-width: 820px; margin: 6px auto 0; font-size: 11.5px; color: var(--text-subtle); text-align: center; }
.welcome { max-width: 640px; margin: 10vh auto 0; text-align: center; padding: 0 24px; }
.welcome h2 { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.welcome p { color: var(--text-muted); margin-top: 8px; }
.suggest { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 26px; }
.suggest button { text-align: left; padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border-subtle); color: var(--text-muted); }
.suggest button:hover { border-color: rgba(229, 106, 74, .4); color: var(--text); }

.att-list { display: grid; gap: 8px; margin: 10px 0 4px; }
.att { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius); background: var(--surface-2); min-width: 0; }
.att img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; flex: none; }
.att audio { height: 32px; max-width: 220px; flex: none; }
.att .att-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-on { color: var(--danger); border-color: var(--danger); }
.rec-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); display: inline-block; animation: rec-blink 1s steps(2) infinite; }
@keyframes rec-blink { 50% { opacity: .2; } }
.speed-table td, .speed-table th { padding: 6px 8px; }
.speed-sum { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 10px 0; }
.request-timer { color: var(--c-blue); font: 13px var(--mono); font-variant-numeric: tabular-nums; padding-block: 6px; }
.request-timer[data-state="done"] { color: var(--c-green); }
.request-timer[data-state="stopped"] { color: var(--c-yellow); }
summary { color: var(--text-muted); padding: 8px 0; }

/* ============ responsive ============ */
.mobile-only { display: none !important; }
@media (max-width: 1023px) {
  .shell > .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 50; transform: translateX(-100%); transition: transform .3s ease-in-out; background: var(--surface); }
  .shell.nav-open > .sidebar { transform: none; }
  .shell.nav-open .backdrop { display: block; }
  .header { padding: 12px 16px 8px; background: color-mix(in srgb, var(--surface) 60%, transparent); backdrop-filter: blur(24px); }
  .header .menu-btn { display: grid; }
  .head-title h1 { font-size: 16px; line-height: 24px; }
  .head-title p { display: none; }
  .content { padding: 24px; }
  .two { grid-template-columns: 1fr; }
  .mobile-only { display: inline-flex !important; }
}
@media (max-width: 640px) {
  .content { padding: 16px; }
  .card { padding: 16px; }
  .chat { grid-template-columns: 1fr; }
  .chat-side { display: none; }
  .chat.show-side .chat-side { display: flex; position: fixed; inset: 57px 0 0 0; z-index: 20; background: var(--surface); }
  .msg { padding: 0 16px; }
  .composer { padding: 10px 12px 14px; }
  .suggest { grid-template-columns: 1fr; }
  .hbar { grid-template-columns: 90px 1fr 56px; }
  .input, textarea, select { font-size: 16px; }
  .modal .grid { grid-template-columns: minmax(0, 1fr) !important; }
  .modal-head .lights { display: none; }
  .modal-head .x { display: grid; }
  .modal-head h3 { padding-left: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
