/* ===========================================================
   Chatbot Phạt Nguội — bảng màu "trạm gác" (civic navy + amber)
   Lấy cảm hứng từ biển báo giao thông và đèn tín hiệu:
   nền xanh navy trầm ổn định, điểm nhấn hổ phách cảnh báo.
   =========================================================== */

:root {
  --navy-950: #0e1f33;
  --navy-900: #16324f;
  --navy-800: #1f4569;
  --navy-100: #e7edf3;
  --paper: #f6f7f5;
  --accent: #e8a33d;
  --accent-dark: #c17d1f;
  --ink: #1a2430;
  --ink-soft: #55636f;
  --line: #d9dee2;
  --danger: #c0463a;
  --bot-bubble: #ffffff;
  --user-bubble: #1f4569;
  --radius: 14px;
  --font-display: "Bahnschrift", "Segoe UI Semibold", "Helvetica Neue", Arial, sans-serif;
  --font-body: "Segoe UI", "Inter", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
}

.app-shell {
  max-width: 720px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  position: relative;
}

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(180deg, var(--navy-950), var(--navy-900));
  color: #fff;
  box-shadow: 0 2px 8px rgba(14, 31, 51, 0.25);
  z-index: 5;
}
.topbar-badge { flex: none; display: flex; }
.topbar-text { flex: 1; min-width: 0; }
.topbar-text h1 {
  font-family: var(--font-display);
  font-size: 16.5px;
  margin: 0;
  letter-spacing: 0.2px;
  line-height: 1.25;
}
.topbar-text p {
  margin: 2px 0 0;
  font-size: 12px;
  color: #b9c8d6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.06);
  color: #e7edf3;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,0.14); }

/* ---------- Tools panel ---------- */
.tools-panel {
  position: absolute;
  top: 62px;
  right: 12px;
  z-index: 10;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(14,31,51,0.18);
  padding: 8px;
  width: min(280px, 80vw);
}
.tools-panel.hidden { display: none; }
.tool-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 10px 10px;
  font-size: 14px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink);
}
.tool-item:hover { background: var(--navy-100); }
.tool-item-danger { color: var(--danger); }
.tools-note {
  font-size: 11.5px;
  color: var(--ink-soft);
  padding: 8px 10px 4px;
  margin: 0;
  border-top: 1px solid var(--line);
  margin-top: 4px;
}

/* ---------- Chat log ---------- */
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg { display: flex; }
.msg-bot { justify-content: flex-start; }
.msg-user { justify-content: flex-end; }

.msg-bubble {
  max-width: 84%;
  padding: 11px 14px;
  border-radius: var(--radius);
  font-size: 14.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg-bot .msg-bubble {
  background: var(--bot-bubble);
  border: 1px solid var(--line);
  border-top-left-radius: 4px;
  color: var(--ink);
}
.msg-user .msg-bubble {
  background: var(--user-bubble);
  color: #fff;
  border-top-right-radius: 4px;
}

.msg-meta {
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: 4px;
}

.related-block {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}
.related-block-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-dark);
  margin-bottom: 6px;
}
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--accent);
  background: #fff6e8;
  color: var(--accent-dark);
  font-size: 12.5px;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.chip:hover { background: var(--accent); color: #fff; }

.typing-bubble .msg-bubble {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 13px 16px;
}
.typing-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ink-soft);
  animation: blink 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.suggestions-msg .msg-bubble { display: none; }
.suggestions-msg.has-content .msg-bubble { display: block; background: transparent; border: none; padding: 0; }

/* ---------- Lookup-tool bubble ---------- */
.lookup-steps { margin: 10px 0; }
.lookup-steps ol { margin: 0; padding-left: 20px; }
.lookup-steps li { margin-bottom: 4px; font-size: 14px; }
.lookup-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding: 9px 14px;
  border-radius: 10px;
  background: var(--navy-900);
  color: #fff;
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 600;
}
.lookup-link-btn:hover { background: var(--navy-800); }

/* ---------- Input bar ---------- */
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: #fff;
}
.chat-input-bar input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 15px;
  outline: none;
  background: var(--paper);
}
.chat-input-bar input:focus {
  border-color: var(--navy-800);
  box-shadow: 0 0 0 3px rgba(31,69,105,0.15);
}
.send-btn {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--navy-950);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.send-btn:hover { background: var(--accent-dark); color: #fff; }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.disclaimer {
  font-size: 11px;
  color: var(--ink-soft);
  text-align: center;
  margin: 0;
  padding: 6px 14px 10px;
  background: #fff;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(14,31,51,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal.hidden { display: none; }
.modal-box {
  background: #fff;
  border-radius: 16px;
  padding: 22px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-box h2 { font-size: 17px; margin: 0 0 8px; font-family: var(--font-display); }
.modal-box p { font-size: 13.5px; color: var(--ink-soft); margin: 0 0 16px; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; }
.btn-primary, .btn-secondary, .btn-ghost, .btn-stay {
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn-primary { background: var(--accent); color: var(--navy-950); font-weight: 600; }
.btn-secondary { background: var(--navy-100); color: var(--navy-900); }
.btn-ghost { background: none; color: var(--danger); border-color: var(--line); }
.btn-stay {
  display: block;
  width: 100%;
  margin-top: 14px;
  background: var(--navy-900);
  color: #fff;
  text-align: center;
}

/* ---------- Responsive ---------- */
@media (min-width: 720px) {
  .app-shell {
    margin: 18px auto;
    height: calc(100dvh - 36px);
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid var(--line);
    box-shadow: 0 12px 40px rgba(14,31,51,0.12);
  }
}
@media (max-width: 400px) {
  .msg-bubble { max-width: 90%; font-size: 14px; }
  .topbar-text h1 { font-size: 15px; }
}
