/* 完全対応コンソール — 軽量・依存ゼロの CSS */

:root {
  --bg:        #0f1115;
  --bg-2:      #161a21;
  --bg-3:      #1d222b;
  --line:      #262c37;
  --fg:        #e6e9ef;
  --fg-dim:    #98a1b0;
  --fg-faint:  #6b7482;
  --accent:    #4c8dff;
  --in-bg:     #1d222b;
  --out-bg:    #2a4a7a;
  --danger:    #ef5350;
  --ok:        #3ddc84;
  --radius:    10px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:       #f5f6f8;
    --bg-2:     #ffffff;
    --bg-3:     #eef0f4;
    --line:     #dde1e8;
    --fg:       #1b1f27;
    --fg-dim:   #5c6673;
    --fg-faint: #8b95a3;
    --in-bg:    #eef0f4;
    --out-bg:   #d6e4ff;
  }
}

* { box-sizing: border-box; }

/*
 * hidden 属性を常に効かせる。
 * ブラウザ既定の [hidden]{display:none} は詳細度がゼロなので、
 * .thread-inner{display:flex} や .more{display:block} のような
 * 後続のクラス指定に負けて、隠したはずの要素が出っぱなしになる。
 * JS 側は el.hidden で表示を切り替えているため、ここは必須。
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

/* ---------- レイアウト ---------- */

.app {
  display: grid;
  grid-template-rows: auto auto 1fr;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 700;
  letter-spacing: .02em;
  white-space: nowrap;
}

.search-wrap { flex: 1; min-width: 80px; }

.search-wrap input {
  width: 100%;
  padding: 7px 12px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  outline: none;
}
.search-wrap input:focus { border-color: var(--accent); }

.seg {
  display: flex;
  background: var(--bg-3);
  border-radius: 999px;
  padding: 2px;
}
.seg button {
  border: 0;
  background: transparent;
  color: var(--fg-dim);
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  font-size: 13px;
}
.seg button.on { background: var(--accent); color: #fff; }

.icon-btn {
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--fg-dim);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  text-decoration: none;
  flex: none;
}
.icon-btn:hover { color: var(--fg); }

.accountbar {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  overflow-x: auto;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--fg-dim);
  cursor: pointer;
  white-space: nowrap;
  font-size: 13px;
}
.chip.on { color: var(--fg); border-color: currentColor; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.chip .badge {
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  text-align: center;
}

.panes {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  min-height: 0;
}

.pane-list {
  border-right: 1px solid var(--line);
  overflow-y: auto;
  min-height: 0;
  background: var(--bg);
}

.pane-thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}

/* ---------- スレッド一覧 ---------- */

.threads { list-style: none; margin: 0; padding: 0; }

.threads li {
  display: grid;
  grid-template-columns: 4px 1fr auto;
  gap: 10px;
  padding: 11px 14px 11px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.threads li:hover { background: var(--bg-2); }
.threads li.on { background: var(--bg-3); }
/* 実際の色は app.js が style 属性でアカウント色を直接入れる。ここは保険。 */
.threads li .bar { background: #888; border-radius: 0 3px 3px 0; }
.threads li.unread .name { font-weight: 700; }

.t-main { min-width: 0; }
.t-top { display: flex; align-items: baseline; gap: 8px; }
.name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-acc { font-size: 11px; color: var(--fg-faint); white-space: nowrap; }
.t-snip {
  color: var(--fg-dim);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.t-snip .out-mark { color: var(--fg-faint); }
.t-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  padding-right: 2px;
}
.t-time { font-size: 11px; color: var(--fg-faint); white-space: nowrap; }
.t-badge {
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  padding: 0 6px;
  min-width: 18px;
  text-align: center;
}
.pin { color: #f2b23b; font-size: 12px; }

.empty, .thread-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--fg-faint);
}
.thread-empty { margin: auto; }

.more {
  display: block;
  width: calc(100% - 24px);
  margin: 12px;
  padding: 10px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--fg-dim);
  cursor: pointer;
}

/* ---------- スレッド詳細 ---------- */

.thread-inner {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.thread-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.thread-head .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.thread-head-main { min-width: 0; flex: 1; }
.thread-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-sub { font-size: 12px; color: var(--fg-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-actions { display: flex; gap: 6px; flex: none; }

.btn {
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--fg);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.ghost { background: transparent; color: var(--fg-dim); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:disabled { opacity: .5; cursor: default; }
.btn.on { color: #f2b23b; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg { max-width: min(760px, 88%); }
.msg.out { align-self: flex-end; }
.msg.in  { align-self: flex-start; }

.msg-meta {
  font-size: 11px;
  color: var(--fg-faint);
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.msg.out .msg-meta { justify-content: flex-end; }

.bubble {
  position: relative;
  background: var(--in-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.out .bubble { background: var(--out-bg); }
.msg.system .bubble {
  background: transparent;
  border-style: dashed;
  color: var(--fg-faint);
  font-size: 13px;
}
.msg.failed .bubble { border-color: var(--danger); }

.msg-subject {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.copy-btn {
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--fg-dim);
  border-radius: 6px;
  padding: 1px 8px;
  font-size: 11px;
  cursor: pointer;
  flex: none;
}
.copy-btn:hover { color: var(--fg); border-color: var(--accent); }
.copy-btn.done { color: var(--ok); border-color: var(--ok); }

.atts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.atts a {
  color: var(--accent);
  font-size: 12px;
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 8px;
}
.atts img {
  max-width: 220px;
  max-height: 220px;
  border-radius: 8px;
  display: block;
}

.msg-error { color: var(--danger); font-size: 12px; margin-top: 4px; }

.html-toggle {
  margin-top: 8px;
  font-size: 12px;
  color: var(--fg-dim);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}
.html-frame {
  width: 100%;
  height: 380px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 8px;
  background: #fff;
}

/* ---------- 返信欄 ---------- */

.composer {
  border-top: 1px solid var(--line);
  background: var(--bg-2);
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
.composer-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.composer-tools select,
.composer-tools input[type=text] {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 13px;
}
.composer-tools input[type=text] { flex: 1; min-width: 160px; }
.composer-hint { font-size: 12px; color: var(--fg-faint); }

.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer-row textarea {
  flex: 1;
  resize: vertical;
  min-height: 44px;
  max-height: 40vh;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  outline: none;
}
.composer-row textarea:focus { border-color: var(--accent); }
.composer-msg { font-size: 12px; margin-top: 6px; min-height: 16px; }
.composer-msg.err { color: var(--danger); }
.composer-msg.ok  { color: var(--ok); }

/* ---------- トースト ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #000c;
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 50;
  backdrop-filter: blur(4px);
}

/* ---------- ログイン ---------- */

.login-body { display: grid; place-items: center; }
.login-card {
  width: min(360px, 92vw);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 24px;
  display: grid;
  gap: 14px;
}
.login-card h1 { margin: 0 0 4px; font-size: 18px; }
.login-card label { display: grid; gap: 5px; font-size: 13px; color: var(--fg-dim); }
.login-card input {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 11px;
  font-weight: 700;
  cursor: pointer;
}
.login-error { color: var(--danger); font-size: 13px; margin: 0; }
.login-note { color: var(--fg-faint); font-size: 12px; margin: 0; }

/* ---------- モバイル ---------- */

.only-mobile { display: none; }

@media (max-width: 820px) {
  .panes { grid-template-columns: 1fr; }
  .pane-thread { display: none; }
  body.thread-open .pane-list { display: none; }
  body.thread-open .pane-thread { display: flex; }
  body.thread-open .only-mobile { display: inline-grid; }
  body.thread-open .accountbar { display: none; }
  .brand { display: none; }
  .seg button { padding: 5px 9px; font-size: 12px; }
  .msg { max-width: 92%; }
  .thread-actions .btn { padding: 6px 9px; }
}

@media (max-width: 480px) {
  .seg button[data-status="all"] { display: none; }
}
