/* ============================================================================
   PHÒNG AI 3D — GIA ĐÌNH TUỆ AN (care.namdung.com/ai-office)
   Thiết kế Hybrid Lite 3D: Mượt trên cả Máy tính & Điện thoại dọc (0 KB trên trang chính)
   ============================================================================ */

:root {
  --bg-deep: #060e1a;
  --bg-panel: rgba(10, 22, 40, 0.82);
  --bg-panel-strong: rgba(8, 17, 32, 0.94);
  --border-glass: rgba(94, 234, 212, 0.24);
  --teal-400: #2dd4bf;
  --teal-500: #14b8a6;
  --cyan-400: #38bdf8;
  --amber-400: #fbbf24;
  --rose-400: #fb7185;
  --emerald-400: #34d399;
  --violet-400: #a78bfa;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 35%, #0d223a 0%, #050b14 78%);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  user-select: none;
}

.hidden {
  display: none !important;
}

/* ==================== MÀN CHỜ XÁC THỰC ==================== */
.auth-gate-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 35%, #0f2942 0%, #050b14 80%);
}

.auth-gate-card {
  width: 100%;
  max-width: 380px;
  padding: 26px 22px;
  border-radius: 20px;
  background: var(--bg-panel-strong);
  border: 1px solid var(--border-glass);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
  text-align: center;
}

.auth-gate-logo {
  width: 58px;
  height: 58px;
  border-radius: 15px;
  margin-bottom: 12px;
  box-shadow: 0 6px 20px rgba(20, 184, 166, 0.35);
}

.auth-gate-title {
  font-size: 18px;
  font-weight: 800;
  color: #f8fafc;
  margin-bottom: 6px;
}

.auth-gate-sub {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 16px;
}

.auth-gate-spinner {
  width: 30px;
  height: 30px;
  margin: 0 auto;
  border-radius: 50%;
  border: 3px solid rgba(45, 212, 191, 0.2);
  border-top-color: var(--teal-400);
  animation: spin360 0.85s linear infinite;
}

@keyframes spin360 {
  to {
    transform: rotate(360deg);
  }
}

/* ==================== BỐ CỤC CHÍNH & CANVAS 3D ==================== */
.office-app {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

.canvas-wrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  touch-action: none;
}

.canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ==================== LỚP NHÃN NỔI 2D HUD ==================== */
.hud-labels-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  overflow: hidden;
}

.node-hud-tag {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -100%);
  pointer-events: auto;
  cursor: pointer;
  max-width: 208px;
  padding: 6px 9px;
  border-radius: 12px;
  background: rgba(8, 18, 34, 0.84);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(148, 163, 184, 0.28);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.42);
  transition: border-color 0.2s, box-shadow 0.2s;
  will-change: transform, opacity;
}

.node-hud-tag:hover,
.node-hud-tag.selected {
  border-color: var(--teal-400);
  box-shadow: 0 0 0 2px rgba(45, 212, 191, 0.28), 0 8px 22px rgba(0, 0, 0, 0.55);
  z-index: 25;
}

.node-hud-tag.status-busy {
  border-color: rgba(251, 191, 36, 0.78);
  box-shadow: 0 0 16px rgba(251, 191, 36, 0.28);
}

.node-hud-tag.gateway-tag {
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(9, 22, 42, 0.78);
  max-width: 175px;
}

.node-hud-tag.boss-tag {
  border-color: rgba(251, 191, 36, 0.65);
  background: linear-gradient(135deg, rgba(30, 22, 8, 0.9), rgba(12, 24, 44, 0.88));
}

.hud-tag-head {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 800;
  color: #f8fafc;
  white-space: nowrap;
}

.hud-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--emerald-400);
  box-shadow: 0 0 7px var(--emerald-400);
}

.hud-status-dot.busy {
  background: var(--amber-400);
  box-shadow: 0 0 9px var(--amber-400);
  animation: pulseFast 0.9s ease-in-out infinite alternate;
}

.hud-status-dot.standby {
  background: #64748b;
  box-shadow: none;
}

.hud-turns-mini {
  margin-left: auto;
  padding: 1px 5px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  background: rgba(45, 212, 191, 0.16);
  color: var(--teal-400);
}

.hud-tag-bubble {
  margin-top: 3px;
  font-size: 10.8px;
  line-height: 1.32;
  color: #cbd5e1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.bubbles-hidden .hud-tag-bubble {
  display: none;
}

@keyframes pulseFast {
  from {
    transform: scale(0.88);
    opacity: 0.75;
  }
  to {
    transform: scale(1.28);
    opacity: 1;
  }
}

/* ==================== THANH HEADER TRÊN CÙNG ==================== */
.hud-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: linear-gradient(180deg, rgba(4, 10, 20, 0.92) 0%, rgba(4, 10, 20, 0.58) 76%, rgba(4, 10, 20, 0) 100%);
  pointer-events: none;
}

.hud-topbar > * {
  pointer-events: auto;
}

.hud-brand-row {
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: 1180px;
  margin: 0 auto;
}

.hud-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 11px;
  border-radius: 11px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.32);
  color: #f8fafc;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.hud-back-btn:hover {
  border-color: var(--teal-400);
}

.hud-title-box {
  flex: 1;
  min-width: 0;
}

.hud-main-title {
  font-size: 15.5px;
  font-weight: 800;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-sub-line {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--emerald-400);
  box-shadow: 0 0 8px var(--emerald-400);
  flex-shrink: 0;
}

.live-dot.offline {
  background: var(--amber-400);
  box-shadow: none;
}

.hud-sep {
  opacity: 0.45;
}

.fps-badge {
  color: var(--teal-400);
  font-weight: 700;
  font-size: 11px;
}

.hud-right-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.role-pill {
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  background: rgba(20, 184, 166, 0.18);
  border: 1px solid rgba(45, 212, 191, 0.35);
  color: #ccfbf1;
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(15, 23, 42, 0.84);
  color: #f8fafc;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  border-color: var(--teal-400);
}

/* ==================== THANH CHUYỂN CHẾ ĐỘ 2 TRONG 1 ==================== */
.hud-mode-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  max-width: 1180px;
  margin: 8px auto 0;
}

.mode-segmented {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border-radius: 13px;
  background: rgba(8, 17, 32, 0.9);
  border: 1px solid rgba(94, 234, 212, 0.28);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.mode-btn {
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 12.8px;
  font-weight: 800;
  padding: 7px 13px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.mode-btn.active {
  background: linear-gradient(135deg, #0d9488 0%, #0284c7 100%);
  color: #ffffff;
  box-shadow: 0 3px 12px rgba(13, 148, 136, 0.45);
}

.hud-tools-row {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.hud-tools-row::-webkit-scrollbar {
  display: none;
}

.tool-chip {
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(10, 22, 40, 0.85);
  color: #e2e8f0;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 11px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.18s;
}

.tool-chip.active {
  border-color: var(--teal-400);
  background: rgba(20, 184, 166, 0.2);
  color: #99f6e4;
}

.tool-chip-sim {
  border-color: rgba(251, 191, 36, 0.55);
  background: linear-gradient(135deg, rgba(180, 83, 9, 0.38), rgba(15, 118, 110, 0.38));
  color: #fde68a;
}

.tool-chip-sim.running {
  background: linear-gradient(135deg, #e11d48, #be123c);
  border-color: #fda4af;
  color: #fff;
}

.sim-banner {
  max-width: 780px;
  margin: 8px auto 0;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(251, 191, 36, 0.6);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
}

.sim-step-badge {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--amber-400);
  color: #0f172a;
  font-weight: 800;
  font-size: 11px;
  flex-shrink: 0;
}

.sim-step-text {
  color: #f8fafc;
  font-weight: 600;
  line-height: 1.35;
}

/* ==================== DẢI CHỌN NHANH DƯỚI ĐÁY ==================== */
.hud-bottom-dock {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 28;
  padding: 6px 10px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(4, 10, 20, 0.92) 0%, rgba(4, 10, 20, 0.55) 75%, rgba(4, 10, 20, 0) 100%);
  pointer-events: none;
}

.hud-bottom-dock > * {
  pointer-events: auto;
}

.pulse-summary-bar {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 7px;
}

.pulse-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(10, 22, 40, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.25);
  font-size: 11.5px;
  font-weight: 700;
  color: #e2e8f0;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.pulse-pill.alert {
  border-color: rgba(251, 113, 133, 0.65);
  background: rgba(136, 19, 55, 0.45);
  color: #ffe4e6;
}

.quick-roster-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  justify-content: center;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.quick-roster-bar::-webkit-scrollbar {
  display: none;
}

.roster-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(10, 22, 40, 0.88);
  border: 1px solid rgba(148, 163, 184, 0.28);
  color: #f1f5f9;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.18s;
}

.roster-chip:hover,
.roster-chip.active {
  border-color: var(--teal-400);
  background: rgba(20, 184, 166, 0.22);
}

/* ==================== NGĂN CHI TIẾT NODE (DRAWER / SHEET) ==================== */
.node-drawer {
  position: fixed;
  top: 108px;
  right: 14px;
  bottom: 84px;
  width: 344px;
  max-width: calc(100vw - 24px);
  z-index: 50;
  background: var(--bg-panel-strong);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.drawer-handle {
  display: none;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}

.drawer-title-wrap {
  min-width: 0;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 20px;
  font-size: 13px;
  line-height: 1.5;
}

.info-block {
  background: rgba(15, 29, 50, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 13px;
  padding: 11px 12px;
  margin-bottom: 10px;
}

.info-block-title {
  font-size: 11.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--teal-400);
  margin-bottom: 6px;
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.kv-card {
  background: rgba(15, 29, 50, 0.75);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 11px;
  padding: 8px 10px;
}

.kv-val {
  font-size: 16px;
  font-weight: 800;
  color: #f8fafc;
}

.kv-lbl {
  font-size: 11px;
  color: var(--text-muted);
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.mini-tag {
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: rgba(56, 189, 248, 0.15);
  color: #bae6fd;
  border: 1px solid rgba(56, 189, 248, 0.28);
}

.mission-item {
  padding: 8px 0;
  border-bottom: 1px dashed rgba(148, 163, 184, 0.18);
}

.mission-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.drawer-cta-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  background: linear-gradient(135deg, #0d9488, #0284c7);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  text-decoration: none;
  margin-top: 6px;
}

/* ==================== TỐI ƯU ĐIỆN THOẠI DỌC (PORTRAIT MOBILE) ==================== */
@media (max-width: 720px) {
  .hud-mode-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .mode-segmented {
    width: 100%;
  }

  .mode-btn {
    padding: 7px 8px;
    font-size: 12.2px;
  }

  .pulse-summary-bar {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .pulse-summary-bar::-webkit-scrollbar {
    display: none;
  }

  .quick-roster-bar {
    justify-content: flex-start;
  }

  .node-hud-tag {
    max-width: 154px;
    padding: 4px 7px;
  }

  .hud-tag-head {
    font-size: 11px;
  }

  .hud-tag-bubble {
    font-size: 10px;
    -webkit-line-clamp: 1;
  }

  .node-drawer {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    max-height: 64dvh;
    border-radius: 22px 22px 0 0;
    border-bottom: none;
  }

  .drawer-handle {
    display: block;
    width: 42px;
    height: 4px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.4);
    margin: 8px auto 2px;
  }
}

@media (max-width: 390px) {
  .hide-xxs {
    display: none;
  }
  .role-pill {
    max-width: 108px;
    font-size: 10.8px;
  }
}

/* ==================== HUY HIỆU CHỮ NHẬN DIỆN 5 CHỊ EM (thay emoji người) ==================== */
.sis-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 900;
  color: #ffffff;
  letter-spacing: 0.01em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.22);
  flex-shrink: 0;
}

.sis-badge-lg {
  min-width: 34px;
  height: 26px;
  font-size: 12.5px;
  padding: 0 8px;
}

.hud-name {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.roster-chip .sis-badge {
  margin-right: 1px;
}

.node-hud-tag.status-busy .hud-tag-head::after {
  content: "ĐANG XỬ LÝ";
  margin-left: 4px;
  padding: 1px 5px;
  border-radius: 999px;
  font-size: 8.5px;
  font-weight: 900;
  background: rgba(251, 191, 36, 0.22);
  color: #fde68a;
}

/* ==================== ĐỒNG HỒ CHI PHÍ API & 2 VÍ (CHỈ QUẢN LÝ ADMIN) ==================== */
.hud-cost-mini {
  padding: 1px 5px;
  border-radius: 999px;
  font-size: 9.5px;
  font-weight: 800;
  background: rgba(251, 191, 36, 0.16);
  color: #fde68a;
  border: 1px solid rgba(251, 191, 36, 0.28);
}

.hud-cost-mini.zero-ide {
  background: rgba(16, 185, 129, 0.16);
  color: #6ee7b7;
  border-color: rgba(16, 185, 129, 0.3);
}

.pulse-pill-btn {
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.18s, transform 0.15s;
}

.pulse-pill-btn:hover {
  border-color: var(--teal-400);
  transform: translateY(-1px);
}

.pulse-pill-credit {
  border-color: rgba(52, 211, 153, 0.42);
  background: rgba(6, 78, 59, 0.42);
  color: #d1fae5;
}

.cost-meter-bar {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  overflow: hidden;
  margin: 6px 0 8px;
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.cost-meter-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #10b981, #2dd4bf);
  transition: width 0.35s ease;
}

.cost-meter-fill.warn {
  background: linear-gradient(90deg, #f59e0b, #fb7185);
}

.wallet-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 0;
  font-size: 12.2px;
  border-bottom: 1px dashed rgba(148, 163, 184, 0.16);
}

.wallet-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.wallet-lbl {
  color: #cbd5e1;
}

.wallet-val {
  font-weight: 800;
  color: #f8fafc;
  white-space: nowrap;
}
