:root {
  --side-bg: #1f1a2e;
  --side-bg-hover: #2c2540;
  --side-active: #4b3f8f;
  --side-ink: #d8d3e6;
  --side-ink-soft: #9a93ad;
  --side-ink-strong: #ffffff;
  --bg: #ffffff;
  --bg-soft: #f6f5f8;
  --bg-hover: #f3f1f6;
  --ink: #1d1c1f;
  --ink-soft: #6b6874;
  --line: #e6e3ec;
  --accent: #4b3f8f;
  --accent-ink: #ffffff;
  --link: #1264a3;
  --ok: #2bac76;
  --off: #8e8a99;
  --alert: #e01e5a;
  --alert-bg: #fdecf1;
  --warn-bg: #fff7e0;
  --code-bg: #f4f3f7;
  --skin: #f5d0b5;
  --cheek: #f4a3a3;
  --chair: #4b5563;
  --shadow: 0 8px 28px rgba(20, 10, 40, .14);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --side-bg: #15121f;
    --side-bg-hover: #221d31;
    --bg: #1a1d21;
    --bg-soft: #202328;
    --bg-hover: #23262b;
    --ink: #e8e6ec;
    --ink-soft: #a19dab;
    --line: #2f3238;
    --link: #5fa8e8;
    --alert-bg: #3a1a26;
    --warn-bg: #3a3220;
    --code-bg: #25282e;
    --shadow: 0 8px 28px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --side-bg: #15121f; --side-bg-hover: #221d31; --bg: #1a1d21; --bg-soft: #202328; --bg-hover: #23262b;
  --ink: #e8e6ec; --ink-soft: #a19dab; --line: #2f3238; --link: #5fa8e8; --alert-bg: #3a1a26;
  --warn-bg: #3a3220; --code-bg: #25282e; --shadow: 0 8px 28px rgba(0, 0, 0, .45); color-scheme: dark;
}

* { box-sizing: border-box; }
/* ページ全体は動かさず、枠(一覧・メッセージ・詳細)の中だけスクロールさせる。拡大縮小もしない */
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; touch-action: manipulation; }
body {
  position: fixed; inset: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
.icon-btn {
  border: 0; background: transparent; width: 36px; height: 36px; border-radius: 8px;
  display: inline-grid; place-items: center; cursor: pointer; font-size: 18px; color: var(--ink-soft); flex: none;
}
.icon-btn:hover { background: var(--bg-hover); }

/* ───── ログイン ───── */
.login { height: var(--app-h, 100dvh); overflow-y: auto; overscroll-behavior: contain; display: grid; place-items: center; padding: 16px; background: var(--side-bg); }
.login-card { width: min(360px, 100%); background: var(--bg); border-radius: 16px; padding: 28px 22px; box-shadow: var(--shadow); text-align: center; }
.login-logo {
  width: 52px; height: 52px; margin: 0 auto; border-radius: 14px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 800; letter-spacing: .02em;
}
.login-card h1 { margin: 12px 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 16px; color: var(--ink-soft); font-size: 14px; }
.login-card input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-soft); color: var(--ink); font-size: 16px;
}
.login-card button {
  width: 100%; margin-top: 10px; padding: 12px; border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 16px; cursor: pointer;
}
.login-error { color: var(--alert) !important; margin-top: 10px !important; min-height: 1em; }

/* ───── 全体のレイアウト ───── */
.channels, .messages, .details-body, .table-wrap, .format-bar, .block pre, .composer textarea { overscroll-behavior: contain; }
.app { height: var(--app-h, 100dvh); display: grid; grid-template-columns: 264px minmax(0, 1fr); overflow: hidden; }
.app.with-details { grid-template-columns: 264px minmax(0, 1fr) 340px; }

/* ───── サイドバー ───── */
.sidebar {
  background: var(--side-bg); color: var(--side-ink); display: flex; flex-direction: column; min-height: 0;
  padding-top: env(safe-area-inset-top);
}
.ws-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,.08);
}
.ws-name { font-weight: 800; font-size: 17px; color: var(--side-ink-strong); }
.presence { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--side-ink-soft); }
.presence::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--off); }
.presence.on::before { background: var(--ok); }
.offline-note {
  margin: 10px 12px 0; padding: 10px 12px; border-radius: 10px; background: rgba(255,255,255,.06);
  font-size: 13px; line-height: 1.5;
}
.offline-note b { display: block; color: var(--side-ink-strong); }
.offline-note span { color: var(--side-ink-soft); font-size: 12px; }
.channels { flex: 1; overflow-y: auto; padding: 8px 8px 24px; }
.section-label { margin: 14px 10px 4px; font-size: 12px; color: var(--side-ink-soft); font-weight: 700; }
.channels ul { list-style: none; margin: 0; padding: 0; }
.ch {
  width: 100%; display: flex; align-items: center; gap: 10px; border: 0; background: transparent; cursor: pointer;
  padding: 6px 10px; border-radius: 8px; color: var(--side-ink); text-align: left; min-height: 40px;
}
.ch:hover { background: var(--side-bg-hover); }
.ch.active { background: var(--side-active); color: #fff; }
.ch.unread .ch-name { color: var(--side-ink-strong); font-weight: 800; }
.ch-hash { width: 28px; text-align: center; font-size: 18px; opacity: .8; flex: none; }
.ch-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ch-name { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-status { font-size: 12px; color: var(--side-ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch.active .ch-status { color: rgba(255,255,255,.75); }
.badge {
  flex: none; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; display: grid; place-items: center;
  font-size: 11px; font-weight: 800; background: var(--alert); color: #fff;
}
.badge.dot { min-width: 8px; width: 8px; height: 8px; padding: 0; background: var(--side-ink-strong); }

/* アバター(キャラの顔) */
.c-skin { fill: var(--skin); }
.c-cheek { fill: var(--cheek); }
.avatar { display: inline-block; vertical-align: top; position: relative; flex: none; width: 28px; height: 28px; border-radius: 8px; background: #3b3450; }
.avatar svg { width: 100%; height: 100%; display: block; border-radius: inherit; }
.avatar.lg { width: 36px; height: 36px; }
.avatar.xl { width: 72px; height: 72px; border-radius: 16px; }
.avatar .pres {
  position: absolute; right: -3px; bottom: -3px; width: 11px; height: 11px; border-radius: 50%;
  background: var(--off); border: 2.5px solid var(--side-bg);
}
.avatar .pres.on { background: var(--ok); }
.avatar .pres.busy { background: #ecb22e; }
.me-avatar {
  flex: none; width: 36px; height: 36px; border-radius: 8px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 14px;
}

/* ───── 会話 ───── */
.conversation { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.conv-head {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; min-height: 56px;
  border-bottom: 1px solid var(--line); padding-top: calc(8px + env(safe-area-inset-top));
}
.back { display: none; font-size: 30px; line-height: 1; }
.conv-avatar:empty { display: none; }
.conv-title { flex: 1; min-width: 0; border: 0; background: transparent; text-align: left; cursor: pointer; padding: 2px 0; }
.conv-name { display: block; font-weight: 800; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-sub { display: block; font-size: 12px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.alert-banner {
  margin: 10px 16px 0; padding: 10px 12px; border-radius: 10px; background: var(--alert-bg);
  border: 1px solid color-mix(in srgb, var(--alert) 35%, transparent); font-size: 14px; display: flex; gap: 8px; align-items: flex-start;
}

.messages { flex: 1; overflow-y: auto; padding: 12px 0 8px; -webkit-overflow-scrolling: touch; }
.intro { padding: 12px 20px 16px; }
.intro .avatar { margin-bottom: 10px; }
.intro h2 { margin: 0 0 4px; font-size: 20px; }
.intro p { margin: 0; color: var(--ink-soft); font-size: 14px; line-height: 1.6; }
.day-sep { display: flex; align-items: center; gap: 10px; margin: 14px 16px 6px; color: var(--ink-soft); font-size: 12px; font-weight: 700; }
.day-sep::before, .day-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.msg { display: flex; gap: 10px; padding: 6px 20px; }
.msg:hover { background: var(--bg-hover); }
.msg.cont { padding-top: 1px; }
.msg.cont .gutter { visibility: hidden; height: 0; }
.gutter { width: 36px; flex: none; }
.msg-main { flex: 1; min-width: 0; }
.msg-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 1px; }
.msg-name { font-weight: 800; font-size: 15px; }
.msg-time { font-size: 12px; color: var(--ink-soft); }
.msg-text { font-size: 15px; line-height: 1.7; overflow-wrap: anywhere; }
.msg-text p { margin: 2px 0; }
.msg-text ul { margin: 2px 0; padding-left: 20px; }
.msg-text .h { font-weight: 800; margin: 8px 0 2px; }
.msg-text pre {
  background: var(--code-bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 6px 0;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 13px; line-height: 1.55;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg-text code { background: var(--code-bg); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: 13px; }
.msg.pending .msg-text { opacity: .6; }
.plain { white-space: pre-wrap; }

.report-card {
  margin-top: 4px; border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px;
  padding: 8px 12px; background: var(--bg-soft);
}
.report-card.alerting { border-left-color: var(--alert); background: var(--alert-bg); }
.report-card pre { white-space: pre; overflow-x: auto; overflow-wrap: normal; }
.report-label { font-size: 12px; font-weight: 800; color: var(--ink-soft); margin-bottom: 2px; }
.report-card.alerting .report-label { color: var(--alert); }

.typing { padding: 4px 20px 6px 66px; font-size: 13px; color: var(--ink-soft); display: flex; align-items: center; gap: 6px; }
.typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--ink-soft); animation: dots 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes dots { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
.notice { margin: 8px 20px; padding: 8px 12px; border-radius: 8px; background: var(--warn-bg); font-size: 13px; color: var(--ink); }

.composer { padding: 8px 16px calc(10px + env(safe-area-inset-bottom)); }
.composer-box {
  display: flex; flex-direction: column; gap: 2px; border: 1px solid var(--line); border-radius: 12px;
  padding: 6px 6px 6px 12px; background: var(--bg);
}
.composer-actions { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.format-bar { display: flex; align-items: center; gap: 2px; overflow-x: auto; scrollbar-width: none; margin-left: -6px; }
.format-bar::-webkit-scrollbar { display: none; }
.format-bar button {
  flex: none; min-width: 30px; height: 30px; padding: 0 6px; border: 0; border-radius: 6px; background: transparent;
  color: var(--ink-soft); cursor: pointer; font-size: 13px; font-family: inherit;
}
.format-bar button:hover { background: var(--bg-hover); color: var(--ink); }
.format-bar .sep { width: 1px; height: 18px; background: var(--line); margin: 0 3px; flex: none; }
.composer-box:focus-within { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); }
.composer textarea {
  flex: none; width: 100%; resize: none; border: 0; outline: 0; background: transparent; color: var(--ink);
  font: inherit; font-size: 16px; line-height: 1.55; padding: 6px 0;
  height: 38px; min-height: 38px; max-height: 40vh; overflow-y: auto;
}
#send {
  flex: none; width: 36px; height: 36px; border: 0; border-radius: 8px; background: var(--accent); color: #fff;
  display: grid; place-items: center; cursor: pointer;
}
#send svg { width: 18px; height: 18px; }
#send:disabled { opacity: .45; cursor: default; }
.composer-hint { margin: 4px 4px 0; font-size: 11px; color: var(--ink-soft); }

/* ───── 詳細パネル ───── */
.details { border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.details-head {
  display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 10px 16px; min-height: 56px;
  border-bottom: 1px solid var(--line); padding-top: calc(10px + env(safe-area-inset-top));
}
.details-body { flex: 1; overflow-y: auto; padding: 16px; }
.profile { text-align: center; margin-bottom: 16px; }
.profile .avatar { margin: 0 auto 8px; }
.profile h3 { margin: 0; font-size: 18px; }
.profile p { margin: 2px 0 0; color: var(--ink-soft); font-size: 13px; }
.facts { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.fact { background: var(--bg-soft); border-radius: 10px; padding: 8px 10px; }
.fact small { display: block; font-size: 11px; color: var(--ink-soft); }
.fact b { display: block; margin-top: 2px; font-size: 13px; }
.details h4 { margin: 14px 0 8px; font-size: 13px; color: var(--ink-soft); }
.team-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.team-row .avatar .pres { border-color: var(--bg); }
.team-row span { font-size: 14px; }
.team-row small { display: block; color: var(--ink-soft); font-size: 12px; }
.tip { font-size: 13px; color: var(--ink-soft); background: var(--bg-soft); padding: 10px 12px; border-radius: 10px; line-height: 1.6; margin-top: 14px; }
.empty { color: var(--ink-soft); font-size: 14px; }

/* ───── スマホ ───── */
@media (max-width: 767px) {
  .app, .app.with-details { grid-template-columns: 100%; }
  .app .conversation { display: none; }
  .app.in-conv .sidebar { display: none; }
  .app.in-conv .conversation { display: flex; }
  .back { display: inline-grid; }
  .details { position: fixed; inset: 0; z-index: 30; border-left: 0; }
  .ch { min-height: 52px; padding: 8px 12px; }
  .avatar { width: 34px; height: 34px; }
  .composer-hint { display: none; }
  .msg { padding: 6px 14px; }
  .typing { padding-left: 60px; }
}
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; } }

/* ───── リッチテキスト ───── */
.msg-text strong { font-weight: 800; }
.msg-text del { opacity: .7; }
.msg-text a { color: var(--link); text-decoration: none; overflow-wrap: anywhere; }
.msg-text a:hover { text-decoration: underline; }
.msg-text ol { margin: 2px 0; padding-left: 22px; }
.msg-text li { margin: 1px 0; }
.msg-text li.nested { margin-left: 18px; list-style-type: circle; }
.msg-text .h1 { font-size: 18px; }
.msg-text .h2 { font-size: 16px; }
.msg-text .h3 { font-size: 15px; }
.msg-text blockquote { margin: 4px 0; padding: 2px 0 2px 12px; border-left: 4px solid var(--line); color: var(--ink-soft); }
.msg-text hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.msg-text, .msg-text pre, .msg-text table { font-variant-numeric: tabular-nums; }

/* コードブロック・表(コピーボタン付き) */
.block { margin: 6px 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--code-bg); }
.block-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 6px 4px 10px;
  border-bottom: 1px solid var(--line); font-size: 11px; color: var(--ink-soft); font-weight: 700;
}
.block-actions { display: flex; gap: 4px; }
.msg-text .block pre { margin: 0; border: 0; border-radius: 0; background: transparent; }
.table-wrap { overflow-x: auto; }
.msg-text table { border-collapse: collapse; width: 100%; font-size: 13.5px; background: var(--bg); }
.msg-text th, .msg-text td { border-bottom: 1px solid var(--line); padding: 6px 10px; text-align: left; white-space: nowrap; }
.msg-text th { background: var(--bg-soft); font-weight: 800; }
.msg-text td.num, .msg-text th.num { text-align: right; }
.msg-text tbody tr:last-child td { border-bottom: 0; }
.copy-btn {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 6px;
  padding: 3px 9px; font-size: 12px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.copy-btn:hover { background: var(--bg-hover); }
.copy-btn.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.copy-scratch { position: fixed; top: -1000px; left: 0; opacity: 0; }
.report-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
.report-bar .report-label { margin-bottom: 0; }
@media (max-width: 767px) {
  .copy-btn { padding: 5px 11px; font-size: 12.5px; }
}
