:root {
  --paper: #f5f3ee;
  --card: #ffffff;
  --ink: #26251f;
  --ink-soft: #6c6a61;
  --line: #ddd9d0;
  --accent: #1e6b57;
  --accent-ink: #ffffff;
  --other: #eceae3;
  --alert: #b0442a;
  --ok: #1e6b57;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", "Meiryo", sans-serif;
  font-size: 18px;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}

.view { display: flex; flex-direction: column; height: 100%; max-width: 780px; margin: 0 auto; }
[hidden] { display: none !important; }

/* --- 共通部品 --- */

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  min-height: 52px;
  padding: 0 20px;
  border: 1px solid transparent;
}
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 500; }
.primary:hover { filter: brightness(1.08); }

.secondary { background: var(--card); color: var(--accent); border-color: var(--accent); font-weight: 500; }
.secondary:hover { background: #eef4f2; }

.danger { background: var(--card); color: var(--alert); border-color: var(--alert); }
.danger:hover { background: #f8ece9; }

.ghost { background: transparent; color: var(--ink-soft); border-color: transparent; min-height: 44px; padding: 0 12px; }
.ghost:hover { color: var(--ink); }

.wide { width: 100%; margin-top: 12px; }

input, textarea {
  font: inherit;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  min-height: 52px;
}
input:focus, textarea:focus { outline: 3px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

label, .label-like { display: block; margin: 18px 0 6px; font-size: 16px; color: var(--ink-soft); }
.error { color: var(--alert); margin: 12px 0 0; }
.ok { color: var(--ok); margin: 12px 0 0; }
.hint { color: var(--ink-soft); font-size: 15px; padding: 16px 20px; margin: 0; }
.hint-plain { color: var(--ink-soft); font-size: 15px; margin: 4px 0 12px; }
.hint-center { color: var(--ink-soft); font-size: 15px; text-align: center; margin: 8px 0 0; }

/* --- ログイン・登録 --- */

#view-login, #view-register, #view-issued { justify-content: center; padding: 24px; overflow-y: auto; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 32px 28px; }
.login-card h1 { margin: 0; font-size: 30px; font-weight: 500; letter-spacing: 0.08em; }
.lead { color: var(--ink-soft); margin: 4px 0 20px; font-size: 16px; }
.login-card .primary { width: 100%; margin-top: 28px; }

.issued-id {
  font-size: 56px;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-align: center;
  margin: 12px 0;
  color: var(--accent);
}

/* --- ヘッダー --- */

.bar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 2;
}
.bar-title { flex: 1; font-size: 19px; font-weight: 500; padding-left: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- 部屋一覧 --- */

.room-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.room-list li { border-bottom: 1px solid var(--line); }
.room-list button {
  display: flex; align-items: center; gap: 14px;
  width: 100%; text-align: left; background: var(--card);
  border-radius: 0; padding: 18px 20px; min-height: 84px;
}
.room-name { font-weight: 500; }
.room-last { color: var(--ink-soft); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-text { flex: 1; min-width: 0; }
.kind-tag {
  font-size: 13px; color: var(--ink-soft);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 1px 8px; flex-shrink: 0;
}
.badge {
  background: var(--alert); color: #fff;
  min-width: 34px; height: 34px; border-radius: 17px;
  display: grid; place-items: center;
  font-size: 16px; font-weight: 500; padding: 0 10px;
  flex-shrink: 0;
}

.fab-row {
  display: flex; gap: 10px; padding: 12px;
  background: var(--card); border-top: 1px solid var(--line);
}
.fab-row button { flex: 1; }

/* --- 会話 --- */

.messages { flex: 1; overflow-y: auto; padding: 20px 16px 8px; display: flex; flex-direction: column; gap: 16px; }
.msg { max-width: 78%; }
.msg .who { font-size: 14px; color: var(--ink-soft); margin-bottom: 4px; }
.msg .bubble {
  background: var(--other); padding: 12px 16px; border-radius: 12px;
  white-space: pre-wrap; word-break: break-word;
}
.msg .when { font-size: 13px; color: var(--ink-soft); margin-top: 4px; }
.msg.mine { align-self: flex-end; }
.msg.mine .bubble { background: var(--accent); color: var(--accent-ink); }
.msg.mine .when { text-align: right; }
.day { align-self: center; font-size: 14px; color: var(--ink-soft); background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 2px 14px; }

.composer { display: flex; gap: 10px; padding: 12px; background: var(--card); border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { resize: none; max-height: 160px; }
.composer .primary { flex-shrink: 0; }

/* --- 設定・管理 --- */

#view-admin, #view-settings, #view-new-group { overflow-y: auto; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin: 16px; padding: 20px 22px; }
.panel h2 { margin: 0; font-size: 19px; font-weight: 500; }
.panel .primary { margin-top: 20px; }
.my-info { margin: 8px 0 0; }
.user-list { list-style: none; margin: 12px 0 0; padding: 0; }
.user-list li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.user-list .u-name { flex: 1; min-width: 0; }
.user-list .u-off { color: var(--ink-soft); text-decoration: line-through; }
.user-list .u-id { color: var(--ink-soft); font-size: 14px; }
.dept {
  color: var(--ink-soft);
  font-size: 15px;   /* 基本18pxより3px小さく */
  font-weight: 400;
}
.who .dept { font-size: 12px; }  /* 送信者名14pxより小さく */

/* ログイン画面下部の案内リンク */
.promo {
  margin: 18px 0 0;
  text-align: center;
  font-size: 14px;
}
.promo a { color: var(--ink-soft); text-decoration: underline; }

/* 添付ファイル */
.attach { font-size: 20px; padding: 8px 10px; }
.bubble.img-only { padding: 0; background: none; }
.att-img {
  max-width: 240px;
  max-height: 240px;
  border-radius: 14px;
  display: block;
  cursor: pointer;
}
.att-file {
  display: inline-block;
  color: inherit;
  text-decoration: underline;
  word-break: break-all;
}
.msg.mine .att-file { color: #fff; }

/* 退会パネルの注意書き */
.note-small {
  font-size: 14px;
  color: var(--ink-soft);
  margin: 0 0 12px;
}
.user-list input[type=checkbox] { width: 24px; height: 24px; min-height: 24px; flex-shrink: 0; }
.user-list .ghost { flex-shrink: 0; }

@media (max-width: 520px) {
  html, body { font-size: 17px; }
  .msg { max-width: 88%; }
  .issued-id { font-size: 44px; }
}

/* 会話画面ヘッダ内の所属(ヘッダは明るい地なので通常のグレー) */
.bar-title .dept { font-size: 15px; }


/* 写真の全画面表示(アプリ内で開閉。別窓は使わない) */
#lightbox[hidden] { display: none; }  /* hiddenを確実に効かせる(display:flexより優先) */
#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  cursor: zoom-out;
}
#lightbox img {
  max-width: 100%;
  max-height: 100%;
}

#lightboxOrig {
  position: absolute;
  top: 14px;
  right: 14px;
  color: #fff;
  background: rgba(255, 255, 255, 0.18);
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 8px;
  text-decoration: none;
}


/* リプライ(引用) */
#replyBar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--card);
  border-top: 1px solid var(--line);
  font-size: 14px;
  color: var(--ink-soft);
}
#replyBar[hidden] { display: none; }
#replyInfo { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.quote {
  border-left: 3px solid rgba(127, 127, 127, 0.45);
  padding: 2px 8px;
  margin-bottom: 6px;
  font-size: 15px;   /* 本文16pxとの差は最小限に(区別はつくが読みにくくない) */
  opacity: 0.92;
  cursor: pointer;
}
.msg.mine .quote { border-left-color: rgba(255, 255, 255, 0.6); }
.quote-name { font-weight: bold; }
.quote-body { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; max-width: 240px; }
.msg.flash { animation: flash-bg 1.2s ease; }
@keyframes flash-bg {
  0% { background: rgba(30, 107, 87, 0.18); }
  100% { background: transparent; }
}


/* メッセージ操作メニュー(長押しで開く) */
#msgMenu {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 90;
  display: flex;
  align-items: flex-end;
}
#msgMenu[hidden] { display: none; }
#msgMenuSheet {
  background: var(--card);
  width: 100%;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* スマホでは吹き出しの長押しを自前メニューに割り当てるため、標準の文字選択を止める
   (コピーはメニューの「本文をコピー」で可能。PCはマウス選択を従来通り残す) */
@media (pointer: coarse) {
  .bubble {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
}


/* PC: 吹き出しに乗せると出る引用ボタン */
.msg { position: relative; }
.reply-hint {
  display: none;
  position: absolute;
  top: -10px;
  right: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 14px;
  line-height: 1;
  padding: 4px 9px;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
.msg.mine .reply-hint { right: auto; left: 6px; }
@media (hover: hover) {
  .msg:hover .reply-hint { display: block; }
}

.quote-thumb {
  display: block;
  max-height: 56px;
  max-width: 120px;
  border-radius: 6px;
  margin-top: 2px;
}


/* 通知設定のチェック行 */
.check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  padding: 8px 0;
}
.check input { width: 20px; height: 20px; }


/* 送信前の確認 */
#sendConfirm {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 95;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#sendConfirm[hidden] { display: none; }
#sendConfirmSheet {
  background: var(--card);
  border-radius: 16px;
  padding: 18px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.confirm-title { margin: 0; font-weight: bold; text-align: center; }
#sendPreviewImg {
  max-width: 100%;
  max-height: 45vh;
  border-radius: 10px;
  align-self: center;
}
#sendPreviewFile { margin: 0; text-align: center; word-break: break-all; }
.confirm-btns { display: flex; gap: 10px; }
.confirm-btns button { flex: 1; }


/* リンクを開く前の確認 */
#urlConfirm {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 95;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#urlConfirm[hidden] { display: none; }
#urlConfirmSheet {
  background: var(--card);
  border-radius: 16px;
  padding: 18px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.url-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.url-domain { font-weight: bold; font-size: 17px; }
.url-full {
  color: #1558c0;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  text-decoration-skip-ink: none;
  font-size: 12px;
  word-break: break-all;
  margin-top: 4px;
}
.url-item { transition: background 0.15s; }
.url-item:active { background: #eef5ff; }


/* 本文中のリンク表示(タップで確認画面へ。直接は開かない) */
.link-text {
  color: #1558c0;
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;   /* 下線を文字から少し離す(日本語で窮屈にならないように) */
  text-decoration-skip-ink: none; /* p,y,g等の足で下線が途切れないように(一本の連続線にする) */
  word-break: break-all;
  cursor: pointer;
  transition: opacity 0.15s;
}
.link-text:active { opacity: 0.55; }  /* 押した瞬間の手応え */
.msg.mine .link-text { color: #d8ecff; }
