/* ============================================
   利知红火填报助手 - 响应式样式表
   移动优先设计，适配手机/平板/桌面
   ============================================ */

/* ===== CSS 自定义属性 ===== */
:root {
  --primary: #D32F2F;
  --primary-dark: #B71C1C;
  --primary-light: #E53935;
  --accent: #C9A44A;
  --accent-light: #f5ecc8;
  --bg: #F5F0EB;
  --bg-page: #F0F4F8;
  --text: #2c3e50;
  --text-secondary: #666;
  --text-muted: #b0a898;
  --text-light: #999;
  --card-bg: #ffffff;
  --border: #d4c8b8;
  --border-light: #e8ddd0;
  --user-bg: #1a3c6e;
  --user-text: #fff;
  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 2px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 24px rgba(0, 0, 0, 0.12);
  --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --card-radius: 12px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --header-height: 48px;
  --tab-bar-height: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  height: 100%;
  background: #e8e0d8;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', sans-serif;
  font-size: 16px;
  color: var(--text);
  line-height: 1.6;
  overflow: hidden;
}

/* ===== App Container ===== */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 100%;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

/* ===== 顶部横幅 — ≤56px 紧凑双行 ===== */
#app-header {
  flex-shrink: 0;
  background: linear-gradient(135deg, #D32F2F 0%, #E53935 100%);
  color: #fff;
  text-align: center;
  position: relative;
  z-index: 10;
  padding: 6px 16px 4px;
}

/* 顶部装饰线隐藏，仅保留底部 */
.gov-ornament {
  display: none;
}
.gov-ornament.bottom {
  display: block;
  height: 1px;
  background: var(--accent);
  opacity: 0.5;
  margin-top: 3px;
}

.gov-title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.gov-star {
  font-size: 14px;
  color: var(--accent);
  line-height: 1;
  opacity: 0.9;
}

.gov-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 3px;
  line-height: 1.2;
}

.gov-subtitle-en {
  display: block;
  font-size: 11px;
  letter-spacing: 1.5px;
  opacity: 0.75;
  margin-top: 1px;
  font-family: 'Times New Roman', 'Georgia', serif;
  line-height: 1.2;
}

.gov-subtitle-zh {
  display: none;
}

/* ===== 主内容区 ===== */
#main-content {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* ===== 页面容器 ===== */
.page {
  display: none;
  height: 100%;
  overflow: hidden;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.page.active {
  display: flex;
  flex-direction: column;
}

/* =============================================
   页面：智能问答
   ============================================= */

/* 消息列表容器 */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

#chat-inner {
  padding: 16px;
  min-height: 100%;
}

/* 消息行 */
.msg-row {
  display: flex;
  margin-bottom: 18px;
  align-items: flex-start;
  animation: msgFadeIn 0.25s ease-out;
}

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

.row-user {
  flex-direction: row-reverse;
}

.row-assistant {
  flex-direction: row;
}

/* 头像 */
.msg-avatar {
  width: 40px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
  letter-spacing: 1px;
}

.msg-avatar.user {
  background: var(--user-bg);
  color: #fff;
  margin-left: 10px;
}

.msg-avatar.assistant {
  background: var(--primary);
  color: #fff;
  margin-right: 10px;
}

/* 消息气泡 */
.msg-box {
  max-width: 74%;
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.65;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg-box.user {
  background: var(--user-bg);
  color: var(--user-text);
  border-radius: 10px 3px 10px 10px;
}

.msg-box.assistant {
  background: var(--card-bg);
  color: var(--text);
  border-radius: 3px 10px 10px 10px;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
}

.msg-time {
  display: block;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
  margin-top: 5px;
  text-align: right;
}

.msg-box.assistant .msg-time {
  color: var(--text-muted);
}

/* 加载动画 */
.loading-row {
  display: flex;
  margin-bottom: 18px;
  align-items: flex-start;
}

.loading-row .msg-avatar {
  background: var(--primary);
  color: #fff;
  margin-right: 10px;
}

.loading-box {
  background: var(--card-bg);
  border-radius: 3px 10px 10px 10px;
  border: 1px solid var(--border-light);
  padding: 14px 18px;
  box-shadow: var(--shadow-sm);
}

.loading-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 0;
}

.loading-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  animation: dotPulse 1.4s infinite ease-in-out;
}

.loading-dot:nth-child(1) { animation-delay: -0.32s; }
.loading-dot:nth-child(2) { animation-delay: -0.16s; }
.loading-dot:nth-child(3) { animation-delay: 0s; }

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

.loading-text {
  font-size: 12px;
  color: var(--text-muted);
  display: block;
  margin-top: 4px;
}

/* =============================================
   空状态 & 常见问题
   ============================================= */
#empty-state {
  padding-top: 12px;
}

.qs-divider {
  display: flex;
  align-items: center;
  margin: 12px 0 16px;
}

.qs-divider::before,
.qs-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.qs-divider-text {
  padding: 0 16px;
  font-size: 14px;
  font-weight: 600;
  color: #8B4513;
  letter-spacing: 4px;
  white-space: nowrap;
}

/* 常见问题网格 — 手机端单列卡片 */
.qs-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.qs-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--card-bg);
  border: 1px solid var(--border-light);
  border-radius: var(--card-radius);
  padding: 18px 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  text-align: center;
  font-family: inherit;
  line-height: 1.4;
  -webkit-user-select: none;
  user-select: none;
  box-shadow: var(--card-shadow);
}

.qs-btn:hover {
  border-color: var(--primary);
  background: #fdf8f3;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.qs-btn:active {
  transform: scale(0.97);
  background: #f5ece3;
}

.qs-btn-icon {
  font-size: 32px;
  line-height: 1;
}

/* ===== 底部输入区 ===== */
#input-area {
  flex-shrink: 0;
  background: var(--card-bg);
  border-top: 3px solid var(--primary);
  padding: 10px 16px;
  padding-bottom: calc(10px + var(--safe-bottom));
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.04);
}

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

#chat-input {
  flex: 1;
  height: 44px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  font-size: 16px; /* 16px prevents iOS zoom on focus */
  color: var(--text);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

#chat-input:focus {
  border-color: var(--primary);
}

#chat-input::placeholder {
  color: var(--text-muted);
}

.btn-send {
  height: 44px;
  line-height: 44px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0 24px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 3px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
  font-family: inherit;
  -webkit-user-select: none;
  user-select: none;
}

.btn-send:hover {
  background: var(--primary-dark);
}

.btn-send:active {
  opacity: 0.85;
  transform: scale(0.97);
}

.btn-send:disabled,
.btn-send.disabled {
  background: #c49090;
  cursor: not-allowed;
  transform: none;
}

.input-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}

.btn-clear {
  background: none;
  border: 1px solid var(--user-bg);
  color: var(--user-bg);
  border-radius: var(--radius-sm);
  padding: 4px 16px;
  font-size: 13px;
  line-height: 1.8;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s, transform 0.15s;
  -webkit-user-select: none;
  user-select: none;
  /* 确保点击区域不小于 48x48 */
  min-height: 36px;
}

.btn-clear:hover {
  background: #eef1f5;
  transform: scale(1.03);
}

.btn-clear:active {
  background: #dce0e6;
  transform: scale(0.97);
}

.input-hint {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 1px;
}

/* ICP备案号 */
.icp-inline {
  width: 100%;
  text-align: center;
  margin-top: 4px;
}
.icp-inline a {
  font-size: 10px;
  color: var(--text-light);
  text-decoration: none;
  white-space: nowrap;
}
.icp-inline a:hover {
  text-decoration: underline;
}

/* =============================================
   页面：使用说明
   ============================================= */
#page-about {
  display: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#page-about.active {
  display: block;
}

.about-content {
  padding: 20px 16px 40px;
  min-height: 100%;
}

.about-section {
  margin-bottom: 24px;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
  padding-left: 2px;
}

.about-card {
  background: var(--card-bg);
  border-radius: var(--card-radius);
  padding: 16px 18px;
  box-shadow: var(--card-shadow);
}

.about-card-warn {
  border-left: 4px solid #FF9800;
}

.card-text {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.8;
  white-space: pre-line;
}

/* 功能列表 */
.feature-list {
  list-style: none;
  margin-top: 10px;
}

.feature-list li {
  display: flex;
  align-items: flex-start;
  margin-bottom: 10px;
  font-size: 14px;
  color: #444;
  line-height: 1.5;
  gap: 8px;
}

.feature-icon {
  flex-shrink: 0;
  font-size: 16px;
  line-height: 1.5;
}

/* 步骤列表 */
.step-list {
  list-style: none;
  padding-left: 2px;
}

.step-list li {
  display: flex;
  align-items: center;
  margin-bottom: 14px;
  font-size: 14px;
  color: #444;
  line-height: 1.5;
  gap: 12px;
}

.step-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* 注意事项列表 */
.warn-list {
  padding-left: 16px;
}

.warn-list li {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.8;
  margin-bottom: 6px;
}

/* 联系方式 */
.contact-text {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.8;
  margin-bottom: 2px;
}

/* 底部版本 */
.about-footer {
  text-align: center;
  padding: 30px 0 10px;
}

.about-footer p {
  font-size: 12px;
  color: var(--text-light);
  line-height: 1.8;
}

/* =============================================
   底部导航栏 — 固定底部，点击区域 ≥48px
   ============================================= */
#tab-bar {
  flex-shrink: 0;
  display: flex;
  background: var(--card-bg);
  border-top: 1px solid var(--border-light);
  padding-bottom: var(--safe-bottom);
  z-index: 20;
  box-shadow: 0 -1px 8px rgba(0, 0, 0, 0.04);
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  min-width: 48px;
  padding: 6px 0 4px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-muted);
  transition: color 0.15s;
  font-family: inherit;
  -webkit-user-select: none;
  user-select: none;
  position: relative;
  gap: 2px;
}

.tab-item.active {
  color: var(--primary);
}

.tab-item.active::after {
  content: '';
  position: absolute;
  top: 0;
  left: 30%;
  right: 30%;
  height: 2px;
  background: var(--primary);
  border-radius: 0 0 2px 2px;
}

.tab-icon {
  width: 22px;
  height: 22px;
}

.tab-label {
  font-size: 10px;
  line-height: 1.2;
  letter-spacing: 0.5px;
}

/* 桌面 hover 效果 */
.tab-item:hover {
  color: var(--primary);
}

/* =============================================
   响应式：平板 (≥ 600px)
   ============================================= */
@media (min-width: 600px) {
  body {
    background: #dcd5cc;
  }

  #app {
    max-width: 600px;
    box-shadow: var(--shadow-md);
  }

  .qs-grid {
    grid-template-columns: 1fr 1fr;
  }

  .qs-btn {
    padding: 20px 16px;
    font-size: 15px;
  }

  .msg-box {
    max-width: 68%;
  }

  .about-content {
    padding: 28px 24px 48px;
  }

  #input-area {
    padding: 12px 20px;
  }
}

/* =============================================
   响应式：桌面 (≥ 900px)
   居中卡片式布局，max-width 1200px
   ============================================= */
@media (min-width: 900px) {
  body {
    background: #c8bfb4;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #app {
    max-width: 1200px;
    width: 100%;
    height: calc(100vh - 60px);
    height: calc(100dvh - 60px);
    border-radius: var(--card-radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
  }

  #app-header {
    padding: 10px 24px 8px;
  }

  .gov-title {
    font-size: 20px;
  }

  .gov-star {
    font-size: 16px;
  }

  .gov-subtitle-en {
    font-size: 12px;
  }

  /* 桌面端常见问题三列 */
  .qs-grid {
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
  }

  .qs-btn {
    padding: 22px 18px;
    font-size: 15px;
  }

  .qs-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  }

  .msg-avatar {
    width: 40px;
    height: 40px;
    line-height: 40px;
  }

  .msg-box {
    max-width: 65%;
    padding: 12px 18px;
    font-size: 15px;
  }

  #chat-input {
    height: 46px;
    font-size: 15px;
  }

  .btn-send {
    height: 46px;
    line-height: 46px;
    padding: 0 32px;
  }

  .btn-clear {
    min-height: 38px;
    padding: 4px 20px;
    font-size: 13px;
  }

  .tab-item {
    min-height: 52px;
    padding: 8px 0 6px;
  }

  .tab-icon {
    width: 24px;
    height: 24px;
  }

  .tab-label {
    font-size: 11px;
  }

  .about-content {
    padding: 32px 32px 48px;
  }

  .about-card {
    padding: 20px 24px;
  }

  .section-title {
    font-size: 18px;
  }
}

/* =============================================
   响应式：大桌面 (≥ 1200px)
   ============================================= */
@media (min-width: 1200px) {
  #app {
    max-width: 1200px;
    height: calc(100vh - 80px);
    height: calc(100dvh - 80px);
  }

  .qs-grid {
    gap: 20px;
  }

  .about-content {
    padding: 40px 48px 60px;
  }
}

/* =============================================
   响应式：移动端专属 — 横幅强制压缩 (≤767px)
   使用 !important 确保不被其他规则覆盖
   桌面端（≥768px）完全不受影响
   ============================================= */
@media (max-width: 767px) {
  #app-header {
    padding: 4px 12px 3px !important;
    height: auto !important;
    min-height: 0 !important;
  }
  .gov-title {
    font-size: 16px !important;
    letter-spacing: 2px !important;
    line-height: 1.2 !important;
  }
  .gov-star {
    font-size: 12px !important;
  }
  .gov-title-row {
    gap: 5px !important;
  }
  .gov-subtitle-en {
    display: none !important;
  }
  .gov-ornament.bottom {
    display: none !important;
  }
}

/* 移动端：常见问题强制紧凑排版 + ICP 合并到一行 (≤767px) */
@media (max-width: 767px) {
  div#empty-state div.qs-grid {
    gap: 12px !important;
  }
  div#empty-state button.qs-btn {
    padding: 12px !important;
    gap: 6px !important;
    font-size: 13px !important;
    border-radius: 10px !important;
    margin: 0 !important;
  }
  div#empty-state span.qs-btn-icon {
    font-size: 24px !important;
  }

  /* ICP 备案号与按钮同行 */
  div.input-bottom {
    flex-wrap: nowrap !important;
    gap: 6px !important;
  }
  span.icp-inline {
    width: auto !important;
    margin-top: 0 !important;
    flex-shrink: 0 !important;
  }
  span.icp-inline a {
    font-size: 10px !important;
  }
  span.input-hint {
    font-size: 10px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    flex: 1 !important;
    min-width: 0 !important;
  }
  button#btn-clear {
    flex-shrink: 0 !important;
    padding: 3px 10px !important;
    font-size: 12px !important;
  }
}

/* =============================================
   超小屏极致压缩 (≤390px) — iPhone SE / 低端安卓
   仅压缩常见问题 & 扩容对话区，不动 header
   ============================================= */
@media (max-width: 390px) {

  /* ----- 常见问题微型化 ----- */
  div#empty-state {
    padding-top: 6px !important;
  }
  div#empty-state div.qs-divider {
    margin: 6px 0 10px !important;
  }
  div#empty-state span.qs-divider-text {
    font-size: 14px !important;
  }
  div#empty-state div.qs-grid {
    gap: 8px !important;
  }
  div#empty-state button.qs-btn {
    padding: 8px !important;
    gap: 4px !important;
    font-size: 12px !important;
    border-radius: 8px !important;
  }
  div#empty-state span.qs-btn-icon {
    font-size: 20px !important;
  }

  /* ----- 对话区扩容：减少留白，显示更多内容 ----- */
  div#chat-inner {
    padding: 8px !important;
  }
  div.msg-row {
    margin-bottom: 12px !important;
  }
  div.msg-box {
    padding: 8px 10px !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
  }
  div.msg-avatar {
    width: 32px !important;
    height: 32px !important;
    line-height: 32px !important;
    font-size: 10px !important;
  }
  div.msg-avatar.user {
    margin-left: 6px !important;
  }
  div.msg-avatar.assistant {
    margin-right: 6px !important;
  }

  /* 输入区略微压缩 */
  div#input-area {
    padding: 6px 12px !important;
  }
  div.input-bottom {
    margin-top: 6px !important;
  }
  span.icp-inline a {
    font-size: 9px !important;
  }
}

/* =============================================
   iOS 安全区适配 & 键盘弹出处理
   ============================================= */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  #input-area {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  #tab-bar {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* =============================================
   滚动条美化
   ============================================= */
#chat-messages::-webkit-scrollbar,
#page-about::-webkit-scrollbar {
  width: 4px;
}

#chat-messages::-webkit-scrollbar-track,
#page-about::-webkit-scrollbar-track {
  background: transparent;
}

#chat-messages::-webkit-scrollbar-thumb,
#page-about::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
}

#chat-messages::-webkit-scrollbar-thumb:hover,
#page-about::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

/* =============================================
   Utility
   ============================================= */
.hide-scrollbar {
  -ms-overflow-style: none;
  scrollbar-width: thin;
}

/* =============================================
   移动端底部栏强制单行布局 (≤768px)
   备案号、按钮、提示文本合并为一行
   ============================================= */
@media (max-width: 768px) {
  /* 底部栏容器：强制禁止换行 + Flex 单行 */
  #footer-container {
    display: flex !important;
    flex-direction: row !important;
    justify-content: space-between !important;
    align-items: center !important;
    flex-wrap: nowrap !important;
    white-space: nowrap !important;
    overflow-x: visible !important;
    gap: 4px !important;
  }

  /* 所有按钮、链接极限压缩 */
  #footer-container button,
  #footer-container a,
  #footer-container .btn-clear {
    padding-left: 4px !important;
    padding-right: 4px !important;
    padding-top: 8px !important;
    padding-bottom: 8px !important;
  }

  /* 提示文本字号放大到 12px */
  #footer-container .input-hint {
    font-size: 12px !important;
    white-space: nowrap !important;
    overflow: visible !important;
    flex-shrink: 0 !important;
  }

  /* 备案号：右推 + 浅灰 */
  #footer-container .beian-link {
    font-size: 10px !important;
    color: #aaaaaa !important;
    margin-left: auto !important;
    flex-shrink: 0 !important;
    text-decoration: none !important;
  }
}

/* ===== 公安备案栏 ===== */
#beian-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 0;
  background: #f5f0eb;
  font-size: 12px;
}
#beian-bar a {
  color: #999;
  text-decoration: none;
}
#beian-bar a:hover {
  text-decoration: underline;
}
.beian-icon {
  width: 18px;
  height: 18px;
  display: inline-block;
}
@media (max-width: 768px) {
  #beian-bar {
    padding: 4px 0 !important;
    font-size: 10px !important;
  }
  .beian-icon {
    width: 16px !important;
    height: 16px !important;
  }
}
