:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --side: #14181f;
  --side-text: #c9d1dc;
  --text: #1c2330;
  --muted: #6b7686;
  --line: #e3e7ed;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --mine: #e8f0fe;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --panel: #171b23;
    --side: #0a0c10;
    --side-text: #aab4c3;
    --text: #e6eaf0;
    --muted: #8793a5;
    --line: #262c37;
    --accent: #4f8cff;
    --accent-text: #08101f;
    --danger: #ff6b5b;
    --mine: #1d2a44;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; margin: 0; }

button {
  font: inherit; cursor: pointer; border: 0; border-radius: 8px;
  padding: 8px 16px; background: var(--accent); color: var(--accent-text);
}
button:disabled { opacity: .5; cursor: default; }
button.icon { background: transparent; color: inherit; padding: 4px 8px; font-size: 18px; }
button.link { background: transparent; color: var(--side-text); padding: 2px 6px; font-size: 13px; text-decoration: underline; }
input[type=text], input[type=password] {
  font: inherit; width: 100%; padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ログイン */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px; display: grid; gap: 14px;
}
.card h1 { margin: 0; font-size: 22px; }
.card p { margin: 0; }

/* レイアウト */
.app { height: 100%; display: grid; grid-template-columns: 240px 1fr; }
.sidebar { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; padding: 14px 10px; min-height: 0; }
.brand { font-weight: 700; color: #fff; padding: 4px 8px 14px; font-size: 17px; }
.section-title { display: flex; justify-content: space-between; align-items: center; font-size: 12px; letter-spacing: .06em; padding: 4px 8px; color: var(--muted); }
.channels { list-style: none; margin: 0; padding: 0; overflow: auto; }
.channels li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 10px; border-radius: 8px; cursor: pointer;
}
.channels li:hover { background: rgba(255,255,255,.06); }
.channels li.active { background: var(--accent); color: var(--accent-text); }
.channels li .dot { width: 8px; height: 8px; border-radius: 50%; background: #fff; }
.spacer { flex: 1; }
.me { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; padding: 8px; border-top: 1px solid rgba(255,255,255,.08); }
.me #me-name { font-weight: 600; margin-right: auto; color: #fff; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: baseline; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.topbar h2 { margin: 0; font-size: 17px; }
.conn { font-size: 12px; color: var(--muted); }
.conn.ok { color: #1a9d55; }
.conn.ng { color: var(--danger); }

.messages { flex: 1; overflow: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 760px; }
.msg .meta { font-size: 12px; color: var(--muted); }
.msg .meta b { color: var(--text); margin-right: 6px; }
.msg .body { white-space: pre-wrap; word-break: break-word; }
.msg.mine .body { background: var(--mine); border-radius: 10px; padding: 6px 10px; display: inline-block; }
.file {
  display: inline-flex; align-items: center; gap: 10px; border: 1px solid var(--line);
  background: var(--panel); border-radius: 10px; padding: 8px 12px; margin-top: 2px;
}
.file a { color: var(--accent); text-decoration: none; font-weight: 600; word-break: break-all; }
.file a:hover { text-decoration: underline; }
.file .size { color: var(--muted); font-size: 12px; }
.file button.del { background: transparent; color: var(--danger); padding: 2px 6px; font-size: 12px; }
.file.gone { color: var(--muted); text-decoration: line-through; }
.more { align-self: center; background: transparent; color: var(--accent); }

.composer { display: flex; gap: 8px; align-items: center; padding: 12px 20px; border-top: 1px solid var(--line); background: var(--panel); }
.status { min-height: 22px; padding: 0 20px 8px; font-size: 12px; color: var(--muted); background: var(--panel); }

/* ダイアログ */
dialog { width: min(640px, calc(100% - 24px)); border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h3 { margin: 4px 0 10px; }
.row { display: flex; gap: 8px; margin-bottom: 10px; }
.row.end { justify-content: flex-end; margin-top: 12px; }
.notice { background: var(--mine); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; word-break: break-all; font-size: 13px; }
.notice code { display: block; margin-top: 4px; font-size: 13px; user-select: all; }
.list { list-style: none; padding: 0; margin: 0 0 14px; }
.list li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.list li.revoked span { color: var(--muted); text-decoration: line-through; }
.check { display: block; font-size: 13px; color: var(--muted); margin: -4px 0 10px; }
.list li .badge { font-size: 11px; background: var(--accent); color: var(--accent-text); border-radius: 6px; padding: 1px 6px; margin-right: 6px; }
.list li { gap: 10px; flex-wrap: wrap; }
.list .actions { display: flex; gap: 4px; flex-wrap: wrap; }
.list button { background: transparent; color: var(--danger); padding: 2px 8px; font-size: 13px; }
.list button.neutral { color: var(--accent); }
.audit { max-height: 220px; overflow: auto; font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.audit div { padding: 2px 0; border-bottom: 1px dashed var(--line); }

/* スマホ */
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { flex-direction: row; align-items: center; padding: 8px; gap: 8px; overflow-x: auto; }
  .brand, .section-title, .spacer { display: none; }
  .channels { display: flex; gap: 4px; }
  .channels li { white-space: nowrap; }
  .me { border: 0; padding: 0; flex-wrap: nowrap; }
  .messages, .composer, .topbar { padding-left: 12px; padding-right: 12px; }
}
