:root {
  color-scheme: light;
  --bg: #f1f5f9;
  --panel: #ffffff;
  --panel-2: #e8edf3;
  --text: #0f172a;
  --muted: #64748b;
  --border: #cbd5e1;
  --accent: #0284c7;
  --mine: #0284c7;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* チャット＋カレンダーの2カラム */
.layout {
  display: flex;
  height: 100dvh;
  max-width: 74rem;
  margin: 0 auto;
}
.app {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
}

/* 制作部カレンダー（右サイド） */
.calendar {
  flex: 0 0 21rem;
  height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 1rem;
}
.cal-head { font-weight: 700; margin-bottom: .75rem; }
.cal-months { display: flex; flex-direction: column; gap: 1.25rem; }
.cal-month { }
.cal-title { font-size: .9rem; font-weight: 700; margin-bottom: .4rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-dow > div {
  text-align: center;
  font-size: .7rem;
  color: var(--muted);
  padding: .15rem 0;
}
.cal-dow .sun { color: #ef4444; }
.cal-dow .sat { color: #3b82f6; }
.cal-day {
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-size: .75rem;
  border-radius: .35rem;
}
.cal-num { line-height: 1; }
.cal-dots { display: flex; gap: 2px; height: .3rem; align-items: center; }
.cal-daydot { width: .3rem; height: .3rem; border-radius: 999px; }
.cal-day.has-event { cursor: pointer; }
.cal-day.has-event:hover { box-shadow: inset 0 0 0 1px var(--accent); }

/* イベント名のツールチップ */
.cal-tip {
  position: fixed;
  z-index: 50;
  max-width: 15rem;
  background: #0f172a;
  color: #fff;
  font-size: .72rem;
  line-height: 1.45;
  padding: .4rem .55rem;
  border-radius: .4rem;
  box-shadow: 0 6px 20px rgba(15, 23, 42, .3);
  pointer-events: none;
}
.cal-tip[hidden] { display: none; }
.cal-tip-ev { font-weight: 600; }
.cal-tip-ev + .cal-tip-ev { margin-top: .15rem; }
.cal-tip-phase {
  margin-top: .3rem;
  padding-top: .3rem;
  border-top: 1px solid rgba(255, 255, 255, .2);
  color: #cbd5e1;
  font-size: .68rem;
}
.cal-day.blank { visibility: hidden; }
.cal-day.sun { color: #ef4444; }
.cal-day.sat { color: #3b82f6; }
.cal-day.in-band { color: var(--text); }
.cal-day.today {
  box-shadow: inset 0 0 0 2px var(--accent);
  font-weight: 700;
}
.cal-legend {
  margin-top: 1rem;
  padding-top: .75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.cal-legend-head {
  font-size: .75rem;
  font-weight: 700;
  color: var(--muted);
  margin: .25rem 0 .1rem;
}
.cal-legend-head:not(:first-child) { margin-top: .6rem; }
.cal-legend-item { display: flex; align-items: flex-start; gap: .5rem; }
.cal-dot {
  flex: 0 0 auto;
  width: .8rem;
  height: .8rem;
  border-radius: .25rem;
  margin-top: .15rem;
}
.cal-ev-name { font-size: .8rem; line-height: 1.4; }
.cal-ev-range { font-size: .72rem; color: var(--muted); }

/* 制作スケジュールのバー（カレンダー内） */
.sched-bars { display: flex; flex-direction: column; gap: 1px; width: 84%; }
.sched-bar { height: 3px; border-radius: 2px; }
.sched-bar.done { opacity: .4; }
.sched-bar.overdue { outline: 1px solid #ef4444; outline-offset: -1px; }
.sched-bar.is-due { height: 4px; box-shadow: 0 0 0 1.5px #0f172a; }

/* 制作スケジュールの一覧（凡例内） */
.sched-group { margin-bottom: .5rem; }
.sched-project { display: flex; align-items: center; gap: .35rem; font-weight: 700; font-size: .78rem; margin: .3rem 0 .2rem; }
.sched-pdot { width: .7rem; height: .7rem; border-radius: .2rem; flex: 0 0 auto; }
.sched-item { display: flex; align-items: flex-start; gap: .4rem; padding: .2rem 0; }
.sched-idot { width: .6rem; height: .6rem; border-radius: .2rem; margin-top: .25rem; flex: 0 0 auto; }
.sched-item-body { flex: 1; min-width: 0; }
.sched-item-main { display: flex; align-items: center; gap: .4rem; font-size: .78rem; }
.sched-item-sub { font-size: .7rem; color: var(--muted); }
.sched-badge { font-size: .62rem; font-weight: 700; color: #fff; border-radius: .7rem; padding: .04rem .45rem; background: #94a3b8; }
.sched-badge.overdue { background: #ef4444; }
.sched-item-btns { display: flex; gap: .2rem; flex: 0 0 auto; }
.sched-mini { font-size: .62rem; background: transparent; border: 1px solid var(--border); border-radius: .3rem; padding: .05rem .35rem; color: var(--muted); cursor: pointer; }
.sched-mini:hover { color: var(--text); border-color: var(--accent); }
.sched-mini.danger:hover { color: #dc2626; border-color: #ef4444; }
.sched-empty { font-size: .75rem; color: var(--muted); padding: .3rem 0; }

/* 予定 追加/編集フォーム */
.sched-form-head { font-size: .75rem; font-weight: 700; color: var(--muted); margin: .7rem 0 .3rem; }
.sched-form { display: flex; flex-direction: column; gap: .35rem; }
.sched-form-row { display: flex; gap: .35rem; }
.sched-field { display: flex; flex-direction: column; gap: .1rem; font-size: .68rem; color: var(--muted); flex: 1; min-width: 0; }
.sched-input {
  font: inherit;
  font-size: .75rem;
  padding: .25rem .35rem;
  border: 1px solid var(--border);
  border-radius: .35rem;
  background: var(--panel);
  color: var(--text);
  width: 100%;
  box-sizing: border-box;
}
.sched-input:focus { outline: none; border-color: var(--accent); }
.sched-form-actions { display: flex; gap: .4rem; margin-top: .2rem; }
.sched-btn {
  font: inherit;
  font-size: .75rem;
  padding: .25rem .7rem;
  border: 1px solid var(--border);
  border-radius: .4rem;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.sched-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }
.sched-btn:disabled { opacity: .5; cursor: default; }

/* 狭い画面ではカレンダーを隠してチャットを優先 */
@media (max-width: 860px) {
  .calendar { display: none; }
}

.topbar {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  padding: .6rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.dot {
  width: .6rem; height: .6rem; border-radius: 999px;
  background: #64748b; transition: background .2s;
}
.dot.online { background: #22c55e; }
.dot.offline { background: #ef4444; }
.presence { font-size: .8rem; color: var(--muted); }

/* 勤怠状態のストリップ */
.attendance {
  display: flex;
  gap: .4rem;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}
.att-chip {
  display: flex;
  align-items: center;
  gap: .3rem;
  flex: 0 0 auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .12rem .55rem .12rem .18rem;
  font-size: .72rem;
}
.att-avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 999px;
  color: #fff;
  font-size: .62rem;
  font-weight: 700;
  flex: 0 0 auto;
}
.att-status-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: .5rem;
  height: .5rem;
  border-radius: 999px;
  border: 2px solid var(--bg);
}
.att-name { font-weight: 600; color: var(--text); }
.att-status { font-weight: 700; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.msg { max-width: 80%; }
.msg .meta {
  display: flex;
  align-items: center;
  gap: .3rem;
  font-size: .72rem;
  color: var(--muted);
  margin: 0 0 .15rem .1rem;
}
.msg .bubble {
  background: var(--panel-2);
  padding: .5rem .75rem;
  border-radius: .8rem;
  border-top-left-radius: .2rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.msg.mine { align-self: flex-end; }
.msg.mine .meta { justify-content: flex-end; margin: 0 .1rem .15rem 0; }
.msg.mine .bubble {
  background: var(--mine);
  color: #ffffff;
  border-top-left-radius: .8rem;
  border-top-right-radius: .2rem;
}
.msg.system {
  align-self: center;
  font-size: .78rem;
  color: var(--muted);
}

/* 編集・削除アクション（ホバーで表示） */
.msg { position: relative; }
.actions {
  display: flex;
  gap: .3rem;
  margin-top: .2rem;
  opacity: 0;
  transition: opacity .15s;
}
.msg.mine .actions { justify-content: flex-end; }
.msg:hover .actions, .actions:focus-within { opacity: 1; }
.action-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: .4rem;
  padding: .1rem .5rem;
  font-size: .72rem;
  cursor: pointer;
}
.action-btn:hover { color: var(--text); border-color: var(--accent); }
.action-btn.danger:hover { color: #dc2626; border-color: #ef4444; }
.action-btn.primary { background: var(--accent); color: #ffffff; border-color: var(--accent); }

/* インライン編集 */
.edit-input {
  width: 100%;
  min-width: 12rem;
  box-sizing: border-box;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: .4rem;
  padding: .4rem .5rem;
  font: inherit;
  resize: vertical;
}
.edit-actions { display: flex; gap: .4rem; margin-top: .4rem; }

/* 削除済みメッセージ */
.msg.deleted .bubble { background: transparent; border: 1px dashed var(--border); }
.deleted-text { color: var(--muted); font-style: italic; }
.msg.mine.deleted .bubble { color: var(--muted); }

/* メンション */
.mention { font-weight: 700; color: #0284c7; }
.msg.mine .mention { color: #eaf6ff; text-decoration: underline; }
/* 自分宛メンションを含むメッセージの強調 */
.msg.mentions-me .bubble {
  box-shadow: inset 0 0 0 2px #f59e0b;
  background: #fffbeb;
}

/* 返信: メッセージ内の引用ブロック */
.reply-quote {
  display: flex;
  flex-direction: column;
  gap: .1rem;
  border-left: 3px solid var(--accent);
  padding: .2rem .5rem;
  margin-bottom: .35rem;
  background: rgba(2, 132, 199, .08);
  border-radius: .25rem;
  cursor: pointer;
  font-size: .75rem;
  max-width: 100%;
}
.reply-quote-name { font-weight: 700; color: var(--accent); }
.reply-quote-text {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg.mine .reply-quote { background: rgba(255, 255, 255, .18); border-left-color: rgba(255, 255, 255, .7); }
.msg.mine .reply-quote-name { color: #fff; }
.msg.mine .reply-quote-text { color: rgba(255, 255, 255, .85); }

/* 返信: ジャンプ時のフラッシュ */
.msg.flash .bubble { animation: msg-flash 1.2s ease; }
@keyframes msg-flash {
  0% { box-shadow: 0 0 0 0 rgba(2, 132, 199, .6); }
  100% { box-shadow: 0 0 0 10px rgba(2, 132, 199, 0); }
}

/* 返信バナー（入力欄の上） */
.reply-banner {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin: 0 .75rem;
  padding: .4rem .6rem;
  background: var(--panel-2);
  border-left: 3px solid var(--accent);
  border-radius: .4rem .4rem 0 0;
  font-size: .8rem;
}
.reply-banner[hidden] { display: none; }
.reply-banner-icon { color: var(--accent); font-weight: 700; }
.reply-banner-text {
  flex: 1;
  min-width: 0;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-cancel {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 .2rem;
}
.reply-cancel:hover { color: var(--text); }

/* メンションボタン */
.mention-wrap { position: relative; flex: 0 0 auto; }
#mention-btn { font-size: 1.1rem; font-weight: 700; }

/* 添付メディア */
.msg .bubble .text + .att { margin-top: .4rem; }
.att {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: .5rem;
}
.att-image { cursor: zoom-in; object-fit: cover; }
.att-video { background: #000; }
.msg .bubble a { display: block; line-height: 0; }

/* 添付プレビュー（送信前） */
.preview {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .75rem;
  margin: 0 .75rem;
  background: var(--panel-2);
  border-radius: .6rem 0.6rem 0 0;
}
.preview-body {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-width: 0;
  flex: 1;
}
.preview-body .att { max-height: 56px; max-width: 96px; border-radius: .4rem; }
.preview-name {
  font-size: .8rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.preview-clear {
  flex: 0 0 auto;
  background: transparent;
  color: var(--muted);
  border: 0;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: .2rem .4rem;
}
.preview-clear:hover { color: var(--text); }

.composer {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  padding: .75rem;
  background: var(--panel);
  border-top: 1px solid var(--border);
}
/* アイコン（丸＋頭文字） */
.avatar {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 999px;
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  line-height: 1;
}
.avatar-sm { width: 1.15rem; height: 1.15rem; font-size: .6rem; }

/* ユーザー選択ボタン */
.user-wrap { position: relative; flex: 0 0 auto; }
.user-btn {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  min-height: 2.55rem;
  max-width: 9rem;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid transparent;
  border-radius: .6rem;
  padding: 0 .55rem;
  font: inherit;
  cursor: pointer;
}
.user-btn:hover { border-color: var(--accent); }
.user-btn.unset { color: var(--muted); }
.user-label {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.chevron { width: 15px; height: 15px; flex: 0 0 auto; color: var(--muted); }

/* ユーザー選択メニュー */
.user-menu {
  position: absolute;
  bottom: calc(100% + .4rem);
  left: 0;
  min-width: 10rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: .6rem;
  padding: .3rem;
  display: flex;
  flex-direction: column;
  gap: .15rem;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .15);
  z-index: 20;
}
.user-menu[hidden] { display: none; }
.user-menu button {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: transparent;
  color: var(--text);
  border: 0;
  border-radius: .4rem;
  padding: .4rem .5rem;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.user-menu button:hover { background: var(--panel-2); }
.user-menu button.selected { background: var(--panel-2); font-weight: 700; }

/* 入力欄と添付ボタンを重ねるためのラッパー */
.input-wrap { position: relative; flex: 1; display: flex; min-width: 0; }
.body-input {
  flex: 1;
  /* 約5行分の高さ。必要なら縦方向にリサイズ可能。 */
  line-height: 1.4;
  min-height: calc(1.4em * 5 + 1.2rem);
  max-height: 40vh;
  resize: vertical;
  overflow-y: auto;
  /* 左下の添付ボタン分のスペースを空ける */
  padding-left: 2.9rem;
}
.composer input,
.composer textarea {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid transparent;
  border-radius: .6rem;
  padding: .6rem .75rem;
  font: inherit;
  min-width: 0;
}
.composer input:focus,
.composer textarea:focus { outline: none; border-color: var(--accent); }
.composer button {
  min-height: 2.55rem;
  background: var(--accent);
  color: #ffffff;
  border: 0;
  border-radius: .6rem;
  padding: 0 1.1rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.composer button:disabled { opacity: .5; cursor: default; }
.icon-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.55rem;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: .6rem;
  padding: 0 .7rem;
  cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.icon-btn:disabled { opacity: .5; cursor: default; }
.icon-btn.loading { color: var(--muted); }
.icon-btn.loading .icon { animation: icon-pulse 1s ease-in-out infinite; }
@keyframes icon-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

/* 線画アイコン共通 */
.icon { width: 20px; height: 20px; display: block; }

/* 添付メニュー（写真 / 動画） */
/* 入力欄の左下に重ねて配置 */
.attach-wrap { position: absolute; left: .35rem; bottom: .35rem; display: flex; }
/* 入力欄内に置くボタンは枠・背景なしで馴染ませる */
.input-wrap .icon-btn {
  min-height: 0;
  padding: .3rem;
  background: transparent;
  border: 0;
}
.input-wrap .icon-btn:hover { color: var(--accent); }
.attach-menu {
  position: absolute;
  bottom: calc(100% + .4rem);
  left: 0;
  min-width: 8rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: .6rem;
  padding: .3rem;
  display: flex;
  flex-direction: column;
  gap: .2rem;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .15);
  z-index: 20;
}
.attach-menu[hidden] { display: none; }
.attach-menu button {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: transparent;
  color: var(--text);
  border: 0;
  border-radius: .4rem;
  padding: .5rem .7rem;
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.attach-menu .icon { width: 18px; height: 18px; color: var(--muted); }
.attach-menu button:hover { background: var(--border); }

@media (max-width: 480px) {
  .user-btn { max-width: 6.5rem; }
  .msg { max-width: 90%; }
}
