/* ============================================================
   OMNIAGENT app.css — ui-spec.md §8 のトークンをそのまま採用。新色は追加しない。
   🔴 CSP（style-src 'self'）のため、index.html・app.js は style="" 属性や <style> タグ、
   cssText 代入を使わない。状態の出し分けはこのファイルのクラス切替と、
   個別プロパティ代入（el.style.display = 'none' 等。CSP style-src の対象外）だけで行う。
   ============================================================ */

:root {
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --border: #e2e8f0;
  --text: #334155;
  --text-muted: #64748b;
  --text-disabled: #94a3b8;
  --text-heading: #0f2a4a;
  --accent: #0284c7;
  --accent-contrast: #ffffff;
  --bubble-user: #f1f5f9;
  --warn-bg: #fffbeb;
  --warn-text: #d97706;
  --ok-bg: #f0fdf4;
  --ok-text: #16a34a;
  --danger-bg: #fef2f2;
  --danger-text: #dc2626;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-xl: 0 20px 40px rgba(15, 23, 42, .18);
}

/* ダーク: OS設定に追従を既定（prefers-color-scheme）。html[data-theme]が付いていれば手動指定が勝つ */
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg-app: #0b1220;
    --bg-surface: #131b2c;
    --border: #25324a;
    --text: #cbd5e1;
    --text-muted: #94a3b8;
    --text-disabled: #64748b;
    --text-heading: #e2e8f0;
    --accent: #38bdf8;
    --accent-contrast: #0b1220;
    --bubble-user: #1c2740;
    --warn-bg: #3a2a0d;
    --warn-text: #fbbf24;
    --ok-bg: #0f2e1a;
    --ok-text: #4ade80;
    --danger-bg: #3a1414;
    --danger-text: #f87171;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-xl: 0 20px 40px rgba(0, 0, 0, .6);
  }
}
html[data-theme="dark"] {
  --bg-app: #0b1220;
  --bg-surface: #131b2c;
  --border: #25324a;
  --text: #cbd5e1;
  --text-muted: #94a3b8;
  --text-disabled: #64748b;
  --text-heading: #e2e8f0;
  --accent: #38bdf8;
  --accent-contrast: #0b1220;
  --bubble-user: #1c2740;
  --warn-bg: #3a2a0d;
  --warn-text: #fbbf24;
  --ok-bg: #0f2e1a;
  --ok-text: #4ade80;
  --danger-bg: #3a1414;
  --danger-text: #f87171;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-xl: 0 20px 40px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg-app);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden; /* 画面全体はアプリシェルの内側だけがスクロールする */
}
button { font-family: inherit; cursor: pointer; }
a { color: inherit; }
.tabular { font-variant-numeric: tabular-nums; }
.scrollbar-hide::-webkit-scrollbar { display: none; }
.scrollbar-hide { scrollbar-width: none; -ms-overflow-style: none; }
.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;
}
[hidden] { display: none !important; }

button:focus-visible, textarea:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

svg.icon { width: 18px; height: 18px; display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
svg.icon-fill { fill: currentColor; stroke: none; }

/* ============================================================
   共通部品
   ============================================================ */
.icon-btn {
  width: 44px; height: 44px; border-radius: 8px; border: none;
  background: transparent; color: var(--text-muted);
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-app); }

.btn-primary {
  height: 44px; padding: 0 18px; border-radius: 8px; border: none;
  background: var(--accent); color: var(--accent-contrast);
  font-size: 14px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-primary:disabled { background: var(--text-disabled); cursor: not-allowed; }
.btn-secondary {
  height: 44px; padding: 0 18px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-surface); color: var(--text);
  font-size: 14px; font-weight: 700;
}
.btn-secondary:disabled { color: var(--text-disabled); cursor: not-allowed; }
.btn-secondary.sm, .btn-primary.sm { height: 36px; padding: 0 14px; font-size: 13px; }
.btn-choice {
  min-height: 44px; padding: 8px 16px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-surface); color: var(--text);
  font-size: 14px; font-weight: 600;
}
.btn-choice:hover { border-color: var(--accent); color: var(--accent); }
.btn-block { width: 100%; }
.link-btn {
  border: none; background: none; color: var(--text-muted); font-size: 13px;
  text-decoration: underline; padding: 8px 0; min-height: 44px;
}

.chip {
  height: 44px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-surface); color: var(--text);
  font-size: 13px; font-weight: 600; white-space: nowrap;
  display: inline-flex; align-items: center; flex-shrink: 0;
}
.chip:hover { background: var(--bg-app); }

.badge-warn {
  background: var(--warn-bg); color: var(--warn-text);
  font-size: 12px; font-weight: 700;
  padding: 10px 10px;
  border-radius: 9999px;
  display: inline-flex; align-items: center; gap: 4px;
  border: none; white-space: nowrap;
  min-height: 44px; flex-shrink: 0;
}
.badge-warn-inline { min-height: auto; padding: 2px 8px; font-size: 11px; }

.card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow-sm);
  padding: 16px; max-width: 480px; align-self: flex-start;
}
.card-flat { background: var(--bg-app); }
.card-title { margin: 0 0 4px; font-size: 15px; font-weight: 700; color: var(--text-heading); }
.card-subtitle { margin: 0 0 10px; font-size: 13px; color: var(--text-muted); }
.card-divider { border-top: 1px solid var(--border); padding-top: 10px; }
.card-row { display: flex; gap: 12px; padding: 4px 0; font-size: 14px; }
.card-row-label { color: var(--text-muted); flex-shrink: 0; white-space: nowrap; }
.card-row-value { flex: 1; text-align: right; }
.card-row-value strong { color: var(--text-heading); }
.card-warn-box {
  margin-top: 10px; padding: 10px 12px; border-radius: 8px;
  background: var(--warn-bg); color: var(--warn-text); font-size: 13px;
  display: flex; gap: 8px; align-items: flex-start;
}
.card-warn-box svg.icon { flex-shrink: 0; margin-top: 2px; width: 16px; height: 16px; }
.card-footnote { margin: 10px 0 0; font-size: 12px; color: var(--text-disabled); }
.card-body-line { margin: 0 0 4px; font-size: 14px; color: var(--text); white-space: pre-wrap; }
.card-actions { margin-top: 12px; display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.card-expired { color: var(--text-disabled); font-size: 13px; margin-top: 12px; }
.card-note { margin: 0 0 8px; font-size: 12px; color: var(--text-disabled); }
.card-state-note { margin: 10px 0 0; font-size: 13px; color: var(--text-disabled); font-weight: 600; }
@keyframes cardFlash { 0%, 100% { box-shadow: var(--shadow-sm); } 30% { box-shadow: 0 0 0 3px var(--warn-text); } }
.card-flash { animation: cardFlash 1.4s ease; }

.result-footer {
  margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.result-footer-note { font-size: 12px; color: var(--text-disabled); }

.followup-row {
  display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 8px 0;
  border-top: 1px solid var(--border);
}
.followup-row:first-child { border-top: none; }
.followup-index { font-size: 13px; color: var(--text-disabled); flex-shrink: 0; }
.followup-text { flex: 1; font-size: 14px; color: var(--text); }

.pii-card { max-width: 560px; }

/* ============================================================
   ログイン画面
   ============================================================ */
.login-view {
  height: 100%; display: flex; align-items: center; justify-content: center;
  padding: 24px 16px; background: var(--bg-app); overflow-y: auto;
}
.login-card { width: 100%; max-width: 360px; }
.login-logo {
  width: 64px; height: 64px; border-radius: 16px; background: #0f2a4a;
  display: flex; align-items: center; justify-content: center; margin: 0 auto 16px;
}
.login-logo-text { color: #fff; font-size: 22px; font-weight: 800; letter-spacing: 1px; }
.login-title { text-align: center; font-size: 18px; font-weight: 700; color: var(--text-heading); margin: 0 0 6px; }
.login-sub { text-align: center; font-size: 13px; color: var(--text-muted); margin: 0 0 24px; }
.login-form { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text); margin: 12px 0 6px; }
.field-label:first-child { margin-top: 0; }
.text-input {
  width: 100%; height: 44px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-surface); color: var(--text); font-size: 16px;
}
.field-error {
  margin: 10px 0 0; font-size: 13px; color: var(--danger-text);
  background: var(--danger-bg); border-radius: 8px; padding: 10px 12px;
}
.login-submit { margin-top: 18px; }
.login-locked-hint { margin-top: 10px; font-size: 12px; color: var(--text-disabled); }

/* ============================================================
   ログイン切れ全画面
   ============================================================ */
.loggedout-view {
  height: 100%; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 24px 16px; background: var(--bg-app);
}
.loggedout-card { max-width: 320px; }
.loggedout-title { font-size: 16px; font-weight: 700; color: var(--text-heading); margin: 0 0 8px; }
.loggedout-sub { font-size: 14px; color: var(--text-muted); margin: 0 0 20px; }

/* ============================================================
   起動中スプラッシュ
   ============================================================ */
.boot-loading {
  height: 100%; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 14px;
}

/* ============================================================
   アプリシェル
   ============================================================ */
.app-shell { display: flex; flex-direction: row; height: 100%; height: 100dvh; overflow: hidden; }

.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .4);
  opacity: 0; pointer-events: none; transition: opacity .15s ease;
  z-index: 40;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.conv-list {
  position: fixed; top: 0; left: 0; bottom: 0; width: 86%; max-width: 320px;
  background: var(--bg-surface); box-shadow: var(--shadow-xl);
  transform: translateX(-100%); visibility: hidden;
  transition: transform .18s ease, visibility 0s linear .18s;
  z-index: 41; display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
}
/* 閉じている間は visibility:hidden にして、shadow-xl のぼかしが 375px 幅の左端に
   はみ出て見える（「影が消えない」UAT指摘）のを防ぐ。開く瞬間だけ即 visible にする */
.conv-list.open { transform: translateX(0); visibility: visible; transition: transform .18s ease, visibility 0s linear 0s; }

.conv-list-header {
  flex-shrink: 0; padding: 12px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.conv-search-wrap { position: relative; flex: 1; }
.conv-search-wrap svg.icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-disabled); width: 15px; height: 15px;
}
.conv-search-input {
  width: 100%; height: 44px; padding: 0 12px 0 34px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-app); color: var(--text); font-size: 14px;
}
.conv-list-body { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; }
.conv-list-footer { flex-shrink: 0; padding: 4px 12px 12px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; }
.conv-empty { padding: 24px 12px; font-size: 13px; color: var(--text-muted); line-height: 1.7; }
.conv-group-heading { font-size: 12px; font-weight: 700; color: var(--text-disabled); margin: 14px 8px 4px; }
.conv-group-heading:first-child { margin-top: 8px; }
.conv-item {
  width: 100%; text-align: left; padding: 10px 8px; border-radius: 8px; border: none;
  background: transparent; display: flex; align-items: center; gap: 8px; min-height: 44px;
}
.conv-item:hover { background: var(--bg-app); }
.conv-item[aria-current="true"] { background: #eff6ff; }
html[data-theme="dark"] .conv-item[aria-current="true"] { background: rgba(56, 189, 248, .12); }
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .conv-item[aria-current="true"] { background: rgba(56, 189, 248, .12); }
}
.conv-marker { width: 4px; height: 32px; border-radius: 2px; flex-shrink: 0; background: transparent; }
.conv-item[aria-current="true"] .conv-marker { background: var(--accent); }
.conv-preview {
  flex: 1; font-size: 13px; color: var(--text-muted); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.conv-item[aria-current="true"] .conv-preview { color: var(--text); }
.conv-unread {
  flex-shrink: 0; min-width: 18px; height: 18px; border-radius: 9999px;
  background: var(--text-disabled); color: #fff; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; padding: 0 5px;
}

@media (min-width: 768px) {
  .conv-list {
    position: static; transform: none; box-shadow: none; visibility: visible;
    width: 288px; flex-shrink: 0; height: auto;
  }
}

.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg-app); }

.chat-header { flex-shrink: 0; border-bottom: 1px solid var(--border); background: var(--bg-surface); }
.chat-header-row { height: 56px; padding: 0 12px; display: flex; align-items: center; gap: 8px; }
.chat-title { font-size: 15px; font-weight: 700; color: var(--text-heading); margin: 0; flex: 1; }
.badge-row, .quick-row {
  padding: 0 12px 10px; display: flex; gap: 8px; overflow-x: auto;
}
.quick-row { padding-bottom: 12px; }
.badge-row:empty, .quick-row:empty { display: none; }

.state-banner {
  flex-shrink: 0; padding: 10px 16px; font-size: 13px;
  background: var(--bg-app); color: var(--text-muted); border-bottom: 1px solid var(--border);
}

.stream { flex: 1; min-height: 0; overflow-y: auto; padding: 20px 16px 24px; -webkit-overflow-scrolling: touch; }
.stream-inner { max-width: 720px; margin: 0 auto; }
.messages-list { display: flex; flex-direction: column; gap: 16px; }

.msg-user {
  align-self: flex-end; max-width: 75%; background: var(--bubble-user); color: var(--text-heading);
  padding: 12px 16px; border-radius: 12px; font-size: 16px; line-height: 1.6; white-space: pre-wrap;
  word-break: break-word;
}
.msg-agent {
  align-self: flex-start; max-width: 75%; color: var(--text); font-size: 16px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
}
.msg-agent-actions { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }

.msg-user-unsent { opacity: .75; border: 1px dashed var(--danger-text); }
.msg-unsent-footer { margin-top: 8px; display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.msg-unsent-label { font-size: 11px; font-weight: 700; color: var(--danger-text); }
.msg-unsent-footer .link-btn { color: var(--accent); min-height: auto; padding: 4px 0; }

.system-conv-notice {
  flex-shrink: 0; padding: 12px 16px; font-size: 13px; text-align: center;
  color: var(--text-muted); background: var(--bg-surface); border-top: 1px solid var(--border);
}
.system-conv-notice p { margin: 0 0 2px; }

.header-test-badge {
  margin-left: 8px; font-size: 10px; font-weight: 700; letter-spacing: .02em;
  color: var(--warn-text); background: var(--warn-bg); padding: 2px 6px; border-radius: 4px;
  vertical-align: middle;
}

.msg-typing { align-self: flex-start; color: var(--text-muted); font-size: 14px; display: flex; align-items: center; gap: 6px; }
.typing-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--text-muted); display: inline-block; animation: typingBlink 1.2s infinite; opacity: .25; }
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes typingBlink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.first-state { text-align: center; padding: 40px 16px; }
.first-state-title { font-size: 16px; font-weight: 700; color: var(--text-heading); margin: 0 0 12px; }
.first-state-list { list-style: none; padding: 0; margin: 0 0 24px; color: var(--text-muted); font-size: 14px; line-height: 1.9; }
.first-state-hint { font-size: 13px; color: var(--text-disabled); margin: 0 0 10px; }
.first-state-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.composer { flex-shrink: 0; border-top: 1px solid var(--border); background: var(--bg-surface); padding: 10px 16px; }
.composer-inner { max-width: 720px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; }
.composer-textarea {
  flex: 1; padding: 11px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-app); color: var(--text); font-size: 16px; resize: none;
  overflow-y: auto; max-height: 120px; min-height: 44px; line-height: 1.5;
}
.composer-textarea:disabled { color: var(--text-disabled); }
.composer-send { width: 44px; height: 44px; padding: 0; flex-shrink: 0; }
.composer-footer { max-width: 720px; margin: 4px auto 0; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.composer-count { font-size: 11px; color: var(--text-disabled); }
.composer-count.over { color: var(--danger-text); font-weight: 700; }
.composer-error { max-width: 720px; margin: 6px auto 0; }

@media (max-width: 767px) {
  .desktop-only { display: none !important; }
}
@media (min-width: 768px) {
  .mobile-only { display: none !important; }
}

/* ============================================================
   トースト（OMPO本体の showToast は別オリジンのため使えない。最小限の自前実装）
   ============================================================ */
.toast-host {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; max-width: calc(100% - 32px);
}
.toast {
  background: var(--text-heading); color: #fff; font-size: 13px; padding: 10px 16px;
  border-radius: 8px; box-shadow: var(--shadow-xl); opacity: 0; transform: translateY(8px);
  transition: opacity .15s ease, transform .15s ease; max-width: 100%;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { background: var(--danger-text); }

/* ============================================================
   確認ダイアログ（window.confirm 禁止のため自前。ボトムシート骨格に準拠）
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 90;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-sheet {
  width: 100%; max-width: 420px; background: var(--bg-surface); border-radius: 12px 12px 0 0;
  box-shadow: var(--shadow-xl); padding: 20px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 16px;
}
.modal-sheet-body { margin: 0; font-size: 14px; color: var(--text); line-height: 1.6; }
.modal-sheet-actions { display: flex; justify-content: flex-end; gap: 8px; }
@media (min-width: 768px) {
  .modal-overlay { align-items: center; }
  .modal-sheet { border-radius: 12px; }
}

.btn-secondary.is-expired { color: var(--text-disabled); }

/* 375px相当のごく狭い幅でもタップ域・折返しを保つための微調整 */
@media (max-width: 380px) {
  .card { max-width: 100%; }
  .msg-user, .msg-agent { max-width: 88%; }
}
