:root {
  --green: #0d8a6a; --green-d: #0a6e55; --green-l: #e6f4ef;
  --bg: #f3f5f7; --line: #e2e6ea; --text: #1f2a33; --muted: #6b7782;
  --mine: #d9f2e8; --red: #d64545; --amber: #b7791f;
}
* { box-sizing: border-box; }
html, body, #app { margin: 0; height: 100%; }
body { font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif; color: var(--text); background: var(--bg); font-size: 15px; }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 14px; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--green); color: #fff; border-color: var(--green); }
button.primary:hover:not(:disabled) { background: var(--green-d); }
button.danger { color: var(--red); border-color: #f0c9c9; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; width: 100%; background: #fff; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--green-l); border-color: var(--green); }
.loading { display: grid; place-items: center; height: 100%; color: var(--muted); }
.error { color: var(--red); font-size: 13px; min-height: 1em; margin: 4px 0; }
.muted { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 32px 12px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #333d; color: #fff; padding: 10px 16px; border-radius: 20px; z-index: 100; font-size: 14px; }

/* ログイン */
.login-wrap { display: grid; place-items: center; min-height: 100%; padding: 24px; background: linear-gradient(160deg, var(--green-l), #fff); }
.login-card { width: 100%; max-width: 360px; background: #fff; border-radius: 16px; padding: 28px 24px; box-shadow: 0 6px 24px #0001; display: grid; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 8px; }
.brand h1 { font-size: 20px; margin: 0; }
.brand.small { justify-content: flex-start; margin: 0; }
.logo { width: 34px; height: 34px; border-radius: 10px; background: var(--green); color: #fff; display: grid; place-items: center; font-weight: 700; }
.sub-link { font-size: 13px; color: var(--muted); text-align: center; }

/* レイアウト */
.layout { display: grid; grid-template-columns: 340px 1fr; height: 100%; }
.side { background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.head-actions { display: flex; gap: 6px; }
.icon-btn { padding: 6px 10px; border: none; background: transparent; font-size: 18px; border-radius: 8px; }
.icon-btn:hover { background: var(--bg); }
.search { margin: 10px 12px; width: auto; }
.group-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.group-row { display: flex; gap: 10px; padding: 10px 14px; cursor: pointer; border-bottom: 1px solid #f1f3f5; }
.group-row:hover { background: #f8faf9; }
.group-row.active { background: var(--green-l); }
.avatar { width: 42px; height: 42px; flex: none; border-radius: 12px; background: #7bb8a6; color: #fff; display: grid; place-items: center; font-weight: 700; }
.avatar.announce { background: var(--amber); }
.avatar.dm { border-radius: 50%; background: #6c8ebf; }
.gr-main { flex: 1; min-width: 0; }
.gr-top, .gr-bottom { display: flex; align-items: center; gap: 6px; }
.gr-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gr-time { margin-left: auto; color: var(--muted); font-size: 12px; flex: none; }
.gr-preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.badge { background: var(--red); color: #fff; font-size: 11px; border-radius: 10px; padding: 1px 7px; flex: none; }
.tag { font-size: 10px; border-radius: 4px; padding: 1px 5px; flex: none; background: var(--bg); color: var(--muted); }
.tag.announce { background: #fdf1dc; color: var(--amber); }
.tag.dm { background: #e6eef9; color: #3f63a0; }
.pin { font-size: 11px; }

/* チャット */
.main { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.empty-main { display: grid; place-items: center; color: var(--muted); }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: #fff; border-bottom: 1px solid var(--line); }
.chat-head .back { display: none; font-size: 26px; }
.ch-title { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.ch-title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notice { background: #fff8e6; color: #7a5a12; font-size: 13px; padding: 8px 14px; border-bottom: 1px solid #f3e3b8; }
.messages { flex: 1; overflow-y: auto; padding: 12px 14px 20px; }
.day { text-align: center; font-size: 12px; color: var(--muted); margin: 14px 0 8px; }
.msg { margin: 8px 0; display: flex; flex-direction: column; align-items: flex-start; }
.msg.mine { align-items: flex-end; }
.sender { font-size: 12px; color: var(--muted); margin: 0 0 2px 4px; }
.msg-row { display: flex; align-items: flex-end; gap: 6px; max-width: 80%; }
.bubble { background: #fff; border-radius: 14px; padding: 8px 12px; white-space: pre-wrap; word-break: break-word; box-shadow: 0 1px 1px #0000000d; }
.mine .bubble { background: var(--mine); }
.bubble.deleted { color: var(--muted); font-style: italic; background: transparent; box-shadow: none; border: 1px dashed var(--line); }
.meta { display: flex; flex-direction: column; align-items: flex-end; font-size: 11px; color: var(--muted); flex: none; }
.msg:not(.mine) .meta { align-items: flex-start; }
.read-link { border: none; background: none; padding: 0; color: var(--green); font-size: 11px; }
.msg-extras { display: flex; gap: 10px; margin-top: 4px; font-size: 12px; }
.msg-extras button { padding: 2px 8px; font-size: 12px; }
.cancel-link, .ack-link { border: none !important; background: none !important; color: var(--muted); }
.ack-btn { background: var(--green) !important; color: #fff; border-color: var(--green) !important; }
.acked { color: var(--green); }
.composer { display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { resize: none; max-height: 160px; }
.send { flex: none; }

/* 画像・ファイル */
.composer-wrap { background: #fff; border-top: 1px solid var(--line); }
.composer-wrap .composer { border-top: none; }
.attach { flex: none; font-size: 20px; padding: 8px 6px; }
.up-status { font-size: 12px; color: var(--green-d); background: var(--green-l); padding: 6px 14px; }
.main.drop { outline: 3px dashed var(--green); outline-offset: -8px; }
.bubble.media { padding: 4px; cursor: zoom-in; background: #fff; }
.bubble.media img { display: block; max-width: min(240px, 60vw); max-height: 320px; border-radius: 10px; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.thumb-wait { width: 200px; height: 120px; display: grid; place-items: center; color: var(--muted); font-size: 12px; padding: 8px; text-align: center; }
.file-card { display: flex; align-items: center; gap: 10px; cursor: pointer; white-space: normal; min-width: 200px; }
.file-card.blocked { cursor: not-allowed; opacity: .85; }
.file-icon { flex: none; width: 40px; height: 40px; border-radius: 8px; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; background: #8a96a3; }
.file-icon.pdf { background: #d64545; } .file-icon.xls { background: #1f7a45; } .file-icon.doc { background: #2b5fb4; } .file-icon.ppt { background: #c4541d; }
.file-info { display: flex; flex-direction: column; min-width: 0; }
.file-name { font-weight: 600; word-break: break-all; }
.file-sub { font-size: 12px; color: var(--muted); }
.modal.viewer { place-items: stretch; padding: 0; background: #000d; display: flex; flex-direction: column; }
.viewer-bar { display: flex; gap: 8px; align-items: center; background: #111; padding: 10px 12px calc(10px); padding-top: calc(10px + env(safe-area-inset-top)); color: #fff; }
.viewer-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-body { flex: 1; min-height: 0; overflow: auto; display: grid; place-items: center; color: #fff; padding: 8px; }
.viewer-body img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.viewer-body.pdf { display: flex; flex-direction: column; align-items: center; gap: 10px; place-items: initial; }
.pdf-page { background: #fff; box-shadow: 0 2px 8px #0006; max-width: 100%; height: auto; }

/* ダイアログ */
.modal { position: fixed; inset: 0; background: #0006; display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: #fff; border-radius: 14px; padding: 20px; width: 100%; max-width: 380px; display: grid; gap: 10px; max-height: 90vh; overflow-y: auto; }
.modal-card.wide { max-width: 460px; }
.modal-card h3 { margin: 0; }
.check-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.check { display: flex; align-items: center; gap: 6px; padding: 6px 0; }
.check input { width: auto; }
.row-btns { display: flex; gap: 8px; justify-content: flex-end; }
.name-list { list-style: none; margin: 0; padding: 0 0 6px; }
.name-list li { padding: 4px 0; border-bottom: 1px solid #f1f3f5; }

/* スマホ */
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .layout.in-chat .side { display: none; }
  .layout:not(.in-chat) .main { display: none; }
  .chat-head .back { display: block; }
  .msg-row { max-width: 88%; }
}
