/* ===== 基本 ===== */
:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1d1f23;
  --muted: #6b7280;
  --line: #e3e5e8;
  --primary: #1f5fbf;
  --primary-ink: #ffffff;
  --mine: #1f5fbf;
  --mine-ink: #ffffff;
  --theirs: #ffffff;
  --danger: #c0392b;
  --unread: #e0e9f8;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1 { font-size: 1.35rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 1.75rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
code { background: #eef0f3; padding: 0 .3em; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }

/* ===== 部品 ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .25rem; min-height: 40px; padding: .45rem 1rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: #fff; color: var(--text); font: inherit; font-size: .95rem;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f0f2f5; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: #194f9f; }
.btn-danger { color: var(--danger); border-color: #efc7c2; }
.btn-ghost { border-color: transparent; background: transparent; }

label { display: block; font-size: .9rem; font-weight: 600; margin: 1rem 0 .3rem; }
label.inline { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
input:not([type=checkbox]), textarea, select {
  width: 100%; padding: .65rem .8rem; font: inherit;
  border: 1px solid #cfd3d9; border-radius: 10px; background: #fff; color: var(--text);
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus, .btn:focus-visible { outline: 2px solid #8fb3ec; outline-offset: 1px; }
.stack label input, .stack label textarea { margin-top: .3rem; font-weight: 400; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }

.note { color: var(--muted); font-size: .85rem; }
.error { color: var(--danger); font-size: .9rem; }
.ok { color: #1e7d3c; font-size: .9rem; }

/* ===== 入口ページ ===== */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.04);
}
.start { max-width: 560px; margin: 2rem auto; padding: 1.75rem 1.5rem; }
.start .btn-primary { width: 100%; margin-top: 1rem; min-height: 48px; font-size: 1rem; }
.welcome { color: #3a3f47; margin-bottom: 1rem; }
.resume { background: #eef4fd; border-radius: 10px; padding: .75rem 1rem; margin: 1rem 0; }
.resume p { margin: 0 0 .5rem; }
.resume .btn-primary { margin-top: 0; }
.cf-turnstile { margin-top: 1rem; }
@media (max-width: 600px) {
  .start { margin: 0; border-radius: 0; min-height: 100%; box-shadow: none; }
}

/* ===== トーク画面（相談者・管理者共通） ===== */
.page-chat { overflow: hidden; }
.chat-app {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  max-width: 760px; margin: 0 auto; background: var(--bg);
}
.chat-header {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .6rem .9rem; background: #fff; border-bottom: 1px solid var(--line);
}
.chat-header > div:first-of-type { flex: 1; min-width: 0; }
.chat-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-sub { color: var(--muted); font-size: .8rem; }
.chat-actions { display: flex; gap: .4rem; }
.menu { background: #fff; border-bottom: 1px solid var(--line); padding: .9rem 1rem; font-size: .9rem; }
.menu p { margin: 0 0 .75rem; }
.notice { background: #fff8e1; color: #6b5500; font-size: .85rem; padding: .6rem 1rem; border-bottom: 1px solid #f1e3b0; }

.messages { flex: 1; overflow-y: auto; padding: 1rem .9rem; -webkit-overflow-scrolling: touch; }
.day { text-align: center; color: var(--muted); font-size: .75rem; margin: .75rem 0; }
.msg { display: flex; flex-direction: column; margin: .35rem 0; max-width: 82%; }
.msg.mine { margin-left: auto; align-items: flex-end; }
.msg.theirs { margin-right: auto; align-items: flex-start; }
.bubble {
  padding: .55rem .85rem; border-radius: 18px;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
}
.mine .bubble { background: var(--mine); color: var(--mine-ink); border-bottom-right-radius: 6px; }
.theirs .bubble { background: var(--theirs); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.time { color: var(--muted); font-size: .7rem; margin-top: .15rem; }

.composer {
  display: flex; gap: .5rem; align-items: flex-end;
  padding: .6rem .75rem calc(.6rem + env(safe-area-inset-bottom));
  background: #fff; border-top: 1px solid var(--line);
}
.composer textarea { resize: none; max-height: 160px; border-radius: 20px; }
.composer .btn { min-height: 44px; }

/* ===== 管理画面 ===== */
.page-admin { overflow: hidden; }
.admin-app { display: flex; height: 100vh; height: 100dvh; }
.sidebar {
  width: 320px; flex-shrink: 0; display: flex; flex-direction: column;
  background: #fff; border-right: 1px solid var(--line);
}
.sidebar-head { padding: .8rem .9rem; border-bottom: 1px solid var(--line); }
.sidebar-tools { display: flex; gap: .4rem; margin-top: .5rem; }
.sidebar-tools select { padding: .35rem .5rem; font-size: .85rem; }
.conv-list { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; }
.conv-empty { padding: 1.5rem 1rem; color: var(--muted); font-size: .9rem; }
.conv { border-bottom: 1px solid #f0f1f3; }
.conv-btn {
  position: relative; display: block; width: 100%; text-align: left;
  padding: .7rem 2.4rem .7rem .9rem; border: 0; background: transparent; font: inherit; cursor: pointer; color: inherit;
}
.conv-btn:hover { background: #f6f7f9; }
.conv.active .conv-btn { background: #eaf1fc; }
.conv.unread .conv-name { font-weight: 700; }
.conv-top { display: flex; justify-content: space-between; gap: .5rem; }
.conv-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { color: var(--muted); font-size: .75rem; flex-shrink: 0; }
.conv-channel { color: var(--primary); font-size: .72rem; }
.conv-preview { color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  position: absolute; right: .8rem; top: 50%; transform: translateY(-50%);
  min-width: 1.4rem; height: 1.4rem; padding: 0 .35rem; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: .75rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.sidebar-foot { display: flex; justify-content: space-between; padding: .4rem; border-top: 1px solid var(--line); }

.pane { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pane-empty { margin: auto; color: var(--muted); }
.admin-chat { max-width: none; width: 100%; margin: 0; }
.back { display: none; font-size: 1.5rem; padding: 0 .5rem; }

.settings { display: flex; flex-direction: column; height: 100%; }
.settings-body { flex: 1; overflow-y: auto; padding: .5rem 1.25rem 2rem; max-width: 720px; }
.channel-row {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  padding: .7rem 0; border-bottom: 1px solid var(--line);
}
.channel-info { flex: 1; min-width: 200px; }
.channel-url { color: var(--muted); font-size: .8rem; overflow-wrap: anywhere; }

@media (max-width: 760px) {
  .sidebar { width: 100%; border-right: 0; }
  .pane { display: none; }
  .show-pane .sidebar { display: none; }
  .show-pane .pane { display: flex; }
  .back { display: inline-flex; }
  .chat-actions .btn { padding: .4rem .7rem; font-size: .85rem; }
}
