:root {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --text: #1e3a5f;
  --muted: #64748b;
  --accent: #0ea5e9;
  --accent-soft: #e0f2fe;
  --accent-mid: #bae6fd;
  --line: #e2eaf2;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(30, 58, 95, 0.05);
  --header-h: 56px;
  --sidebar-w: 180px;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Noto Sans CJK JP", Meiryo, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3, p { margin: 0; }
button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
.icon {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.noscript { position: fixed; inset: auto 16px 16px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }

/* ヘッダー */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 30;
  height: var(--header-h); padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; white-space: nowrap; }
.brand__name { font-size: 16px; font-weight: 700; color: var(--accent); }
.brand__sep { color: var(--line); }
.brand__sub { font-size: 13px; font-weight: 600; }
.account { display: flex; align-items: center; gap: 8px; font-size: 13px; white-space: nowrap; }

/* サイドバー */
.sidebar {
  position: fixed; top: var(--header-h); bottom: 0; left: 0; z-index: 20;
  width: var(--sidebar-w); padding: 12px 0;
  background: var(--surface); border-right: 1px solid var(--line);
  overflow-y: auto;
}
.nav__item {
  width: 100%; height: 42px; padding: 0 16px 0 13px;
  display: flex; align-items: center; gap: 10px;
  background: none; border: 0; border-left: 3px solid transparent;
  color: var(--muted); font-size: 13px; text-align: left;
  transition: background-color .15s, color .15s;
}
.nav__item:hover { background: var(--bg); color: var(--text); }
.nav__item[aria-current="page"] {
  background: var(--accent-soft); border-left-color: var(--accent);
  color: var(--text); font-weight: 600;
}
.nav__item[aria-current="page"] .icon { color: var(--accent); }

/* メイン */
.main {
  margin: var(--header-h) 0 0 var(--sidebar-w);
  padding: 20px 24px 16px;
  min-height: calc(100vh - var(--header-h));
  min-height: calc(100dvh - var(--header-h));
}
.pagehead {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px 20px; flex-wrap: wrap; margin-bottom: 16px;
}
.pagehead__title { font-size: 20px; font-weight: 700; line-height: 1.4; }
.pagehead__sub { color: var(--muted); font-size: 12px; }

.switcher {
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.switcher__btn {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 4px 12px;
  background: none; border: 0; border-radius: 6px;
  color: var(--muted); font-size: 13px; font-weight: 600;
}
.switcher__btn:hover { color: var(--text); }
.switcher__btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--text); }
.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: var(--text);
  font-size: 11px; line-height: 18px; text-align: center;
}

/* 共通ボタン */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); font-size: 13px; font-weight: 600;
  transition: border-color .15s, background-color .15s;
}
.btn:hover { border-color: var(--accent); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--text); }
.btn--primary:hover { background: var(--accent-mid); }
.btn--primary:disabled { background: var(--line); border-color: var(--line); color: var(--muted); cursor: not-allowed; box-shadow: none; }
.btn--ghost { background: none; border-color: transparent; box-shadow: none; color: var(--muted); }

.avatar {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--line); color: var(--text); font-weight: 700;
}
.avatar--sm { width: 28px; height: 28px; font-size: 12px; }
.avatar--bot { background: var(--accent); font-size: 10px; }

/* 感情ステータス：色はガイドラインの配色内の濃淡で区別し、形はアイコンで補う */
.status {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 10px 2px 7px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.status .icon { width: 15px; height: 15px; }
.status--tense { background: var(--accent-mid); color: var(--text); }
.status--irritated { background: var(--text); color: #fff; }
.status--down { background: var(--muted); color: #fff; }
.status--tired { background: var(--surface); color: var(--text); box-shadow: inset 0 0 0 1px var(--muted); }

/* KPI（兼 絞り込み） */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi {
  padding: 10px 14px; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); transition: border-color .15s, background-color .15s;
}
.kpi:hover { border-color: var(--accent); }
.kpi[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.kpi__label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 600; }
.kpi__label .icon { width: 15px; height: 15px; }
.kpi[aria-pressed="true"] .kpi__label { color: var(--text); }
.kpi__num { font-size: 22px; font-weight: 700; line-height: 1.3; }
.kpi__unit { margin-left: 2px; color: var(--muted); font-size: 12px; font-weight: 400; }

/* ダッシュボード */
.dash { display: flex; align-items: flex-start; gap: 16px; }
.cards {
  flex: 1 1 auto; min-width: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(236px, 1fr)); gap: 12px;
}
.card {
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); transition: border-color .15s;
}
.card:hover { border-color: var(--accent); }
.card[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.card__top { display: flex; align-items: center; gap: 10px; min-width: 0; }
.card__who { min-width: 0; }
.card__name { display: block; font-size: 15px; font-weight: 700; line-height: 1.4; }
.card__dept { display: block; color: var(--muted); font-size: 12px; }
.card__row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 24px; }
.card__follow { padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--text); font-size: 12px; font-weight: 600; white-space: nowrap; }
.card__action { display: block; border-top: 1px solid var(--line); padding-top: 8px; font-size: 12px; }
.card__time { display: block; font-weight: 600; }
.card__text { display: block; }

/* アドバイス送信パネル */
.advice {
  flex: 0 0 360px; width: 360px;
  position: sticky; top: calc(var(--header-h) + 16px);
  height: calc(100vh - var(--header-h) - 184px);
  height: calc(100dvh - var(--header-h) - 184px);
  min-height: 460px; max-height: 760px;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.advice__head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.advice__who { flex: 1; min-width: 0; }
.advice__name { font-weight: 700; }
.advice__meta { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.iconbtn {
  flex: none; width: 32px; height: 32px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: 0; border-radius: var(--radius); color: var(--muted);
}
.iconbtn:hover { background: var(--bg); color: var(--text); }
.advice__log { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; background: var(--bg); }
.note { align-self: center; max-width: 100%; color: var(--muted); font-size: 11px; text-align: center; }
.tmsg { max-width: 84%; display: flex; flex-direction: column; }
.tmsg--user { align-self: flex-start; }
.tmsg--admin { align-self: flex-end; align-items: flex-end; }
.tmsg__bubble { padding: 7px 11px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; }
.tmsg--admin .tmsg__bubble { background: var(--accent-mid); border-color: var(--accent-mid); }
.tmsg__time { color: var(--muted); font-size: 11px; }
.advice__templates { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px 0; border-top: 1px solid var(--line); }
.chip {
  min-height: 30px; padding: 3px 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); font-size: 12px;
}
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.composer { padding: 10px 14px 12px; }
.composer textarea {
  display: block; width: 100%; padding: 8px 10px; resize: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 16px; line-height: 1.5;
}
.composer textarea::placeholder { color: var(--muted); font-size: 13px; }
.composer textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.composer__foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.composer__count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.placeholder { padding: 48px 20px; text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.placeholder__text { margin-bottom: 14px; color: var(--muted); }

/* スマホ画面 */
.userview { display: flex; align-items: flex-start; justify-content: center; gap: 28px; }
.phone {
  flex: 0 1 372px; width: 372px; max-width: 100%;
  height: calc(100vh - var(--header-h) - 130px);
  height: calc(100dvh - var(--header-h) - 130px);
  min-height: 600px; max-height: 760px;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 6px solid var(--text); border-radius: 28px;
  box-shadow: var(--shadow);
}
.phone__status { flex: none; display: flex; align-items: center; justify-content: space-between; height: 28px; padding: 0 16px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.phone__notch { width: 72px; height: 14px; border-radius: 7px; background: var(--text); }
.phone__head { flex: none; display: flex; align-items: center; gap: 8px; padding: 6px 12px 8px; border-bottom: 1px solid var(--line); }
.phone__title { font-weight: 700; line-height: 1.3; }
.phone__sub { color: var(--muted); font-size: 11px; line-height: 1.3; }
.phone__foot { flex: none; padding: 8px 10px 12px; background: var(--surface); border-top: 1px solid var(--line); }
.phone__prompt { margin-bottom: 6px; color: var(--muted); font-size: 12px; text-align: center; }
.emotions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.emotion {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: 56px; padding: 7px 2px 5px;
  background: var(--accent-soft); border: 1px solid var(--accent-mid); border-radius: var(--radius);
  font-size: 13px; font-weight: 600; transition: background-color .15s, transform .1s;
}
.emotion:hover { background: var(--accent-mid); }
.emotion:active { transform: scale(.96); }

.chat {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 12px 10px; display: flex; flex-direction: column; gap: 10px;
  background: var(--line);
}
.chat__date { align-self: center; padding: 1px 10px; border-radius: 999px; background: rgba(100, 116, 139, .7); color: #fff; font-size: 11px; }
.msg { display: flex; gap: 6px; max-width: 100%; }
.msg--new { animation: msg-in .22s ease-out; }
.msg--mine { flex-direction: row-reverse; }
.msg__body { min-width: 0; display: flex; flex-direction: column; gap: 3px; max-width: 76%; }
.msg__sender { color: var(--muted); font-size: 11px; }
.msg__line { display: flex; align-items: flex-end; gap: 4px; }
.msg--mine .msg__line { flex-direction: row-reverse; }
.msg__meta { flex: none; color: var(--muted); font-size: 10px; line-height: 1.3; text-align: right; }
.msg--mine .msg__meta { text-align: right; }
.bubble { min-width: 0; padding: 7px 11px; background: var(--surface); border-radius: 14px 14px 14px 4px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.msg--mine .bubble { background: var(--accent-mid); border-radius: 14px 14px 4px 14px; }

/* 管理者の割り込みメッセージ */
.msg--admin .msg__body { max-width: 86%; }
.msg--admin .avatar { background: var(--text); color: #fff; }
.bubble--admin { border-left: 3px solid var(--accent); border-radius: 4px 14px 14px 4px; }
.msg__tag { color: var(--text); font-size: 11px; font-weight: 700; }

/* エクササイズカード */
.msg--wide .msg__body { flex: 1; max-width: calc(100% - 34px); }
.xcard { overflow: hidden; background: var(--surface); border-radius: 12px; }
.xcard__body { padding: 9px 12px 11px; }
.xcard__title { font-size: 14px; font-weight: 700; }
.xcard__time { margin-left: 6px; color: var(--muted); font-size: 11px; font-weight: 400; }
.xcard__lead { margin-top: 2px; font-size: 13px; }

/* GIF画像の差し替え位置 */
.gif {
  position: relative; height: 128px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent);
}
.gif__badge { position: absolute; top: 7px; right: 7px; padding: 0 6px; border-radius: 4px; background: var(--text); color: #fff; font-size: 10px; font-weight: 700; letter-spacing: .04em; }
.gif__ring { position: absolute; width: 56px; height: 56px; border: 2px solid var(--accent); border-radius: 50%; opacity: 0; animation: ring 3s ease-out infinite; }
.gif__ring:nth-of-type(2) { animation-delay: 1s; }
.gif__ring:nth-of-type(3) { animation-delay: 2s; }
.gif__art { position: relative; width: 72px; height: 72px; color: var(--accent); animation: press 3s ease-in-out infinite; }
.gif__art--solid { fill: currentColor; stroke: none; }

/* チェックリスト */
.checks { padding: 9px 12px 8px; background: var(--surface); border-radius: 12px; }
.checks__title { margin-bottom: 4px; font-size: 13px; font-weight: 700; }
.check { display: flex; align-items: flex-start; gap: 8px; padding: 6px 0; font-size: 13px; line-height: 1.5; cursor: pointer; }
.check + .check { border-top: 1px solid var(--line); }
.check input { flex: none; width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--accent); cursor: pointer; }

.typing { display: flex; align-items: center; gap: 4px; min-height: 36px; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }

/* 操作の流れ */
.flow { flex: 0 0 280px; width: 280px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.flow__title { margin-bottom: 10px; font-size: 14px; font-weight: 700; }
.flow__steps { margin: 0; padding: 0; list-style: none; }
.step { position: relative; display: flex; gap: 10px; padding-bottom: 14px; color: var(--muted); font-size: 13px; }
.step:not(:last-child)::before { content: ""; position: absolute; top: 24px; bottom: 2px; left: 11px; width: 1px; background: var(--line); }
.step__num { flex: none; width: 23px; height: 23px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--bg); font-size: 12px; font-weight: 700; }
.step__num .icon { width: 14px; height: 14px; stroke-width: 2.4; }
.step__desc { display: block; font-size: 12px; }
.step--now { color: var(--text); font-weight: 600; }
.step--now .step__num { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); color: var(--text); }
.step--now .step__desc { color: var(--muted); font-weight: 400; }
.step--done { color: var(--text); }
.step--done .step__num { background: var(--accent); color: var(--text); }
.flow__actions { display: flex; flex-direction: column; gap: 6px; }

.notice { margin-top: 16px; color: var(--muted); font-size: 11px; }

@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes ring { 0% { opacity: .55; transform: scale(.8); } 100% { opacity: 0; transform: scale(2.6); } }
@keyframes press { 0%, 100% { transform: translateY(-3px); } 50% { transform: translateY(3px); } }
@keyframes blink { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }

@media (prefers-reduced-motion: no-preference) {
  .chat, .advice__log { scroll-behavior: smooth; }
}
@media (prefers-reduced-motion: reduce) {
  .msg--new, .gif__art, .gif__ring, .typing span { animation: none; }
  .gif__ring:first-of-type { opacity: .4; }
}

/* ノートPC幅：パネルをカードの上に重ねる */
@media (max-width: 1100px) {
  .advice {
    position: fixed; top: var(--header-h); right: 0; bottom: 0; z-index: 25;
    height: auto; max-height: none; max-width: 100%;
    border-width: 0 0 0 1px; border-radius: 0;
  }
}
@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .userview { flex-direction: column; align-items: center; }
  .flow { flex: none; width: 372px; max-width: 100%; }
}
/* スマホ幅：サイドバーを横スクロールのメニューへ */
@media (max-width: 640px) {
  .topbar { padding: 0 16px; }
  .brand__sub { display: none; }
  .brand__sep { display: none; }
  .sidebar {
    top: var(--header-h); bottom: auto; right: 0; width: auto; padding: 0;
    display: flex; overflow-x: auto; overflow-y: hidden;
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  .nav__item { flex: none; width: auto; padding: 0 12px; border-left: 0; border-bottom: 3px solid transparent; white-space: nowrap; }
  .nav__item[aria-current="page"] { border-bottom-color: var(--accent); }
  .main { margin: calc(var(--header-h) + 43px) 0 0; padding: 14px 16px 16px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .switcher { width: 100%; }
  .switcher__btn { flex: 1; justify-content: center; padding: 4px 6px; font-size: 12px; }
  .advice { top: var(--header-h); width: 100%; flex-basis: 100%; }
}
