/* TALON AIアシスタント — UIスタイル
   ブランド: talon.jp 準拠（プライマリ #0171bb / ネイビー #1f2d44 / 淡青 #e8f3fb・#f2f6fa / 白基調） */
:root {
  --brand: #0171bb;
  --brand-dark: #0a4a86;
  --brand-tint: #e8f3fb;
  --navy: #1f2d44;
  --bg: #f2f6fa;
  --panel: #ffffff;
  --ink: #2b3548;
  --ink-soft: #4a5568;
  --ink-faint: #8b96a8;
  --line: #e3e8ef;
  --line-strong: #b9c6d6;
  --ok: #1f7a58;
  --warn: #b45309;
  --err: #c22f2f;
  --radius: 8px;
  --font: "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Segoe UI", Meiryo, sans-serif;
  --mono: Consolas, "SF Mono", Menlo, monospace;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; } /* hidden属性をdisplay指定より優先させる */
html, body { height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.75; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

#app { display: flex; height: 100vh; }

/* ======================= サイドバー（白・実ロゴ） ======================= */
#sidebar {
  width: 260px; min-width: 260px; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 20px 16px 14px; gap: 16px;
  transition: margin-left .25s ease;
}
.brand { padding: 0 2px; display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 34px; height: auto; flex-shrink: 0; }
.brand-name { font-size: 13.5px; font-weight: 700; color: var(--navy); letter-spacing: .02em; line-height: 1.3; }
.brand-sub { font-size: 10.5px; color: var(--ink-faint); margin-top: 2px; letter-spacing: .03em; }
.beta {
  display: inline-block; border: 1px solid var(--brand); color: var(--brand);
  border-radius: 3px; padding: 0 5px; font-size: 10px; font-weight: 600; margin-left: 2px; vertical-align: 1px;
}

.new-chat-btn {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--brand); color: #fff; border-radius: 6px; padding: 9px;
  font-size: 13px; font-weight: 600; transition: background .15s;
}
.new-chat-btn:hover { background: var(--brand-dark); }

.modes { display: flex; flex-direction: column; gap: 2px; }
.mode-btn {
  display: flex; align-items: center; gap: 11px; padding: 9px 10px;
  border-radius: 6px; border-left: 3px solid transparent;
  color: var(--ink-soft); text-align: left; transition: background .15s, border-color .15s; width: 100%;
}
.mode-btn:hover { background: var(--bg); }
.mode-btn.active { background: var(--brand-tint); border-left-color: var(--brand); color: var(--navy); }
.mode-icon { color: var(--brand); flex-shrink: 0; }
.mode-label { display: flex; flex-direction: column; font-size: 13px; font-weight: 600; line-height: 1.35; }
.mode-label small { font-size: 10.5px; font-weight: 400; color: var(--ink-faint); }

.history { flex: 1; overflow-y: auto; min-height: 40px; border-top: 1px solid var(--line); padding-top: 10px; }
.history-title { font-size: 11px; color: var(--ink-faint); padding: 0 6px 4px; letter-spacing: .08em; }
#historyList { list-style: none; }
#historyList li {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 5px;
  font-size: 12.5px; color: var(--ink-soft); cursor: pointer; white-space: nowrap; overflow: hidden;
}
#historyList li:hover { background: var(--bg); }
#historyList li.active { background: var(--brand-tint); color: var(--navy); }
#historyList li .h-title { flex: 1; overflow: hidden; text-overflow: ellipsis; }
#historyList li .h-del { opacity: 0; font-size: 12px; color: var(--ink-faint); padding: 0 3px; }
#historyList li:hover .h-del { opacity: 1; }
#historyList li .h-del:hover { color: var(--err); }

.usage { border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; background: #f7fafd; }
.usage-row { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--ink-soft); margin-bottom: 6px; }
.usage-bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
#usageFill { height: 100%; background: var(--brand); border-radius: 2px; transition: width .4s, background .4s; }
#usageFill.warn { background: #d97706; }
#usageFill.full { background: var(--err); }

.admin-link {
  display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ink-soft);
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; text-decoration: none;
  transition: all .15s;
}
.admin-link:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-tint); }
.admin-link svg { color: var(--brand); }

.sidebar-footer {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  border-top: 1px solid var(--line); padding-top: 12px;
}
.user-card { display: flex; align-items: center; gap: 9px; min-width: 0; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--brand-tint); color: var(--brand-dark);
  font-size: 13px; font-weight: 700; display: flex; align-items: center; justify-content: center;
  overflow: hidden; flex-shrink: 0; border: 1px solid var(--line);
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.4; }
.user-name { font-size: 12.5px; font-weight: 600; color: var(--navy); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-org { font-size: 10.5px; color: var(--ink-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#logoutBtn { font-size: 11px; color: var(--ink-faint); text-decoration: none; flex-shrink: 0; }
#logoutBtn:hover { color: var(--brand); text-decoration: underline; }

/* ======================= メイン ======================= */
#main { flex: 1; display: flex; flex-direction: column; position: relative; min-width: 0; }
#sidebarToggle {
  display: none; position: absolute; top: 12px; left: 12px; z-index: 30;
  width: 36px; height: 36px; border-radius: 6px; background: var(--panel); border: 1px solid var(--line);
  font-size: 16px; color: var(--ink-soft);
}

#chatScroll { flex: 1; overflow-y: auto; padding: 30px 0 12px; scroll-behavior: smooth; }
#messages, #welcome { max-width: 840px; margin: 0 auto; padding: 0 28px; }

/* ---------- ウェルカム ---------- */
#welcome { text-align: center; padding-top: 8vh; }
.welcome-mark { margin-bottom: 16px; }
#welcome h1 { font-size: 22px; font-weight: 700; color: var(--navy); letter-spacing: .02em; }
.welcome-lead { color: var(--ink-soft); font-size: 13.5px; margin: 10px 0 30px; }
.welcome-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 24px; }
.w-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 15px; text-align: left; transition: border-color .15s, box-shadow .15s;
}
.w-card:hover { border-color: var(--brand); box-shadow: 0 2px 10px rgba(1, 113, 187, .1); }
.w-card-head { display: flex; align-items: center; gap: 7px; font-weight: 700; font-size: 13px; color: var(--navy); }
.w-card-head svg { color: var(--brand); }
.w-card p { font-size: 12px; color: var(--ink-soft); margin-top: 7px; line-height: 1.65; }
.welcome-examples { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.ex-chip {
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px; font-size: 12px; color: var(--ink-soft); transition: all .15s;
}
.ex-chip:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-tint); }

/* ---------- メッセージ ---------- */
.msg { margin-bottom: 24px; display: flex; flex-direction: column; }
.msg-user { align-items: flex-end; }
.msg-user .bubble {
  background: var(--brand); color: #fff; border-radius: 8px 8px 2px 8px;
  padding: 10px 15px; max-width: 76%; white-space: pre-wrap; word-break: break-word; font-size: 13.5px;
}
.msg-user .imgs { display: flex; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; justify-content: flex-end; }
.msg-user .imgs img { max-height: 110px; max-width: 160px; border-radius: 6px; border: 1px solid var(--line); cursor: zoom-in; }

.msg-ai { align-items: stretch; }
.msg-ai .ai-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.ai-avatar {
  width: 26px; height: 26px; border-radius: 6px; background: var(--panel); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
}
.ai-name { font-size: 12px; font-weight: 600; color: var(--ink-soft); }

.tools { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.tool-chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--brand-dark);
  background: var(--brand-tint); border: 1px solid #cfe4f5; border-radius: 4px; padding: 3px 10px;
}
.tool-chip .spin {
  width: 10px; height: 10px; border: 2px solid #b3d4ec; border-top-color: var(--brand);
  border-radius: 50%; animation: spin .7s linear infinite;
}
.tool-chip.done .spin { display: none; }
.tool-chip.done::before { content: "✓"; color: var(--ok); font-weight: 700; }
.tool-chip.ng::before { content: "！"; color: var(--warn); font-weight: 700; }
@keyframes spin { to { transform: rotate(360deg); } }

.ai-body {
  background: var(--panel); border: 1px solid var(--line); border-radius: 2px 8px 8px 8px;
  padding: 14px 20px; overflow-wrap: break-word; font-size: 13.5px;
}
.ai-body.streaming::after {
  content: ""; display: inline-block; width: 7px; height: 14px; background: var(--brand);
  margin-left: 3px; vertical-align: text-bottom; animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.msg-note { font-size: 12px; color: var(--warn); margin-top: 6px; }
.msg-error {
  background: #fdf3f3; border: 1px solid #efc9c9; color: var(--err);
  border-radius: 6px; padding: 10px 14px; font-size: 13px; margin-top: 8px;
}

/* markdown */
.ai-body h1, .ai-body h2, .ai-body h3 { font-size: 14.5px; margin: 15px 0 6px; color: var(--navy); }
.ai-body h1 { font-size: 16px; }
.ai-body p { margin: 7px 0; }
.ai-body ul, .ai-body ol { padding-left: 22px; margin: 7px 0; }
.ai-body li { margin: 3px 0; }
.ai-body a { color: var(--brand); text-decoration: none; }
.ai-body a:hover { text-decoration: underline; }
.ai-body strong { color: var(--navy); }
.ai-body code { background: var(--brand-tint); color: var(--brand-dark); border-radius: 3px; padding: 1px 6px; font-family: var(--mono); font-size: 12px; }
.ai-body pre {
  position: relative; background: var(--navy); color: #dbe4f0; border-radius: 6px;
  padding: 14px 16px; overflow-x: auto; margin: 10px 0; font-size: 12.5px; line-height: 1.6;
}
.ai-body pre code { background: none; color: inherit; padding: 0; font-size: inherit; }
.copy-btn {
  position: absolute; top: 8px; right: 8px; background: rgba(255,255,255,.14); color: #c3cede;
  border-radius: 4px; padding: 3px 10px; font-size: 11px; opacity: 0; transition: opacity .15s;
}
.ai-body pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { background: rgba(255,255,255,.28); }
.ai-body table { border-collapse: collapse; margin: 10px 0; font-size: 12.5px; display: block; overflow-x: auto; }
.ai-body th, .ai-body td { border: 1px solid var(--line); padding: 6px 12px; }
.ai-body th { background: #f2f6fa; color: var(--navy); }
.ai-body blockquote { border-left: 3px solid var(--line-strong); padding-left: 12px; color: var(--ink-soft); margin: 8px 0; }
.ai-body hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }

.fb { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.fb button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 5px;
  padding: 3px 10px; font-size: 12px; color: var(--ink-soft); transition: all .15s;
}
.fb button:hover { border-color: var(--brand); color: var(--brand); }
.fb button.sel { background: var(--brand-tint); border-color: var(--brand); color: var(--brand-dark); }
.fb .fb-done { font-size: 11.5px; color: var(--ok); }
.fb input {
  flex: 1; max-width: 320px; border: 1px solid var(--line); border-radius: 5px;
  padding: 4px 10px; font-size: 12px; font-family: inherit;
}

/* ======================= 入力エリア ======================= */
#composerWrap { max-width: 840px; margin: 0 auto; width: 100%; padding: 0 28px 14px; }
.mode-fields { margin-bottom: 8px; display: flex; flex-direction: column; gap: 8px; }
.mode-fields input[type="text"], .mode-fields textarea, .mode-fields select {
  width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 9px 12px;
  font-family: inherit; font-size: 13px; background: var(--panel); color: var(--ink); resize: vertical;
}
.mode-fields textarea { font-family: var(--mono); font-size: 12px; }
.mode-fields :focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(1, 113, 187, .12); }
.log-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cg-row { display: grid; grid-template-columns: 1fr 180px; gap: 8px; }

#imagePreview { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
#imagePreview:empty { display: none; }
.img-thumb { position: relative; }
.img-thumb img { height: 64px; border-radius: 6px; border: 1px solid var(--line); display: block; }
.img-thumb button {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--navy); color: #fff; font-size: 11px; line-height: 1;
}

#composer {
  display: flex; align-items: flex-end; gap: 8px; background: var(--panel);
  border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 8px 10px;
  transition: border-color .15s, box-shadow .15s;
}
#composer:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(1, 113, 187, .12); }
#composer.dragover { border-color: var(--brand); background: var(--brand-tint); }
#input {
  flex: 1; border: none; outline: none; resize: none; font-family: inherit; font-size: 14px;
  line-height: 1.6; max-height: 200px; padding: 6px 2px; background: transparent; color: var(--ink);
}
#attachBtn { color: var(--ink-faint); padding: 8px; border-radius: 6px; }
#attachBtn:hover { background: var(--bg); color: var(--brand); }
#sendBtn, #stopBtn {
  width: 38px; height: 38px; border-radius: 6px; display: flex; align-items: center; justify-content: center;
  background: var(--brand); color: #fff; transition: background .15s; flex-shrink: 0;
}
#sendBtn:hover { background: var(--brand-dark); }
#sendBtn:disabled { background: var(--line-strong); cursor: default; }
#stopBtn { background: var(--navy); }
#composerHint { text-align: center; font-size: 11px; color: var(--ink-faint); margin-top: 7px; line-height: 1.7; }
#composerHint strong { color: var(--ink-soft); font-weight: 600; }

/* ======================= ログイン画面 ======================= */
#loginView {
  position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 0;
  background: linear-gradient(180deg, #f7fafd 0%, #e8f3fb 100%);
}
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  border-top: 3px solid var(--brand);
  padding: 40px 44px 32px; width: 460px; max-width: 92vw; text-align: center;
  box-shadow: 0 8px 32px rgba(31, 45, 68, .1);
}
.login-logo { width: 150px; height: auto; }
.login-product { font-size: 14px; color: var(--navy); font-weight: 600; margin: 10px 0 18px; letter-spacing: .05em; }
.login-lead { font-size: 12.5px; color: var(--ink-soft); margin-bottom: 22px; line-height: 1.9; }
.login-error {
  background: #fdf3f3; border: 1px solid #efc9c9; color: var(--err);
  border-radius: 6px; padding: 9px 12px; font-size: 12.5px; margin-bottom: 14px;
}
#loginBtn {
  width: 100%; background: var(--brand); color: #fff; border-radius: 6px; padding: 12px;
  font-size: 14px; font-weight: 700; transition: background .15s;
}
#loginBtn:hover { background: var(--brand-dark); }
.login-note { font-size: 11px; color: var(--ink-faint); margin-top: 18px; line-height: 1.9; }
.login-note a { color: var(--brand); }
.login-footer { margin-top: 26px; font-size: 11px; color: var(--ink-faint); }

/* ======================= レスポンシブ ======================= */
@media (max-width: 900px) {
  #sidebar { position: fixed; z-index: 40; height: 100vh; margin-left: -276px; box-shadow: 4px 0 24px rgba(31,45,68,.18); }
  #sidebar.open { margin-left: 0; }
  #sidebarToggle { display: block; }
  .welcome-cards { grid-template-columns: 1fr; }
  .log-grid, .cg-row { grid-template-columns: 1fr; }
  #messages, #welcome, #composerWrap { padding-left: 14px; padding-right: 14px; }
}
