/* YPTeams の画面。配置: トーク一覧 | トーク画面 (| メンバーと現状) の 3 列。900px 未満は一覧 ⇔ トークの切り替え。
   色はすべて :root のトークン。ダークは prefers-color-scheme と data-theme の両方で切り替える */
:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --chat-bg: #e3eae5;
  --fg: #1b231f;
  --muted: #65716a;
  --line: #d3dbd6;
  --me: #c4e5cb;
  --me-fg: #12261a;
  --other: #ffffff;
  --accent: #1d6a55;
  --accent-fg: #ffffff;
  --accent-soft: #dcefe6;
  --warn: #b8741a;
  --warn-bg: #fff3df;
  --danger: #b33a3a;
  --sys-bg: #cfd8d2;
  --sys-fg: #4b5650;
  --task: #5f52ad;
  --avatar-fg: #ffffff;
  --shadow: 0 1px 1px rgba(20, 35, 28, .08);
  --font-display: "Hiragino Maru Gothic ProN", "Zen Maru Gothic", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  --font-body: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Noto Sans Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141917; --surface: #1b2220; --chat-bg: #0f1412; --fg: #e2e9e5; --muted: #95a29b; --line: #2b3531;
    --me: #2c5a3e; --me-fg: #e4f3e9; --other: #222b28; --accent: #5cba97; --accent-fg: #0c1a14; --accent-soft: #1d3329;
    --warn: #e3a64e; --warn-bg: #2d2414; --danger: #e07a7a; --sys-bg: #252f2b; --sys-fg: #a7b4ad; --task: #7c70c9;
    --shadow: 0 1px 1px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141917; --surface: #1b2220; --chat-bg: #0f1412; --fg: #e2e9e5; --muted: #95a29b; --line: #2b3531;
  --me: #2c5a3e; --me-fg: #e4f3e9; --other: #222b28; --accent: #5cba97; --accent-fg: #0c1a14; --accent-soft: #1d3329;
  --warn: #e3a64e; --warn-bg: #2d2414; --danger: #e07a7a; --sys-bg: #252f2b; --sys-fg: #a7b4ad; --task: #7c70c9;
  --shadow: 0 1px 1px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

html { height: 100%; box-sizing: border-box; -webkit-text-size-adjust: 100%; }
*, *::before, *::after { box-sizing: inherit; }
#root { height: 100%; }
body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font-family: var(--font-body); font-size: 14px; line-height: 1.55; overflow: hidden; }
button { font: inherit; color: inherit; }
input, textarea { font: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.gut { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }

/* 起動中・ログイン */
.boot { height: 100%; display: grid; place-items: center; color: var(--muted); }
.login { height: 100%; display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.login-card { width: min(100%, 380px); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 24px 20px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.login-card h1 { margin: 0; font-family: var(--font-display); font-size: 22px; }
.login-card p { margin: 0; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field span { font-size: 12px; color: var(--muted); }
.input { width: 100%; border: 1px solid var(--line); background: var(--bg); color: var(--fg); border-radius: 8px; padding: 8px 10px; }
.msg-err { color: var(--danger); font-size: 12.5px; min-height: 1em; overflow-wrap: anywhere; }

/* 全体 */
.app { height: 100%; display: grid; grid-template-columns: minmax(0, 1fr); overflow: hidden; }
.side { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); }
.main { display: flex; min-width: 0; min-height: 0; }
.app[data-view="list"] .main { display: none; }
.app[data-view="chat"] .side, .app[data-view="settings"] .side { display: none; }
@media (min-width: 900px) {
  .app { grid-template-columns: 320px minmax(0, 1fr); }
  .app[data-view] .side { display: flex; border-right: 1px solid var(--line); }
  .app[data-view] .main { display: flex; }
}

/* 一覧 */
.side-head { display: flex; flex-direction: column; gap: 10px; padding-block: 14px 10px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand h1 { margin: 0; font-family: var(--font-display); font-size: 20px; font-weight: 700; letter-spacing: .02em; }
.search { width: 100%; border: 1px solid var(--line); background: var(--bg); color: var(--fg); border-radius: 8px; padding: 7px 10px; }
.side-body { flex: 1; min-height: 0; overflow-y: auto; }
.rooms { list-style: none; margin: 0; padding: 0; }
.room { width: 100%; display: flex; align-items: center; gap: 12px; padding-block: 10px; background: none; border: 0; text-align: left; cursor: pointer; }
.room:hover { background: var(--bg); }
.room.on { background: var(--accent-soft); }
.room .txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.room .top { display: flex; justify-content: space-between; gap: 8px; }
.room .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 4px; min-width: 0; }
.room .nm .cnt { color: var(--muted); font-weight: 400; flex: none; }
.room .tm { color: var(--muted); font-size: 11px; font-family: var(--font-mono); font-variant-numeric: tabular-nums; flex: none; }
.room .bot { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.room .pv { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.badge { flex: none; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--accent-fg); font-size: 11px; font-weight: 700; display: grid; place-items: center; font-variant-numeric: tabular-nums; }
.grp-ic { width: 14px; height: 14px; flex: none; fill: none; stroke: var(--muted); stroke-width: 1.6; }
.empty { padding: 24px 16px; color: var(--muted); font-size: 13px; text-align: center; }

/* 下のタブ (スマホ) と上のタブ (PC) */
.tabs { display: flex; border-top: 1px solid var(--line); background: var(--surface); padding-bottom: env(safe-area-inset-bottom, 0px); }
.tabs button { flex: 1; border: 0; background: none; padding: 8px 4px 9px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); cursor: pointer; }
.tabs button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--accent); font-weight: 700; }

/* アバター */
.av { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--avatar-fg); font-family: var(--font-display); font-weight: 700; font-size: 17px; position: relative; background: var(--muted); overflow: hidden; }
.av.sm { width: 34px; height: 34px; font-size: 14px; }
.av.task { border-radius: 9px; font-family: var(--font-mono); font-size: 12px; letter-spacing: .02em; background: var(--task); }
.av.task.sm { font-size: 11px; }
.av.grp { border-radius: 12px; font-size: 13px; }
.av .dot { position: absolute; right: 1px; bottom: 1px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); }

/* トーク画面 */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--chat-bg); position: relative; }
.chat-head { display: flex; align-items: center; gap: 10px; padding-block: 10px; background: var(--surface); border-bottom: 1px solid var(--line); min-height: 57px; }
.chat-head .t { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-head .t b { font-family: var(--font-display); font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .t span { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .t span.thinking { color: var(--accent); }
.icon-btn { flex: none; width: 36px; height: 36px; border-radius: 8px; border: 0; background: none; cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: var(--bg); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.on { color: var(--accent); }
.back { display: grid; }
@media (min-width: 900px) { .back { display: none; } }
.placeholder { flex: 1; display: grid; place-items: center; color: var(--muted); padding: 24px; text-align: center; }

.msgs { flex: 1; overflow-y: auto; overflow-x: hidden; padding-block: 14px 18px; display: flex; flex-direction: column; gap: 4px; overscroll-behavior: contain; }
.more { align-self: center; font-size: 11.5px; color: var(--muted); padding: 4px 0 8px; }
.date, .sys { display: flex; justify-content: center; margin-block: 8px 4px; }
.date span, .sys span { background: var(--sys-bg); color: var(--sys-fg); border-radius: 12px; padding: 2px 12px; font-size: 11.5px; text-align: center; max-width: 92%; overflow-wrap: anywhere; }
.date span { font-family: var(--font-display); font-weight: 500; }
.row { display: flex; gap: 8px; align-items: flex-start; }
.row.cont { margin-top: -1px; }
.row .gap { width: 34px; flex: none; }
.row.me { justify-content: flex-end; }
.col { display: flex; flex-direction: column; gap: 3px; min-width: 0; max-width: min(80%, 540px); }
.row.me .col { align-items: flex-end; }
.who { font-size: 11.5px; color: var(--muted); display: flex; gap: 6px; align-items: baseline; min-width: 0; }
.who b { color: var(--fg); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who i { font-style: normal; }
.bl { display: flex; align-items: flex-end; gap: 6px; min-width: 0; max-width: 100%; }
.row.me .bl { flex-direction: row-reverse; }
.bub { background: var(--other); color: var(--fg); border-radius: 16px; padding: 7px 12px; box-shadow: var(--shadow); overflow-wrap: anywhere; white-space: pre-wrap; min-width: 0; }
.row:not(.me).first .b1 .bub { border-top-left-radius: 4px; }
.row.me .bub { background: var(--me); color: var(--me-fg); }
.row.me.first .b1 .bub { border-top-right-radius: 4px; }
.bub code { font-family: var(--font-mono); font-size: 12.5px; background: rgba(127, 127, 127, .15); border-radius: 4px; padding: 0 4px; }
.bub a { color: var(--accent); text-underline-offset: 2px; }
.row.me .bub a { color: inherit; }
.bub ul { margin: 2px 0; padding-left: 18px; white-space: normal; }
.bub li { white-space: pre-wrap; }
.meta { flex: none; display: flex; flex-direction: column; align-items: flex-end; font-size: 10px; color: var(--muted); line-height: 1.3; font-variant-numeric: tabular-nums; }
.row:not(.me) .meta { align-items: flex-start; }
.meta .tm { font-family: var(--font-mono); }
.note { font-size: 10.5px; color: var(--muted); }
.grounds { font-size: 10.5px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip { border: 1px solid var(--accent); color: var(--accent); background: var(--surface); border-radius: 16px; padding: 4px 12px; cursor: pointer; font-size: 12.5px; }
.chip:hover { background: var(--accent-soft); }
.chip.rec::before { content: "★ "; }
.chip.picked { background: var(--accent); color: var(--accent-fg); }
.chip:disabled { cursor: default; }
.chip:disabled:not(.picked) { opacity: .45; }
.brief { background: var(--other); border-radius: 14px; box-shadow: var(--shadow); padding: 10px 14px; width: min(100%, 380px); }
.brief summary { cursor: pointer; font-family: var(--font-display); font-weight: 700; list-style: none; display: flex; justify-content: space-between; gap: 8px; }
.brief summary::-webkit-details-marker { display: none; }
.brief summary::after { content: "開く"; font-family: var(--font-body); font-weight: 400; font-size: 12px; color: var(--accent); flex: none; }
.brief[open] summary::after { content: "たたむ"; }
.brief .bub { box-shadow: none; padding: 6px 0 0; background: none; }

/* 入力中 */
.typing { display: inline-flex; gap: 4px; align-items: center; padding: 11px 14px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: bob 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bob { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; opacity: .7; } }

/* 入力欄 */
.composer { display: flex; gap: 8px; align-items: flex-end; padding-block: 10px; padding-bottom: max(10px, env(safe-area-inset-bottom, 0px)); background: var(--surface); border-top: 1px solid var(--line); position: relative; }
.composer textarea { flex: 1; min-width: 0; resize: none; border: 1px solid var(--line); background: var(--bg); color: var(--fg); border-radius: 18px; padding: 8px 14px; line-height: 1.45; max-height: 140px; }
.send { flex: none; height: 36px; padding: 0 16px; border-radius: 18px; border: 0; background: var(--accent); color: var(--accent-fg); font-weight: 700; cursor: pointer; }
.send:disabled { opacity: .5; cursor: default; }
.mention { position: absolute; bottom: calc(100% + 6px); left: max(16px, env(safe-area-inset-left, 0px)); width: min(320px, calc(100% - 32px)); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 6px 20px rgba(0, 0, 0, .15); padding: 6px; display: flex; flex-direction: column; gap: 2px; z-index: 5; }
.mention .hd { font-size: 11px; color: var(--muted); padding: 2px 8px; }
.mention button { display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 6px 8px; border-radius: 8px; text-align: left; cursor: pointer; min-width: 0; }
.mention button:hover, .mention button.hl { background: var(--accent-soft); }
.mention button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.mention button small { color: var(--muted); flex: none; }

/* メンバーと現状 (右の欄。PC だけ) */
.info { display: none; width: 300px; flex: none; flex-direction: column; background: var(--surface); border-left: 1px solid var(--line); min-height: 0; overflow-y: auto; }
@media (min-width: 900px) { .app.info-open .info { display: flex; } }
.info section { padding-block: 14px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--line); }
.info h2 { margin: 0; font-size: 11px; letter-spacing: .1em; color: var(--muted); font-weight: 700; }
.info p { margin: 0; font-size: 12.5px; overflow-wrap: anywhere; color: var(--muted); }
.mem { display: flex; align-items: center; gap: 10px; min-width: 0; width: 100%; border: 0; background: none; text-align: left; padding: 6px 0; cursor: default; }
button.mem { cursor: pointer; }
.mem .nm { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mem .nm b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mem .nm small { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mem .nm small.thinking { color: var(--accent); }
.mem-head { font-size: 11px; letter-spacing: .1em; color: var(--muted); font-weight: 700; padding-top: 14px; }

/* 設定 */
.settings { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.settings-body { flex: 1; overflow-y: auto; padding-block: 16px 32px; display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; width: min(100%, 640px); }
.card h2 { margin: 0; font-family: var(--font-display); font-size: 15px; }
.card p { margin: 0; font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.form-row .input { flex: 1; min-width: 160px; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 13px; }
.btn.pri { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 700; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.pill { display: inline-flex; align-items: center; border-radius: 10px; padding: 0 8px; font-size: 11px; font-weight: 700; background: var(--accent-soft); color: var(--accent); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.off { background: var(--bg); color: var(--muted); }
.meter { height: 8px; border-radius: 4px; background: var(--bg); overflow: hidden; border: 1px solid var(--line); }
.meter i { display: block; height: 100%; background: var(--accent); }
.meter.warn i { background: var(--warn); }
.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); min-width: 0; flex-wrap: wrap; }
.list-row:first-child { border-top: 0; }
.list-row .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.list-row .grow b { font-weight: 500; overflow-wrap: anywhere; }
.list-row .grow small { color: var(--muted); font-size: 11.5px; }

/* 知らせ */
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 8px 14px; border-radius: 10px; font-size: 13px; max-width: calc(100% - 32px); z-index: 20; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); overflow-wrap: anywhere; }
.conn { position: fixed; top: 8px; left: 50%; transform: translateX(-50%); background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); padding: 2px 12px; border-radius: 12px; font-size: 12px; z-index: 20; }
