/* =====================================================================
   共通スタイル（スマホ → タブレット → PC の順にレスポンシブ）
   ===================================================================== */

:root {
  --main: #4F7CFF;
  --main-dark: #3A63E0;
  --main-soft: #EAF0FF;
  --accent: #FF6B6B;
  --accent-soft: #FFECEC;
  --ok: #22C55E;
  --ok-soft: #E8F8EE;
  --text: #1F2937;
  --muted: #6B7280;
  --line: #E5E7EB;
  --bg: #F5F7FB;
  --surface: #FFFFFF;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(17, 24, 39, .06), 0 4px 14px rgba(17, 24, 39, .05);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  font-size: 16px;
}

h1 { font-size: 1.4rem; margin: 0 0 16px; }
.h2 { font-size: 1.05rem; margin: 0 0 12px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.link { color: var(--main); text-decoration: none; }
.link:hover { text-decoration: underline; }
[hidden] { display: none !important; }

/* ---------- レイアウト ---------- */
.container { max-width: 1080px; margin: 0 auto; padding: 20px 16px 40px; }
.container.narrow { max-width: 640px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-lg { display: flex; flex-direction: column; gap: 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.section-title { margin-top: 24px; }

/* ---------- ヘッダー ---------- */
.app-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.logo { font-weight: 700; color: var(--main); text-decoration: none; white-space: nowrap; }
.header-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-name { font-size: .9rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }

/* ---------- 下部ナビ（クライアント・スマホ） ---------- */
.has-bottom-nav { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .75rem; color: var(--muted); text-decoration: none; padding: 4px 0;
}
.bottom-nav a span { font-size: 1.3rem; line-height: 1; }
.bottom-nav a[aria-current="page"] { color: var(--main); font-weight: 700; }

/* ---------- カード ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card-title { font-size: 1rem; margin: 0 0 12px; }
.card-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px;
  border: 1px solid transparent; border-radius: 10px;
  font: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:focus-visible { outline: 3px solid rgba(79, 124, 255, .35); outline-offset: 2px; }
.btn-primary { background: var(--main); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--main-dark); }
.btn-outline { background: var(--surface); color: var(--main); border-color: var(--main); }
.btn-outline:hover:not(:disabled) { background: var(--main-soft); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }
.btn-ghost.danger { color: var(--accent); }
.btn-ghost.danger:hover { background: var(--accent-soft); }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: .85rem; }
.btn-block { width: 100%; }

/* ---------- フォーム ---------- */
label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; font-weight: 600; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text);
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
textarea { resize: vertical; }
input[type="color"] { padding: 4px; height: 44px; cursor: pointer; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--main); box-shadow: 0 0 0 3px rgba(79, 124, 255, .18); }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.form-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.form-row .grow { flex: 1 1 160px; }
.form-row .narrow { flex: 0 0 84px; }
.form-message { min-height: 1.2em; font-size: .9rem; }
.form-message.error { color: var(--accent); }
.form-message.success { color: var(--ok); }

/* ---------- 状態表示（ローディング・エラー・空） ---------- */
.state { padding: 28px 16px; text-align: center; color: var(--muted); border-radius: var(--radius); }
.state-loading { display: flex; align-items: center; justify-content: center; gap: 10px; }
.state-error { background: var(--accent-soft); color: #B42318; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.state-empty { background: var(--surface); border: 1px dashed var(--line); }
.card-grid > .state { grid-column: 1 / -1; }
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 3px solid var(--main-soft); border-top-color: var(--main);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- トースト ---------- */
.toast {
  position: fixed; left: 50%; bottom: 90px; z-index: 100;
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 10px 18px; border-radius: 999px;
  background: var(--text); color: #fff; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-success { background: #15803D; }
.toast-error { background: var(--accent); }

/* ---------- ダイアログ ---------- */
.dialog {
  width: min(480px, calc(100% - 32px));
  border: none; border-radius: var(--radius); padding: 20px;
  box-shadow: 0 20px 50px rgba(17, 24, 39, .25);
}
.dialog::backdrop { background: rgba(17, 24, 39, .45); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- 進捗バー ---------- */
.progress { height: 8px; background: var(--main-soft); border-radius: 999px; overflow: hidden; }
.progress-lg { height: 14px; }
.progress-bar { height: 100%; background: var(--main); border-radius: inherit; transition: width .35s ease; }

/* 達成率の文字色 */
.rate { font-size: 1.2rem; }
.rate-l4 { color: var(--main); }
.rate-l3 { color: var(--main); }
.rate-l2 { color: #5B6BA8; }
.rate-l1, .rate-l0 { color: var(--accent); }
.rate-none { color: var(--muted); }

/* ---------- ログイン ---------- */
.login-page { min-height: 100vh; background: linear-gradient(160deg, var(--main-soft), var(--bg) 60%); }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 400px; padding: 28px 24px; }
.brand { text-align: center; margin-bottom: 20px; }
.brand h1 { margin: 8px 0 4px; }
.brand-mark {
  display: inline-grid; place-items: center; width: 52px; height: 52px; border-radius: 16px;
  background: var(--main); color: #fff; font-size: 1.6rem; font-weight: 700;
}

/* ---------- コーチ：クライアントカード ---------- */
.client-card { display: flex; flex-direction: column; gap: 10px; color: inherit; text-decoration: none; transition: transform .15s, box-shadow .15s; }
.client-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(79, 124, 255, .15); }
.client-card:focus-visible { outline: 3px solid rgba(79, 124, 255, .4); }
.client-card-head { display: flex; align-items: center; gap: 10px; }
.client-card-head h3 { margin: 0; font-size: 1.05rem; }
.avatar {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
  background: var(--main-soft); color: var(--main); font-weight: 700; flex-shrink: 0;
}
.client-card-rate { display: flex; align-items: baseline; justify-content: space-between; }
.label { font-size: .85rem; color: var(--muted); }

/* ---------- コーチ：クライアント個別 ---------- */
.back { display: inline-block; margin-bottom: 6px; }
.client-title { margin-bottom: 12px; }
.tabs {
  display: flex; gap: 4px; margin-bottom: 16px; padding: 4px;
  background: var(--surface); border-radius: 12px; box-shadow: var(--shadow);
}
.tabs [role="tab"] {
  flex: 1; min-height: 42px; border: none; border-radius: 9px; background: transparent;
  font: inherit; font-weight: 600; color: var(--muted); cursor: pointer;
}
.tabs [role="tab"][aria-selected="true"] { background: var(--main); color: #fff; }

.chip-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 4px 4px 12px; border-radius: 999px; font-size: .9rem;
  background: color-mix(in srgb, var(--chip) 14%, white);
  border: 1px solid color-mix(in srgb, var(--chip) 40%, white);
}
.chip-del {
  width: 26px; height: 26px; border: none; border-radius: 50%;
  background: transparent; color: var(--muted); cursor: pointer; font-size: 1rem;
}
.chip-del:hover { background: var(--accent-soft); color: var(--accent); }

.category-block { border-left: 5px solid var(--cat, var(--main)); }
.category-title { display: flex; align-items: center; gap: 6px; margin: 0 0 10px; font-size: 1rem; }

.todo-admin-list { list-style: none; margin: 0; padding: 0; }
.todo-admin-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.todo-admin-list li:first-child { border-top: none; }
.todo-admin-text { min-width: 0; overflow-wrap: anywhere; }
.todo-admin-actions { display: flex; flex-shrink: 0; }

/* コメント */
.comment { padding: 14px 16px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.comment-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .85rem; margin-bottom: 6px; }
.comment-author { font-weight: 700; color: var(--main); }
.comment-body { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- クライアント：今日 ---------- */
.summary { margin-bottom: 16px; }
.today-date { font-size: 1.3rem; margin: 0 0 10px; }
.summary-rate { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.summary-rate strong { font-size: 2rem; color: var(--main); line-height: 1.1; }
.all-done-msg { display: none; margin-top: 10px; color: var(--main); font-weight: 700; }
.summary.all-done .all-done-msg { display: block; }
.summary.all-done .progress-bar { background: linear-gradient(90deg, var(--main), #7FA0FF); }

.message-card { margin-bottom: 16px; border-top: 4px solid var(--accent); }
.message-card .comment-body { margin-bottom: 6px; }
.message-card .link { display: inline-block; margin-top: 8px; font-size: .9rem; }
.message-card .state { padding: 12px; }

.check-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.check-item {
  position: relative; flex-direction: row; align-items: center; gap: 12px;
  padding: 12px; border-radius: 10px; cursor: pointer; font-weight: 400;
  background: var(--bg); transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.check-item:hover { background: var(--main-soft); }
.check-item input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.check-box {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 8px;
  border: 2px solid #C7D2FE; background: #fff;
  display: grid; place-items: center; transition: background .15s, border-color .15s;
}
.check-item input:checked + .check-box { background: var(--main); border-color: var(--main); }
.check-item input:checked + .check-box::after { content: "✓"; color: #fff; font-weight: 700; }
.check-item input:focus-visible + .check-box { outline: 3px solid rgba(79, 124, 255, .35); outline-offset: 2px; }
.check-text { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.check-item.is-done .check-title { color: var(--muted); text-decoration: line-through; }
.check-item.is-saving { opacity: .6; }

/* ---------- 達成カレンダー（月表示・履歴／進捗タブ共通） ---------- */
:root {
  --cal-full: #4F7CFF;   /* 100% */
  --cal-high: #7CB9FF;   /* 70〜99% */
  --cal-low: #FFB347;    /* 1〜69% */
  --cal-zero: #EEEEEE;   /* 0%（未チェック） */
  --cal-future: #FFFFFF; /* 未来 */
}
.hint { margin-top: 10px; }
.mcal { display: flex; flex-direction: column; gap: 12px; }
.mcal-nav { display: flex; align-items: center; justify-content: space-between; }
.mcal-month { margin: 0; font-size: 1.2rem; }
.mcal-arrow {
  width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 50%;
  background: var(--surface); color: var(--text); font-size: 1.5rem; line-height: 1; cursor: pointer;
}
.mcal-arrow:hover:not(:disabled) { background: var(--main-soft); color: var(--main); }
.mcal-arrow:disabled { opacity: .3; cursor: not-allowed; }
.mcal-summary { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; font-weight: 600; }
.mcal-summary-rate { font-size: 1.6rem; color: var(--main); line-height: 1.1; }
.mcal-today { margin-left: auto; }

.mcal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.mcal-week { text-align: center; font-size: .75rem; color: var(--muted); padding-bottom: 2px; }
.mcal-week.sun, .mcal-day.sun .mcal-num { color: var(--accent); }
.mcal-week.sat, .mcal-day.sat .mcal-num { color: var(--main); }
.mcal-day {
  position: relative; min-height: 52px; padding: 4px 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 2px;
  border: 1px solid transparent; border-radius: 10px;
  font: inherit; color: var(--text); cursor: pointer;
  transition: transform .1s, box-shadow .15s;
  -webkit-tap-highlight-color: transparent;
}
.mcal-day:not(:disabled):hover { box-shadow: 0 2px 8px rgba(17, 24, 39, .15); }
.mcal-day:not(:disabled):active { transform: scale(.95); }
.mcal-day:focus-visible { outline: 3px solid rgba(79, 124, 255, .45); outline-offset: 1px; }
.mcal-day:disabled { cursor: default; }
.mcal-num { font-weight: 700; font-size: .9rem; line-height: 1.2; }
.mcal-rate { font-size: .65rem; font-weight: 600; line-height: 1; }
.mcal-comment { position: absolute; top: 1px; right: 2px; font-size: .6rem; }

/* 達成率の色 */
.lv-full { background: var(--cal-full); }
.lv-high { background: var(--cal-high); }
.lv-low { background: var(--cal-low); }
.lv-zero { background: var(--cal-zero); }
.lv-future { background: var(--cal-future); border-color: var(--line); }
.lv-none { background: var(--surface); border-color: var(--line); border-style: dashed; }
.mcal-day.lv-full, .mcal-day.lv-full .mcal-num { color: #fff; }
.mcal-day.lv-future .mcal-num { color: #C0C4CC; }
.mcal-day.lv-none .mcal-num { color: var(--muted); }

/* 今日：赤いリングで強調 */
.mcal-day.is-today { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.mcal-day.is-today .mcal-num::after { content: "今日"; display: block; font-size: .55rem; font-weight: 700; }

.mcal-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; font-size: .75rem; color: var(--muted); }
.mcal-legend li { display: flex; align-items: center; gap: 4px; }
.mcal-legend i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }

/* ---------- スライドアップパネル ---------- */
body.sheet-open { overflow: hidden; }
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(17, 24, 39, .4); opacity: 0; transition: opacity .25s; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 85vh; max-height: 85dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(17, 24, 39, .2);
  transform: translateY(100%); transition: transform .25s ease;
}
.sheet.is-open .sheet-backdrop { opacity: 1; }
.sheet.is-open .sheet-panel { transform: translateY(0); }
.sheet-handle { width: 40px; height: 5px; border-radius: 999px; background: var(--line); margin: 0 auto 8px; }
.sheet-head { position: sticky; top: -8px; display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--surface); padding: 4px 0 8px; z-index: 1; }
.sheet-title { margin: 0; font-size: 1.1rem; }
.sheet-close {
  width: 40px; height: 40px; border: none; border-radius: 50%;
  background: var(--bg); color: var(--muted); font-size: 1.4rem; cursor: pointer;
}
.sheet-close:hover { background: var(--accent-soft); color: var(--accent); }
.sheet-body { display: flex; flex-direction: column; gap: 14px; }
.sheet-stats { display: flex; align-items: baseline; gap: 10px; }
.sheet-count { font-size: 1.4rem; }
.sheet-rate { font-weight: 700; padding: 2px 10px; border-radius: 999px; font-size: .9rem; }
.lv-text-full { background: var(--cal-full); color: #fff; }
.lv-text-high { background: var(--cal-high); color: #0B3A82; }
.lv-text-low { background: var(--cal-low); color: #6B3A00; }
.lv-text-zero { background: var(--cal-zero); color: var(--muted); }
.sheet-cat { border-left: 4px solid var(--cat, var(--main)); padding-left: 10px; }
.sheet-cat-title { margin: 0 0 6px; font-size: .95rem; }
.sheet-todos { list-style: none; margin: 0; padding: 0; }
.sheet-todos li { display: flex; align-items: flex-start; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.sheet-todos li:first-child { border-top: none; }
.sheet-todos .ng { color: var(--muted); }
.sheet-comments { background: var(--accent-soft); border-radius: 12px; padding: 12px; }
.sheet-comment + .sheet-comment { margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(255, 107, 107, .25); }
.sheet-form { border-top: 1px solid var(--line); padding-top: 14px; }

/* =====================================================================
   タブレット以上
   ===================================================================== */
@media (min-width: 640px) {
  .container { padding: 28px 24px 48px; }
  h1 { font-size: 1.6rem; }
  .card { padding: 20px; }
  .card-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .span-2 { grid-column: 1 / -1; }
  .mcal-grid { gap: 6px; }
  .mcal-day { min-height: 64px; }
  .mcal-rate { font-size: .75rem; }
}

/* =====================================================================
   PC
   ===================================================================== */
@media (min-width: 1024px) {
  .card-grid { grid-template-columns: repeat(3, 1fr); }
  /* PC ではクライアントの下部ナビをヘッダー下の横並びに */
  .has-bottom-nav { padding-bottom: 0; }
  .bottom-nav {
    position: sticky; top: 53px; bottom: auto;
    justify-content: center; gap: 8px; padding: 6px;
    border-top: none; border-bottom: 1px solid var(--line);
  }
  .bottom-nav a { flex: 0 0 auto; flex-direction: row; gap: 6px; font-size: .9rem; padding: 6px 16px; border-radius: 8px; }
  .bottom-nav a span { font-size: 1rem; }
  .bottom-nav a[aria-current="page"] { background: var(--main-soft); }
  .toast { bottom: 32px; }
  .mcal-day { min-height: 76px; }
  .mcal-num { font-size: 1rem; }
  /* PC ではパネルを画面下中央の幅固定シートに */
  .sheet-panel { left: 50%; right: auto; width: 560px; transform: translate(-50%, 100%); }
  .sheet.is-open .sheet-panel { transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
