/* ============================================
   CHAT.CSS — Chat page (Phase 2)
   Dịch Quẻ · I Ching Oracle
   Sử dụng CSS variables từ base.css.
   Không hardcode màu — dùng color-mix() khi cần tint.
============================================ */

/* ══════════════════════════════════════════
   PAGE LAYOUT (mobile-first)
   Trừ topnav (56px) vì .main-content có padding-top:56px.
   Khi chat active → JS đã ẩn .bottom-nav nên không cần trừ thêm.
══════════════════════════════════════════ */
.chat-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px);
  height: calc(100dvh - 56px);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.main-content:has(#page-chat.active) {
  padding-bottom: 0 !important;
  min-height: 0;
}

.chat-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.chat-rail { display: none; }

/* ══════════════════════════════════════════
   HEADER
══════════════════════════════════════════ */
.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  min-height: 52px;
}

/* ── Classes được JS render trong renderChatHeader() ── */
.chat-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.chat-header-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.chat-que-name {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-que-han {
  font-family: var(--font-serif);
  font-size: 22px;
  color: var(--gold);
  line-height: 1;
  flex-shrink: 0;
}

/* Status badge — ẩn trên mobile (quá chật), hiện trên desktop */
.chat-status-dot {
  display: none;
  font-size: 10px;
  letter-spacing: 0.06em;
  white-space: nowrap;
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 20px;
}
.chat-status-dot.open {
  color: var(--gold);
  background: color-mix(in srgb, var(--gold) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--gold) 30%, transparent);
}
.chat-status-dot.closed {
  color: var(--text3);
  background: var(--bg2);
  border: 1px solid var(--border);
}

/* Phần bên phải header: status dot + nút đóng */
.chat-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Nút đóng / quay lại — luôn hiển thị, không bị clip */
.chat-close-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text2);
  border-radius: var(--radius-sm);
  padding: 5px 12px;
  font-size: 11px;
  letter-spacing: 0.05em;
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
  font-family: var(--font-sans);
  transition: background var(--transition), color var(--transition);
}
.chat-close-btn:hover { background: var(--bg2); color: var(--text); }

/* ══════════════════════════════════════════
   SUBHEADER
══════════════════════════════════════════ */
.chat-subheader {
  padding: 7px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  font-size: 11px;
  color: var(--text3);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.subheader-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.chat-question {
  font-style: italic;
  color: var(--text2);
  font-size: 12px;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subheader-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.que-phu-slots {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--text3);
}

.que-phu-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.que-phu-dot.filled,
.que-phu-dot.used   { background: var(--gold); }
.que-phu-dot.empty  { background: var(--border); border: 1px solid var(--border); }

.quota-badge {
  font-size: 10px;
  color: var(--text3);
  opacity: 0.8;
  letter-spacing: 0.02em;
}

.chat-note {
  font-size: 10px;
  color: var(--text3);
  opacity: 0.7;
}

/* ══════════════════════════════════════════
   MESSAGES AREA
══════════════════════════════════════════ */
.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  scroll-behavior: smooth;
}

/* ── Row wrappers ── */
.chat-msg {
  animation: fadeUp 0.25s ease both;
}

/* ── AI message row ── */
.ai-msg-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 85%;
}

.ai-badge {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--bg);
  font-family: var(--font-serif);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
  line-height: 1;
}
.ai-badge.ai-badge-hopluan {
  background: color-mix(in srgb, var(--gold) 40%, var(--bg2));
  color: var(--gold);
  border: 1px solid var(--gold);
}

.ai-msg-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  overflow: hidden;
}

.ai-msg-label {
  font-size: 9px;
  letter-spacing: 0.1em;
  color: var(--text3);
  text-transform: uppercase;
  margin-bottom: 2px;
}

/* ── AI bubble text ── */
.ai-msg-text {
  background: var(--bg2);
  border: 1px solid var(--border-light, var(--border));
  color: var(--text);
  padding: 10px 14px;
  border-radius: 4px 16px 16px 16px;
  font-size: 13px;
  line-height: 1.7;
  word-wrap: break-word;
}

/* Headings trong AI response (Bug 4) */
.ai-msg-text h3 {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
  font-family: var(--font-sans);
  font-weight: 500;
  margin: 18px 0 6px;
}
.ai-msg-text h3:first-child { margin-top: 0; }

.ai-msg-text p { margin: 0 0 22px; }
.ai-msg-text p:last-child { margin-bottom: 0; }

.ai-msg-text ol,
.ai-msg-text ul {
  margin: 4px 0 12px;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ai-msg-text ul { list-style-type: disc; }
.ai-msg-text ol { list-style-type: decimal; }
.ai-msg-text li { line-height: 1.65; }
.ai-msg-text li:last-child { margin-bottom: 0; }

.ai-msg-text strong { font-weight: 700; color: var(--text); }
.ai-msg-text em { font-style: italic; opacity: 0.85; }

/* ── User bubble ── */
.msg-bubble.user-bubble {
  background: var(--text);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  font-size: 13px;
  line-height: 1.7;
  word-wrap: break-word;
  max-width: 75%;
  margin-left: auto;
}

.chat-msg-user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.msg-time {
  font-size: 10px;
  color: var(--text3);
  padding: 0 2px;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Quẻ phụ result card ── */
.que-phu-result-card {
  background: var(--bg2);
  border: 1px solid color-mix(in srgb, var(--gold) 30%, transparent);
  border-radius: var(--radius, 8px);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.5;
  max-width: 85%;
}

.qp-result-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.qp-result-label {
  font-size: 9px;
  letter-spacing: 0.1em;
  color: var(--gold);
  text-transform: uppercase;
}
.qp-result-time {
  font-size: 10px;
  color: var(--text3);
  margin-left: auto;
}
.qp-result-question {
  font-style: italic;
  color: var(--text2);
  font-size: 12px;
  margin-bottom: 8px;
}
.qp-result-body {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.qp-result-hex { flex-shrink: 0; }
.qp-result-info { display: flex; flex-direction: column; gap: 2px; }
.qp-result-name {
  font-family: var(--font-serif);
  font-size: 14px;
  color: var(--text);
}
.qp-result-meaning {
  font-size: 11px;
  color: var(--text3);
}
.qp-result-moving {
  font-size: 11px;
  color: var(--text3);
  margin-top: 8px;
}

/* ── Hex pair: quẻ chính → quẻ biến ── */
.qp-hex-pair {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 4px;
}
.qp-hex-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.qp-hex-arrow {
  font-size: 14px;
  color: var(--text3);
  flex-shrink: 0;
  padding-top: 10px;
}
.qp-hex-label {
  font-family: var(--font-serif);
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
}
.qp-hex-meaning {
  font-size: 10px;
  color: var(--text3);
  line-height: 1.4;
}

/* ── Quẻ phụ input / confirm cards ── */
.que-phu-input-card,
.que-phu-confirm-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius, 8px);
  padding: 16px;
  font-size: 14px;
}
.qp-card-title {
  font-size: 13px;
  color: var(--text2);
  margin: 0 0 10px;
}
.suggested-question {
  font-style: italic;
  color: var(--gold);
  margin: 0 0 12px;
  font-size: 14px;
}
.que-phu-input-card input {
  width: 100%;
  box-sizing: border-box;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 6px);
  background: var(--surface, var(--bg));
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
  margin-bottom: 10px;
}
.que-phu-input-card input:focus { border-color: var(--gold); }
.qp-card-actions {
  display: flex;
  gap: 8px;
}

/* ── Gieo phụ widget ── */
.gieo-phu-widget {
  border: 1px solid var(--border);
  border-radius: var(--radius, 8px);
  padding: 16px;
  background: var(--bg2);
  font-size: 13px;
  color: var(--text2);
  max-width: 300px;
  align-self: flex-start;
}
.gieo-phu-header {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--gold);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.gieo-phu-question {
  font-style: italic;
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 12px;
}
.gieo-phu-lines {
  margin-bottom: 12px;
}
.gieo-phu-coins {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  min-height: 24px;
}
.coin-result {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
}
.coin-result.yang {
  background: color-mix(in srgb, var(--gold) 15%, transparent);
  color: var(--gold);
  border: 1px solid color-mix(in srgb, var(--gold) 40%, transparent);
}
.coin-result.yin {
  background: var(--bg);
  color: var(--text3);
  border: 1px solid var(--border);
}
.coin-sum-label {
  font-size: 11px;
  color: var(--text3);
  margin-left: 4px;
}
/* Context block bên trên câu hỏi gieo phụ */
.gieo-phu-context {
  font-size: 11px;
  color: var(--text3);
  line-height: 1.5;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border-light, var(--border));
  display: flex;
  flex-direction: column; 
  gap: 2px;
}

.gieo-phu-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  gap: 8px;
}

/* Nút hủy kiểu link nhỏ bên trái */
.gieo-phu-footer .gieo-cancel {
  background: transparent;
  border: none;
  color: var(--text3);
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font-sans);
  padding: 4px 0;
  transition: color var(--transition);
  flex-shrink: 0;
}
.gieo-phu-footer .gieo-cancel:hover { color: var(--text); }

/* ══════════════════════════════════════════
   QUICK REPLIES
══════════════════════════════════════════ */
.chat-quickreplies {
  display: flex;
  gap: 8px;
  padding: 6px 16px 8px;
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}
.chat-quickreplies:empty { display: none; }
.chat-quickreplies::-webkit-scrollbar { display: none; }

.quick-reply-chip {
  white-space: nowrap;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  background: var(--bg);
  color: var(--text2);
  cursor: pointer;
  font-family: var(--font-sans);
  transition: background var(--transition), border-color var(--transition);
  flex-shrink: 0;
}
.quick-reply-chip:hover {
  background: var(--bg2);
  border-color: var(--gold);
  color: var(--text);
}

/* ══════════════════════════════════════════
   INPUT BAR
══════════════════════════════════════════ */
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--bg);
  align-items: center;
  flex-shrink: 0;
  position: relative;
}

.chat-input-bar input {
  flex: 1;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg2);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
  min-width: 0;
}
.chat-input-bar input:focus {
  border-color: var(--gold);
  background: var(--surface, var(--bg));
}
.chat-input-bar input::placeholder { color: var(--text3); }
.chat-input-bar input:disabled { opacity: 0.5; cursor: not-allowed; }

/* send button */
#btn-chat-send {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--text);
  color: var(--bg);
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: filter var(--transition), opacity var(--transition);
}
#btn-chat-send:hover { filter: brightness(1.15); }
#btn-chat-send:disabled { opacity: 0.35; cursor: not-allowed; }

/* gieo phụ button */
.btn-gieo-phu {
  flex-shrink: 0;
  height: 36px;
  background: transparent !important;
  color: var(--gold) !important;
  border: 1px solid var(--gold) !important;
  border-radius: 18px;
  font-family: var(--font-serif);
  font-size: 15px;
  padding: 0 12px;
  gap: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  transition: opacity var(--transition), filter var(--transition);
}
.btn-gieo-phu .slot-count {
  font-size: 10px;
  color: var(--text3);
  font-family: var(--font-sans);
  margin-left: 2px;
}
.btn-gieo-phu:disabled,
.btn-gieo-phu.disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ══════════════════════════════════════════
   TYPING INDICATOR
══════════════════════════════════════════ */
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--bg2);
  border: 1px solid var(--border-light, var(--border));
  border-radius: 4px 16px 16px 16px;
}
.typing-dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text3);
  animation: typingBounce 1.2s infinite ease-in-out both;
}
.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40%           { transform: scale(1);   opacity: 1; }
}

/* ══════════════════════════════════════════
   QUOTA BANNERS
══════════════════════════════════════════ */
.chat-quota-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius, 8px);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text2);
  line-height: 1.5;
}
.quota-banner-icon { font-size: 18px; flex-shrink: 0; }

.quota-exhausted-banner {
  background: var(--bg2);
  border: 1px solid var(--border);
  padding: 12px 16px;
  text-align: center;
  border-radius: var(--radius, 8px);
  margin: 12px 16px;
  color: var(--text2);
  font-size: 13px;
  line-height: 1.5;
}
.quota-exhausted-banner strong {
  display: block;
  font-family: var(--font-serif);
  font-size: 15px;
  color: var(--text);
  margin-bottom: 4px;
}

/* ══════════════════════════════════════════
   DESKTOP LAYOUT (≥768px)
══════════════════════════════════════════ */
@media (min-width: 768px) {
  /* Bug 2 fix: explicit height + overflow để rail có thể scroll nội bộ */
  .chat-layout {
    flex-direction: row;
    height: calc(100dvh - 56px);
    overflow: hidden;
  }

  /* Bug 3 fix: hiện status badge khi đủ chỗ */
  .chat-status-dot {
    display: inline-flex;
    align-items: center;
  }

  /* Rail sidebar */
  .chat-rail {
    display: flex;
    flex-direction: column;
    width: 33.333%;
    min-width: 220px;
    max-width: 380px;
    border-right: 1px solid var(--border-light, var(--border));
    background: var(--bg);
    overflow-y: auto;
    flex-shrink: 0;
    padding: 28px 28px 40px;
  }

  .rail-section {
    padding: 12px 0;
    border-bottom: 1px solid var(--border-light, var(--border));
  }
  .rail-section:last-child { border-bottom: none; }

  .rail-hex { margin-bottom: 10px; }

  .rail-que-name {
    font-family: var(--font-serif);
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 2px;
    line-height: 1.3;
  }
  .rail-que-han {
    font-family: var(--font-serif);
    font-size: 22px;
    color: var(--gold);
    line-height: 1.2;
    margin-bottom: 4px;
  }
  .rail-meaning {
    font-size: 11px;
    color: var(--text3);
    line-height: 1.5;
  }
  .rail-label {
    font-size: 9px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text3);
    margin-bottom: 4px;
  }
  .rail-value {
    font-size: 13px;
    color: var(--text2);
    line-height: 1.5;
  }
  .rail-que-phu-card {
    background: var(--surface, var(--bg2));
    border: 1px solid var(--border);
    border-radius: var(--radius-sm, 6px);
    padding: 10px 12px;
    margin-bottom: 8px;
  }
  .rail-qp-index {
    font-size: 9px;
    letter-spacing: 0.1em;
    color: var(--gold);
    text-transform: uppercase;
    margin-bottom: 3px;
  }
  .rail-qp-name {
    font-family: var(--font-serif);
    font-size: 14px;
    color: var(--text);
    margin-bottom: 3px;
  }
  .rail-qp-question {
    font-size: 11px;
    font-style: italic;
    color: var(--text3);
    line-height: 1.4;
  }

  /* Biến quẻ hex wrap trong rail */
  .rail-bien-hex-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
  }
  .rail-bien-arrow {
    font-size: 14px;
    color: var(--text3);
    flex-shrink: 0;
  }

  .chat-main { flex: 1; min-width: 0; }
  .chat-input-bar input { font-size: 15px; }
}

/* Ngăn iOS Safari tự zoom khi focus input — font-size phải >= 16px trên mobile */
@media (max-width: 767px) {
  .chat-input-bar input { font-size: 16px; }
  .que-phu-input-card input { font-size: 16px; }
}

/* ══════════════════════════════════════════
   STICKY AI BUBBLE (ketqua page)
══════════════════════════════════════════ */
.ai-bubble {
  position: fixed;
  bottom: 80px;
  right: 16px;
  z-index: 100;
  width: auto;
  height: auto;
  background: transparent;
  border: none;
  outline: none;
  border-radius: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.ai-bubble-fab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  transition: transform var(--transition), box-shadow var(--transition);
  user-select: none;
}
.ai-bubble-fab:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.ai-bubble-card {
  width: 280px;
  background: var(--surface, var(--bg2));
  border: 1px solid var(--border);
  border-radius: var(--radius, 8px);
  padding: 16px;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  color: var(--text2);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ai-bubble-card .ai-bubble-card-title {
  font-family: var(--font-serif);
  font-size: 16px;
  color: var(--text);
  margin-bottom: 4px;
}
.ai-bubble-card ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ai-bubble-card ul li {
  position: relative;
  padding-left: 14px;
  font-size: 12.5px;
  line-height: 1.5;
}
.ai-bubble-card ul li::before {
  content: "·";
  position: absolute;
  left: 4px;
  color: var(--gold);
  font-weight: bold;
}
.ai-bubble-card button {
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 13px;
  border-radius: var(--radius-sm, 6px);
  padding: 9px 14px;
  border: none;
  transition: filter var(--transition), background var(--transition);
}
.ai-bubble-card button:first-of-type {
  background: var(--text);
  color: var(--bg);
}
.ai-bubble-card button:first-of-type:hover { filter: brightness(1.1); }
.ai-bubble-card button:last-of-type {
  background: transparent;
  color: var(--text3);
  font-size: 11px;
  padding: 4px;
  align-self: flex-end;
}
.ai-bubble-card button:last-of-type:hover { color: var(--text); }

@media (min-width: 768px) {
  .ai-bubble { bottom: 24px; right: 24px; }
}

/* ══════════════════════════════════════════
   DISCLAIMER OVERLAY (centered modal)
══════════════════════════════════════════ */
.disclaimer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.disclaimer-sheet {
  background: var(--bg);
  border-radius: var(--radius, 8px);
  padding: 32px 28px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

/* Header block — icon + tiêu đề + tên quẻ canh giữa */
.disclaimer-header {
  text-align: center;
  margin-bottom: 20px;
}

.disclaimer-icon {
  font-family: var(--font-serif);
  font-size: 36px;
  color: var(--gold);
  line-height: 1;
  margin-bottom: 8px;
  display: block;
}

.disclaimer-title {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 500;
  color: var(--text);
  margin: 0 0 4px;
}

.disclaimer-que {
  font-size: 13px;
  color: var(--text2);
  margin: 0;
}

.disclaimer-features {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.disclaimer-features > div {
  background: var(--bg2);
  border: 1px solid var(--border-light, var(--border));
  border-radius: var(--radius-sm, 6px);
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text2);
  line-height: 1.5;
}

/* 3rd feature spans full width */
.disclaimer-features > div:nth-child(3) {
  grid-column: 1 / -1;
}

.disclaimer-note {
  font-size: 11px;
  color: var(--text3);
  font-style: italic;
  line-height: 1.5;
  margin-bottom: 6px;
}

.disclaimer-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.disclaimer-actions .btn-primary {
  width: 100%;
  height: 48px;
  font-size: 15px;
  justify-content: center;
}

.disclaimer-actions > button:not(.btn-primary) {
  background: transparent;
  border: none;
  color: var(--text3);
  font-size: 13px;
  cursor: pointer;
  padding: 6px;
  font-family: var(--font-sans);
  text-align: center;
  transition: color var(--transition);
}
.disclaimer-actions > button:not(.btn-primary):hover { color: var(--text); }

/* ══════════════════════════════════════════
   CLOSE SESSION MODAL
══════════════════════════════════════════ */
.close-session-overlay {
  position: fixed; inset: 0;
  background: rgba(26,24,20,0.55);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.close-session-panel {
  width: 300px;
  border-radius: 16px;
  overflow: hidden;
  background: #f5f2ec;
  border: 0.5px solid rgba(184,146,74,0.2);
  box-shadow: 0 20px 60px rgba(26,24,20,0.12);
}

.close-session-top {
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%, rgba(184,146,74,0.45) 30%,
    rgba(184,146,74,0.7) 50%, rgba(184,146,74,0.45) 70%, transparent 100%);
}

.close-session-body {
  padding: 22px 22px 0;
}

.close-session-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.close-session-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #3a8a5a;
  flex-shrink: 0;
}

.close-session-title {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  color: #1a1814;
  letter-spacing: 0.03em;
}

.close-session-desc {
  font-size: 12px;
  color: #9a958e;
  line-height: 1.7;
  padding-bottom: 20px;
}

.close-desc-highlight {
  font-weight: 700;
  color: #b8924a;
}

.close-session-divider {
  height: 0.5px;
  background: rgba(184,146,74,0.15);
}

.close-session-actions { display: flex; }

.btn-close-cancel, .btn-close-confirm {
  flex: 1;
  padding: 15px 0;
  background: transparent;
  border: none;
  font-family: var(--font-sans);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-close-cancel {
  font-weight: 600;
  color: #2a2620;
  border-right: 0.5px solid rgba(184,146,74,0.15);
  border-bottom-left-radius: 16px;
}
.btn-close-cancel:hover { background: rgba(0,0,0,0.03); }

.btn-close-confirm {
  font-weight: 600;
  color: #736e66;
  border-bottom-right-radius: 16px;
}
.btn-close-confirm:hover { color: #433e3b; }

/* dark */
[data-theme="dark"] .close-session-panel {
  background: #0f2e2e;
  border-color: #1e4f4a;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
[data-theme="dark"] .close-session-top {
  background: linear-gradient(90deg,
    transparent 0%, rgba(232,184,90,0.5) 30%,
    rgba(255,220,100,0.75) 50%, rgba(232,184,90,0.5) 70%, transparent 100%);
}
[data-theme="dark"] .close-session-dot { background: #72b27d; }
[data-theme="dark"] .close-desc-highlight { color: #e8b85a; }
[data-theme="dark"] .close-session-title { color: #f8f4ec; }
[data-theme="dark"] .close-session-desc { color: #908880; }
[data-theme="dark"] .close-session-divider { background: rgba(232,184,90,0.12); }
[data-theme="dark"] .btn-close-cancel {
  color: #c8c0b0;
  border-right-color: rgba(232,184,90,0.12);
}
[data-theme="dark"] .btn-close-cancel:hover { background: rgba(255,255,255,0.04); }
[data-theme="dark"] .btn-close-confirm { color: #8c837d; }
[data-theme="dark"] .btn-close-confirm:hover { color: #decfc0; }

/* ══ TIMEOUT BANNER ══ */
.timeout-banner {
  padding: 10px 16px;
  flex-shrink: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.timeout-banner-text {
  font-size: 12px;
  color: var(--text2);
  line-height: 1.5;
  flex: 1;
}
.timeout-banner-text strong {
  color: var(--text);
  font-weight: 500;
  display: block;
  margin-bottom: 1px;
  font-size: 13px;
}
.timeout-icon {
  font-size: 18px;
  flex-shrink: 0;
}

/* ══ VIEW-ONLY NOTICE ══ */
.view-only-notice {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text3);
  font-size: 12px;
  letter-spacing: 0.03em;
  font-style: italic;
  justify-content: center;
  width: 100%;
  padding: 4px 0;
}

/* ══ ERROR + RETRY BUTTON ══ */
.btn-retry-inline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding: 5px 13px;
  background: transparent;
  color: var(--text2);
  border: 1px solid var(--border);
  border-radius: 16px;
  font-size: 12px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-retry-inline:hover:not(:disabled) {
  background: var(--bg2);
  border-color: var(--text3);
}
.btn-retry-inline--disabled,
.btn-retry-inline:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.retry-countdown {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text3);
}
.retry-cd-badge {
  background: var(--bg2);
  color: var(--text2);
  border-radius: 8px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
  min-width: 34px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ══ QUẺ PHỤ TOOLTIP ══ */
.quephu-tooltip-wrap {
  position: absolute;
  bottom: calc(100% + 6px);
  right: 40px;          /* canh mép trái của nút 占 (width 40px + gap 8px từ nút ↑) */
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  z-index: 100;
  pointer-events: auto;
}
.quephu-tooltip-box {
  background: var(--bg);           /* sáng hơn surface trên dark */
  color: var(--text);              /* text đậm hơn */
  border: 1.5px solid var(--gold);
  border-radius: 10px 10px 2px 10px;
  padding: 9px 28px 9px 10px;
  max-width: 220px;
  font-size: 12px;
  line-height: 1.5;
  position: relative;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.quephu-tooltip-icon {
  font-family: var(--font-serif);
  color: var(--gold);
  margin-right: 4px;
}
.quephu-tooltip-close {
  position: absolute;
  top: 5px;
  right: 7px;
  font-size: 14px;
  line-height: 1;
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  opacity: 0.45;
  padding: 0;
}
.quephu-tooltip-close:hover { opacity: 0.85; }
.quephu-tooltip-arrow {
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-top: 7px solid var(--gold);
  align-self: flex-end;
  margin-right: 20px;   /* canh arrow vào tâm nút 占 (nút width 40px → tâm = 20px từ mép phải) */
}

/* ══════════════════════════════════════════
   DARK THEME — Modal teal overrides
   Chỉ áp dụng trên dark, light giữ nguyên
══════════════════════════════════════════ */
[data-theme="dark"] .disclaimer-sheet {
  background: #0f2e2e;
  border: 1px solid #1e4f4a;
  box-shadow: 0 8px 40px rgba(0,0,0,0.7);
}
 
[data-theme="dark"] .disclaimer-features > div {
  background: #0a2424;
  border-color: #1e4040;
  color: var(--text2);
}
 
[data-theme="dark"] .disclaimer-note {
  color: #7ab3ae;
}
