/* まとめ受信箱 — 地色と文字色は必ず対でトークン化（明・暗とも） */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --surface-hover: #e6eaee;
  --text: #1b1f24;
  --text-2: #56606b;
  --border: #d6dbe1;
  --accent: #0b7a5c;
  --accent-text: #ffffff;
  --accent-soft: #dcf1e8;
  --accent-soft-text: #0c3b2c;
  --link: #0b6b52;
  --open-bg: #fde6e1;
  --open-text: #9b2414;
  --done-bg: #e2f1e8;
  --done-text: #165c39;
  --danger: #b42318;
  --danger-text: #ffffff;
  --error-bg: #fdecea;
  --error-text: #8a1c11;
  --focus: #1f6feb;
  --unread-bg: #0b7a5c;
  --unread-text: #ffffff;
  --shadow: 0 8px 30px rgba(15, 23, 42, .18);
  --ch-line_oa: #06c755;
  --ch-chatwork: #e8380d;
  --ch-demo: #8a63d2;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1114;
    --surface: #161a1f;
    --surface-2: #20262d;
    --surface-hover: #283039;
    --text: #e8ebee;
    --text-2: #a6b0ba;
    --border: #2e3640;
    --accent: #3cc497;
    --accent-text: #05231a;
    --accent-soft: #163a2e;
    --accent-soft-text: #d9f5ea;
    --link: #6fdcb5;
    --open-bg: #4b1f18;
    --open-text: #ffc2b8;
    --done-bg: #183829;
    --done-text: #a5e6c3;
    --danger: #f97066;
    --danger-text: #2a0703;
    --error-bg: #3d1712;
    --error-text: #ffc9c2;
    --focus: #6ea8fe;
    --unread-bg: #3cc497;
    --unread-text: #05231a;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1114;
  --surface: #161a1f;
  --surface-2: #20262d;
  --surface-hover: #283039;
  --text: #e8ebee;
  --text-2: #a6b0ba;
  --border: #2e3640;
  --accent: #3cc497;
  --accent-text: #05231a;
  --accent-soft: #163a2e;
  --accent-soft-text: #d9f5ea;
  --link: #6fdcb5;
  --open-bg: #4b1f18;
  --open-text: #ffc2b8;
  --done-bg: #183829;
  --done-text: #a5e6c3;
  --danger: #f97066;
  --danger-text: #2a0703;
  --error-bg: #3d1712;
  --error-text: #ffc9c2;
  --focus: #6ea8fe;
  --unread-bg: #3cc497;
  --unread-text: #05231a;
  --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--link); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 7px 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-hover); }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: var(--danger-text); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn {
  border: 0; background: transparent; color: var(--text); padding: 6px 10px; border-radius: 8px; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-hover); }

/* ---------- 上部バー ---------- */
.topbar {
  height: 52px; display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: var(--surface); color: var(--text); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; }
.ws-name { color: var(--text-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .spacer { flex: 1; }

/* ---------- 3段組み ---------- */
.app {
  display: grid; grid-template-columns: 220px 340px minmax(0, 1fr);
  height: calc(100dvh - 52px);
}
.sidebar {
  background: var(--surface); color: var(--text); border-right: 1px solid var(--border);
  padding: 12px 8px; overflow-y: auto;
}
.side-title { font-size: 12px; color: var(--text-2); margin: 16px 10px 6px; font-weight: 600; }
.side-item {
  width: 100%; display: flex; align-items: center; gap: 8px; text-align: left;
  border: 0; background: transparent; color: var(--text); padding: 8px 10px; border-radius: 8px; cursor: pointer;
}
.side-item:hover { background: var(--surface-hover); }
.side-item.active { background: var(--accent-soft); color: var(--accent-soft-text); font-weight: 600; }
.side-item .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item .count { font-size: 12px; color: inherit; opacity: .9; }
.side-item .warn { color: var(--danger); font-size: 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--text-2); }
.dot[data-ch="line_oa"] { background: var(--ch-line_oa); }
.dot[data-ch="chatwork"] { background: var(--ch-chatwork); }
.dot[data-ch="demo"] { background: var(--ch-demo); }
.side-add { margin: 12px 10px 0; width: calc(100% - 20px); }

/* ---------- 会話一覧 ---------- */
.list-pane {
  background: var(--surface); color: var(--text); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.list-head { padding: 10px 12px; border-bottom: 1px solid var(--border); display: grid; gap: 8px; }
.search {
  width: 100%; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 8px; padding: 8px 10px;
}
.search::placeholder { color: var(--text-2); }
.chips { display: none; gap: 6px; overflow-x: auto; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 4px 12px; font-size: 13px; white-space: nowrap; cursor: pointer;
}
.chip.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv {
  display: flex; gap: 10px; padding: 11px 12px; border-bottom: 1px solid var(--border);
  cursor: pointer; background: var(--surface); color: var(--text);
}
.conv:hover { background: var(--surface-hover); }
.conv.active { background: var(--accent-soft); color: var(--accent-soft-text); }
.conv .body { flex: 1; min-width: 0; }
.conv .row1 { display: flex; align-items: baseline; gap: 6px; }
.conv .title { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .time { font-size: 12px; color: var(--text-2); flex: none; }
.conv.active .time, .conv.active .preview, .conv.active .ch { color: var(--accent-soft-text); }
.conv .row2 { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.conv .preview { flex: 1; min-width: 0; color: var(--text-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .ch { font-size: 11px; color: var(--text-2); display: flex; align-items: center; gap: 4px; margin-top: 3px; }
.unread {
  background: var(--unread-bg); color: var(--unread-text); border-radius: 999px;
  font-size: 11px; font-weight: 700; min-width: 20px; padding: 1px 6px; text-align: center;
}
.empty { color: var(--text-2); text-align: center; padding: 40px 20px; font-size: 14px; }

.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none; overflow: hidden;
  background: var(--surface-2); color: var(--text); display: grid; place-items: center;
  font-weight: 700; position: relative;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- 会話画面 ---------- */
.thread-pane { display: flex; flex-direction: column; min-height: 0; background: var(--bg); color: var(--text); }
.thread-empty { margin: auto; color: var(--text-2); text-align: center; padding: 20px; }
.thread-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--surface); color: var(--text); border-bottom: 1px solid var(--border);
}
.thread-head .info { flex: 1; min-width: 0; }
.thread-head .title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-head .sub { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 5px; }
.back { display: none; }
.badge { font-size: 12px; border-radius: 999px; padding: 2px 10px; font-weight: 600; white-space: nowrap; }
.badge-open { background: var(--open-bg); color: var(--open-text); }
.badge-done { background: var(--done-bg); color: var(--done-text); }

.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.day { align-self: center; font-size: 12px; color: var(--text-2); background: var(--surface-2); padding: 2px 12px; border-radius: 999px; margin: 6px 0; }
.msg { max-width: min(78%, 560px); display: flex; flex-direction: column; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg .who { font-size: 12px; color: var(--text-2); margin: 0 4px 2px; }
.bubble {
  padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; word-break: break-word;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
.msg.out .bubble { background: var(--accent-soft); color: var(--accent-soft-text); border-color: transparent; }
.msg .at { font-size: 11px; color: var(--text-2); margin: 2px 4px 0; }

.composer {
  display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px;
  background: var(--surface); color: var(--text); border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1; resize: none; min-height: 42px; max-height: 180px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--text);
}
.composer textarea::placeholder { color: var(--text-2); }
.composer .hint { font-size: 11px; color: var(--text-2); }
.composer-wrap { display: flex; flex-direction: column; gap: 4px; flex: 1; }

/* ---------- 設定ダイアログ ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(680px, calc(100vw - 24px));
  max-height: calc(100dvh - 40px); background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dlg-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.dlg-head h2 { margin: 0; font-size: 17px; flex: 1; }
.dlg-body { padding: 16px 18px 22px; overflow-y: auto; max-height: calc(100dvh - 110px); }
.dlg-body h3 { font-size: 14px; margin: 18px 0 8px; }
.conn-card {
  border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px;
  background: var(--surface); color: var(--text);
}
.conn-card .top { display: flex; align-items: center; gap: 8px; }
.conn-card .name { font-weight: 700; flex: 1; min-width: 0; }
.conn-card .meta { font-size: 13px; color: var(--text-2); margin-top: 4px; }
.conn-card .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.err { background: var(--error-bg); color: var(--error-text); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-top: 8px; }
.copy-row { display: flex; gap: 6px; margin-top: 8px; }
.copy-row input {
  flex: 1; min-width: 0; font-size: 12px; border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 8px; background: var(--surface-2); color: var(--text);
}
.kind-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.kind-card {
  text-align: left; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  background: var(--surface); color: var(--text); cursor: pointer;
}
.kind-card:hover { background: var(--surface-hover); }
.kind-card.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-soft-text); }
.kind-card .k-title { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.kind-card .k-desc { font-size: 12px; margin-top: 3px; color: inherit; opacity: .92; }
.form { display: grid; gap: 12px; margin-top: 14px; }
.form label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; }
.form input {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--surface-2); color: var(--text);
  font-weight: 400;
}
.form input::placeholder, .copy-row input::placeholder { color: var(--text-2); opacity: 1; }
.form .help { font-weight: 400; font-size: 12px; color: var(--text-2); }
.steps { margin: 8px 0 0; padding-left: 20px; font-size: 13px; color: var(--text); }
.steps li { margin-bottom: 4px; }
.coming { font-size: 13px; color: var(--text-2); margin-top: 8px; }

/* ---------- お知らせ ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; box-shadow: var(--shadow); max-width: calc(100vw - 32px); z-index: 50;
}
.toast.error { background: var(--error-bg); color: var(--error-text); border: 1px solid var(--danger); }

/* ---------- ログイン ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: var(--bg); color: var(--text); }
.login-card {
  width: min(380px, 100%); background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 14px; padding: 26px 22px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p { margin: 0 0 18px; color: var(--text-2); font-size: 13px; }
.login-card .btn-primary { width: 100%; padding: 10px; margin-top: 4px; }

/* ---------- スマホ ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .chips { display: flex; }
  .list-pane { border-right: 0; }
  .thread-pane { display: none; }
  body.show-thread .list-pane { display: none; }
  body.show-thread .thread-pane { display: flex; }
  .back { display: inline-flex; }
  .msg { max-width: 86%; }
  .composer .hint { display: none; }
  .topbar { padding: 0 10px; gap: 6px; }
  .ws-name { display: none; }
  .thread-head { padding: 8px 10px; gap: 8px; }
  .thread-head .badge { display: none; }
  .thread-head .avatar { width: 34px; height: 34px; }
  .thread-head .sub span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
.brand, .topbar .btn, .topbar .icon-btn, .thread-head .btn { white-space: nowrap; flex: none; }
