/* TrungKienHa Command Center. Lớp giao diện độc lập, giữ nguyên renderer nghiệp vụ cũ. */
:root {
  --tkh-bg: #050a12;
  --tkh-surface: rgba(10, 22, 34, 0.82);
  --tkh-surface-strong: #0b1622;
  --tkh-line: rgba(86, 218, 255, 0.16);
  --tkh-cyan: #5bdcff;
  --tkh-cyan-soft: rgba(91, 220, 255, 0.12);
  --tkh-orange: #ff9b5e;
  --tkh-text: #edf9ff;
  --tkh-muted: #8ba7b7;
  --tkh-radius: 18px;
  --bg: var(--tkh-bg);
  --bg2: #08111b;
  --bg3: #0b1824;
  --border: #173244;
  --accent: var(--tkh-orange);
  --accent2: var(--tkh-cyan);
  --text: var(--tkh-text);
  --text2: #b5cbd6;
  --text3: var(--tkh-muted);
  --green: #53e6ac;
  --panel-bg: var(--tkh-surface);
  --panel-solid: #08131e;
  --hairline: var(--tkh-line);
  --field-bg: rgba(6, 16, 25, 0.92);
  --accent2-wash: var(--tkh-cyan-soft);
  --accent2-line: rgba(91, 220, 255, 0.36);
  --link-ink: #8ee7ff;
}

:root[data-theme="light"] {
  --tkh-bg: #f3f8fb;
  --tkh-surface: rgba(255, 255, 255, 0.88);
  --tkh-surface-strong: #ffffff;
  --tkh-line: rgba(20, 108, 134, 0.18);
  --tkh-cyan: #087c9c;
  --tkh-cyan-soft: rgba(8, 124, 156, 0.09);
  --tkh-orange: #c95f1e;
  --tkh-text: #122631;
  --tkh-muted: #527080;
  --bg: var(--tkh-bg);
  --bg2: #ffffff;
  --bg3: #e8f1f5;
  --border: #c7dce5;
  --accent: var(--tkh-orange);
  --accent2: var(--tkh-cyan);
  --text: var(--tkh-text);
  --text2: #355361;
  --text3: var(--tkh-muted);
  --green: #167854;
  --panel-bg: var(--tkh-surface);
  --panel-solid: #ffffff;
  --hairline: var(--tkh-line);
  --field-bg: rgba(255, 255, 255, 0.96);
  --accent2-wash: var(--tkh-cyan-soft);
  --accent2-line: rgba(8, 124, 156, 0.30);
  --link-ink: #086b87;
}

html, body { background: var(--tkh-bg); }
.skip-link { position: fixed; left: 14px; top: -60px; z-index: 10000; padding: 10px 14px; color: #041018; background: var(--tkh-cyan); border-radius: 8px; font-weight: 700; transition: top .16s ease; }
.skip-link:focus { top: 12px; }
:is(button,a,input,textarea,select,[tabindex]):focus-visible { outline: 2px solid var(--tkh-cyan) !important; outline-offset: 3px; }
body.tkh-command-center {
  color: var(--tkh-text);
  background:
    radial-gradient(circle at 72% 12%, rgba(24, 133, 171, 0.12), transparent 32%),
    radial-gradient(circle at 18% 82%, rgba(255, 135, 72, 0.06), transparent 26%),
    var(--tkh-bg);
}
body.tkh-command-center::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .16;
  background-image: linear-gradient(var(--tkh-line) 1px, transparent 1px), linear-gradient(90deg, var(--tkh-line) 1px, transparent 1px);
  background-size: 52px 52px;
  mask-image: linear-gradient(to bottom, black, transparent 86%);
}
.brand-mode { margin-left: 9px; color: var(--tkh-muted); font-size: 9px; letter-spacing: .18em; }
.hud-top, .rail { background: rgba(5, 12, 20, .9); border-color: var(--tkh-line); backdrop-filter: blur(18px); }
.rail { box-shadow: 14px 0 50px rgba(0,0,0,.16); }
.rail-brand img { box-shadow: 0 0 18px rgba(91,220,255,.22); }
.rail-grp-lbl { color: #6f8c9c; font: 700 10px/1.2 var(--mono); letter-spacing: .08em; }
.rail-item { border-radius: 9px; color: #91aebd; }
.rail-item:hover { color: var(--tkh-text); background: rgba(91,220,255,.06); }
.rail-item.active { color: #c9f5ff; background: linear-gradient(90deg, rgba(91,220,255,.15), rgba(91,220,255,.035)); }
.rail-item.active::before { background: var(--tkh-cyan); box-shadow: 0 0 13px var(--tkh-cyan); }
.cview { background: radial-gradient(circle at 85% 5%, rgba(26,120,151,.1), transparent 28%), var(--tkh-bg); }
.cview-head { min-height: 78px; padding: 18px 28px; border-color: var(--tkh-line); background: rgba(7,16,25,.86); backdrop-filter: blur(16px); }
.cview-title { color: var(--tkh-text); letter-spacing: -.015em; }
.cview-title .ico { color: var(--tkh-cyan); }
.cview-body { padding: 26px 30px; }
.cview-body :is(.si-card,.kn-panel,.set-sec,.acc-card,.model-card,.conn-card,.studio-card) { border-color: var(--tkh-line); background: linear-gradient(145deg, rgba(12,27,41,.88), rgba(7,17,27,.74)); border-radius: 14px; box-shadow: none; }
.cview-body :is(input,textarea,select) { border-color: #1d3b4d; background: rgba(5,14,23,.9); }
.cview-body :is(input,textarea,select):focus { outline: 2px solid rgba(91,220,255,.35); outline-offset: 1px; border-color: var(--tkh-cyan); }
.cview-body :is(.s-btn,.primary) { border-color: rgba(255,155,94,.42); background: rgba(255,155,94,.14); color: #ffd4bc; }
.notification-panel, .settings-modal, .folder-modal, .studio-editor .editor-box, .run-drawer { background: #07131e; border-color: var(--tkh-line); }
.theme-menu {
  position: fixed;
  z-index: 10020;
  top: 58px;
  right: 118px;
  width: min(220px, calc(100vw - 28px));
  display: grid;
  gap: 4px;
  padding: 7px;
  border: 1px solid var(--tkh-line);
  border-radius: 13px;
  background: var(--panel-solid);
  box-shadow: 0 18px 48px rgba(0, 0, 0, .24);
}
.theme-menu[hidden] { display: none; }
.theme-menu button {
  min-height: 42px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 18px;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--text2);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.theme-menu button:hover { color: var(--text); background: var(--tkh-cyan-soft); }
.theme-menu button:focus-visible { outline: 2px solid var(--tkh-cyan); outline-offset: 1px; }
.theme-menu button[aria-checked="true"] { color: var(--tkh-cyan); border-color: var(--tkh-line); background: var(--tkh-cyan-soft); }
.theme-menu-check { opacity: 0; font-weight: 800; }
.theme-menu button[aria-checked="true"] .theme-menu-check { opacity: 1; }
.theme-menu-icon { text-align: center; font-size: 17px; }
.tkh-dashboard {
  position: absolute;
  inset: var(--top-h, 54px) 0 112px 0;
  overflow: auto;
  padding: 30px 34px 42px calc(72px + 34px);
  z-index: 2;
}
.tkh-dash-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin: 0 0 24px; }
.tkh-eyebrow, .tkh-panel-kicker { color: var(--tkh-cyan); font: 700 10px/1.3 var(--mono); letter-spacing: .18em; }
.tkh-dash-head h1 { margin: 5px 0 6px; font-size: clamp(24px, 3vw, 38px); letter-spacing: -.035em; }
.tkh-dash-intro { color: var(--tkh-muted); margin: 0; font-size: 14px; }
.tkh-live { display: grid; grid-template-columns: 9px auto; column-gap: 9px; align-items: center; color: #c8f7e5; font-size: 12px; }
.tkh-live > span { width: 8px; height: 8px; border-radius: 50%; background: #53e6ac; box-shadow: 0 0 14px #53e6ac; grid-row: 1 / 3; }
.tkh-live small { color: var(--tkh-muted); }
.tkh-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.tkh-kpi, .tkh-panel, .tkh-presence {
  border: 1px solid var(--tkh-line);
  background: linear-gradient(145deg, rgba(12, 27, 41, .9), rgba(6, 16, 25, .78));
  border-radius: var(--tkh-radius);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.025), 0 18px 48px rgba(0,0,0,.18);
}
.tkh-kpi { padding: 17px 18px; min-height: 104px; display: flex; flex-direction: column; }
.tkh-kpi > span { color: var(--tkh-muted); font-size: 12px; }
.tkh-kpi strong { margin: auto 0 7px; font-size: clamp(17px, 2vw, 24px); font-weight: 650; }
.tkh-kpi small { color: #607b8a; font-size: 10px; }
.tkh-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(270px, .72fr) minmax(0, .9fr); gap: 14px; }
.tkh-panel { min-height: 232px; padding: 18px; }
.tkh-panel-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; padding-bottom: 14px; border-bottom: 1px solid var(--tkh-line); }
.tkh-panel h2 { font-size: 16px; margin: 4px 0 0; }
.tkh-panel button, .tkh-presence button { border: 1px solid rgba(91,220,255,.24); background: var(--tkh-cyan-soft); color: #bfefff; border-radius: 9px; padding: 7px 10px; cursor: pointer; }
.tkh-panel button:hover, .tkh-presence button:hover { border-color: var(--tkh-cyan); background: rgba(91,220,255,.18); }
.tkh-list { display: grid; gap: 8px; padding-top: 12px; }
.tkh-empty { min-height: 105px; display: grid; place-items: center; color: var(--tkh-muted); font-size: 12px; text-align: center; }
.tkh-row { display: grid; grid-template-columns: 28px minmax(0,1fr); align-items: center; gap: 10px; min-height: 48px; padding: 8px 9px; border: 1px solid rgba(91,220,255,.08); border-radius: 10px; background: rgba(91,220,255,.025); }
.tkh-row b, .tkh-row small { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tkh-row b { font-size: 12px; font-weight: 600; }
.tkh-row small { color: var(--tkh-muted); font-size: 10px; margin-top: 3px; }
.tkh-status { width: 9px; height: 9px; border-radius: 50%; margin-left: 8px; background: #78909c; box-shadow: 0 0 10px currentColor; }
.tkh-status.running { background: var(--tkh-cyan); }
.tkh-status.blocked, .tkh-status.review { background: var(--tkh-orange); }
.tkh-avatar { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; color: #bff3ff; background: var(--tkh-cyan-soft); border: 1px solid rgba(91,220,255,.2); font: 700 11px var(--mono); }
.tkh-project-mark { width: 22px; height: 22px; margin-left: 3px; border: 1px solid var(--tkh-cyan); border-radius: 5px; transform: rotate(45deg); }
.tkh-alert-mark { width: 25px; height: 25px; display: grid; place-items: center; border-radius: 50%; color: #ffd1b6; border: 1px solid rgba(255,155,94,.35); background: rgba(255,155,94,.1); font-weight: 800; }
.tkh-row.warning { border-color: rgba(255,155,94,.13); background: rgba(255,155,94,.035); }
.tkh-presence { grid-row: span 2; min-height: 478px; padding: 18px; position: relative; overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.tkh-presence::before { content: ""; position: absolute; inset: 9% 10%; border-radius: 50%; background: radial-gradient(circle, rgba(91,220,255,.13), transparent 66%); filter: blur(10px); }
.tkh-hologram-placeholder { width: 190px; height: 270px; position: relative; filter: drop-shadow(0 0 20px rgba(91,220,255,.38)); }
.tkh-holo-head { position: absolute; width: 61px; height: 75px; top: 15px; left: 65px; border-radius: 46% 46% 40% 40%; border: 1px solid rgba(131,235,255,.72); background: radial-gradient(circle at 50% 45%, rgba(129,234,255,.25), rgba(23,98,126,.08) 63%, transparent 64%); }
.tkh-holo-body { position: absolute; width: 158px; height: 178px; left: 16px; top: 84px; border-radius: 45% 45% 22% 22%; border: 1px solid rgba(91,220,255,.5); clip-path: polygon(29% 0,71% 0,100% 34%,83% 100%,17% 100%,0 34%); background: repeating-linear-gradient(100deg, transparent 0 6px, rgba(91,220,255,.11) 7px 8px); }
.tkh-holo-core { position: absolute; z-index: 2; width: 34px; height: 34px; left: 78px; top: 126px; border-radius: 50%; background: radial-gradient(circle, #fff2df 0 9%, var(--tkh-orange) 18%, rgba(255,132,62,.25) 48%, transparent 70%); box-shadow: 0 0 24px var(--tkh-orange); }
.tkh-holo-ring { position: absolute; inset: 0; border: 1px solid rgba(91,220,255,.2); border-radius: 50%; transform: rotateX(68deg); animation: tkh-orbit 8s linear infinite; }
.tkh-presence[data-assistant-state="listening"] .tkh-hologram-placeholder { filter: drop-shadow(0 0 30px rgba(91,220,255,.75)); }
.tkh-presence[data-assistant-state="processing"] .tkh-holo-ring { animation-duration: 1.8s; border-color: rgba(91,220,255,.62); }
.tkh-presence[data-assistant-state="processing"] .tkh-holo-core { animation: tkh-core-pulse 1.1s ease-in-out infinite; }
.tkh-presence[data-assistant-state="speaking"] .tkh-holo-core { animation: tkh-core-speak .55s ease-in-out infinite alternate; }
.tkh-presence[data-assistant-state="approval-required"] { border-color: rgba(255,155,94,.55); }
.tkh-presence[data-assistant-state="approval-required"] .tkh-hologram-placeholder { filter: drop-shadow(0 0 28px rgba(255,155,94,.45)); }
.tkh-presence[data-assistant-state="error"] { border-color: rgba(244,86,90,.58); }
.tkh-presence[data-assistant-state="error"] .tkh-hologram-placeholder { filter: grayscale(.45) drop-shadow(0 0 20px rgba(244,86,90,.5)); }
.tkh-presence-copy { position: relative; z-index: 2; text-align: center; }
.tkh-presence-copy span { color: var(--tkh-cyan); font: 700 11px/1 var(--mono); letter-spacing: .2em; }
.tkh-presence-copy p { color: var(--tkh-muted); font-size: 12px; line-height: 1.55; max-width: 220px; }
.tkh-agents { grid-column: 1; }
.tkh-projects { grid-column: 3; }
.tkh-command-center .hud-body { visibility: hidden; pointer-events: none; }
.tkh-command-center.on-chat .hud-body { visibility: visible; pointer-events: auto; }
.tkh-command-center .hud-voice, .tkh-command-center .model-bar, .tkh-command-center .attach-bar, .tkh-command-center .bg-strip { z-index: 9; }
@keyframes tkh-orbit { to { transform: rotateX(68deg) rotateZ(360deg); } }
@keyframes tkh-core-pulse { 50% { transform: scale(1.18); opacity: .82; } }
@keyframes tkh-core-speak { to { transform: scale(1.28); box-shadow: 0 0 38px var(--tkh-orange); } }

@media (max-width: 1200px) {
  .tkh-grid { grid-template-columns: minmax(0, 1.25fr) minmax(250px, .75fr); }
  .tkh-presence { grid-column: 2; grid-row: 1 / 3; }
  .tkh-decisions, .tkh-projects { grid-column: 1; }
  .tkh-agents { grid-column: 1; }
}
@media (max-width: 900px) {
  .tkh-dashboard { padding: 24px 20px 150px 82px; }
  .tkh-kpis { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .tkh-grid { grid-template-columns: 1fr; }
  .tkh-presence, .tkh-decisions, .tkh-agents, .tkh-projects { grid-column: 1; grid-row: auto; }
  .tkh-presence { min-height: 390px; }
}
@media (max-width: 600px) {
  .brand-mode { display: none; }
  .theme-menu { top: 58px; right: 14px; }
  .tkh-dashboard { inset: var(--top-h, 54px) 0 116px; padding: 18px 14px 140px; }
  .tkh-dash-head { align-items: flex-start; flex-direction: column; gap: 14px; }
  .tkh-kpis { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 5px; }
  .tkh-kpi { min-width: 72vw; scroll-snap-align: start; }
  .tkh-presence { min-height: 330px; }
  .tkh-hologram-placeholder { transform: scale(.78); margin: -24px 0; }
}

/* Lớp TKH nạp sau design system gốc, nên các override sáng ở đây phải phủ những
   bề mặt Command Center đã cố ý làm tối. Các trang nghiệp vụ còn lại dùng token chung. */
:root[data-theme="light"] body.tkh-command-center {
  background:
    radial-gradient(circle at 72% 12%, rgba(8, 124, 156, .08), transparent 32%),
    radial-gradient(circle at 18% 82%, rgba(201, 95, 30, .05), transparent 26%),
    var(--tkh-bg);
}
:root[data-theme="light"] body.tkh-command-center::before { opacity: .22; }
:root[data-theme="light"] .hud-top,
:root[data-theme="light"] .rail { background: rgba(255, 255, 255, .90); }
:root[data-theme="light"] .rail { box-shadow: 14px 0 42px rgba(35, 75, 92, .10); }
:root[data-theme="light"] .rail-grp-lbl { color: #5a7481; }
:root[data-theme="light"] .rail-item { color: #496775; }
:root[data-theme="light"] .rail-item:hover { color: var(--tkh-text); background: var(--tkh-cyan-soft); }
:root[data-theme="light"] .rail-item.active { color: #075f78; background: linear-gradient(90deg, rgba(8,124,156,.14), rgba(8,124,156,.035)); }
:root[data-theme="light"] .cview { background: radial-gradient(circle at 85% 5%, rgba(8,124,156,.06), transparent 28%), var(--tkh-bg); }
:root[data-theme="light"] .cview-head { background: rgba(255,255,255,.88); }
:root[data-theme="light"] .cview-body :is(.si-card,.kn-panel,.set-sec,.acc-card,.model-card,.conn-card,.studio-card),
:root[data-theme="light"] .tkh-kpi,
:root[data-theme="light"] .tkh-panel,
:root[data-theme="light"] .tkh-presence { background: linear-gradient(145deg, rgba(255,255,255,.98), rgba(235,245,249,.88)); box-shadow: 0 18px 42px rgba(35,75,92,.09); }
:root[data-theme="light"] .cview-body :is(input,textarea,select) { border-color: #bfd6df; background: var(--field-bg); }
:root[data-theme="light"] .cview-body :is(.s-btn,.primary) { border-color: rgba(201,95,30,.34); background: rgba(201,95,30,.09); color: #8e3b0d; }
:root[data-theme="light"] .notification-panel,
:root[data-theme="light"] .settings-modal,
:root[data-theme="light"] .folder-modal,
:root[data-theme="light"] .studio-editor .editor-box,
:root[data-theme="light"] .run-drawer { background: var(--panel-solid); }
:root[data-theme="light"] .tkh-live { color: #146b4e; }
:root[data-theme="light"] .tkh-live > span { background: #1b9168; box-shadow: 0 0 10px rgba(27,145,104,.45); }
:root[data-theme="light"] .tkh-kpi small { color: #607d8a; }
:root[data-theme="light"] .tkh-panel button,
:root[data-theme="light"] .tkh-presence button { color: #075f78; border-color: rgba(8,124,156,.24); background: var(--tkh-cyan-soft); }
:root[data-theme="light"] .tkh-row { border-color: rgba(8,124,156,.10); background: rgba(8,124,156,.035); }
:root[data-theme="light"] .tkh-avatar { color: #075f78; border-color: rgba(8,124,156,.22); }
:root[data-theme="light"] .tkh-alert-mark { color: #964414; }
@media (prefers-reduced-motion: reduce) {
  .tkh-holo-ring, .tkh-holo-core { animation: none !important; }
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
