:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --ink: #1f2a24;
  --muted: #5f6b64;
  --line: #dde3df;
  --brand: #2f8f62;
  --brand-ink: #ffffff;
  --brand-soft: #e3f2ea;
  --warn: #b25d00;
  --warn-soft: #fff1dd;
  --danger: #c0392b;
  --subj: #3d7cc9;
  --act: #e0663a;
  --radius: 12px;
  --tap: 44px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }

/* ---- ヘッダー ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--brand); color: var(--brand-ink);
}
.topbar h1 { flex: 1; margin: 0; font-size: 17px; font-weight: 700; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { display: block; font-size: 12px; font-weight: 400; opacity: .85; }
.iconbtn {
  min-width: var(--tap); height: var(--tap); border: 0; border-radius: 10px;
  background: rgba(255,255,255,.15); color: inherit; font-size: 15px; padding: 0 10px;
}

.tabs {
  position: sticky; top: 56px; z-index: 19;
  display: flex; gap: 4px; overflow-x: auto; padding: 8px 12px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: none; padding: 8px 14px; border-radius: 999px; text-decoration: none;
  color: var(--muted); font-size: 14px; font-weight: 600; white-space: nowrap;
}
.tabs a.on { background: var(--brand-soft); color: var(--brand); }

main { max-width: 860px; margin: 0 auto; padding: 16px; }

/* ---- カード ---- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.card h2 { margin: 0 0 4px; font-size: 18px; }
.card h3 { margin: 16px 0 8px; font-size: 15px; }
.card > p:first-of-type { margin-top: 4px; }
.lead { color: var(--muted); font-size: 14px; margin: 4px 0 12px; }
.note { color: var(--muted); font-size: 13px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 20px 4px 8px; letter-spacing: .04em; }

.elhead { border-left: 6px solid var(--el, var(--brand)); background: var(--el-soft, var(--brand-soft)); }
.elhead h2 { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.elhead .kw { font-size: 13px; font-weight: 400; color: var(--muted); }

/* ---- ボタン ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600; text-decoration: none; color: var(--ink);
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--danger); border-color: #efc4be; }
.btn.block { display: flex; width: 100%; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ---- フォーム ---- */
.field { margin-bottom: 12px; }
.field > label, .field > .label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.input, select.input, textarea.input {
  width: 100%; min-height: var(--tap); padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
textarea.input { min-height: 80px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.inline { display: flex; align-items: center; gap: 8px; }
.inline .input { flex: 1; }
.unit { color: var(--muted); font-size: 14px; white-space: nowrap; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); }
.check input { width: 22px; height: 22px; accent-color: var(--brand); }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  flex: 1 1 0; min-width: 64px; min-height: var(--tap); padding: 4px 8px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 14px; font-weight: 600;
}
.seg button.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---- 4段階評価 ---- */
.pair { border-top: 1px solid var(--line); padding: 14px 0 6px; }
.pair:first-of-type { border-top: 0; padding-top: 4px; }
.pair .no { font-size: 12px; font-weight: 700; color: var(--muted); }
.pair .hint { font-size: 12px; color: var(--muted); margin: 2px 0 6px; }
.q { margin: 8px 0 10px; }
.q .qlabel { display: flex; gap: 8px; align-items: flex-start; font-size: 15px; margin-bottom: 6px; }
.tag { flex: none; display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; color: #fff; margin-top: 2px; }
.tag.subj { background: var(--subj); }
.tag.act { background: var(--act); }
.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.rate button {
  min-height: 52px; padding: 4px 2px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.2;
}
.rate button b { font-size: 18px; }
.rate button span { font-size: 10.5px; color: var(--muted); }
.rate.subj button.on { background: var(--subj); border-color: var(--subj); color: #fff; }
.rate.act button.on { background: var(--act); border-color: var(--act); color: #fff; }
.rate button.on span { color: rgba(255,255,255,.9); }
.auto { font-size: 13px; color: var(--muted); }
.memo-toggle { font-size: 13px; background: none; border: 0; color: var(--brand); padding: 6px 0; min-height: 32px; }

/* ---- カウンター ---- */
.counter-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.counter-row:first-child { border-top: 0; }
.counter-row .clabel { flex: 1; font-size: 14px; }
.counter-row .clabel small { display: block; color: var(--muted); font-size: 12px; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button {
  width: 48px; height: 48px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-size: 22px; font-weight: 700;
}
.stepper button.plus { background: var(--brand); border-color: var(--brand); color: #fff; }
.stepper .val { min-width: 36px; text-align: center; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stepper.sm button { width: 40px; height: 40px; font-size: 18px; }
.stepper.sm .val { min-width: 28px; font-size: 17px; }

.subgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.cell { border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 4px; align-items: center; }
.cell .clabel { font-size: 13px; font-weight: 600; text-align: center; }

/* ---- 一覧 ---- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list a.row, .list .row { display: flex; align-items: center; gap: 12px; padding: 12px 0; text-decoration: none; color: var(--ink); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 700; }
.row .meta { font-size: 13px; color: var(--muted); }
.chev { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }

.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.progress > i { display: block; height: 100%; background: var(--brand); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--brand-soft); color: var(--brand); }
.pill.gray { background: #eef0ee; color: var(--muted); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

.sectionnav { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sectionnav a {
  display: block; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  text-decoration: none; color: var(--ink); font-weight: 600; font-size: 14px;
  border-left: 5px solid var(--el, var(--brand));
}
.sectionnav a small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }

.warnbox { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 8px 12px; font-size: 13px; margin: 8px 0; }

.pager { display: flex; gap: 8px; margin: 18px 0 32px; }
.pager .btn { flex: 1; }

/* ---- 分析結果 ---- */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { background: var(--bg); border-radius: 10px; padding: 10px; }
.kpi .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 26px; font-weight: 800; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi .v small { font-size: 12px; font-weight: 600; color: var(--muted); }
.kpi .d { font-size: 12px; color: var(--muted); }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); margin: 6px 0 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

.barrow { padding: 10px 0; border-top: 1px solid var(--line); }
.barrow:first-of-type { border-top: 0; }
.barrow .bl { font-size: 13.5px; margin-bottom: 4px; }
.bar { display: grid; grid-template-columns: 34px 1fr 36px; align-items: center; gap: 6px; margin: 3px 0; }
.bar .t { font-size: 11px; font-weight: 700; color: var(--muted); }
.bar .track { position: relative; height: 14px; background: #eef0ee; border-radius: 4px; }
.bar .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; }
.bar .fill.subj { background: var(--subj); }
.bar .fill.act { background: var(--act); }
.bar .fill.neutral { background: var(--el, var(--brand)); }
.bar .past { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); opacity: .55; }
.bar .grid { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(0,0,0,.08); }
.bar .num { font-size: 13px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.bar .num.none { color: var(--muted); font-weight: 400; }
.spread { font-size: 11px; color: var(--muted); }

.stack { display: flex; height: 22px; border-radius: 6px; overflow: hidden; background: #eef0ee; }
.stack i { display: block; height: 100%; }
.stackrow { display: grid; grid-template-columns: 64px 1fr; gap: 8px; align-items: center; margin: 6px 0; font-size: 13px; }
.stacklegend { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.stacklegend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

.donuts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.donut { text-align: center; min-width: 0; }
.donut .label { font-size: 13px; line-height: 1.3; min-height: 2.6em; display: flex; align-items: flex-end; justify-content: center; }
.donut .ring { width: min(120px, 100%); aspect-ratio: 1; margin: 6px auto; border-radius: 50%; position: relative; }
.donut .ring::after { content: ""; position: absolute; inset: 18%; background: var(--surface); border-radius: 50%; }
.donut .ring b { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 1; font-size: 18px; }
.donut .cap { font-size: 12px; color: var(--muted); }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th, .tbl td { text-align: left; padding: 7px 6px; border-top: 1px solid var(--line); vertical-align: top; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 700; }
.tbl td.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tblwrap { overflow-x: auto; }
.ans { display: inline-block; min-width: 40px; text-align: center; border-radius: 6px; padding: 0 6px; font-weight: 700; font-size: 12px; }
.ans.y { background: var(--brand-soft); color: var(--brand); }
.ans.n { background: #fbe4e1; color: var(--danger); }
.ans.u { background: #eef0ee; color: var(--muted); }

.insight { border-radius: 10px; padding: 10px 12px; margin: 8px 0; background: var(--bg); }
.insight h4 { margin: 0 0 4px; font-size: 14px; }
.insight ul { margin: 0; padding-left: 18px; font-size: 13.5px; }
.insight li { margin: 3px 0; }
.insight .sc { color: var(--muted); font-size: 12px; white-space: nowrap; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #1f2a24; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 50;
  box-shadow: 0 4px 16px rgba(0,0,0,.2); max-width: calc(100% - 32px);
}

@media (max-width: 420px) {
  main { padding: 12px; }
  .card { padding: 14px; }
  .kpi .v { font-size: 22px; }
  .grid2 { grid-template-columns: 1fr; }
}

/* ---- 印刷（分析結果のレポート） ---- */
@media print {
  body { background: #fff; font-size: 12px; }
  .topbar, .tabs, .noprint, .btnrow, .pager { display: none !important; }
  main { max-width: none; padding: 0; }
  .card { break-inside: avoid; border: 1px solid #ccc; }
  .barrow { break-inside: avoid; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---- 同期状態 ---- */
.syncbar { font-size: 12.5px; padding: 6px 16px; background: var(--brand-soft); color: var(--brand); text-align: center; }
.syncbar.warn { background: var(--warn-soft); color: var(--warn); }
.syncbar.err { background: #fbe4e1; color: var(--danger); }
.syncbar:empty { display: none; }
.linkbtn { background: none; border: 0; padding: 0 4px; color: inherit; text-decoration: underline; font-size: inherit; font-weight: 700; }
.btn:disabled { opacity: .5; }
input:disabled { opacity: .6; }
.tbl.trend { font-size: 12.5px; }
.tbl.trend th, .tbl.trend td { padding: 6px 4px; white-space: nowrap; }
