/* ═══════════════════════════════════════════════
   DESIGN TOKENS
═══════════════════════════════════════════════ */
:root {
  --primary:        #2563eb;
  --primary-dark:   #1d4ed8;
  --primary-light:  #dbeafe;
  --accent:         #f59e0b;
  --accent-light:   #fef3c7;
  --success:        #10b981;
  --success-light:  #d1fae5;
  --danger:         #ef4444;
  --bg-page:        #f1f5f9;
  --bg-card:        #ffffff;
  --bg-chat:        #e8f0fe;
  --text-primary:   #0f172a;
  --text-secondary: #475569;
  --text-muted:     #94a3b8;
  --border:         #e2e8f0;
  --shadow-sm:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:      0 4px 16px rgba(0,0,0,.10), 0 2px 6px rgba(0,0,0,.06);
  --shadow-lg:      0 10px 40px rgba(0,0,0,.14);
  --radius:         18px;
  --radius-sm:      12px;
  --radius-xs:      8px;
  --header-h:       80px;
  --footer-h:       80px;
  --hero-h:         160px;
  --topics-h:       84px;
  --font:           'Be Vietnam Pro', system-ui, sans-serif;
  --transition:     all .25s cubic-bezier(.4,0,.2,1);
}

/* ═══════════════════════════════════════════════
   RESET & BASE
═══════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 0;
}

/* ═══════════════════════════════════════════════
   MOBILE SHELL
═══════════════════════════════════════════════ */
.mobile-shell {
  width: 100%;
  max-width: 430px;
  height: 100dvh;
  max-height: 900px;
  background: var(--bg-page);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

@media (min-width: 500px) {
  body { padding: 20px; background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%); }
  .mobile-shell { border-radius: 36px; }
}

/* ═══════════════════════════════════════════════
   HEADER
═══════════════════════════════════════════════ */
.app-header {
  flex-shrink: 0;
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
  color: #fff;
  position: relative;
  z-index: 10;
  padding-top: env(safe-area-inset-top, 0px);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 8px;
  gap: 12px;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.logo-icon {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 8px rgba(59,130,246,.6));
  animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { filter: drop-shadow(0 2px 8px rgba(59,130,246,.5)); }
  50%       { filter: drop-shadow(0 2px 16px rgba(59,130,246,.9)); }
}

.header-text { min-width: 0; }
.app-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-subtitle {
  font-size: .7rem;
  font-weight: 400;
  opacity: .8;
  white-space: nowrap;
}

.btn-refresh {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,.3);
  background: rgba(255,255,255,.1);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  backdrop-filter: blur(8px);
}
.btn-refresh svg { width: 16px; height: 16px; }
.btn-refresh:hover { background: rgba(255,255,255,.25); transform: rotate(180deg); }
.btn-refresh.spinning svg { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.status-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 18px 10px;
  font-size: .7rem;
  opacity: .85;
}
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  flex-shrink: 0;
  transition: var(--transition);
}
.status-bar.ok .status-dot   { background: #34d399; box-shadow: 0 0 0 2px rgba(52,211,153,.3); }
.status-bar.err .status-dot  { background: #f87171; }
.status-bar.load .status-dot { background: var(--accent); animation: blink .8s step-start infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ═══════════════════════════════════════════════
   HERO BANNER
═══════════════════════════════════════════════ */
.hero-banner {
  flex-shrink: 0;
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
  position: relative;
  color: #fff;
  text-align: center;
  padding: 10px 20px 0;
}
.hero-content { position: relative; z-index: 1; }
.hero-icon { font-size: 2.2rem; margin-bottom: 6px; animation: bounce-in .6s ease-out; }
@keyframes bounce-in {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}
.hero-title {
  font-size: .95rem;
  font-weight: 700;
  margin-bottom: 4px;
  line-height: 1.3;
}
.hero-desc {
  font-size: .75rem;
  opacity: .85;
  line-height: 1.5;
  margin-bottom: 8px;
}
.hero-wave {
  position: relative;
  height: 40px;
  margin-top: -2px;
}
.hero-wave svg {
  position: absolute;
  bottom: 0; left: 0;
  width: 100%; height: 100%;
}

/* ═══════════════════════════════════════════════
   QUICK TOPICS
═══════════════════════════════════════════════ */
.quick-topics {
  flex-shrink: 0;
  padding: 12px 16px 10px;
  background: var(--bg-page);
}
.section-label {
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.chips-wrap {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.chips-wrap::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: 40px;
  padding: 6px 14px;
  font-size: .75rem;
  font-weight: 500;
  color: var(--primary);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  font-family: var(--font);
}
.chip:hover, .chip:focus-visible {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.chip-skeleton {
  flex-shrink: 0;
  width: 110px;
  height: 32px;
  border-radius: 40px;
  background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ═══════════════════════════════════════════════
   CHAT AREA
═══════════════════════════════════════════════ */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}
.chat-area::-webkit-scrollbar { width: 4px; }
.chat-area::-webkit-scrollbar-track { background: transparent; }
.chat-area::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* Message rows */
.msg-row {
  display: flex;
  gap: 8px;
  animation: slide-up .3s ease-out;
}
@keyframes slide-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.msg-row.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
}
.msg-avatar.bot  { background: linear-gradient(135deg, #2563eb, #1d4ed8); box-shadow: 0 2px 8px rgba(37,99,235,.4); }
.msg-avatar.user { background: linear-gradient(135deg, #f59e0b, #d97706); box-shadow: 0 2px 8px rgba(245,158,11,.4); }

.msg-bubble-wrap { max-width: calc(100% - 48px); display: flex; flex-direction: column; gap: 2px; }
.msg-row.user .msg-bubble-wrap { align-items: flex-end; }

.msg-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: .85rem;
  line-height: 1.55;
  color: var(--text-primary);
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
  word-break: break-word;
}
.msg-bubble.bot  { border-bottom-left-radius: 4px; }
.msg-bubble.user {
  border-bottom-right-radius: 4px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  box-shadow: 0 4px 16px rgba(37,99,235,.35);
}
.msg-bubble.result {
  background: var(--bg-card);
  border: 1.5px solid var(--primary-light);
}
.msg-bubble.no-result {
  background: #fff7ed;
  border: 1.5px solid #fed7aa;
}
.msg-time {
  font-size: .62rem;
  color: var(--text-muted);
  padding: 0 4px;
}

/* Result card */
.result-card { display: flex; flex-direction: column; gap: 8px; }
.result-name {
  font-weight: 700;
  font-size: .88rem;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.result-badge {
  font-size: .62rem;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 30px;
  padding: 2px 7px;
}
.result-instructions {
  font-size: .82rem;
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-wrap;
}
.result-footer {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}
.btn-detail {
  font-size: .75rem;
  font-weight: 600;
  border: none;
  border-radius: 30px;
  padding: 6px 14px;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.btn-detail.primary { background: var(--primary); color: #fff; }
.btn-detail.primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-detail.outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-detail.outline:hover { background: var(--primary-light); }

/* Multiple results list */
.multi-result-list { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.multi-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-page);
  border-radius: var(--radius-xs);
  padding: 8px 10px;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: var(--transition);
}
.multi-result-item:hover { border-color: var(--primary); background: var(--primary-light); }
.multi-result-idx {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.multi-result-name { font-size: .82rem; font-weight: 500; color: var(--text-primary); flex: 1; }
.multi-arrow { color: var(--text-muted); font-size: .8rem; }

/* Typing indicator */
.typing-row { display: flex; gap: 8px; align-items: flex-end; }
.typing-bubble {
  background: var(--bg-card);
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  display: flex;
  gap: 5px;
  box-shadow: var(--shadow-sm);
}
.typing-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing-bounce 1.4s infinite;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .5; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* ═══════════════════════════════════════════════
   INPUT BAR
═══════════════════════════════════════════════ */
.input-bar {
  flex-shrink: 0;
  padding: 10px 14px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
  box-shadow: 0 -2px 16px rgba(0,0,0,.06);
}
.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-page);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 6px 8px 14px;
  transition: var(--transition);
}
.input-wrap:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.user-textarea {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: .875rem;
  color: var(--text-primary);
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
}
.user-textarea::placeholder { color: var(--text-muted); }

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: var(--transition);
  box-shadow: 0 2px 8px rgba(37,99,235,.4);
}
.send-btn svg { width: 18px; height: 18px; }
.send-btn:hover:not(:disabled) { transform: scale(1.08); box-shadow: 0 4px 16px rgba(37,99,235,.5); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; background: #94a3b8; }

.input-hint {
  font-size: .62rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 6px;
}

/* ═══════════════════════════════════════════════
   MODAL
═══════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}
.modal-card {
  width: 100%;
  max-width: 430px;
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  overflow: hidden;
  transform: translateY(100%);
  transition: transform .35s cubic-bezier(.32,.72,0,1);
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
}
.modal-overlay.open .modal-card { transform: translateY(0); }

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.modal-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  flex: 1;
  line-height: 1.35;
}
.modal-close {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--bg-page);
  color: var(--text-secondary);
  font-size: .85rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: var(--transition);
}
.modal-close:hover { background: var(--border); }

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
  font-size: .875rem;
  line-height: 1.7;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}

.modal-footer {
  padding: 12px 20px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ═══════════════════════════════════════════════
   EMPTY STATE
═══════════════════════════════════════════════ */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  padding: 20px;
  pointer-events: none;
}
.empty-icon { font-size: 3rem; opacity: .5; }
.empty-title { font-size: .9rem; font-weight: 600; color: var(--text-secondary); }
.empty-desc { font-size: .78rem; color: var(--text-muted); line-height: 1.5; max-width: 240px; }

/* ═══════════════════════════════════════════════
   UTILITIES
═══════════════════════════════════════════════ */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

/* ═══════════════════════════════════════════════
   CƠ QUAN TIẾP NHẬN (trong result card)
═══════════════════════════════════════════════ */
.agency-section {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.agency-header {
  font-size: .75rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.agency-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 7px 9px;
  background: var(--bg-page);
  border-radius: var(--radius-xs);
  margin-bottom: 6px;
  border: 1px solid var(--border);
}
.agency-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 1px; }
.agency-info { flex: 1; min-width: 0; }
.agency-name {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}
.agency-addr {
  font-size: .76rem;
  color: var(--text-secondary);
  margin-top: 2px;
}
.agency-phone {
  font-size: .76rem;
  color: var(--primary);
  font-weight: 600;
  margin-top: 3px;
  display: block;
  text-decoration: none;
}
.agency-phone:hover { text-decoration: underline; }

/* ═══════════════════════════════════════════════
   CSKV – HỎI CÓ/KHÔNG
═══════════════════════════════════════════════ */
.msg-bubble.cskv-card {
  background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
  border: 1.5px solid #bae6fd;
}
.cskv-ask p {
  font-size: .84rem;
  color: var(--text-primary);
  line-height: 1.55;
  margin-bottom: 10px;
}
.cskv-btns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.btn-yesno {
  flex: 1;
  min-width: 110px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: .82rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: var(--transition);
}
.btn-yesno.yes {
  background: linear-gradient(135deg, var(--success), #059669);
  color: #fff;
  box-shadow: 0 2px 8px rgba(16,185,129,.35);
}
.btn-yesno.yes:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(16,185,129,.5); }
.btn-yesno.no {
  background: var(--bg-page);
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
}
.btn-yesno.no:hover:not(:disabled) { background: var(--border); }
.btn-yesno:disabled { opacity: .5; cursor: not-allowed; transform: none !important; }

/* ═══════════════════════════════════════════════
   CSKV – KẾT QUẢ TRA CỨU
═══════════════════════════════════════════════ */
.cskv-result { display: flex; flex-direction: column; gap: 8px; }
.cskv-header {
  font-weight: 700;
  font-size: .88rem;
  color: var(--primary);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--primary-light);
}
.cskv-addr-query {
  font-size: .78rem;
  color: var(--text-muted);
}
.cskv-officer {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px;
  background: var(--bg-page);
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  transition: var(--transition);
}
.cskv-officer:hover { border-color: var(--primary); background: var(--primary-light); }
.officer-avatar {
  font-size: 1.6rem;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #eff6ff, #dbeafe);
  border-radius: 50%;
}
.officer-info { flex: 1; min-width: 0; }
.officer-name { font-size: .84rem; font-weight: 700; color: var(--text-primary); }
.officer-addr { font-size: .77rem; color: var(--text-secondary); margin-top: 3px; }
.officer-phone {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 5px;
  background: var(--primary);
  color: #fff;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 600;
  text-decoration: none;
  transition: var(--transition);
}
.officer-phone:hover { background: var(--primary-dark); transform: translateY(-1px); }

/* ═══════════════════════════════════════════════
   MODAL – INSTRUCTIONS
═══════════════════════════════════════════════ */
.modal-instructions {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.75;
  color: var(--text-secondary);
}

/* ═══════════════════════════════════════════════
   CSKV – Ghi chú địa chỉ lân cận
═══════════════════════════════════════════════ */
.cskv-nearby-note {
  font-size: .8rem;
  line-height: 1.6;
  color: #92400e;
  background: #fef3c7;
  border: 1px solid #fde68a;
  border-radius: var(--radius-xs);
  padding: 9px 11px;
  margin-bottom: 6px;
}
.cskv-no-officer {
  font-size: .82rem;
  color: var(--text-muted);
  background: var(--bg-page);
  border: 1px dashed var(--border);
  border-radius: var(--radius-xs);
  padding: 10px 12px;
  text-align: center;
}

