/* 社内FAQ AI — chat page skin.
   Overrides style.css's warm たより palette with the same flat, cobalt-accent
   design system used on /admin and /leads (see admin.css): white surfaces,
   hairline borders, tight radii, no decorative animation. Loaded after
   style.css, before nothing else. */

:root {
  --bg: #f8f7f6;
  --surface: #ffffff;
  --surface-2: #f2f1f0;
  --surface-hover: #edebe8;
  --border: #d6d3d0;
  --border-strong: #c1bdb7;
  --text: #23221e;
  --text-2: #706d65;
  --text-3: #8f8b83;

  --primary: #0a3a66;
  --primary-hover: #082c4e;
  --primary-soft: #e8edf3;
  --primary-contrast: #ffffff;
  --brand: #00c4cc;

  --success: #0f7f85;
  --success-soft: #e7f2f3;
  --danger: #e01e5a;
  --danger-soft: #fce6ed;
  --warning: #7a5a00;
  --warning-soft: #fff3c4;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 6px;
  --shadow-sm: 0 1px 2px rgba(35, 34, 30, .12);
  --shadow-md: 0 4px 16px rgba(35, 34, 30, .10);

  --font-display: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
}

body {
  /* 100dvh keeps the composer above iOS Safari's toolbar; 100vh first as the
     fallback for Safari < 15.4 without dvh support */
  display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden;
  background: var(--bg);
}

.brand-mark { background: #0a3a66; border-radius: 10px; box-shadow: none; }

header {
  background: var(--surface);
  border-top: 3px solid var(--brand);
  border-bottom: 1px solid var(--border);
  padding: 12px 22px; display: flex; align-items: center; gap: 12px; flex-shrink: 0;
  z-index: 10;
}
header h1 { font-family: var(--font-display); font-size: 16.5px; font-weight: 700; }
header .sub { font-size: 12px; color: var(--text-2); margin-top: 1px; }
.header-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.header-actions .btn {
  background: var(--surface); border-color: var(--border-strong); color: var(--text-2);
}
.header-actions .btn:hover:not(:disabled) {
  background: var(--surface-hover); border-color: var(--border-strong); color: var(--text);
}

/* .chat-area holds the fixed viewport bounds; #chat-scroll is the part that
   actually scrolls. The scroll-to-bottom button lives in .chat-area (not
   #chat-scroll) so its absolute position anchors to the visible viewport
   instead of scrolling away with the message list. */
.chat-area { flex: 1; min-height: 0; position: relative; display: flex; }
#chat-scroll { flex: 1; min-height: 0; overflow-y: auto; }
.inner { max-width: 760px; margin: 0 auto; padding: 24px 20px 16px; }

.welcome {
  position: relative;
  padding: 24px 26px; margin-bottom: 22px;
  animation: rise .35s var(--ease);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.welcome h2 { font-family: var(--font-display); font-size: 16.5px; font-weight: 700; margin-bottom: 7px; color: var(--text); }
.welcome p { font-size: 13px; color: var(--text-2); line-height: 1.75; }
.welcome-icon {
  width: 42px; height: 42px; border-radius: var(--radius-md); background: var(--primary-soft);
  color: var(--primary); display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px;
}
.welcome-icon svg { width: 22px; height: 22px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.suggestion {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); border-radius: var(--radius-md); padding: 8px 14px; cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease);
}
.suggestion svg { width: 13px; height: 13px; color: var(--primary); flex-shrink: 0; }
.suggestion:hover { background: var(--surface-hover); border-color: var(--border-strong); }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.row { display: flex; gap: 10px; margin-bottom: 18px; animation: rise .25s var(--ease); }
.row.user { justify-content: flex-end; }
.row.bot .avatar {
  width: 30px; height: 30px; border-radius: var(--radius-md); flex-shrink: 0; margin-top: 2px;
  background: var(--primary-soft);
  display: flex; align-items: center; justify-content: center;
}
.row.bot .avatar svg { width: 16px; height: 16px; color: var(--primary); }
.bubble-col { display: flex; flex-direction: column; max-width: 78%; }
.row.user .bubble-col { align-items: flex-end; }

.bubble {
  padding: 13px 17px; font-size: 14.5px; line-height: 1.85; font-family: var(--font-display);
  white-space: pre-wrap; word-break: break-word;
  border-radius: var(--radius-lg);
}
.row.user .bubble {
  background: var(--primary);
  color: #fff;
}
.row.bot .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.row.bot .bubble.refusal { color: var(--text-2); font-style: normal; }
.bubble ul { margin: 3px 0 5px 1.15em; padding: 0; }
.bubble li { margin: 2px 0; }
.bubble strong { font-weight: 700; }

.sources { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.source-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-md); padding: 4px 10px; cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease);
  font-family: inherit;
}
.source-chip:hover { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-hover); }
.source-chip svg { width: 12px; height: 12px; flex-shrink: 0; }
.source-chip .chevron { transition: transform .15s var(--ease); }
.source-chip.open .chevron { transform: rotate(180deg); }

.excerpt-panel {
  margin-top: 8px; padding: 12px 14px; background: var(--surface-2);
  border-left: 2.5px solid var(--primary); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 12.5px; line-height: 1.75; color: var(--text-2);
  display: none; animation: expand .18s var(--ease);
}
.excerpt-panel.open { display: block; }
.excerpt-panel .excerpt-title { font-size: 11.5px; font-weight: 700; color: var(--text); margin-bottom: 5px; }
@keyframes expand { from { opacity: 0; transform: translateY(-4px); } }

.meta-row { display: flex; align-items: center; gap: 12px; margin-top: 9px; }
.mode-tag { font-size: 11px; color: var(--text-3); }
.feedback { display: flex; gap: 4px; }
.fb-btn {
  width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
  border: 1px solid transparent; background: transparent; border-radius: var(--radius-sm); cursor: pointer;
  color: var(--text-3); transition: all .15s var(--ease);
}
.fb-btn svg { width: 15px; height: 15px; }
.fb-btn:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--border); color: var(--text); }
.fb-btn.selected.good { color: var(--success); background: var(--success-soft); }
.fb-btn.selected.bad { color: var(--danger); background: var(--danger-soft); }
.fb-btn:disabled { cursor: default; }
.fb-btn:disabled:not(.selected) { opacity: .3; }

.typing-row .bubble { display: flex; align-items: center; padding: 14px 16px; }
.typing { display: inline-flex; gap: 4px; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25 } 40% { opacity: 1 } }

.scroll-btn {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(8px);
  width: 36px; height: 36px; border-radius: 50%; background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow-md);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  color: var(--text-2); opacity: 0; pointer-events: none;
  transition: all .2s var(--ease);
}
.scroll-btn.visible { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }
.scroll-btn svg { width: 16px; height: 16px; }

footer {
  background: var(--surface);
  border-top: 1px solid var(--border); padding: 14px 20px 16px; flex-shrink: 0;
}
/* One merged pill for input+send, like a real message composer, instead
   of two separate boxes — the textarea sheds its own border/background
   and the send button becomes a rounded square nested inside. */
.input-row {
  max-width: 760px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end;
  background: var(--surface); border: 1.5px solid var(--border-strong); border-radius: var(--radius-lg);
  padding: 6px 6px 6px 18px;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.input-row:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
#q {
  flex: 1; resize: none; max-height: 140px; min-height: 32px;
  line-height: 1.6; padding: 9px 0; border: none; background: none; box-shadow: none;
}
#q:focus { border: none; box-shadow: none; }
#send {
  height: 40px; width: 40px; padding: 0; border-radius: var(--radius-md); flex-shrink: 0;
  background: var(--primary);
  transition: background .15s var(--ease);
}
#send:hover:not(:disabled) { background: var(--primary-hover); }
#send svg { width: 17px; height: 17px; display: block; }
.disclaimer { max-width: 760px; margin: 9px auto 0; font-size: 11px; color: var(--text-3); text-align: center; }

@media (max-width: 560px) {
  header h1 { font-size: 14px; }
  /* Icon-only on phones -- except 管理画面, which keeps its label: a bare gear icon isn't
     recognizable as "the admin page", and that button is a company rep's only way back. */
  .header-actions .btn:not(#admin-link) span { display: none; }
  .bubble-col { max-width: 88%; }
  .inner { padding: 16px 14px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .row, .welcome { animation: none; }
}

/* prospect demo banner (only rendered on /demo tenants) */
.demo-banner {
  background: var(--warning-soft); color: var(--warning); border-bottom: 1px solid var(--border-strong);
  padding: 8px 16px; font-size: 12.5px; text-align: center; line-height: 1.6;
}
.demo-banner a { color: var(--primary-hover); font-weight: 700; }
