:root {
  --bg: #F4F5F3;
  --panel: #FFFFFF;
  --ink: #1B1F1D;
  --ink2: #3A423E;
  --muted: #5A635E;
  --line: #DDE1DE;
  --line2: #EBEDEB;
  --accent: #1E5A45;
  --accent-dark: #143D2F;
  --accent-soft: #E6EFEB;
  --side: #1E3A30;
  --side-ink: #E8EFEB;
  --side-muted: #A9BDB3;
  --side-on: #2E5446;
  --warn: #9A4A00;
  --warn-soft: #FFF7EC;
  --badge: #F2C48D;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: 'Noto Sans JP', sans-serif; font-size: 15px; }
a { color: var(--accent); }
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: 8px; border: 1px solid #C5CBC7; background: #fff; text-decoration: none; color: var(--ink); cursor: pointer; font-size: 14px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 40px; padding: 0; font-size: 20px; flex: none; }
.btn.wide { width: 100%; height: 44px; }
.btn.danger { color: #A12B2B; }
.link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; }

/* ログイン */
#login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 32px; width: 100%; max-width: 420px; text-align: center; }
.login-card h1 { font-size: 22px; margin: 12px 0 8px; }
.login-card p { line-height: 1.7; color: var(--ink2); font-size: 14px; }
.dev-list { display: flex; flex-direction: column; gap: 8px; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--side-ink); color: var(--side); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.brand-mark.big { width: 56px; height: 56px; font-size: 26px; background: var(--side); color: var(--side-ink); border-radius: 14px; }

/* 全体の並び */
#app { height: 100%; display: grid; grid-template-columns: 264px minmax(0, 1fr) 320px; }
@media (max-width: 1180px) { #app { grid-template-columns: 240px minmax(0, 1fr); } #right { display: none; } }

/* 左 */
#side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; gap: 12px; padding: 16px 12px; min-height: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-weight: 700; font-size: 16px; }
.brand-me { font-size: 11px; color: var(--side-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; gap: 6px; }
.tab { flex: 1; padding: 7px 0; border-radius: 6px; border: 1px solid #3F6556; background: transparent; color: var(--side-ink); cursor: pointer; font-size: 13px; }
.tab.on { background: #fff; color: var(--side); font-weight: 700; border-color: #fff; }
.search { height: 34px; border-radius: 8px; border: 1px solid #3F6556; background: #17302A; color: var(--side-ink); padding: 0 10px; font-size: 13px; }
.search::placeholder { color: var(--side-muted); }
.room-list { scrollbar-color: #3F6556 transparent; scrollbar-width: thin; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.group-title { font-size: 11px; font-weight: 700; color: var(--side-muted); padding: 0 10px 4px; }
.room-item { width: 100%; display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 6px; border: none; background: none; color: var(--side-ink);
  text-align: left; cursor: pointer; font-size: 14px; }
.room-item:hover { background: #274A3D; }
.room-item.on { background: var(--side-on); color: #fff; font-weight: 700; }
.room-item.unread .rname { font-weight: 700; color: #fff; }
.room-item .rname { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-item .peek { font-size: 10px; color: var(--side-muted); border: 1px solid #3F6556; border-radius: 4px; padding: 0 4px; }
.count { font-size: 11px; background: var(--badge); color: var(--side); border-radius: 10px; padding: 0 7px; font-weight: 700; }
.count.at { background: #fff; }
.side-foot { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid #335447; padding-top: 10px; }
.side-link { background: none; border: none; color: var(--side-ink); text-align: left; padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; text-decoration: none; }
.side-link:hover { background: #274A3D; }

/* 真ん中 */
#main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); border-right: 1px solid var(--line); }
#roomHead { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.room-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.room-title h1 { margin: 0; font-size: 18px; }
#roomTopic { font-size: 13px; }
.banner { margin: 10px 20px 0; padding: 8px 12px; border-radius: 8px; background: var(--warn-soft); border: 1px solid #E8C99E; font-size: 13px; color: var(--ink2); }
.messages { flex: 1; overflow-y: auto; padding: 12px 20px 16px; display: flex; flex-direction: column; min-height: 0; }
.more { align-self: center; margin: 4px 0 12px; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 14px 0 6px; background: var(--bg); padding: 2px 12px; border-radius: 10px; }
.msg { position: relative; display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 0 12px; padding: 6px 8px; border-radius: 8px; }
.msg:hover { background: #F8F9F8; }
.msg.cont { padding-top: 1px; }
.msg.cont .avatar, .msg.cont .meta { display: none; }
.msg.flash { background: var(--accent-soft); }
.msg.mine-mention { background: #FFF9EE; }
.avatar { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; grid-row: span 3; }
.avatar.bot { border-radius: 50%; }
.meta { display: flex; align-items: baseline; gap: 8px; }
.meta .who { font-weight: 700; font-size: 14px; }
.meta .when { font-size: 11px; color: var(--muted); }
.tag-ai { font-size: 10px; font-weight: 700; color: var(--accent); border: 1px solid var(--accent); border-radius: 4px; padding: 0 5px; }
.body { grid-column: 2; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.7; }
.body .edited { font-size: 11px; color: var(--muted); }
.ment { background: var(--accent-soft); color: var(--accent); border-radius: 4px; padding: 0 3px; font-weight: 500; }
.ment.me { background: var(--badge); color: var(--side); }
.quote { grid-column: 2; font-size: 12px; color: var(--muted); border-left: 3px solid var(--line); padding-left: 8px; margin-bottom: 2px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.atts { grid-column: 2; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.atts img { max-width: 320px; max-height: 240px; border-radius: 8px; border: 1px solid var(--line); }
.file-chip { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; text-decoration: none; color: var(--ink); }
.reacts { grid-column: 2; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.react { height: 26px; display: inline-flex; align-items: center; gap: 4px; padding: 0 8px; border-radius: 13px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 13px; }
.react.me { border-color: var(--accent); background: var(--accent-soft); }
.actions { position: absolute; top: -14px; right: 12px; display: none; gap: 2px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 2px; box-shadow: 0 2px 6px rgba(0,0,0,.06); }
.msg:hover .actions, .actions:focus-within { display: flex; }
.actions button { border: none; background: none; height: 28px; min-width: 28px; padding: 0 6px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.actions button:hover { background: var(--bg); }
.edit-box { grid-column: 2; display: flex; flex-direction: column; gap: 6px; }
.edit-box textarea { width: 100%; border: 1px solid var(--accent); border-radius: 8px; padding: 8px; min-height: 60px; }
.empty { margin: auto; text-align: center; color: var(--muted); line-height: 1.8; }
.search-hit { cursor: pointer; }
.search-hit .room-tag { font-size: 11px; color: var(--accent); font-weight: 700; }

.composer { border-top: 1px solid var(--line); padding: 10px 20px 14px; position: relative; display: flex; flex-direction: column; gap: 6px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
#input { flex: 1; resize: none; min-height: 40px; max-height: 220px; border: 1px solid #C5CBC7; border-radius: 10px; padding: 9px 12px; line-height: 1.5; }
#input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.reply-bar, .file-bar { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.file-bar .file-chip { font-size: 12px; padding: 3px 8px; }
.pop { position: absolute; bottom: 64px; left: 68px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 18px rgba(0,0,0,.1);
  min-width: 220px; max-height: 260px; overflow-y: auto; padding: 4px; z-index: 5; }
.pop button { display: flex; width: 100%; gap: 8px; align-items: center; border: none; background: none; padding: 6px 10px; border-radius: 6px; cursor: pointer; text-align: left; }
.pop button.on, .pop button:hover { background: var(--accent-soft); }

/* 右 */
#right { padding: 16px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.card h2 { margin: 0; font-size: 14px; }
.card.note { background: var(--bg); }
.mini-list { display: flex; flex-direction: column; gap: 6px; }
.mini-item { border: none; background: none; text-align: left; padding: 6px 8px; border-radius: 8px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.mini-item:hover { background: var(--bg); }
.mini-item .t { font-size: 13px; color: var(--ink2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.mini-item .s { font-size: 11px; color: var(--muted); }
.person { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.dot { width: 22px; height: 22px; border-radius: 6px; color: #fff; font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.role { font-size: 11px; color: var(--muted); }

/* ダイアログ */
dialog { border: none; border-radius: 14px; padding: 0; width: min(640px, calc(100% - 32px)); max-height: calc(100% - 64px); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20,30,25,.35); }
#dlgForm { padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; }
#dlgForm h2 { margin: 0; font-size: 18px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.field input, .field select, .field textarea { height: 38px; border: 1px solid #C5CBC7; border-radius: 8px; padding: 0 10px; font-size: 14px; }
.field textarea { height: auto; padding: 8px 10px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; max-height: 240px; overflow-y: auto; border: 1px solid var(--line2); border-radius: 8px; padding: 10px; }
.checks label { display: flex; gap: 6px; align-items: center; font-size: 14px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line2); vertical-align: middle; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 500; }
.token { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: var(--bg); padding: 8px; border-radius: 8px; word-break: break-all; user-select: all; }
.inactive { opacity: .5; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--side); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 50; }
