:root{
  --navy-950: #f4f9ff;
  --navy-900: #e4effa;
  --navy-800: #d0e3f5;
  --navy-700: #bce0fd;
  --ice-500: #35b7ff;
  --ice-300: #00509e;
  --text: #061827;
  --muted: #555555;
  --card: #ffffff;
  --card-2: #f9f9f9;
  --stroke: #cce6ff;
  --shadow: 0 4px 15px rgba(0,0,0,0.05);
  --radius: 18px;
  --radius-sm: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
}

.bubble ul, .bubble ol { margin-top: 6px; margin-bottom: 6px; padding-left: 20px; }
.bubble li { margin-bottom: 4px; }

.bubble p { margin: 0 0 8px 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px 0; padding-left: 20px; }
.bubble li { margin-bottom: 4px; }
.bubble > *:last-child { margin-bottom: 0; }


*{box-sizing:border-box}

html, body {
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

body{
  display:flex;
  justify-content:center;
  font-family:var(--font);
  color:#061827;
  background:
    radial-gradient(1200px 800px at 20% 10%, rgba(53,183,255,.18), transparent 60%),
    radial-gradient(1200px 800px at 90% 30%, rgba(138,217,255,.10), transparent 55%),
    linear-gradient(180deg, var(--navy-950), var(--navy-900));
}

.page{
  width:100%;
  max-width:1200px;
  height:100%;
  display:flex;
  flex-direction:column;
  padding:0;
  margin:0;
}

.shell{
  flex:1;
  width:100%;
  height:100%;
  background:#ffffff;
  border:none;
  border-radius:0;
  box-shadow:none;
  overflow:hidden;
  backdrop-filter: blur(10px);
  display:flex;
  flex-direction:column;
}

.topbar{
  padding:16px 18px;
  display:flex;
  flex-direction:row;
  align-items:center;
  justify-content:space-between;
  flex-wrap:nowrap;
  gap:10px;
  border-bottom:1px solid var(--stroke);
  background:#ffffff;
}

/* Desktop header layout: single row */
.header-main{
  display:flex;
  align-items:center;
  gap:12px;
  min-width:0;
}

.header-meta{
  display:flex;
  align-items:center;
  gap:10px;
}

.brand{display:flex; gap:12px; align-items:center; min-width:0}
.brand__logo{
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 10px;
  flex: 0 0 auto;
}
.brand__text{min-width:0}
.brand__name{font-weight:700; letter-spacing:.2px; white-space:nowrap}
.brand__sub{font-size:12px; color:var(--muted); margin-top:2px}

.meta{display:flex; gap:10px; align-items:center; flex-wrap:wrap; justify-content:flex-end}
.meta__pill{
  font-size:12px;
  color:var(--muted);
  border:1px solid var(--stroke);
  padding:7px 10px;
  border-radius:999px;
  background:rgba(255,255,255,.04);
}

.chat{flex:1; display:flex; flex-direction:column; min-height:0; position:relative}
.messages{
  flex:1;
  overflow:auto;
  padding:18px;
  display:flex;
  flex-direction:column;
  gap:12px;
}

.msg{display:flex; align-items:flex-end; gap:10px; max-width:100%}
.msg--user{justify-content:flex-end}
.msg--bot{justify-content:flex-start}

.bubble{
  width: fit-content;
  max-width: 100%;
  padding:12px 14px;
  border-radius:16px;
  border:1px solid var(--stroke);
  background:rgba(255,255,255,.06);
  color:var(--text);
  line-height:1.45;
  white-space:pre-wrap;
  word-wrap:break-word;
}

.badge-source {
  user-select: none; -webkit-user-select: none; pointer-events: none;
  display: inline-block; margin-left: 6px; font-size: 11px; font-weight: 800;
  padding: 2px 6px; border-radius: 4px; vertical-align: middle; opacity: 0.8;
}
.badge-cache { color: #f1c40f; background: rgba(241, 196, 15, 0.15); }
.badge-gemini { color: #3498db; background: rgba(52, 152, 219, 0.15); }
.badge-openai { color: #2ecc71; background: rgba(46, 204, 113, 0.15); }

.msg--user .bubble {
  background: #ebf5ff;
  border-color: #cce6ff;
  color: #061827;
}

.msg--bot .bubble {
  background: #ffffff;
  border-color: #e1ecf4;
  color: #061827;
}

.avatar{
  width:36px; height:36px;
  border-radius:50%;
  border:2px solid var(--ice-500);
  background:var(--navy-800);
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
  flex:0 0 auto;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.avatar__img{
  width:100%;
  height:100%;
  object-fit:cover;
}

.avatar__svg{
  width: 20px;
  height: 20px;
  display: block;
  color: var(--ice-300);
}

.msg--user .avatar__svg{
  color: var(--muted);
}

.bubble-wrapper{
  position:relative;
  display:flex;
  flex-direction:column;
  width: fit-content;
  max-width:min(720px, 85%);
}

.msg--user .bubble-wrapper{align-items:flex-end}
.msg--bot .bubble-wrapper{align-items:flex-start}

.bubble__copy{
  position:absolute;
  bottom:-22px;
  right:0;
  background:transparent;
  border:none;
  color:var(--muted);
  cursor:pointer;
  padding:4px;
  display:flex;
  align-items:center;
  justify-content:center;
  opacity:0.4;
  transition:opacity 0.2s, color 0.2s;
}

.msg:hover .bubble__copy{opacity:1; color:var(--ice-300)}

.toast{
  position:fixed;
  bottom:100px;
  left:50%;
  transform:translateX(-50%) translateY(20px);
  background:rgba(11,34,56,0.95);
  color:var(--ice-300);
  padding:10px 20px;
  border-radius:20px;
  border:1px solid var(--ice-500);
  font-size:14px;
  font-weight:600;
  z-index:9999;
  opacity:0;
  pointer-events:none;
  transition:all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast--show{
  opacity:1;
  transform:translateX(-50%) translateY(0);
}

.composer{
  padding:14px;
  border-top: 1px solid #cce6ff;
  display:flex;
  gap:10px;
  align-items:center;
  background: #f4f9ff;
}

.composer__input{
  flex:1;
  width:100%;
  max-width:none;
  resize:none;
  border-radius:var(--radius-sm);
  border:1px solid #bce0fd;
  background:#f0f7ff;
  color:#061827;
  padding:14px 16px;
  outline:none;
  font-size:15px;
  min-height:48px;
  max-height:140px;
}

.composer__send{
  height:48px;
  padding:0 20px;
  border-radius:var(--radius-sm);
  border:1px solid rgba(53,183,255,.40);
  background:linear-gradient(180deg, rgba(53,183,255,.35), rgba(53,183,255,.18));
  color:var(--text);
  cursor:pointer;
  font-weight:700;
  font-size:15px;
  flex:0 0 auto;
}

.typing{
  display:inline-flex;
  gap:4px;
  align-items:center;
  padding:4px 0;
}
.dot{
  width:6px; height:6px; border-radius:50%;
  background: rgba(6, 24, 39, 0.7);
  animation: bounce 1.2s infinite ease-in-out;
}
.dot:nth-child(2){animation-delay:.2s}
.dot:nth-child(3){animation-delay:.4s}
@keyframes bounce{
  0%, 60%, 100% {transform: translateY(0)}
  30% {transform: translateY(-6px)}
}

/* ADMIN PANEL (full-screen overlay; opened via JS) */
.admin{
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
  max-width:none;
  background:#f0f7ff;
  color: #061827;
  display:none;
  flex-direction:column;
  padding:14px;
  gap:12px;
  z-index:9999;
}
.admin.is-open{display:flex;}

.admin__header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}
.admin__title{
  font-weight:900;
  letter-spacing:.2px;
  font-size:18px;
  color: #061827;
}

.admin__back{
  border:1px solid rgba(211,84,0,.55);
  background:linear-gradient(180deg, rgba(211,84,0,.45), rgba(211,84,0,.24));
  color:#fff;
  border-radius:14px;
  padding:10px 14px;
  font-weight:900;
  cursor:pointer;
}

.admin__auth{
  border:1px solid #cce6ff;
  background:#ffffff;
  border-radius:14px;
  padding:12px;
  color: #061827;
}

.admin__btn-small{
  background: transparent;
  border: none;
  color: #00509e;
  font-size: 11px;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  font-weight: bold;
}
.admin__btn-small:hover{color: #d35400;}

#adminAuthControls.is-hidden,
.admin__password.is-hidden,
.admin__hint.is-hidden{
  display: none !important;
}

.admin__hint{margin-top:6px; font-size:12px; color:#555555; font-weight: 600;}

.admin__label{font-size:12px; color:#555555; font-weight: 600;}
.admin__password{margin-top:6px; display:flex; gap:10px; align-items:center}
.admin__input{
  flex:1;
  height:52px;
  border-radius:14px;
  border:1px solid #bce0fd;
  background:#ffffff;
  color:#061827;
  padding:0 16px;
  outline:none;
  font-size:16px;
  margin-bottom: 8px;
}
.admin__eye{
  width:44px;
  height:44px;
  border-radius:14px;
  border:1px solid #bce0fd;
  background:#ffffff;
  color:#555555;
  cursor:pointer;
}

.admin__tabs{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  align-items: center;
}

.guide-select-wrapper {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.guide-label {
  color: #555555;
  font-size: 13px;
  font-weight: 600;
}
#guideSelect {
  background-color: #ffffff !important;
  color: #061827 !important;
  font-weight: 600;
  height: 36px;
  border-radius: 8px;
  padding: 0 10px;
  border: 1px solid #bce0fd;
  width: auto;
  max-width: 250px;
}
#guideSelect option {
  color: #333333;
  background-color: #ffffff;
}

.admin__tab{
  border:1px solid #cce6ff;
  background:#ffffff;
  color:#555555;
  border-radius:12px;
  padding:10px 12px;
  font-size:12px;
  cursor:pointer;
  font-weight:800;
}
.admin__tab.admin__tab--active{
  border-color:#35b7ff;
  color:#061827;
  background:#ebf5ff;
}

.admin__section{
  flex:1;
  overflow:auto;
  border:1px solid #cce6ff;
  border-radius:14px;
  padding:12px;
  background:#ffffff;
  color: #061827;
}

.admin__section[data-admin-section="guides"]{
  display:flex;
  flex-direction:column;
  padding:0;
  overflow:hidden;
}

#guideFrame,
.admin__guide-frame{
  width:100%;
  height:100%;
  flex:1;
  border:none;
  border-radius:0 0 14px 14px;
  background:#ffffff;
}

.admin__form{display:flex; flex-direction:column; gap:12px}
.admin__field{display:flex; flex-direction:column; gap:8px}

.admin__file{
  border:1px dashed #35b7ff;
  background:#f4f9ff;
  border-radius:14px;
  padding:10px;
  color:#061827;
}
.admin__filename{font-size:12px; color:#00509e; font-weight: bold;}

.admin__select{height:44px; border-radius:14px; border:1px solid #bce0fd; background:#ffffff; color:#061827; padding:0 12px; outline:none}

/* Styling for dropdown options in admin panel */
.admin__select option {
  color: #c0392b; /* Màu đỏ */
  background-color: #ffffff; /* Nền trắng */
  font-weight: 600;
}

/* Styling for dropdown options in admin panel */
.admin__select option {
  color: #c0392b; /* Màu đỏ */
  background-color: #ffffff; /* Nền trắng */
  font-weight: 600;
}

/* Styling for dropdown options in admin panel */
.admin__select option {
  color: #c0392b; /* Màu đỏ */
  background-color: #ffffff; /* Nền trắng */
  font-weight: 600;
}

/* Styling for dropdown options in admin panel */
.admin__select option {
  color: #c0392b; /* Màu đỏ */
  background-color: #ffffff; /* Nền trắng */
  font-weight: 600;
}

.admin__btn{
  height:48px;
  border-radius:14px;
  border:1px solid rgba(53,183,255,.40);
  background:linear-gradient(180deg, rgba(53,183,255,.35), rgba(53,183,255,.18));
  color:var(--text);
  cursor:pointer;
  font-weight:900;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:10px;
}
.admin__btn[disabled]{opacity:.6; cursor:not-allowed}

.admin__spinner{
  width:16px;
  height:16px;
  border-radius:50%;
  border:2px solid rgba(234,242,255,.25);
  border-top-color: rgba(234,242,255,.85);
  display:none;
  animation: spin 0.9s linear infinite;
}
.admin__btn.is-loading .admin__spinner{display:inline-block;}
@keyframes spin{to{transform:rotate(360deg)}}

.admin__result{
  font-size:13px;
  color:#061827;
  border:1px solid #bce0fd;
  background:#f4f9ff;
  border-radius:12px;
  padding:10px;
}

.admin__tableWrap{overflow:auto}
.admin__table{
  width:100%;
  border-collapse:separate;
  border-spacing:0;
  border:1px solid #cce6ff;
  border-radius:14px;
  overflow:hidden;
  color: #061827;
}
.admin__table th,
.admin__table td{
  padding:10px 12px;
  border-bottom:1px solid #cce6ff;
  font-size:12px;
}
.admin__table th{color:#061827; text-align:left; background:#ebf5ff; font-weight: bold;}
.admin__table tr:last-child td{border-bottom:none}

.admin__danger{
  border:1px solid rgba(255,82,82,.55);
  background:linear-gradient(180deg, rgba(255,82,82,.30), rgba(255,82,82,.18));
  color:#fff;
  border-radius:12px;
  padding:8px 10px;
  cursor:pointer;
  font-weight:900;
}

.admin__code{
  margin:0;
  padding:12px;
  border-radius:14px;
  background:#f4f9ff;
  border:1px solid #bce0fd;
  overflow:auto;
  color:#061827;
  font-size:12px;
}

/* LOGIN OVERLAY (keeps existing navy brand) */
.login-overlay{
  position:fixed;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:24px;
  background:rgba(6,24,39,.92);
  z-index:10000;
}
.login-overlay.is-hidden{display:none;}
.login-card{
  width:min(420px, 100%);
  border-radius:18px;
  border:1px solid rgba(255,255,255,.14);
  background:linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.04));
  box-shadow:0 18px 55px rgba(0,0,0,.45);
  padding:18px 18px 16px;
  backdrop-filter: blur(10px);
}
.login-title{font-weight:800; letter-spacing:.2px; font-size:18px}
.login-welcome{margin-top:8px; color:var(--ice-300); font-size:14px; line-height:1.45; white-space:pre-wrap}
.login-sub{margin-top:10px; color:var(--muted); font-size:12px}
.login-form{margin-top:12px; display:flex; flex-direction:column; gap:10px}
.login-input{
  flex:1;
  height:44px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.18);
  background:rgba(255,255,255,.06);
  color:var(--text);
  padding:0 12px;
  outline:none;
}
.login-btn{
  height:44px;
  padding:0 14px;
  border-radius:14px;
  border:1px solid rgba(53,183,255,.40);
  background:linear-gradient(180deg, rgba(53,183,255,.35), rgba(53,183,255,.18));
  color:var(--text);
  font-weight:800;
  cursor:pointer;
}
.login-error{margin-top:10px; color:#ffb4b4; font-size:12px; min-height:16px}

@media (max-width:640px){
  .page{padding:0}
  .shell{height:100%; width:100%; border-radius:0; border:none}

  /* Keep existing 2-line mobile header rules */
  .topbar {
    padding: 10px 14px;
    flex-direction: column; /* Quan trọng: Đổi thành xếp dọc để không bị nén */
    align-items: stretch;
    height: auto;
    gap: 10px;
  }
  .header-main{
    display:flex;
    justify-content:space-between;
    align-items:center;
    width:100%;
    gap:10px;
  }
  .header-meta{
    display:flex;
    gap:5px;
    margin-top:5px;
    font-size:10px;
    width:100%;
    justify-content:flex-end;
  }
  .meta__pill{font-size:10px; padding:5px 8px}

  .brand__logo{width:28px; height:28px}
  .brand__name{font-size:14px}

  .messages{padding:14px}
  .bubble-wrapper{max-width:90%}
  .bubble{padding:10px 14px; font-size:15px}
  .avatar{width:32px; height:32px}
  .composer{padding:10px; gap:8px}
  .bubble__copy{opacity:0.6; bottom:-20px}

  .admin{position:fixed; inset:0; padding:14px; z-index:9999}
  .admin__guide-frame{height:calc(100vh - 220px)}

  .login-form{flex-direction:column}
  .login-btn{width:100%}
}
/* Ép ẩn tuyệt đối các section và kết quả rỗng */
.admin__section[hidden] {
  display: none !important;
}
#adminUploadResult:empty {
  display: none !important;
  padding: 0 !important;
  border: none !important;
}

/* Role switch divider in chat */
.role-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 20px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}
.role-divider::before, .role-divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--stroke);
}
.role-divider span {
  padding: 0 15px;
  color: var(--ice-300);
}

/* Bảng HTML cho AI Chat */
.bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 15px 0;
  display: block;
  overflow-x: auto; /* Tạo thanh cuộn ngang chống vỡ layout */
  white-space: normal; /* Reset lại để text trong bảng không bị lỗi pre-wrap */
  font-size: 13px;
}
.bubble th, .bubble td {
  border: 1px solid #cce6ff;
  padding: 10px 14px;
  text-align: left;
}
.bubble th {
  background: #ebf5ff;
  color: #061827;
  font-weight: bold;
  white-space: nowrap;
}
.bubble tr:nth-child(even) {
  background: #f7fbff;
}

/* --- ADMIN LOG VIEWER --- */
.admin__log-container { background: #ffffff; border: 1px solid #cce6ff; border-radius: 14px; padding: 15px; margin-top: 15px; color: #061827; }
.admin__log-content { max-height: 400px; overflow-y: auto; background: #f4f9ff; border-radius: 8px; padding: 10px; border: 1px solid #e1ecf4; }
.log-msg { margin-bottom: 12px; font-size: 13px; line-height: 1.4; padding: 10px; border-radius: 8px; word-break: break-word; color: #061827; }
.log-msg--user { background: #ebf5ff; border-left: 4px solid #35b7ff; }
.log-msg--assistant { background: #ffffff; border-left: 4px solid #b9c8de; border: 1px solid #e1ecf4; }
