/* トレーナー管理画面。色はミニアプリ（miniapp/style.css）のトークンに揃える（P・F・C の色を含む） */
:root {
  --accent: #0e7c66;
  --accent-strong: #0a6150;
  --accent-soft: #e3f3ee;
  --bg: #f4f7f5;
  --surface: #ffffff;
  --text: #1c2622;
  --muted: #5f6f69;
  --border: #dbe4e0;
  --error: #c62828;
  --error-soft: #fdecea;
  --warn: #9a5b00;
  --warn-soft: #fff4e0;
  --shadow: 0 1px 2px rgba(16, 40, 32, 0.06), 0 4px 16px rgba(16, 40, 32, 0.06);
  --c-protein: #4f8fd1;
  --c-fat: #d0675e;
  --c-carb: #e0a243;
  --line-green: #06c755;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #3fbf9f;
    --accent-strong: #5fd4b6;
    --accent-soft: #173a31;
    --bg: #0f1513;
    --surface: #18211e;
    --text: #e6eeeb;
    --muted: #9db0a9;
    --border: #2a3632;
    --error: #ff8a80;
    --error-soft: #3a1f1d;
    --warn: #f0b860;
    --warn-soft: #3a2c14;
    --shadow: none;
    --c-protein: #8fb8e6;
    --c-fat: #e39a92;
    --c-carb: #e8bb6c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", "Yu Gothic", "Meiryo", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.4; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* ---- 読み込み中・ログイン ---- */
.state {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px 16px;
  text-align: center;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}
.login-title { font-size: 22px; }
.eyebrow { margin: 0; color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: 0.08em; }

/* ---- ボタン・入力 ---- */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 16px;
  border: 1.5px solid transparent;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.button:hover { background: var(--accent-strong); }
.button:disabled { opacity: 0.55; cursor: not-allowed; }
.button:focus-visible, .tab:focus-visible, .tab-close:focus-visible, .chip:focus-visible, .link-button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 2px;
}
.button-line { background: var(--line-green); min-height: 48px; font-size: 16px; }
.button-line:hover { background: color-mix(in srgb, var(--line-green) 85%, #000); }
.button-secondary { background: var(--surface); color: var(--accent-strong); border-color: var(--accent); }
.button-secondary:hover { background: var(--accent-soft); }
.button-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.button-ghost:hover { background: var(--accent-soft); color: var(--text); }
.button-small { min-height: 32px; padding: 4px 12px; font-size: 13px; }
.link-button {
  border: none;
  background: none;
  padding: 0;
  color: var(--accent-strong);
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}
.link-button:hover { text-decoration: underline; }

input[type="number"], input[type="date"], input[type="text"], select {
  min-height: 38px;
  padding: 6px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[aria-invalid="true"] { border-color: var(--error); }

.notice { padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); font-size: 14px; }
.notice-error { background: var(--error-soft); color: var(--error); }
.notice-warn { background: var(--warn-soft); color: var(--warn); }
.notice code { user-select: all; font-size: 13px; word-break: break-all; }

/* ---- 本体の枠 ---- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-title { display: flex; flex-direction: column; min-width: 0; }
.trainer-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- タブ（「一覧」は固定、お客様のタブは横スクロール） ---- */
.tabbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.tab-fixed { flex: none; display: flex; border-right: 1px solid var(--border); }
.tab-scroll {
  flex: 1;
  min-width: 0;
  display: flex;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}
.tab-item {
  flex: none;
  display: flex;
  align-items: center;
  max-width: 220px;
  border-right: 1px solid var(--border);
  border-bottom: 3px solid transparent;
}
.tab-item.active { border-bottom-color: var(--accent); background: var(--bg); }
.tab {
  min-height: 42px;
  padding: 8px 14px;
  border: none;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.tab-item .tab { border-bottom: none; padding-right: 4px; }
.tab.active, .tab-item.active .tab { color: var(--text); }
.tab-fixed .tab.active { border-bottom-color: var(--accent); background: var(--bg); }
.tab-close {
  flex: none;
  width: 28px;
  height: 28px;
  margin-right: 6px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.tab-close:hover { background: var(--accent-soft); color: var(--text); }
.attention-dot { color: var(--error); font-size: 11px; margin-right: 4px; }

/* ---- タブの中身 ---- */
.panes { flex: 1; padding: 16px; }
.pane { max-width: 1280px; margin: 0 auto; }
.pane-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 14px;
}
.pane-title { font-size: 20px; }
.pane-meta { color: var(--muted); font-size: 13px; }

/* 一覧 */
.list-section { margin-bottom: 20px; }
.list-section-title { font-size: 14px; color: var(--muted); margin: 0 0 6px; }
.client-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.client-row {
  display: grid;
  grid-template-columns: minmax(160px, 2fr) 1.2fr 1.2fr 1fr;
  gap: 8px 12px;
  align-items: center;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}
.client-row:first-child { border-top: none; }
.client-row.head { background: var(--bg); color: var(--muted); font-size: 12px; font-weight: 700; padding-top: 6px; padding-bottom: 6px; }
.client-name { display: flex; align-items: center; min-width: 0; }
.client-name .link-button { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}
.badge-ok { background: var(--accent-soft); color: var(--accent-strong); border-color: transparent; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.cell-label { display: none; color: var(--muted); font-size: 12px; margin-right: 6px; }
details.collapsible > summary { cursor: pointer; font-weight: 700; color: var(--muted); padding: 4px 0; }
.empty { padding: 16px; color: var(--muted); text-align: center; }

@media (max-width: 720px) {
  .client-row { grid-template-columns: 1fr 1fr; }
  .client-row.head { display: none; }
  .client-row .client-name { grid-column: 1 / -1; }
  .cell-label { display: inline; }
}

/* パネル */
.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr));
  gap: 16px;
  align-items: start;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
}
.panel.wide { grid-column: 1 / -1; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.panel-title { font-size: 16px; }
.panel-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

.stats { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.stat { padding: 8px 12px; border-radius: 10px; background: var(--bg); min-width: 110px; }
.stat-label { display: block; font-size: 12px; color: var(--muted); }
.stat-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

dl.qa { margin: 0; display: grid; grid-template-columns: minmax(110px, 30%) 1fr; gap: 6px 12px; }
dl.qa dt { color: var(--muted); font-size: 13px; }
dl.qa dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.history { margin-top: 12px; }
.history-item { border-top: 1px solid var(--border); padding: 8px 0; }

/* 目標の設定 */
.current-goal { padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); margin-bottom: 12px; font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.chip {
  padding: 6px 12px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); }
.field-row { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .field > .field-label { font-size: 12px; font-weight: 700; color: var(--muted); }
.field input[type="number"] { width: 110px; }
.field-help { font-size: 12px; color: var(--muted); }
.field-error { font-size: 12px; color: var(--error); }
.goal-inputs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 10px; }
.goal-inputs .field input { width: 100%; }
.goal-inputs .field { border-left: 4px solid var(--pfc-color, var(--accent)); padding-left: 8px; }
.pfc-protein { --pfc-color: var(--c-protein); }
.pfc-fat { --pfc-color: var(--c-fat); }
.pfc-carb { --pfc-color: var(--c-carb); }
.pfc-label { color: color-mix(in srgb, var(--pfc-color) 70%, var(--text)); font-weight: 700; }
@media (max-width: 560px) { .goal-inputs { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.warnings { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.confirm-box { border: 1.5px solid var(--accent); border-radius: 12px; padding: 12px; margin-top: 10px; background: var(--accent-soft); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* 食事 */
.date-nav { display: flex; align-items: center; gap: 6px; }
.totals { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
@media (max-width: 560px) { .totals { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.total { padding: 8px 10px; border-radius: 10px; background: color-mix(in srgb, var(--pfc-color, var(--accent)) 12%, var(--surface)); }
.total-label { display: block; font-size: 12px; font-weight: 700; color: color-mix(in srgb, var(--pfc-color, var(--accent)) 70%, var(--text)); }
.total-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.total-goal { font-size: 12px; color: var(--muted); }
.bar { height: 6px; border-radius: 3px; background: color-mix(in srgb, var(--pfc-color, var(--accent)) 18%, transparent); overflow: hidden; margin-top: 4px; }
.bar span { display: block; height: 100%; background: var(--pfc-color, var(--accent)); }
.bar.over span { background: var(--error); }
.slots { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 12px; }
.slot { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.slot-head { display: flex; justify-content: space-between; font-weight: 700; margin-bottom: 6px; }
.slot-items { list-style: none; margin: 0; padding: 0; }
.slot-items li { padding: 6px 0; border-top: 1px dashed var(--border); font-size: 14px; }
.slot-items li:first-child { border-top: none; }
.item-line { display: flex; justify-content: space-between; gap: 8px; }
.item-name { min-width: 0; word-break: break-word; }
.item-sub { font-size: 12px; color: var(--muted); }

/* 体重 */
.chart { width: 100%; max-width: 760px; height: auto; display: block; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.table-wrap { max-height: 360px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; margin-top: 12px; }
table.log { width: 100%; border-collapse: collapse; font-size: 14px; }
table.log th, table.log td { padding: 6px 10px; border-top: 1px solid var(--border); text-align: left; vertical-align: top; }
table.log thead th { position: sticky; top: 0; background: var(--bg); border-top: none; font-size: 12px; color: var(--muted); }
table.log td.memo { white-space: pre-wrap; word-break: break-word; min-width: 160px; }
/* 日ごとの一覧（体重・食事の合計・睡眠・メモ）。列が多いので狭い画面では横にスクロールする */
.daily-wrap { max-height: 480px; }
table.log.daily { min-width: 860px; }
table.log.daily td.nowrap { white-space: nowrap; }
table.log.daily td.intake { white-space: nowrap; }
table.log.daily td.intake .goal-rate { display: block; font-size: 11px; color: var(--muted); line-height: 1.3; }
table.log.daily td.intake.over,
table.log.daily td.intake.over .goal-rate { color: var(--error); font-weight: 700; }
table.log.daily th.pfc-head { color: color-mix(in srgb, var(--pfc-color) 70%, var(--text)); }
table.log.daily tr.daily-row { cursor: pointer; }
table.log.daily tr.daily-row:hover td { background: var(--accent-soft); }
table.log.daily tr.daily-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.daily-hint { margin: 6px 0 0; }
.daily-style { margin: 4px 0 8px; }
/* 承認済み（今の目標と同じ内容）のボタン：押せないが、薄くせずに「済み」と分かる見た目にする */
.button.button-done:disabled { opacity: 1; background: var(--accent-soft); color: var(--accent-strong, var(--accent)); border-color: transparent; cursor: default; }

/* スプシ風：細い縦横の罫線・小さめの文字・詰めた行・見出し固定・日付列固定 */
.daily-sheet { border-radius: 4px; }
.daily-sheet table.log.daily { border-collapse: collapse; font-size: 12px; min-width: 760px; }
.daily-sheet table.log.daily th,
.daily-sheet table.log.daily td { padding: 3px 8px; border: 1px solid var(--border); line-height: 1.35; }
.daily-sheet table.log.daily th { position: sticky; top: 0; z-index: 2; background: var(--bg); font-size: 11px; }
.daily-sheet table.log.daily td:first-child,
.daily-sheet table.log.daily th:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.daily-sheet table.log.daily th:first-child { z-index: 3; background: var(--bg); }
.daily-sheet table.log.daily td.num { text-align: right; font-variant-numeric: tabular-nums; }
.daily-sheet table.log.daily td:first-child { text-align: left; }
.daily-sheet table.log.daily td.intake .goal-rate { display: inline; margin-left: 4px; font-size: 10px; }
.daily-sheet table.log.daily td.memo { max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.daily-sheet table.log.daily tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--bg) 60%, var(--surface)); }
.daily-sheet table.log.daily tbody tr:nth-child(even) td:first-child { background: color-mix(in srgb, var(--bg) 60%, var(--surface)); }

/* 写真 */
.photos { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 560px) { .photos { grid-template-columns: repeat(1, minmax(0, 1fr)); } }
.photo { margin: 0; }
.photo figcaption { font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.photo-frame {
  aspect-ratio: 3 / 4;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
}
.photo-frame img { width: 100%; height: 100%; object-fit: contain; display: block; }
/* スプシ風では％を出さない（超過の赤と、マウスを乗せたときの目標表示は残す） */
.daily-sheet table.log.daily td.intake .goal-rate { display: none; }
