:root {
  /* 智能船舶综合运营服务平台主题色 */
  --primary: #1b5eb1;
  --primary-dark: #164e96;
  --primary-accent: #1890ff;
  --primary-light: #e6f4ff;
  --gradient-start: #2778c4;
  --gradient-end: #50a1e3;
  --header-gradient: linear-gradient(90deg, var(--gradient-start) 0%, var(--gradient-end) 100%);
  --brand-gradient: linear-gradient(135deg, var(--primary) 0%, var(--gradient-end) 100%);

  --bg: #f0f4f8;
  --surface: #ffffff;
  --text: #333333;
  --text-muted: #8c8c8c;
  --border: #e8eef5;
  --shadow: 0 4px 16px rgba(27, 94, 177, 0.08);
  --radius: 8px;
  --sidebar-w: 240px;
  --faq-panel-w: 360px;
  --assistant-min-w: 420px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app.hidden {
  display: none;
}

.app {
  max-width: 1440px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app.embed .topbar,
.app.embed .hero {
  display: none;
}

.app.embed .workspace {
  min-height: 100vh;
}

.app.embed .faq-panel,
.app.embed .assistant-panel {
  max-height: 100vh;
}

.app.embed {
  max-width: none;
}

/* 小程序 web-view：单列对话布局（不影响 PC 默认与 admin_web 新窗口 embed） */
.app.embed.mobile {
  min-height: 100vh;
  height: 100vh;
}

.app.embed.mobile .workspace {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  height: 100vh;
  max-height: 100vh;
}

.app.embed.mobile .sidebar {
  flex-shrink: 0;
  border-right: none;
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  position: relative;
  z-index: 3;
  background: var(--surface);
}

.app.embed.mobile .sidebar h2 {
  display: none;
}

.app.embed.mobile .category-nav {
  flex-direction: row;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
  position: relative;
  z-index: 3;
}

.app.embed.mobile .cat-btn {
  width: auto;
  flex-shrink: 0;
  padding: 8px 12px;
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  z-index: 2;
}

.app.embed.mobile .faq-panel {
  display: none;
}

.app.embed.mobile .assistant-panel {
  display: flex !important;
  flex: 1;
  min-height: 0;
  max-height: none;
  border-left: none;
}

body.faq-mobile {
  overscroll-behavior: none;
}

body.faq-mobile .chat-input-bar {
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.mobile-cat-bubble {
  max-width: 92%;
  padding: 12px 14px 10px;
}

.mobile-cat-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
}

.mobile-faq-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mobile-faq-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  padding: 10px 12px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.mobile-faq-item:active {
  background: var(--primary-light);
  border-color: var(--primary-accent);
  color: var(--primary);
}

/* ── Top bar ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 16px 32px;
  background: var(--header-gradient);
  border-bottom: none;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
}

.brand-sub {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.82);
}

.topbar-search {
  flex: 1;
  max-width: 560px;
  position: relative;
}

.topbar-search input {
  width: 100%;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 4px;
  padding: 0 20px 0 44px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.topbar-search input::placeholder {
  color: var(--text-muted);
}

.topbar-search input:focus {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.45);
  background: #fff;
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.92);
  flex-shrink: 0;
}

.status-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}

/* ── Hero ── */
.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px 32px 22px;
  background: var(--header-gradient);
  color: #fff;
}

.hero-text h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
}

.hero-text p {
  font-size: 15px;
  opacity: 0.85;
}

.hero-stats {
  display: flex;
  gap: 32px;
}

.stat {
  text-align: center;
}

.stat strong {
  display: block;
  font-size: 28px;
  font-weight: 700;
}

.stat span {
  font-size: 12px;
  opacity: 0.75;
}

/* ── Workspace ── */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(280px, var(--faq-panel-w)) minmax(var(--assistant-min-w), 1fr);
  gap: 0;
  min-height: calc(100vh - 200px);
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
}

.sidebar h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding: 0 8px;
}

.category-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cat-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-radius: 10px;
  background: none;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.cat-btn:hover {
  background: var(--bg);
}

.cat-btn.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.cat-btn .cat-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.cat-btn.active .cat-icon {
  background: var(--primary-accent);
  color: #fff;
}

/* ── FAQ panel ── */
.faq-panel {
  padding: 20px 16px;
  overflow-y: auto;
  max-height: calc(100vh - 200px);
  border-right: 1px solid var(--border);
  background: var(--bg);
}

.panel-head {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  margin-bottom: 16px;
}

.panel-head h2 {
  font-size: 18px;
  font-weight: 700;
}

.panel-count {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
  word-break: break-all;
}

.faq-grid {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.faq-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
  display: flex;
  align-items: center;
  gap: 10px;
}

.faq-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.faq-card.active {
  border-color: var(--primary);
  background: var(--primary-light);
}

.faq-card .num {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--bg);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.faq-card.active .num {
  background: var(--primary-accent);
  color: #fff;
}

.faq-card .q-text {
  font-size: 14px;
  line-height: 1.45;
  flex: 1;
}

.faq-card .arrow {
  color: var(--text-muted);
  font-size: 18px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
}

.faq-card:hover .arrow,
.faq-card.active .arrow {
  opacity: 1;
}

/* ── Assistant panel ── */
.assistant-panel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 200px);
  min-height: 0;
  overflow: hidden;
}

.assistant-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.assistant-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.assistant-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--brand-gradient);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.assistant-name {
  font-size: 15px;
  font-weight: 600;
}

.assistant-tip {
  font-size: 12px;
  color: var(--text-muted);
}

.chat {
  flex: 0 0 auto;
  padding: 16px 20px;
  min-height: 80px;
}

.msg-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

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

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--brand-gradient);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.msg-row.user .msg-avatar {
  background: #94a3b8;
  font-size: 11px;
}

.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

.msg-row.bot .bubble {
  background: var(--bg);
  color: var(--text);
  border-bottom-left-radius: 4px;
  max-height: 420px;
  overflow-y: auto;
}

.bubble.bubble-answer {
  max-width: 92%;
  max-height: 360px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.65;
}

.bubble-answer .answer-lead {
  margin: 0 0 8px;
  font-size: 13px;
}

.bubble-answer .answer-section-title {
  margin: 10px 0 6px;
  font-size: 12px;
}

.bubble-answer .answer-step-title {
  margin: 12px 0 6px;
  font-size: 13px;
}

.bubble-answer .answer-para {
  margin: 0 0 8px;
  font-size: 13px;
}

.bubble-answer .answer-list {
  margin: 0 0 8px;
  padding-left: 18px;
  font-size: 13px;
}

.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 180px;
  color: var(--text-muted);
}

.typing-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #cbd5e1;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

.typing-text {
  font-size: 13px;
}

.typing-dots span {
  animation: typing-dot 1.2s infinite;
  opacity: 0.2;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes typing-dot {
  0%,
  80%,
  100% {
    opacity: 0.2;
  }
  40% {
    opacity: 1;
  }
}

.answer-body.is-typing::after {
  content: "▍";
  color: var(--primary);
  animation: caret-blink 0.8s step-end infinite;
  margin-left: 2px;
}

@keyframes caret-blink {
  50% {
    opacity: 0;
  }
}

.msg-row.user .bubble {
  background: var(--primary-accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.answer-card {
  flex-shrink: 0;
  margin: 0 20px 16px;
  padding: 16px 18px;
  background: #f8fafc;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.answer-card.hidden {
  display: none;
}

.answer-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 8px;
}

.answer-card h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
  line-height: 1.4;
}

.answer-body {
  font-size: 14px;
  line-height: 1.75;
  color: var(--text);
}

.answer-lead {
  margin: 0 0 12px;
  font-weight: 600;
  color: var(--primary);
}

.answer-section-title {
  margin: 14px 0 8px;
  font-size: 13px;
  font-weight: 700;
  color: #334155;
  padding-left: 10px;
  border-left: 3px solid var(--primary);
}

.answer-step-title {
  margin: 16px 0 8px;
  font-size: 14px;
  font-weight: 700;
  color: #1e293b;
}

.answer-para {
  margin: 0 0 10px;
  color: #475569;
  text-align: justify;
}

.answer-list {
  margin: 0 0 12px;
  padding-left: 20px;
  color: #475569;
}

.answer-list li {
  margin-bottom: 6px;
  line-height: 1.7;
}

.answer-list li::marker {
  color: var(--primary);
}

.answer-block-hidden {
  opacity: 0;
  transform: translateY(6px);
}

.answer-block-show {
  animation: answer-block-in 0.35s ease forwards;
}

@keyframes answer-block-in {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-input-bar {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.chat-input-bar input {
  flex: 1;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 18px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.chat-input-bar input:focus {
  border-color: var(--primary-accent);
}

.chat-input-bar button {
  height: 42px;
  padding: 0 22px;
  border: none;
  border-radius: 4px;
  background: var(--primary-accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.chat-input-bar button:hover:not(:disabled) {
  background: var(--primary);
}

.chat-input-bar button:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.chat-input-bar input:disabled {
  background: #f1f5f9;
  cursor: not-allowed;
}

.human-service-tip {
  margin-top: 4px;
  color: var(--text);
}

.human-service-hours {
  color: var(--text-muted);
  font-size: 13px;
}

.human-service-qr {
  display: block;
  width: min(220px, 100%);
  margin: 12px auto 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
}

.msg-row.bot .bubble .human-service-qr {
  max-width: 100%;
}

/* ── Suggest dropdown ── */
.suggest {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(27, 94, 177, 0.15);
  max-height: 280px;
  overflow-y: auto;
  display: none;
  z-index: 200;
}

.suggest.show {
  display: block;
}

.suggest-item {
  padding: 12px 18px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.suggest-item:last-child {
  border-bottom: none;
}

.suggest-item:hover {
  background: var(--primary-light);
}

.empty {
  grid-column: 1 / -1;
  padding: 48px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.search-hint {
  padding: 20px 0;
  text-align: left;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

/* ── Responsive ── */
@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 200px 1fr;
  }
  .assistant-panel {
    display: none;
  }
}

@media (max-width: 768px) {
  .hero-stats {
    display: none;
  }
  .workspace {
    grid-template-columns: 1fr;
  }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .category-nav {
    flex-direction: row;
    overflow-x: auto;
  }
  .cat-btn {
    white-space: nowrap;
    flex-shrink: 0;
  }
}

.access-gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e6f4ff 0%, #f0f4f8 100%);
}

.access-gate.hidden {
  display: none;
}

.access-gate-card {
  max-width: 420px;
  padding: 40px 32px;
  text-align: center;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.access-gate-card h1 {
  margin-bottom: 12px;
  font-size: 22px;
  color: var(--primary);
}

.access-gate-card p {
  color: var(--text-muted);
  line-height: 1.6;
}
