/* ==========================================================================
   FENTILA · AI分析 对话界面 (Impeccable Product Register)
   Scoped under .fai-* — Warm neutral canvas (#FAF8F5 / #F7F5F0), terracotta (#9A4E32)
   Zero side-stripe accents, zero ghost-card chrome, zero gradient text
   ========================================================================== */

.fai-root {
  --fai-canvas: #F7F5F0;
  --fai-surface: #FFFFFF;
  --fai-sunken: #EFECE6;
  --fai-line: rgba(34, 28, 24, 0.085);
  --fai-line-strong: rgba(34, 28, 24, 0.15);
  --fai-ink: #1C1917;
  --fai-ink-2: #443F3B;
  --fai-ink-3: #5F5953;
  --fai-accent: #9A4E32;
  --fai-accent-ink: #7D3B23;
  --fai-accent-soft: #F6ECE6;
  --fai-ok: #1D7A4C;
  --fai-warn: #945205;
  --fai-warn-soft: #FCF0DC;
  --fai-danger: #B43225;
  --fai-danger-soft: #FBE9E6;
  --fai-ease: cubic-bezier(0.22, 1, 0.36, 1);

  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--fai-canvas);
  color: var(--fai-ink);
  font-variant-numeric: tabular-nums;
}

.fai-root *,
.fai-root *::before,
.fai-root *::after {
  box-sizing: border-box;
}

.fai-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Compact Top Status Strip ---------- */
.fai-status-bar {
  flex-shrink: 0;
  padding: 7px 14px;
  background: var(--fai-surface);
  border-bottom: 1px solid var(--fai-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.fai-status-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.fai-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--fai-ink-3);
  flex-shrink: 0;
}

.fai-dot.is-ok {
  background: var(--fai-ok);
}

.fai-dot.is-warn {
  background: #C7780A;
}

.fai-dot.is-err {
  background: var(--fai-danger);
}

.fai-engine-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--fai-ink);
  white-space: nowrap;
  flex-shrink: 0;
}

.fai-scope-pill {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--fai-sunken);
  color: var(--fai-ink-2);
  font-size: 10.5px;
  font-weight: 600;
}

.fai-status-right {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.fai-ghost-btn {
  height: 25px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid var(--fai-line-strong);
  background: var(--fai-surface);
  color: var(--fai-ink-2);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 150ms var(--fai-ease), color 150ms var(--fai-ease);
}

.fai-ghost-btn:active {
  background: var(--fai-sunken);
}

.fai-ghost-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.fai-history-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.fai-history-btn.is-open {
  background: var(--fai-accent-soft);
  border-color: rgba(154, 78, 50, 0.35);
  color: var(--fai-accent-ink);
}

.fai-history-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 15px;
  height: 15px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--fai-sunken);
  color: var(--fai-ink-2);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.fai-history-btn.is-open .fai-history-count {
  background: var(--fai-accent);
  color: #FFFFFF;
}

/* ---------- History Conversations Drawer ---------- */
.fai-history-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 25, 23, 0.34);
  z-index: 20;
}

.fai-history-drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(86%, 320px);
  background: var(--fai-surface);
  border-left: 1px solid var(--fai-line);
  box-shadow: -8px 0 24px rgba(28, 25, 23, 0.14);
  z-index: 21;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.fai-history-head {
  flex-shrink: 0;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--fai-line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.fai-history-head-main {
  min-width: 0;
  flex: 1;
}

.fai-history-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--fai-ink);
  display: flex;
  align-items: center;
  gap: 6px;
}

.fai-history-total {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--fai-ink-3);
}

.fai-history-sub {
  margin: 3px 0 0;
  font-size: 11px;
  color: var(--fai-ink-3);
  line-height: 1.35;
}

.fai-history-close {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: var(--fai-sunken);
  color: var(--fai-ink-2);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.fai-history-actions {
  flex-shrink: 0;
  padding: 9px 12px;
  background: var(--fai-canvas);
  border-bottom: 1px solid var(--fai-line);
  display: flex;
  align-items: center;
  gap: 8px;
}

.fai-history-new-btn {
  flex: 1;
  height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: var(--fai-accent);
  color: #FFFFFF;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}

.fai-history-clear-btn {
  height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--fai-line-strong);
  background: var(--fai-surface);
  color: var(--fai-ink-2);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.fai-history-clear-btn.is-confirm {
  background: var(--fai-danger-soft);
  border-color: rgba(180, 50, 37, 0.35);
  color: var(--fai-danger);
}

.fai-history-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 8px 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.fai-history-item {
  display: flex;
  align-items: stretch;
  gap: 4px;
  border-radius: 10px;
  border: 1px solid var(--fai-line);
  background: var(--fai-surface);
  transition: background 140ms var(--fai-ease), border-color 140ms var(--fai-ease);
}

.fai-history-item.is-active {
  background: var(--fai-accent-soft);
  border-color: rgba(154, 78, 50, 0.34);
}

.fai-history-item-main {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 9px 4px 9px 10px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.fai-history-item-top {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.fai-history-item-title {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--fai-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fai-history-now-tag {
  flex-shrink: 0;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--fai-accent);
  color: #FFFFFF;
  font-size: 9.5px;
  font-weight: 700;
}

.fai-history-item-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 10.5px;
  color: var(--fai-ink-3);
}

.fai-history-ttl {
  color: var(--fai-ink-3);
}

.fai-history-ttl.is-soon {
  color: var(--fai-warn);
  font-weight: 650;
}

.fai-history-del-btn {
  flex-shrink: 0;
  width: 30px;
  border: 0;
  border-radius: 0 9px 9px 0;
  background: transparent;
  color: var(--fai-ink-3);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.fai-history-del-btn:active {
  background: var(--fai-danger-soft);
  color: var(--fai-danger);
}

.fai-history-empty {
  padding: 36px 16px;
  text-align: center;
  color: var(--fai-ink-3);
  font-size: 12px;
  line-height: 1.6;
}

.fai-history-empty strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
  color: var(--fai-ink-2);
}

/* ---------- Scrollable Thread & Welcome State ---------- */
.fai-thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.fai-thread::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.fai-welcome {
  margin: 0;
  padding: 4px 0 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fai-welcome-title {
  margin: 0;
  font-size: 16px;
  font-weight: 750;
  letter-spacing: -0.01em;
  color: var(--fai-ink);
  text-wrap: balance;
}

.fai-welcome-desc {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--fai-ink-2);
  max-width: 65ch;
}

.fai-prompt-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 2px;
}

.fai-prompt-chip {
  width: 100%;
  padding: 8.5px 11px;
  border-radius: 11px;
  border: 1px solid var(--fai-line-strong);
  background: var(--fai-surface);
  color: var(--fai-ink);
  font-size: 12px;
  font-weight: 550;
  line-height: 1.42;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  transition: border-color 150ms var(--fai-ease), background 150ms var(--fai-ease);
}

.fai-prompt-chip:hover {
  border-color: var(--fai-accent);
  background: #FFFDFB;
}

.fai-prompt-chip:active {
  background: var(--fai-accent-soft);
}

.fai-prompt-text {
  flex: 1;
  min-width: 0;
}

.fai-prompt-arrow {
  flex-shrink: 0;
  color: var(--fai-accent);
  font-size: 13px;
  font-weight: 700;
}

/* ---------- Messages ---------- */
.fai-msg {
  display: flex;
  flex-direction: column;
}

.fai-msg.is-user {
  align-items: flex-end;
}

.fai-user-bubble {
  max-width: 86%;
  padding: 9px 13px;
  border-radius: 12px 12px 4px 12px;
  background: var(--fai-accent);
  color: #FFFFFF;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  user-select: text;
  overflow-wrap: anywhere;
}

.fai-ai-card {
  width: 100%;
  padding: 12px 13px;
  border-radius: 12px;
  border: 1px solid var(--fai-line);
  background: var(--fai-surface);
  color: var(--fai-ink);
  user-select: text;
}

.fai-ai-card.is-error {
  border-color: rgba(180, 50, 37, 0.25);
  background: #FFFDFC;
}

.fai-ai-meta {
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--fai-line);
  font-size: 11px;
  font-weight: 600;
  color: var(--fai-ink-3);
}

/* ---------- XSS-Safe Rendered Markdown ---------- */
.fai-md {
  font-size: 13px;
  line-height: 1.62;
  color: var(--fai-ink);
  overflow-wrap: anywhere;
}

.fai-md-h {
  margin: 12px 0 5px;
  font-size: 13.5px;
  font-weight: 750;
  color: var(--fai-ink);
  line-height: 1.35;
}

.fai-md > .fai-md-h:first-child {
  margin-top: 0;
}

.fai-md-p {
  margin: 0 0 8px;
  max-width: 68ch;
}

.fai-md-p:last-child {
  margin-bottom: 0;
}

.fai-md-list {
  margin: 4px 0 9px;
  padding-left: 18px;
}

.fai-md-list:last-child {
  margin-bottom: 0;
}

.fai-md-list li {
  margin-bottom: 4px;
}

.fai-md-list li:last-child {
  margin-bottom: 0;
}

.fai-code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--fai-sunken);
  color: var(--fai-accent-ink);
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
}

.fai-table-wrap {
  margin: 8px 0;
  overflow-x: auto;
  border: 1px solid var(--fai-line);
  border-radius: 8px;
  background: var(--fai-surface);
}

.fai-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
  line-height: 1.4;
  white-space: nowrap;
}

.fai-table th,
.fai-table td {
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid var(--fai-line);
}

.fai-table th {
  background: var(--fai-canvas);
  color: var(--fai-ink-2);
  font-weight: 700;
}

.fai-table tr:last-child td {
  border-bottom: 0;
}

/* ---------- Thinking / Error States ---------- */
.fai-thinking-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.fai-thinking-text {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fai-ink-2);
}

.fai-stop-inline {
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(180, 50, 37, 0.28);
  background: var(--fai-danger-soft);
  color: var(--fai-danger);
  font-size: 11.5px;
  font-weight: 650;
  cursor: pointer;
}

.fai-skel-lines {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.fai-skel-lines i {
  display: block;
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(100deg, #ECE9E3 30%, #F5F3EF 50%, #ECE9E3 70%);
  background-size: 300% 100%;
  animation: fai-shimmer 1.4s ease-in-out infinite;
}

.fai-err-text {
  margin: 0 0 10px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--fai-danger);
}

.fai-err-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.fai-retry-btn {
  height: 27px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: var(--fai-accent);
  color: #FFFFFF;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}

/* ---------- Bottom Composer ---------- */
.fai-composer-wrap {
  flex-shrink: 0;
  background: var(--fai-surface);
  border-top: 1px solid var(--fai-line);
}

.fai-offline-banner {
  padding: 6px 14px;
  background: var(--fai-warn-soft);
  border-bottom: 1px solid rgba(148, 82, 5, 0.2);
  color: var(--fai-warn);
  font-size: 11.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.fai-link-btn {
  border: 0;
  background: transparent;
  color: var(--fai-accent-ink);
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  white-space: nowrap;
  text-decoration: underline;
}

.fai-composer {
  padding: 8px 12px 9px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.fai-input {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  max-height: 96px;
  padding: 8px 11px;
  border-radius: 10px;
  border: 1px solid var(--fai-line-strong);
  background: var(--fai-canvas);
  color: var(--fai-ink);
  font-size: 13px;
  line-height: 1.42;
  resize: none;
  outline: none;
  transition: border-color 150ms var(--fai-ease), background 150ms var(--fai-ease);
}

.fai-input::placeholder {
  color: var(--fai-ink-3);
}

.fai-input:focus {
  background: var(--fai-surface);
  border-color: var(--fai-accent);
}

.fai-send-btn {
  flex-shrink: 0;
  height: 36px;
  padding: 0 15px;
  border: 0;
  border-radius: 999px;
  background: var(--fai-accent);
  color: #FFFFFF;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
  transition: background 150ms var(--fai-ease), transform 150ms var(--fai-ease);
}

.fai-send-btn:active {
  background: var(--fai-accent-ink);
  transform: scale(0.96);
}

.fai-send-btn:disabled {
  background: var(--fai-sunken);
  color: var(--fai-ink-3);
  cursor: default;
  transform: none;
}

.fai-send-btn.is-stop {
  background: var(--fai-danger);
  color: #FFFFFF;
}

.fai-root :focus-visible {
  outline: 2px solid var(--fai-accent);
  outline-offset: 2px;
}

@keyframes fai-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@media (prefers-reduced-motion: reduce) {
  .fai-root *,
  .fai-root *::before,
  .fai-root *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
