/* エミエル 個別支援計画システム — タブレット・スマホ優先 */
:root {
  --bg: #f6f4f1;
  --surface: #ffffff;
  --text: #2f2a28;
  --muted: #7a716c;
  --line: #e7e1dc;
  --primary: #c8577f;
  --primary-dark: #a8436a;
  --primary-soft: #fbeef3;
  --overdue: #c9302c;
  --overdue-soft: #fdecea;
  --soon: #b7791f;
  --soon-soft: #fdf4e3;
  --done: #2f855a;
  --done-soft: #e8f5ee;
  --normal: #4a6fa5;
  --normal-soft: #eaf0f8;
  --radius: 14px;
  --tap: 44px;
  font-size: 16px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "BIZ UDPGothic", "Yu Gothic UI", "Meiryo", sans-serif;
  line-height: 1.6;
  padding-bottom: 72px; /* 下部ナビの分 */
}
a { color: var(--primary-dark); }
h1 { font-size: 1.35rem; margin: 0 0 12px; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ── ヘッダー ── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--primary); text-decoration: none; white-space: nowrap; }
.topnav { display: none; gap: 4px; flex: 1; }
.topnav a, .bottomnav a {
  text-decoration: none; color: var(--text); border-radius: 10px;
}
.topnav a { padding: 8px 12px; }
.topnav a.active, .topnav a:hover { background: var(--primary-soft); color: var(--primary-dark); }
.usermenu { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.usermenu form { margin: 0; }
.role-chip { font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--primary-soft); color: var(--primary-dark); }

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a { flex: 1; text-align: center; padding: 10px 4px; font-size: .8rem; min-height: 56px; }
.bottomnav a .ico { display: block; font-size: 1.25rem; line-height: 1.2; }
.bottomnav a.active { color: var(--primary-dark); font-weight: 700; }

@media (max-width: 599px) {
  .topbar { padding: 8px 12px; gap: 8px; }
  .brand { font-size: .95rem; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .usermenu { font-size: .85rem; gap: 6px; flex-shrink: 0; }
  .usermenu .role-chip, .usermenu .uname { display: none; }
}

@media (min-width: 900px) {
  .topnav { display: flex; }
  .bottomnav { display: none; }
  body { padding-bottom: 0; }
}

main { max-width: 1200px; margin: 0 auto; padding: 16px; }

/* ── カード・レイアウト ── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-main { grid-template-columns: 2fr 1fr; } }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.page-head h1 { margin: 0; flex: 1; min-width: 0; }

/* ── KPI ── */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { display: block; text-decoration: none; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .num { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.kpi .lbl { font-size: .85rem; color: var(--muted); }
.kpi.overdue .num { color: var(--overdue); }
.kpi.soon .num { color: var(--soon); }
.kpi.review .num { color: var(--normal); }

/* ── ボタン・フォーム ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 8px 16px; border-radius: 10px; border: 1px solid var(--primary);
  background: var(--primary); color: #fff; font-size: 1rem; text-decoration: none; cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: var(--surface); color: var(--primary-dark); }
.btn.secondary:hover { background: var(--primary-soft); }
.btn.danger { background: var(--surface); color: var(--overdue); border-color: var(--overdue); }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: .9rem; }
.btn.link { background: none; border: none; color: var(--primary-dark); padding: 4px 8px; min-height: auto; }

label { display: block; font-weight: 600; margin: 12px 0 4px; font-size: .95rem; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=search], select, textarea {
  width: 100%; min-height: var(--tap); padding: 8px 12px; font-size: 1rem; font-family: inherit;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
.check { display: flex; align-items: center; gap: 8px; font-weight: normal; min-height: var(--tap); margin: 0; }
.check input { width: 22px; height: 22px; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 4px 12px; }
.form-grid { display: grid; gap: 0 16px; }
@media (min-width: 700px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.inline-form { display: inline; margin: 0; }

/* ── メッセージ ── */
.flash { background: var(--done-soft); color: var(--done); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; }
.error { background: var(--overdue-soft); color: var(--overdue); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; }

/* ── 状態バッジ ── */
.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.st-overdue { background: var(--overdue-soft); color: var(--overdue); }
.st-soon { background: var(--soon-soft); color: var(--soon); }
.st-done { background: var(--done-soft); color: var(--done); }
.st-normal, .st-nodue { background: var(--normal-soft); color: var(--normal); }

/* ── 表 ── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #faf7f5; }

/* 進捗マトリクス */
.matrix td.cell { text-align: center; padding: 6px 4px; }
.matrix th.cell { text-align: center; }
.dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 50%; font-size: .75rem; font-weight: 700; text-decoration: none;
}
.dot.st-done { font-size: 1rem; }
.dot.st-overdue { box-shadow: inset 0 0 0 2px var(--overdue); }
.dot.empty { background: none; color: var(--line); }
.child-name { font-weight: 700; text-decoration: none; color: var(--text); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: .8rem; color: var(--muted); margin-top: 8px; }

/* やることリスト（スマホでも読みやすいリスト型） */
.tasklist { list-style: none; margin: 0; padding: 0; }
.tasklist li { border-bottom: 1px solid var(--line); }
.tasklist a { display: flex; align-items: center; gap: 10px; padding: 12px 4px; text-decoration: none; color: var(--text); min-height: 56px; }
.tasklist .t-main { flex: 1; min-width: 0; }
.tasklist .t-title { font-weight: 600; }
.tasklist .t-sub { font-size: .85rem; color: var(--muted); }
.tasklist .t-due { text-align: right; font-size: .85rem; white-space: nowrap; }
@media (max-width: 599px) { .tasklist .t-cycle { display: none; } }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters select { width: auto; min-width: 140px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg a { padding: 8px 14px; min-height: var(--tap); display: inline-flex; align-items: center; text-decoration: none; color: var(--text); background: var(--surface); }
.seg a.active { background: var(--primary); color: #fff; }

/* ── タイムライン ── */
.child-head { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: baseline; }
.child-head .name { font-size: 1.5rem; font-weight: 700; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .9rem; color: var(--muted); }
.cycle { border-left: 4px solid var(--line); padding-left: 16px; margin: 0 0 24px 6px; position: relative; }
.cycle.phase-実施中 { border-color: var(--primary); }
.cycle.phase-準備中 { border-color: var(--soon); }
.cycle-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.cycle-head h2 { margin: 0; }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; width: 140px; }
.progress > span { display: block; height: 100%; background: var(--done); }
.docs { list-style: none; padding: 0; margin: 0; }
.doc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; }
.doc summary { list-style: none; display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer; min-height: 56px; }
.doc summary::-webkit-details-marker { display: none; }
.doc .d-title { font-weight: 700; flex: 1; }
.doc .d-dates { font-size: .85rem; color: var(--muted); text-align: right; }
.doc .d-body { padding: 0 14px 14px; border-top: 1px solid var(--line); }
.doc.st-border-overdue { border-color: var(--overdue); }
.doc.st-border-soon { border-color: var(--soon); }
details.collapse > summary { cursor: pointer; padding: 8px 0; color: var(--muted); }

.history { list-style: none; padding: 0; margin: 0; font-size: .85rem; }
.history li { padding: 6px 0; border-bottom: 1px dashed var(--line); }

/* ── ログイン ── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(135deg, #fbeef3, #eef3fb); }
.login-box { background: var(--surface); border-radius: 20px; padding: 32px 24px; width: 100%; max-width: 380px; box-shadow: 0 8px 30px rgba(0,0,0,.07); }
.login-box h1 { color: var(--primary); text-align: center; font-size: 1.25rem; }
.login-box .btn { width: 100%; margin-top: 20px; }

.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
.pager { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }

/* ── AI作成中 ── */
.ai-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(47, 42, 40, .45); display: none; align-items: center; justify-content: center; padding: 16px; }
.ai-overlay.show { display: flex; }
.ai-box { background: var(--surface); border-radius: var(--radius); padding: 24px; max-width: 360px; text-align: center; }
.spinner { width: 44px; height: 44px; margin: 0 auto 12px; border: 4px solid var(--primary-soft); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn.ai { background: #6b5bd2; border-color: #6b5bd2; }
.btn.ai:hover { background: #5646b8; }

/* ── 書類の画面 ── */
.doc-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.doc-head h1 { margin: 0; flex: 1; min-width: 0; }
.status-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0; }
.status-form select { width: auto; }
.locked { background: var(--done-soft); color: var(--done); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; }
.goal-row { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; background: #fffdfb; }
.goal-row-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
/* 提供記録の画像 */
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 10px; }
.image-item { margin: 0; border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: var(--surface); }
.image-item img { display: block; width: 100%; height: 120px; object-fit: cover; border-radius: 6px; }
/* 目標ごとのチェック（HUGの －・◎・○・△・×） */
.mark-group { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 6px 0; }
.mark-group .muted { margin-right: 4px; }
.mark { margin: 0; cursor: pointer; }
.mark input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.mark span { display: inline-flex; align-items: center; justify-content: center; min-width: var(--tap); min-height: var(--tap);
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: 1.15rem; font-weight: normal; }
.mark input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }
.mark input:focus-visible + span { outline: 3px solid var(--primary-soft); outline-offset: 1px; }
.goal-no { display: inline-flex; width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff; align-items: center; justify-content: center; font-weight: 700; }
.goal-row-head select { width: auto; }
.carried { font-size: .8rem; color: var(--normal); background: var(--normal-soft); border-radius: 8px; padding: 6px 10px; margin-top: 8px; }
.domain-checks { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.domain-checks .check { min-height: 36px; font-size: .9rem; }
.chip { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--primary-soft); color: var(--primary-dark); margin: 2px 2px 0 0; }
.compare { display: grid; gap: 12px; }
@media (min-width: 800px) { .compare { grid-template-columns: 1fr 1fr; } }
.prev-box { background: #f8f6f3; border-radius: 10px; padding: 10px 12px; font-size: .9rem; }
.prev-box .lbl { font-size: .75rem; color: var(--muted); }
.ach-達成 { background: var(--done-soft); color: var(--done); }
.ach-一部達成 { background: var(--soon-soft); color: var(--soon); }
.ach-未達成 { background: var(--overdue-soft); color: var(--overdue); }
.rec-snippet { font-size: .85rem; border-left: 3px solid var(--line); padding: 2px 0 2px 10px; margin: 6px 0; white-space: pre-wrap; }
.hug-text { width: 100%; min-height: 240px; font-family: "BIZ UDGothic", "MS Gothic", monospace; font-size: .85rem; }
textarea { line-height: 1.7; }

/* 目標の推移 */
.lineage td, .lineage th { vertical-align: top; min-width: 220px; }
.lineage .g { background: #fffdfb; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: .9rem; }
.lineage .arrow { color: var(--muted); font-size: .8rem; }

/* 提供記録 */
.rec { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.rec-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 6px; }
.rec-body { white-space: pre-wrap; font-size: .95rem; }
.today-list { list-style: none; margin: 0; padding: 0; }
.today-list li { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); min-height: 64px; }
.today-list .name { font-weight: 700; flex: 1; }

/* 今日のやること */
.todo-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-height: 48px; }
.todo-row .t-main { flex: 1; min-width: 8em; }
.todo-time { font-size: 1.15rem; font-variant-numeric: tabular-nums; min-width: 3.2em; }
.todo-check { margin: 0; padding: 4px 8px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.todo-check input:checked + span { color: var(--done); font-weight: 700; }
.change-list { list-style: none; padding: 0; margin: 4px 0; font-size: .9rem; }
.change-list li { padding: 4px 0; border-bottom: 1px dashed var(--line); }
