/* TaiLexi AI 日本法 AI リサーチ（/ai）：独立したページの画面。色・書体は日本站と共通の変数（styles.css の :root と配色）。
   画面全体を左の欄＋本体に分け、ページ全体ではなく本体の中だけがスクロールする（チャットのアプリと同じ）。 */
html:has(body.ai-body) { height: 100%; }
body.ai-body { height: 100%; margin: 0; overflow: hidden; background: var(--bg); color: var(--ink); font-family: var(--sans); }
.ai-root { height: 100%; }
.ai-root .spin { display: inline-block; width: 14px; height: 14px; flex: none; border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0 18%, color-mix(in srgb, var(--shu) 35%, transparent) 40%, var(--shu) 100%);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2.2px), #000 calc(100% - 2px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 2.2px), #000 calc(100% - 2px));
  animation: tl-spin .75s linear infinite; }
.ai-loading { display: grid; place-items: center; height: 100%; }
.ai-loading .spin { width: 22px; height: 22px; }
:where(.ai-root, .ai-pop, .ai-dialog, .ai-panel) button { font: inherit; color: inherit; }   /* :where＝優先度 0：各ボタンの色指定（白文字など）を上書きしない */
.ai-root svg, .ai-pop svg, .ai-panel svg { fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 骨組み ---------- */
.ai-app { display: grid; grid-template-columns: 276px minmax(0, 1fr); height: 100dvh; transition: grid-template-columns .18s ease; }
.ai-side { display: flex; flex-direction: column; gap: 6px; min-height: 0; padding: 14px 12px 12px; background: var(--paper-2);
  border-right: 1px solid var(--line); }
.ai-side-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 10px; }
.ai-brand { display: flex; align-items: center; gap: 9px; min-width: 0; color: var(--ink); text-decoration: none; }
.ai-brand:hover { text-decoration: none; }
.ai-ico { flex: none; width: 28px; height: 28px; display: block; }
.ai-name { font-family: var(--serif); font-size: 18px; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.ai-sub { padding-left: 9px; border-left: 1px solid var(--line); color: var(--muted); font-size: 12px; letter-spacing: .04em; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.ai-icon-btn { display: grid; place-items: center; flex: none; width: 38px; height: 38px; border: 0; border-radius: 9px; background: none;
  color: var(--ink-2); cursor: pointer; }
.ai-icon-btn:hover { background: var(--paper); }
.ai-icon-btn svg { width: 19px; height: 19px; }
.ai-close { display: none; }
.ai-fold { color: var(--faint); }
.ai-fold:hover { color: var(--ink); }
/* 左の欄の商品名：名前と説明を 2 行に（1 行だと説明が切れる） */
.ai-side .ai-brand { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 10px; align-items: center; }
.ai-side .ai-ico { grid-row: 1 / 3; width: 32px; height: 32px; }
.ai-side .ai-name { line-height: 1.25; }
.ai-side .ai-sub { padding-left: 0; border-left: 0; line-height: 1.35; }
.ai-new, .ai-db { display: flex; align-items: center; gap: 9px; height: 42px; padding: 0 13px; border-radius: 10px; font-size: 14px; cursor: pointer;
  text-decoration: none; }
.ai-new { border: 0; background: var(--ai); color: var(--ai-ink); font-weight: 600; }
.ai-new:hover { background: var(--ai-2); }
.ai-db { border: 1px solid var(--line); background: var(--paper); color: var(--ink-2); }
.ai-db:hover { border-color: var(--ai-2); color: var(--ai); text-decoration: none; }
.ai-new svg, .ai-db svg { width: 18px; height: 18px; flex: none; }
.ai-db span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-db .ext { width: 14px; height: 14px; color: var(--faint); }
.ai-side h2 { margin: 14px 8px 2px; color: var(--faint); font-size: 11.5px; font-weight: 600; letter-spacing: .1em; }
.ai-convs { flex: 1; min-height: 0; margin: 0; padding: 0; overflow-y: auto; list-style: none; }
.ai-fill { flex: 1; }
.ai-convs li { display: flex; align-items: center; border-radius: 8px; }
.ai-convs li.on, .ai-convs li:hover { background: var(--paper); }
.ai-convs li.on > button:first-child { color: var(--ai); font-weight: 600; }
.ai-convs li > button:first-child { flex: 1; min-width: 0; padding: 8px 10px; border: 0; background: none; color: var(--ink-2); font-size: 13.5px;
  text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.ai-convs li.empty { padding: 8px 10px; color: var(--faint); font-size: 13px; }
.ai-convs li.more button { width: 100%; padding: 8px 10px; border: 0; background: none; color: var(--ai-2); font-size: 13px; text-align: left; cursor: pointer; }
.ai-convs li.more:hover { background: none; }
.ai-convs li.more button:hover { text-decoration: underline; }
.ai-x { display: grid; place-items: center; width: 30px; height: 30px; margin-right: 2px; border: 0; border-radius: 6px; background: none;
  color: var(--faint); cursor: pointer; opacity: 0; }
.ai-x svg { width: 15px; height: 15px; }
.ai-convs li:hover .ai-x, .ai-convs li.on .ai-x, .ai-x:focus-visible { opacity: 1; }
.ai-x:hover { color: var(--shu); }
.ai-acct { position: relative; padding-top: 8px; border-top: 1px solid var(--line); }
.ai-acct-btn { display: flex; align-items: center; gap: 9px; width: 100%; padding: 9px 10px; border: 0; border-radius: 8px; background: none;
  color: var(--ink-2); font-size: 13px; cursor: pointer; }
.ai-acct-btn:hover { background: var(--paper); }
.ai-acct-btn svg { width: 18px; height: 18px; flex: none; }
.ai-acct-btn span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-acct-menu { position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); z-index: 20; padding: 8px; background: var(--paper);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.ai-m-h { padding: 6px 6px 4px; color: var(--faint); font-size: 11px; font-weight: 600; letter-spacing: .08em; }
.ai-seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 0 2px 4px; }
.ai-seg button { display: flex; align-items: center; justify-content: center; gap: 5px; min-height: 32px; padding: 4px; border: 1px solid var(--line-2);
  border-radius: 8px; background: none; font-size: 12px; cursor: pointer; }
.ai-seg button.on { border-color: var(--ai-2); color: var(--ai); font-weight: 600; }
.ai-seg .sw { width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--line); flex: none; }
.ai-acct-menu hr { margin: 6px 2px; border: 0; border-top: 1px solid var(--line-2); }
.ai-m-i { display: block; width: 100%; padding: 8px 8px; border: 0; border-radius: 6px; background: none; color: var(--ink-2); font-size: 13.5px;
  text-align: left; text-decoration: none; cursor: pointer; }
.ai-m-i:hover { background: var(--paper-2); text-decoration: none; }
.ai-m-i.danger { color: var(--shu); }
.ai-scrim, .ai-top { display: none; }
/* 電腦版：左欄を収めるとアイコンだけの細い欄（新しい質問・データベース・アカウントはそのまま押せる） */
@media (min-width: 901px) {
  .ai-app.folded { grid-template-columns: 64px minmax(0, 1fr); }
  .ai-app.folded .ai-side { align-items: center; padding: 14px 10px 12px; }
  .ai-app.folded .ai-side-top { flex-direction: column; gap: 8px; padding: 2px 0 10px; }
  .ai-app.folded .ai-side .ai-name, .ai-app.folded .ai-side .ai-sub, .ai-app.folded .ai-side h2, .ai-app.folded .ai-convs,
  .ai-app.folded .ai-new span, .ai-app.folded .ai-db span, .ai-app.folded .ai-db .ext, .ai-app.folded .ai-acct-btn span { display: none; }
  .ai-app.folded .ai-side .ai-brand { display: block; }
  .ai-app.folded .ai-new, .ai-app.folded .ai-db { justify-content: center; width: 42px; padding: 0; }
  .ai-app.folded .ai-acct { width: 100%; margin-top: auto; }
  .ai-app.folded .ai-acct-btn { justify-content: center; padding: 9px 0; }
  .ai-app.folded .ai-acct-menu { left: calc(100% + 20px); right: auto; bottom: 0; width: 264px; }   /* 欄の内側余白 10px＋境界線の外へ */
}

.ai-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.ai-scroll { flex: 1; min-height: 0; overflow-y: auto; }
.ai-thread { width: 100%; max-width: 800px; margin: 0 auto; padding: 28px 24px 12px; }
.ai-composer { width: 100%; max-width: 800px; margin: 0 auto; padding: 10px 24px 12px; }
.ai-box { display: flex; flex-direction: column; gap: 6px; padding: 7px; background: var(--paper); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow); }
.ai-box:focus-within { border-color: var(--ai-2); }
.ai-row { display: flex; align-items: flex-end; gap: 4px; }
#ai-q { flex: 1; min-height: 40px; max-height: 240px; padding: 8px 0 8px 2px; border: 0; outline: 0; resize: none; background: transparent; color: var(--ink);
  font: inherit; font-size: 16px; line-height: 1.6; }
.ai-attach { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border: 0; border-radius: 50%; background: none;
  color: var(--muted); cursor: pointer; }
.ai-attach:hover { background: var(--paper-2); color: var(--ink); }
.ai-attach svg { width: 20px; height: 20px; }
/* ＋ のメニュー（入力欄の上に開く）とオンの機能の札 */
.ai-plus-wrap { position: relative; flex: none; }
.ai-attach { border: 1px solid var(--line); }
.ai-plusmenu { position: absolute; left: 0; bottom: calc(100% + 10px); z-index: 30; width: min(320px, calc(100vw - 32px)); padding: 6px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 8px 28px rgba(20, 20, 30, .16); }
.ai-pm { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 10px; border: 0; border-radius: 10px; background: none; text-align: left; cursor: pointer; }
.ai-pm:hover { background: var(--paper-2); }
.ai-pm > svg { width: 19px; height: 19px; flex: none; color: var(--muted); }
.ai-pm > svg:last-child { width: 16px; height: 16px; color: var(--ai); stroke-width: 2.4; }
.ai-pm span { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ai-pm b { font-size: 14px; font-weight: 600; color: var(--ink); }
.ai-pm small { color: var(--faint); font-size: 12px; }
.ai-pm.on > svg:first-child { color: var(--ai); }
.ai-modes { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; align-self: center; }
.ai-modes:empty { display: none; }
.ai-mode { display: inline-flex; align-items: center; gap: 4px; height: 30px; padding: 0 4px 0 9px; border-radius: 999px; background: var(--ai-soft);
  color: var(--ai); font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.ai-mode > svg { width: 14px; height: 14px; }
.ai-mode button { display: grid; place-items: center; width: 20px; height: 20px; border: 0; border-radius: 50%; background: none; color: inherit; cursor: pointer; }
.ai-mode button:hover { background: color-mix(in srgb, var(--ai) 15%, transparent); }
.ai-mode button svg { width: 12px; height: 12px; }
@media (max-width: 600px) { .ai-mode > span { display: none; } .ai-mode { padding-left: 7px; } }
/* 添付ファイル（入力欄の上・質問の上） */
.ai-atts { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 2px 0; }
.ai-att { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 30px; padding: 3px 4px 3px 9px; border: 1px solid var(--line);
  border-radius: 9px; background: var(--paper-2); font-size: 12.5px; box-sizing: border-box; }
.ai-att > svg { width: 15px; height: 15px; flex: none; color: var(--ai); }
.ai-att .spin { width: 13px; height: 13px; }
.ai-att b { min-width: 0; max-width: 220px; overflow: hidden; color: var(--ink-2); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.ai-att small { color: var(--faint); white-space: nowrap; }
.ai-att.err { border-color: color-mix(in srgb, var(--shu) 45%, transparent); }
.ai-att.err > svg, .ai-att.err small { color: var(--shu); white-space: normal; }
.ai-att.done:not(:has(.ai-att-x)) { padding-right: 10px; }
.ai-att-x { display: grid; place-items: center; flex: none; width: 24px; height: 24px; border: 0; border-radius: 6px; background: none;
  color: var(--faint); cursor: pointer; }
.ai-att-x:hover { color: var(--shu); }
.ai-att-x svg { width: 13px; height: 13px; }
.ai-send { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--ai);
  color: var(--ai-ink); cursor: pointer; }
.ai-send:hover { background: var(--ai-2); }
.ai-send svg { width: 19px; height: 19px; stroke-width: 2.3; }
.ai-send.stop { background: var(--shu); }
.ai-send.stop svg { fill: currentColor; stroke: none; }
.ai-opts { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 6px 0; color: var(--muted); font-size: 12.5px; }
.ai-opt-l { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; }
.ai-think { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.ai-think input { width: 15px; height: 15px; margin: 0; accent-color: var(--ai); }
.ai-think span { display: inline-flex; align-items: center; gap: 4px; }
.ai-think span svg { width: 14px; height: 14px; }
.ai-note { margin: 18px 0 0; color: var(--faint); font-size: 12px; line-height: 1.65; text-align: center; text-wrap-style: balance; }
.ai-note > span { display: inline-block; }   /* 兩句各自成一塊：放得下就同一行，放不下就整句換行 */
.ai-composer .ai-note { margin: 6px 0 0; font-size: 11.5px; }

/* ---------- ログイン（ダイアログ）：2 回目の質問・添付・左欄の「ログイン」から ---------- */
.ai-dialog.ai-login { position: fixed; width: min(400px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto; padding: 26px 22px 20px; }
.ai-login h2 { margin: 0 32px 6px 0; font-family: var(--serif); font-size: 20px; letter-spacing: .03em; }
.ai-login .ai-login-sub { margin: 0; color: var(--muted); font-size: 13.5px; word-break: auto-phrase; text-wrap: balance; }
.ai-dlg-x { position: absolute; top: 12px; right: 12px; }
.ai-login .ai-auth { margin-top: 18px; padding: 0; border: 0; box-shadow: none; background: none; }
.ai-login .ai-pending { margin-top: 14px; }
.ai-login-btn { width: 100%; margin: 0 0 10px; }
.ai-app.folded .ai-login-btn { display: none; }
/* ログイン後に送る質問を見せる */
.ai-pending { display: grid; gap: 4px; margin: 20px 0 0; padding: 12px 15px; border: 1px solid var(--line); border-left: 3px solid var(--ai-2);
  border-radius: 10px; background: var(--paper); color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.ai-pending b { color: var(--ink); font-size: 14.5px; font-weight: 600; overflow-wrap: anywhere; }
.ai-auth { margin-top: 24px; padding: 22px 22px 18px; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.ai-gsi { display: flex; justify-content: center; min-height: 44px; }
.ai-or { display: flex; align-items: center; gap: 12px; margin: 16px 0; color: var(--faint); font-size: 12.5px; }
.ai-or::before, .ai-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.ai-form label, .ai-dialog label { display: block; margin-bottom: 12px; }
.ai-form label span, .ai-dialog label span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 13px; }
.ai-form input, .ai-dialog input { width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--paper-2); color: var(--ink); font: inherit; font-size: 16px; box-sizing: border-box; }   /* 16px：iOS で入力時に拡大しない */
.ai-form input:focus, .ai-dialog input:focus { outline: 2px solid color-mix(in srgb, var(--ai-2) 35%, transparent); border-color: var(--ai-2); }
.ai-btn { display: inline-flex; align-items: center; justify-content: center; height: 44px; padding: 0 18px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--paper); color: var(--ink); font-weight: 600; cursor: pointer; }
.ai-btn.primary { width: 100%; background: var(--ai); border-color: var(--ai); color: var(--ai-ink); }
.ai-btn.primary:hover { background: var(--ai-2); }
.ai-btn:disabled { opacity: .6; cursor: default; }
.ai-btn.danger { background: var(--shu); border-color: var(--shu); color: #fff; }
.ai-err { margin: 2px 0 12px; color: var(--shu); font-size: 13.5px; line-height: 1.6; }
.ai-switch { margin: 14px 0 0; text-align: center; color: var(--muted); font-size: 13.5px; }
.ai-switch button { margin-left: 6px; padding: 0; border: 0; background: none; color: var(--ai-2); font-weight: 600; cursor: pointer; }

/* ---------- メッセージ ---------- */
.ai-msg { margin: 0 0 26px; }
.ai-msg.user { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.ai-q-atts { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: 86%; }
.ai-q-text { max-width: 86%; padding: 10px 15px; border-radius: 16px 16px 4px 16px; background: var(--ai-soft); color: var(--ink); font-size: 15px;
  line-height: 1.75; white-space: pre-wrap; overflow-wrap: anywhere; }
.ai-steps { display: grid; gap: 7px; margin: 0 0 12px; padding: 0; list-style: none; color: var(--muted); font-size: 13.5px; }
.ai-steps li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 9px; }
.ai-steps li svg { width: 15px; height: 15px; flex: none; stroke: var(--kin); stroke-width: 2.6; }
.ai-steps li.cur { color: var(--ink-2); }
.ai-steps small { flex-basis: 100%; padding-left: 24px; color: var(--faint); font-size: 12.5px; line-height: 1.6; }
.ai-steps li.ai-thinking { position: relative; padding-bottom: 8px; }
.ai-steps li.ai-thinking > svg, .ai-think-done svg { width: 15px; height: 15px; flex: none; fill: none; stroke: var(--shu); stroke-width: 2; }
.ai-steps li.ai-thinking > svg { animation: tl-glow 1.6s ease-in-out infinite; }
.ai-secs { color: var(--muted); font-style: normal; font-variant-numeric: tabular-nums; }
.ai-think-bar { position: absolute; left: 24px; right: 0; bottom: 0; height: 2px; overflow: hidden; border-radius: 2px; background: var(--line-2); }
.ai-think-bar::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 30%; border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--shu), transparent); animation: tl-sweep 1.8s ease-in-out infinite; }
@keyframes tl-glow { 50% { opacity: .35; } }
@keyframes tl-sweep { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
@media (prefers-reduced-motion: reduce) { .ai-steps li.ai-thinking > svg, .ai-think-bar::after { animation: none; } }
.ai-think-done { display: flex; align-items: center; gap: 7px; margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.ai-a-text { color: var(--ink); font-size: 15.5px; line-height: 1.9; overflow-wrap: anywhere; }
.ai-a-text h3 { margin: 1.5em 0 .5em; font-family: var(--serif); font-size: 17px; line-height: 1.5; }
.ai-a-text h3:first-child { margin-top: 0; }
.ai-a-text p { margin: 0 0 .9em; }
.ai-a-text ul, .ai-a-text ol { margin: 0 0 .9em; padding-left: 1.5em; }
.ai-a-text li { margin: .3em 0; }
.ai-a-text strong { font-weight: 700; }
.ai-a-text blockquote { margin: 0 0 .9em; padding: .35em 1em; border-left: 3px solid var(--kin); background: var(--paper-2); color: var(--ink-2); }
.ai-a-text code { padding: 0 .3em; border-radius: 4px; background: var(--paper-2); font-size: .92em; }
.ai-table { margin: 0 0 1em; overflow-x: auto; }
.ai-table table { border-collapse: collapse; font-size: 14px; line-height: 1.65; }
.ai-table th, .ai-table td { min-width: 5em; padding: .45em .75em; border: 1px solid var(--line); text-align: left; vertical-align: top; }
.ai-table th { background: var(--paper-2); font-weight: 600; }
.ai-cite { display: inline-block; margin: 0 2px; padding: 0 7px; border: 0; border-radius: 6px; background: var(--ai-soft); color: var(--ai);
  font-family: var(--sans); font-size: 12px; font-weight: 600; line-height: 1.8; vertical-align: 1px; white-space: nowrap; cursor: pointer; }
.ai-cite:hover { background: var(--ai); color: var(--ai-ink); }
.ai-cite.law { background: var(--kin-soft); color: var(--kin); }
.ai-cite.law:hover { background: var(--kin); color: #fff; }
.ai-cite.up, .ai-cite.web { background: var(--paper-2); color: var(--ink-2); box-shadow: inset 0 0 0 1px var(--line); font-weight: 500; }
.ai-cite.up:hover, .ai-cite.web:hover { background: var(--ink-2); color: var(--paper); box-shadow: none; }
.ai-flag { display: inline-flex; align-items: center; gap: 3px; margin: 0 2px; padding: 0 6px; border: 1px solid color-mix(in srgb, var(--shu) 50%, transparent);
  border-radius: 6px; background: color-mix(in srgb, var(--shu) 8%, transparent); color: var(--shu); font-family: var(--sans); font-size: 11.5px;
  font-weight: 600; line-height: 1.7; vertical-align: 1px; white-space: nowrap; cursor: pointer; }
.ai-flag svg { width: 12px; height: 12px; }
.ai-muted { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13.5px; }
/* 参考資料（本文で引用した順）と、たたんだ「そのほかの検索結果」「ウェブ検索の結果」 */
.ai-refs { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.ai-refs h4 { margin: 0 0 10px; color: var(--ink-2); font-size: 13.5px; font-weight: 600; letter-spacing: .04em; }
.ai-srcs { margin-top: 12px; }
.ai-srcs summary { color: var(--ink-2); font-size: 13.5px; font-weight: 600; cursor: pointer; }
.ai-srcs summary small { margin-left: 8px; color: var(--faint); font-weight: 400; }
.ai-refs > ol, .ai-srcs ol { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.ai-srcs ol { margin-top: 12px; }
:is(.ai-refs, .ai-srcs) li { display: flex; gap: 10px; }
:is(.ai-refs, .ai-srcs) .n { display: grid; place-items: center; flex: none; width: 22px; height: 22px; border: 1px solid var(--line); border-radius: 50%;
  background: var(--paper-2); color: var(--muted); font-size: 11.5px; }
:is(.ai-refs, .ai-srcs) li > div { min-width: 0; }
.ai-src-out { display: block; color: var(--kin); font-size: 11.5px; }
.ai-verify { display: flex; align-items: flex-start; gap: 7px; margin: 12px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.ai-verify svg { width: 15px; height: 15px; flex: none; margin-top: 2px; stroke: var(--kin); stroke-width: 2.4; }
.ai-verify.bad svg { stroke: var(--shu); stroke-width: 2; }
.ai-webs { display: grid; gap: 7px; margin: 10px 0 0; padding: 0; list-style: none; font-size: 13px; line-height: 1.55; }
.ai-webs a { color: var(--ai-2); overflow-wrap: anywhere; }
.ai-webs small { margin-left: 8px; color: var(--faint); }
.ai-src-t { padding: 0; border: 0; background: none; color: var(--ai); font-size: 14px; font-weight: 600; text-align: left; cursor: pointer; }
.ai-src-t:hover { text-decoration: underline; }
.ai-src-t small { margin-left: 6px; color: var(--muted); font-weight: 400; }
.ai-src-name { display: block; color: var(--ink-2); font-size: 13px; }
.ai-src-meta { color: var(--faint); font-size: 12px; }
.ai-src-t + .ai-src-meta { margin-left: 8px; }
.ai-src-meta i { margin-right: 8px; padding: 0 6px; border-radius: 4px; background: var(--paper-2); font-style: normal; }
.ai-srcs p { display: -webkit-box; margin: 4px 0 0; overflow: hidden; color: var(--muted); font-size: 13px; line-height: 1.7;
  -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.ai-actions { display: flex; gap: 2px; margin-top: 10px; }
.ai-actions button { display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 8px; background: none; color: var(--faint); cursor: pointer; }
.ai-actions button:hover { background: var(--paper); color: var(--ink); }
/* 作成した文書：Word・PDF で保存（回答の下、参考資料の上） */
.ai-doc-card { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; margin: 16px 0 4px; padding: 12px 14px; border: 1px solid var(--line);
  border-left: 3px solid var(--ai-2); border-radius: 12px; background: var(--paper); }
.ai-doc-card > svg { width: 22px; height: 22px; flex: none; color: var(--ai); }
.ai-doc-card > b { flex: 1; min-width: 10em; font-size: 14.5px; color: var(--ink); overflow-wrap: anywhere; }
.ai-doc-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.ai-doc-btns .ai-btn { height: 36px; padding: 0 14px; gap: 6px; font-size: 13.5px; font-weight: 600; }
.ai-doc-btns .ai-btn svg { width: 17px; height: 17px; }
@media (max-width: 600px) { .ai-doc-btns { width: 100%; } .ai-doc-btns .ai-btn { flex: 1; } }
.ai-actions button.on { color: var(--ai); }
.ai-actions svg { width: 17px; height: 17px; }
.ai-empty { padding: 11vh 0 4vh; text-align: center; }
.ai-empty h1 { margin: 0 0 8px; font-family: var(--serif); font-size: clamp(25px, 4.5vw, 32px); letter-spacing: .04em; }
.ai-empty p { margin: 0 0 24px; color: var(--ink-2); }
.ai-ex-in { display: grid; gap: 8px; max-width: 520px; margin: 0 auto; padding: 0; list-style: none; }
.ai-ex-in button { width: 100%; padding: 11px 15px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink-2);
  font-size: 14px; line-height: 1.6; text-align: left; cursor: pointer; }
.ai-ex-in button:hover { border-color: var(--ai-2); color: var(--ai); }

/* ---------- 出典の小窓 ---------- */
.ai-pop { position: fixed; z-index: 90; width: min(440px, calc(100vw - 16px)); max-height: min(420px, 70vh); overflow-y: auto; padding: 14px 16px 12px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 32px rgba(20, 20, 30, .18); color: var(--ink); }
.ai-pop.sheet { left: 0 !important; right: 0; bottom: 0; top: auto !important; width: 100%; max-height: 66vh; border-radius: 16px 16px 0 0;
  padding-bottom: calc(14px + env(safe-area-inset-bottom)); box-sizing: border-box; animation: sheetUp .18s ease; }
.ai-pop-x { position: absolute; top: 8px; right: 8px; display: grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 8px;
  background: none; color: var(--faint); cursor: pointer; }
.ai-pop-x svg { width: 16px; height: 16px; }
.ai-pop-h { padding-right: 30px; }
.ai-pop-h b { display: block; font-size: 15px; }
.ai-pop-h small { display: block; margin-top: 2px; color: var(--muted); font-size: 13px; }
.ai-pop-m { margin-top: 6px; color: var(--faint); font-size: 12.5px; }
.ai-pop-t { margin-top: 10px; color: var(--ink-2); font-family: var(--serif); font-size: 14px; line-height: 1.85; white-space: pre-wrap; }
.ai-pop-a { display: inline-flex; align-items: center; gap: 5px; margin-top: 8px; color: var(--ai-2); font-size: 13px; font-weight: 600; }
.ai-pop-a svg { width: 14px; height: 14px; }
.ai-pop-o { margin: 10px 0 0; color: var(--kin); font-size: 12.5px; }
.ai-pop-flag { display: inline-flex !important; align-items: center; gap: 5px; color: var(--shu); }
.ai-pop-flag svg { width: 16px; height: 16px; }

/* ---------- 検索結果（重排後の全部）：回答の下のボタン → 右の欄（スマートフォンは全画面） ---------- */
.ai-allres { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; margin-top: 14px; padding: 8px 13px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--paper); color: var(--ink-2); font-size: 13.5px; font-weight: 600; text-align: left; cursor: pointer; }
.ai-allres:hover { border-color: var(--ai-2); color: var(--ai); }
.ai-allres svg { width: 16px; height: 16px; flex: none; }
.ai-allres small { color: var(--faint); font-weight: 400; }
.ai-pscrim { position: fixed; inset: 0; z-index: 75; background: rgba(10, 12, 16, .28); }
.ai-panel { position: fixed; top: 0; right: 0; bottom: 0; z-index: 80; display: flex; flex-direction: column; width: min(520px, 100vw);
  background: var(--paper); border-left: 1px solid var(--line); box-shadow: -8px 0 32px rgba(20, 20, 30, .16); color: var(--ink);
  animation: panelIn .18s ease; }
@keyframes panelIn { from { transform: translateX(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.ai-phead { position: relative; display: flex; align-items: baseline; gap: 10px; padding: 16px 52px 10px 20px; }
.ai-phead b { font-size: 16px; }
.ai-phead small { color: var(--faint); font-size: 12px; }
.ai-phead .ai-pop-x { top: 10px; right: 10px; }
.ai-ptabs { display: flex; gap: 2px; padding: 0 14px; border-bottom: 1px solid var(--line); }
.ai-ptabs button { padding: 9px 12px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); font-size: 14px; cursor: pointer; }
.ai-ptabs button small { margin-left: 5px; color: var(--faint); font-size: 12px; }
.ai-ptabs button.on { border-bottom-color: var(--ai); color: var(--ai); font-weight: 600; }
.ai-ptools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 20px; border-bottom: 1px solid var(--line-2); font-size: 13px; color: var(--ink-2); }
.ai-ptools input[type=search] { flex: 1 1 160px; min-width: 0; height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper-2);
  color: var(--ink); font: inherit; font-size: 14px; }
.ai-ptools label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.ai-ptools input[type=checkbox] { width: 15px; height: 15px; margin: 0; accent-color: var(--ai); }
.ai-ptools select { height: 34px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper-2); color: var(--ink); font: inherit; font-size: 13px; }
.ai-pbody { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 20px calc(16px + env(safe-area-inset-bottom)); }
.ai-pnone { color: var(--faint); font-size: 13.5px; }
.ai-plist { margin: 0; padding: 0; list-style: none; }
.ai-res { padding: 12px 0; border-bottom: 1px solid var(--line-2); }
.ai-res.low { opacity: .62; }
.ai-res-top { display: flex; align-items: baseline; gap: 8px; }   /* 長い標題は自分の欄の中で折り返す（番号だけ前の行に残らない） */
.ai-res-k { flex: none; min-width: 22px; color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.ai-res-t { flex: 0 1 auto; min-width: 0; color: var(--ai); font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.ai-res-top small { flex: 1 1 auto; min-width: 0; color: var(--muted); font-size: 12.5px; }
.ai-res-m { margin: 3px 0 0 30px; color: var(--ink-2); font-size: 12.5px; line-height: 1.6; }
.ai-res-m i { margin-right: 6px; padding: 0 6px; border-radius: 4px; background: var(--paper-2); color: var(--muted); font-style: normal; }
.ai-res-r { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; margin: 5px 0 0 30px; color: var(--faint); font-size: 12px; }
.ai-res-r .bar { width: 64px; height: 5px; border-radius: 3px; background: var(--line-2); overflow: hidden; }
.ai-res-r .bar b { display: block; height: 100%; background: var(--kin); }
.ai-res-r em { padding: 0 6px; border-radius: 4px; background: var(--paper-2); color: var(--muted); font-style: normal; }
.ai-res-r em.cited { background: var(--ai-soft); color: var(--ai); font-weight: 600; }
.ai-res-g { display: -webkit-box; margin: 6px 0 0 30px; overflow: hidden; color: var(--muted); font-size: 13px; line-height: 1.7;
  -webkit-line-clamp: 3; -webkit-box-orient: vertical; }

/* ---------- ダイアログ ---------- */
.ai-dialog { width: min(420px, calc(100vw - 32px)); padding: 22px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper);
  color: var(--ink); box-shadow: var(--shadow); }
.ai-dialog::backdrop { background: rgba(10, 12, 16, .4); }
.ai-dialog h2 { margin: 0 0 14px; font-size: 17px; }
.ai-dialog p { color: var(--ink-2); font-size: 14px; line-height: 1.7; }
.ai-dlg-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.ai-dlg-btns .ai-btn.primary { width: auto; }

/* ---------- 狭い画面：左の欄は引き出し、上に細い帯 ---------- */
@media (max-width: 900px) {
  .ai-app { grid-template-columns: minmax(0, 1fr); }
  .ai-side { position: fixed; top: 0; bottom: 0; left: 0; z-index: 70; width: min(300px, 86vw); box-shadow: var(--shadow);
    transform: translateX(-102%); transition: transform .2s ease; }
  .ai-app.drawer .ai-side { transform: none; }
  .ai-app.drawer .ai-scrim { display: block; position: fixed; inset: 0; z-index: 65; background: rgba(10, 12, 16, .35); }
  .ai-close { display: grid; }
  .ai-fold { display: none; }
  .ai-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--paper) 92%, transparent); }
  .ai-top .ai-brand { gap: 7px; }
  .ai-top .ai-ico { width: 24px; height: 24px; }
  .ai-top .ai-name { font-size: 16px; }
  .ai-top .ai-sub { font-size: 11px; padding-left: 7px; }
  .ai-thread { padding: 16px 16px 6px; }
  .ai-composer { padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
  .ai-q-text { max-width: 92%; }
  .ai-a-text { font-size: 15px; }
  .ai-x { opacity: 1; }
}
@media (max-width: 600px) {
  .ai-att b { max-width: 140px; }
  .ai-empty { padding-top: 6vh; }
}
@media (max-width: 380px) { .ai-top .ai-sub { display: none; } }
