:root {
  --bg: #f6f7f5; --panel: #fff; --line: #e3e6e1; --text: #1d2420; --muted: #66706a;
  --accent: #1f6f5c; --accent-weak: #e4f1ec; --err: #b3261e;
  --line-c: #06c755; --ig-c: #c13584;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  color: var(--text); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; line-break: strict; overflow-wrap: anywhere; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; border-radius: 8px; background: var(--accent); color: #fff; padding: 10px 16px; }
button.ghost { background: transparent; color: var(--accent); padding: 8px 10px; }
.err { color: var(--err); min-height: 1.2em; margin: 4px 12px; font-size: 14px; }
[hidden] { display: none !important; }

.login-box { max-width: 360px; margin: 12vh auto 0; padding: 28px 24px; background: var(--panel); border-radius: 14px; border: 1px solid var(--line); }
.login-box h1 { margin: 0 0 4px; font-size: 22px; }
.login-box p { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.login-box label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.login-box input { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 8px; letter-spacing: .08em; margin-bottom: 14px; font-size: 16px; }
.login-box button { width: 100%; }

#app { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; height: 100dvh; }
.pane { display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
#listPane { border-right: 1px solid var(--line); }
.bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); min-height: 56px; }
.bar h1 { font-size: 17px; margin: 0; flex: 1; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; background: none; color: var(--muted); border-radius: 0; padding: 10px 4px; border-bottom: 2px solid transparent; }
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.badge:not(:empty) { display: inline-block; min-width: 1.5em; padding: 0 6px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 12px; }
.filters { display: flex; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.filters select, .filters input { padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; min-width: 0; font-size: 16px; }
.filters input { flex: 1; }

.threads { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.threads li { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; padding: 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.threads li[aria-current="true"] { background: var(--accent-weak); }
.threads .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.threads .time { color: var(--muted); font-size: 12px; }
.threads .prev { grid-column: 2 / 4; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.threads li.unread .name::after { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-left: 6px; vertical-align: middle; }
.chip { grid-row: 1 / 3; align-self: center; font-size: 11px; font-weight: 700; color: #fff; border-radius: 6px; padding: 4px 6px; }
.chip.line { background: var(--line-c); }
.chip.instagram { background: var(--ig-c); }
.empty, .nothing { color: var(--muted); text-align: center; padding: 40px 16px; }

#threadPane { position: relative; }
.who { flex: 1; min-width: 0; }
.who strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { color: var(--muted); font-size: 12px; }
.back { display: none; font-size: 26px; line-height: 1; }
.msgs { flex: 1; overflow-y: auto; padding: 16px 12px; display: flex; flex-direction: column; gap: 8px; background: var(--bg); }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; }
.msg.in { align-self: flex-start; background: #fff; border: 1px solid var(--line); }
.msg.out { align-self: flex-end; background: var(--accent); color: #fff; }
.msg .meta { display: block; font-size: 11px; opacity: .7; margin-top: 4px; }
.note { margin: 0; padding: 8px 12px; background: #fff4e5; color: #7a4b00; font-size: 13px; }
.composer { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; padding: 10px; border: 1px solid var(--line); border-radius: 10px; font-size: 16px; }
.composer button:disabled { opacity: .5; cursor: default; }
.nothing { position: absolute; inset: 0; background: var(--panel); display: flex; align-items: center; justify-content: center; }
#threadPane.open .nothing { display: none; }

/* スマホ: 一覧とスレッドを切り替える */
@media (max-width: 720px) {
  #app { grid-template-columns: 1fr; }
  #threadPane { display: none; }
  #app.reading #listPane { display: none; }
  #app.reading #threadPane { display: flex; }
  .back { display: block; }
  .composer { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
}
