:root {
  --green: #06a550;
  --green-dark: #04863f;
  --green-soft: #e7f6ee;
  --bubble-me: #b9ecb0;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #e3e5e8;
  --text: #1d2125;
  --sub: #6b7280;
  --red: #e5484d;
  --amber: #b86e00;
  --radius: 12px;
  --tabbar-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { overscroll-behavior: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--green-dark); }
.hidden { display: none !important; }

/* ---------- レイアウト ---------- */
#app { height: 100%; display: flex; flex-direction: column; }
.shell { flex: 1; display: flex; min-height: 0; }
.nav {
  display: flex; background: var(--panel); border-top: 1px solid var(--line);
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
}
.nav button {
  flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; color: var(--sub); position: relative; padding: 0;
}
.nav button svg { width: 24px; height: 24px; }
.nav button.active { color: var(--green); font-weight: 600; }
.badge {
  min-width: 18px; height: 18px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; padding: 0 5px; line-height: 1;
}
.nav .badge { position: absolute; top: 5px; left: calc(50% + 6px); }

.pane { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); }
.pane-list { padding-bottom: calc(var(--tabbar-h) + var(--safe-b)); }
.pane-detail { display: none; }

@media (min-width: 900px) {
  .shell { padding-left: 76px; }
  .nav {
    flex-direction: column; top: 0; right: auto; width: 76px; height: 100%; border-top: 0; border-right: 1px solid var(--line);
    padding: calc(12px + var(--safe-t)) 0 0; justify-content: flex-start; gap: 4px; background: #11331f;
  }
  .nav button { flex: 0 0 64px; color: #a9c7b4; }
  .nav button.active { color: #fff; }
  .nav .badge { top: 6px; }
  .pane-list { flex: 0 0 360px; border-right: 1px solid var(--line); padding-bottom: 0; }
  .pane-detail { display: flex; }
  .pane-detail.empty { align-items: center; justify-content: center; color: var(--sub); background: var(--bg); }
}
@media (max-width: 899px) {
  body.detail-open .pane-list { display: none; }
  body.detail-open .pane-detail { display: flex; }
  body.detail-open .nav { display: none; }
}

/* ---------- ヘッダー ---------- */
.hdr {
  display: flex; align-items: center; gap: 8px; padding: calc(10px + var(--safe-t)) 14px 10px; min-height: 56px;
  border-bottom: 1px solid var(--line); background: var(--panel); flex-shrink: 0;
}
.hdr h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hdr h1 small { font-size: 13px; color: var(--sub); font-weight: 400; margin-left: 4px; }
.icon-btn {
  border: 0; background: none; width: 38px; height: 38px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--text); flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg); }
.icon-btn svg { width: 22px; height: 22px; }
.back-btn { margin-left: -8px; }
@media (min-width: 900px) { .pane-detail .back-btn { display: none; } }

.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; min-height: 0; }
.search { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.search input { width: 100%; border: 0; background: var(--bg); border-radius: 10px; padding: 9px 12px; outline: none; }

/* ---------- リスト ---------- */
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-bottom: 1px solid #f0f1f3; cursor: pointer; background: var(--panel);
}
.list-item:hover { background: #fafbfb; }
.list-item.selected { background: var(--green-soft); }
.avatar {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 17px; background: #8a94a6;
}
.avatar.sm { width: 34px; height: 34px; font-size: 13px; }
.avatar.group { border-radius: 14px; background: var(--green); }
.avatar.auto { border-radius: 14px; background: #2f6f4a; }
.li-main { flex: 1; min-width: 0; }
.li-top { display: flex; align-items: baseline; gap: 8px; }
.li-title { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-time { font-size: 12px; color: var(--sub); flex-shrink: 0; }
.li-sub { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.li-sub span:first-child { flex: 1; font-size: 13px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag {
  display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 6px; background: var(--bg); color: var(--sub); font-weight: 600; white-space: nowrap;
}
.tag.red { background: #fdecec; color: var(--red); }
.tag.green { background: var(--green-soft); color: var(--green-dark); }
.tag.amber { background: #fff4e0; color: var(--amber); }
.section-title { font-size: 12px; color: var(--sub); font-weight: 700; padding: 14px 14px 6px; background: var(--bg); }
.empty-note { color: var(--sub); text-align: center; padding: 40px 20px; font-size: 14px; line-height: 1.7; }
.unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); flex-shrink: 0; }

/* ---------- トーク ---------- */
.messages { background: #dfe9e3; padding: 12px 10px 6px; }
.msg-date { text-align: center; margin: 14px 0 10px; }
.msg-date span { background: rgba(0,0,0,.18); color: #fff; font-size: 12px; padding: 3px 10px; border-radius: 10px; }
.msg-system { text-align: center; font-size: 12px; color: #4f5b55; margin: 10px 20px; }
.msg { display: flex; gap: 8px; margin: 6px 0; align-items: flex-start; }
.msg .avatar { width: 34px; height: 34px; font-size: 13px; }
.msg-body { max-width: min(75%, 520px); display: flex; flex-direction: column; }
.msg-name { font-size: 12px; color: #3f4a45; margin: 0 0 3px 2px; }
.msg-row { display: flex; align-items: flex-end; gap: 6px; }
.bubble {
  background: #fff; padding: 8px 12px; border-radius: 16px; border-top-left-radius: 4px; white-space: pre-wrap; word-break: break-word;
  line-height: 1.5; font-size: 15px;
}
.msg-meta { font-size: 10.5px; color: #55625b; display: flex; flex-direction: column; line-height: 1.3; flex-shrink: 0; }
.msg.me { flex-direction: row-reverse; }
.msg.me .msg-body { align-items: flex-end; }
.msg.me .msg-row { flex-direction: row-reverse; }
.msg.me .bubble { background: var(--bubble-me); border-top-left-radius: 16px; border-top-right-radius: 4px; }
.msg.me .msg-meta { align-items: flex-end; }
.msg-read { color: var(--green-dark); font-weight: 600; cursor: pointer; }
.bubble.deleted { background: transparent; color: #55625b; font-size: 13px; padding: 4px 6px; }
.bubble a { color: #0b62c4; }
.msg-img { max-width: 240px; max-height: 300px; border-radius: 12px; display: block; cursor: zoom-in; background: #fff; }
.file-card {
  display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 12px; padding: 10px 12px; text-decoration: none; color: inherit;
  min-width: 200px;
}
.file-card .ext { width: 38px; height: 44px; border-radius: 6px; background: #e8453c; color: #fff; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.file-card .fname { font-size: 14px; word-break: break-all; }
.file-card .fsize { font-size: 12px; color: var(--sub); }
.stamp { font-size: 60px; line-height: 1; text-align: center; }
.stamp small { display: block; font-size: 12px; color: #3f4a45; margin-top: 4px; font-weight: 600; }

.composer {
  display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px calc(8px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--panel);
}
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 20px; padding: 9px 14px; max-height: 140px; outline: none; line-height: 1.45;
  background: var(--bg);
}
.composer textarea:focus { border-color: var(--green); background: #fff; }
.send-btn { background: var(--green); color: #fff; border-radius: 50%; }
.send-btn:hover { background: var(--green-dark); }
.send-btn:disabled { background: #b8c4bd; }
.stamp-panel { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 10px; border-top: 1px solid var(--line); background: #fafbfb; max-height: 220px; overflow-y: auto; }
.stamp-panel button { border: 0; background: #fff; border-radius: 10px; padding: 8px 4px; font-size: 34px; line-height: 1; }
.stamp-panel button small { display: block; font-size: 11px; margin-top: 4px; color: var(--sub); }
.load-more { text-align: center; padding: 6px; }
.disabled-composer { padding: 14px; text-align: center; color: var(--sub); border-top: 1px solid var(--line); font-size: 13px; padding-bottom: calc(14px + var(--safe-b)); }

/* ---------- カード・フォーム ---------- */
.content { padding: 16px; max-width: 760px; width: 100%; margin: 0 auto; }
.card { background: var(--panel); border-radius: var(--radius); border: 1px solid var(--line); padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 18px; margin: 0 0 6px; }
.card h3 { font-size: 15px; margin: 0 0 10px; }
.meta { font-size: 13px; color: var(--sub); display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.body-text { white-space: pre-wrap; word-break: break-word; line-height: 1.75; margin-top: 14px; font-size: 15px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input[type=text], .field input[type=password], .field input[type=date], .field input[type=time], .field input[type=datetime-local], .field textarea, .field select {
  width: 100%; border: 1px solid #cfd4da; border-radius: 10px; padding: 10px 12px; background: #fff; outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(6,165,80,.12); }
.field textarea { min-height: 120px; resize: vertical; line-height: 1.6; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 6px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--green); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid #cfd4da; background: #fff; border-radius: 18px; padding: 6px 12px; font-size: 13px; }
.chip.on { background: var(--green); color: #fff; border-color: var(--green); }
.btn {
  border: 0; background: var(--green); color: #fff; padding: 11px 18px; border-radius: 10px; font-weight: 700; font-size: 15px;
}
.btn:hover { background: var(--green-dark); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.sub { background: #fff; color: var(--text); border: 1px solid #cfd4da; }
.btn.sub:hover { background: var(--bg); }
.btn.danger { background: #fff; color: var(--red); border: 1px solid #f3c5c6; }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 12px; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.error { color: var(--red); font-size: 13px; margin: 8px 0; }
.note { font-size: 13px; color: var(--sub); line-height: 1.7; }
.fab {
  position: fixed; right: 18px; bottom: calc(var(--tabbar-h) + var(--safe-b) + 18px); width: 54px; height: 54px; border-radius: 50%;
  background: var(--green); color: #fff; border: 0; box-shadow: 0 4px 14px rgba(0,0,0,.2); display: flex; align-items: center; justify-content: center; z-index: 15;
}
.fab svg { width: 26px; height: 26px; }
@media (min-width: 900px) { .fab { left: calc(76px + 360px - 74px); right: auto; bottom: 20px; } }

/* ---------- アンケート ---------- */
.opt { display: flex; align-items: center; gap: 10px; border: 1px solid #cfd4da; border-radius: 10px; padding: 12px; margin-bottom: 8px; cursor: pointer; background: #fff; }
.opt.on { border-color: var(--green); background: var(--green-soft); }
.opt input { width: 18px; height: 18px; accent-color: var(--green); }
.result { margin-bottom: 12px; }
.result-head { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; }
.bar { height: 10px; background: var(--bg); border-radius: 5px; overflow: hidden; }
.bar div { height: 100%; background: var(--green); border-radius: 5px; }
.voters { font-size: 12px; color: var(--sub); margin-top: 4px; line-height: 1.6; }
.opt-edit { display: flex; gap: 6px; margin-bottom: 6px; }
.opt-edit input { flex: 1; }

/* ---------- カレンダー ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; }
.cal-head strong { font-size: 17px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); border-top: 1px solid var(--line); }
.cal-dow { text-align: center; font-size: 11px; color: var(--sub); padding: 6px 0; border-bottom: 1px solid var(--line); }
.cal-cell { min-height: 54px; border-right: 1px solid #f0f1f3; border-bottom: 1px solid #f0f1f3; padding: 3px; font-size: 12px; cursor: pointer; overflow: hidden; }
.cal-cell:nth-child(7n) { border-right: 0; }
.cal-cell.other { color: #c3c7cc; }
.cal-cell.today .dnum { background: var(--green); color: #fff; border-radius: 50%; }
.cal-cell.sel { background: var(--green-soft); }
.dnum { display: inline-flex; width: 22px; height: 22px; align-items: center; justify-content: center; font-weight: 600; }
.cal-cell.sun .dnum { color: var(--red); } .cal-cell.sat .dnum { color: #2563eb; }
.cal-cell.today .dnum { color: #fff; }
.cal-cell.other .dnum { color: #c3c7cc !important; }
.cal-dot { display: block; font-size: 10px; background: var(--green-soft); color: var(--green-dark); border-radius: 4px; padding: 0 3px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-item { display: flex; gap: 12px; padding: 12px 14px; border-bottom: 1px solid #f0f1f3; cursor: pointer; }
.ev-time { width: 64px; font-size: 13px; color: var(--sub); flex-shrink: 0; }
.ev-title { font-weight: 600; }

/* ---------- モーダル ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 700px) { .modal-bg { align-items: center; } }
.modal {
  background: #fff; width: 100%; max-width: 520px; max-height: 88vh; border-radius: 18px 18px 0 0; display: flex; flex-direction: column;
  padding-bottom: var(--safe-b);
}
@media (min-width: 700px) { .modal { border-radius: 18px; } }
.modal-hdr { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-hdr h3 { flex: 1; margin: 0; font-size: 16px; }
.modal-body { overflow-y: auto; padding: 16px; }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
.img-viewer { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 200; display: flex; align-items: center; justify-content: center; }
.img-viewer img { max-width: 96vw; max-height: 90vh; }
.sheet-menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 14px 16px; font-size: 15px; border-bottom: 1px solid #f0f1f3; }
.sheet-menu button.danger { color: var(--red); }

/* ---------- ログイン ---------- */
.login-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(160deg, #0b4d2a, #06a550); }
.login-card { background: #fff; border-radius: 18px; padding: 28px 24px; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-card h1 { font-size: 20px; margin: 0 0 4px; text-align: center; }
.login-card .logo { width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 14px; display: block; }
.login-card p.sub { text-align: center; color: var(--sub); font-size: 13px; margin: 0 0 20px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 20px); transform: translateX(-50%); background: rgba(20,24,22,.92); color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 300; max-width: 90vw;
}
.conn-banner { background: #fff4e0; color: var(--amber); font-size: 12px; text-align: center; padding: 4px; }
