:root {
  --bg: #f5f6f8; --surface: #fff; --ink: #1c2230; --muted: #5d6677; --line: #d9dde5;
  --brand: #1f5fbf; --brand-ink: #fff; --ok: #1a7f4b; --warn: #a45b00; --bad: #c0302d;
  --sub: #eef2f9; --total: #e3ebf8; --pending: #f3e9d2;
  --tap: 44px; --radius: 10px; --gutter: 16px;
  --h1: 36px; /* PC表 見出し1段目の高さ */
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif;
  overflow-wrap: anywhere;
}
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { font-size: 16px; /* iOSの自動ズーム防止・16px以上 */ }
button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
a { color: var(--brand); }

/* ---- レイアウト ---- */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 6px var(--gutter); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-height: 52px;
}
.topbar .brand { font-weight: 700; }
.topbar .g-label { display: flex; align-items: center; gap: 6px; min-width: 0; }
.topbar .g-name { font-weight: 700; background: var(--sub); border-radius: 999px; padding: 4px 12px; max-width: 60vw; }
.topbar select { min-height: var(--tap); border: 1px solid var(--line); border-radius: 8px; padding: 0 8px; background: #fff; max-width: 55vw; }
.topbar .spacer { flex: 1; }
.sample-banner { background: #fff3cd; color: #6b4e00; padding: 6px var(--gutter); font-size: 14px; border-bottom: 1px solid #ecd58a; }
main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: var(--gutter) var(--gutter) 96px; min-width: 0; }
main.wide { max-width: none; padding-bottom: 96px; }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--surface); border-top: 1px solid var(--line);
  display: flex; padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1; min-height: 56px; display: flex; align-items: center; justify-content: center; text-align: center;
  text-decoration: none; color: var(--muted); font-size: 14px; font-weight: 600; padding: 4px 2px;
}
.nav a.on { color: var(--brand); box-shadow: inset 0 3px 0 var(--brand); }
@media (min-width: 900px) {
  .nav { position: sticky; top: 52px; bottom: auto; border-top: 0; border-bottom: 1px solid var(--line); justify-content: flex-start; }
  .nav a { flex: 0 0 auto; padding: 0 22px; min-height: var(--tap); }
  .nav a.on { box-shadow: inset 0 -3px 0 var(--brand); }
  main { padding-bottom: 40px; }
  main.wide { padding: 16px 20px 40px; }
}

h1 { font-size: 20px; margin: 4px 0 12px; }
h2 { font-size: 17px; margin: 22px 0 8px; }
h3 { font-size: 16px; margin: 16px 0 6px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0 0 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.muted { color: var(--muted); font-size: 14px; }
.empty { color: var(--muted); text-align: center; padding: 20px 0; }

/* ---- フォーム（縦1列・44px以上・16px以上） ---- */
form, .form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-weight: 700; font-size: 15px; display: flex; gap: 8px; align-items: center; }
.req { font-size: 11px; font-weight: 700; background: var(--bad); color: #fff; padding: 1px 6px; border-radius: 4px; }
.hint { color: var(--muted); font-size: 13px; }
.err { color: var(--bad); font-size: 14px; }
input[type=text], input[type=search], input[type=date], input[type=month], input[type=number], input[type=password], input[type=email], select, textarea {
  width: 100%; min-height: var(--tap); padding: 9px 12px; border: 1px solid #b9c0cd; border-radius: 8px; background: #fff;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 3px solid #9ec2f7; outline-offset: 1px; }
.btn {
  min-height: var(--tap); padding: 0 18px; border-radius: 8px; border: 1px solid #b9c0cd; background: #fff; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none; color: var(--ink);
  transition: transform 60ms, background-color 60ms;
}
.btn:active { transform: scale(0.98); background: #e8edf6; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:active { background: #174b97; }
.btn.danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.small { min-height: var(--tap); padding: 0 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.save-status { min-height: 22px; font-size: 14px; margin-top: 6px; font-weight: 600; }
.save-status.ok { color: var(--ok); } .save-status.warn { color: var(--warn); } .save-status.fail { color: var(--bad); }
.errbox { background: #fdeceb; color: var(--bad); border: 1px solid #f1b9b6; border-radius: 8px; padding: 10px 12px; }

.segmented { display: flex; gap: 8px; flex-wrap: wrap; }
.seg, .choice {
  flex: 1 1 auto; min-height: var(--tap); padding: 0 14px; border-radius: 8px; border: 1px solid #b9c0cd; background: #fff; font-weight: 700; cursor: pointer;
}
.seg:active, .choice:active { background: #e8edf6; }
.seg.on, .choice.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.choices { display: flex; flex-direction: column; gap: 8px; }
.choice { text-align: left; font-weight: 600; }
.reason-note { font-size: 13px; color: var(--muted); margin-top: 4px; }
.reason { display: flex; flex-direction: column; gap: 6px; }
.reason-body { display: flex; flex-direction: column; gap: 8px; }

/* ---- 人物選択 ---- */
.picker { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn { min-height: var(--tap); display: inline-flex; align-items: center; gap: 8px; border-radius: 999px; padding: 0 14px; background: var(--sub); border: 1px solid #9fb3d6; font-weight: 700; cursor: pointer; }
.chip-btn:active { background: #d7e2f4; }
.chip-btn .x { font-size: 18px; color: var(--muted); }
.results { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 8px; max-height: 40vh; overflow: auto; background: #fff; }
.results[hidden] { display: none; }
.result { width: 100%; min-height: var(--tap); text-align: left; padding: 0 14px; background: #fff; border: 0; border-bottom: 1px solid #eef0f4; display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.result:active { background: #e8edf6; }
.badge { font-size: 11px; background: var(--sub); border-radius: 4px; padding: 1px 6px; color: var(--brand); }

/* ---- 一覧・カード ---- */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.tabs a { flex: 1 0 auto; min-height: var(--tap); display: flex; align-items: center; justify-content: center; padding: 0 14px; border-radius: 8px; background: #fff; border: 1px solid var(--line); text-decoration: none; color: var(--ink); font-weight: 700; white-space: nowrap; }
.tabs a.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.frames { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 10px 0; }
@media (min-width: 560px) { .frames { grid-template-columns: repeat(4, 1fr); } }
.frame { min-height: 64px; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 700; }
.frame .n { font-size: 22px; }
.frame.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.chip { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: var(--sub); color: var(--brand); }
.chip.st-hold { background: #fff0d6; color: #8a5300; } .chip.st-machi_keiyaku { background: #e5f4ea; color: var(--ok); }
.chip.st-keiyaku_zumi { background: #dff3ff; color: #07608f; } .chip.st-closed { background: #eceef2; color: #555d6c; }
.case-title { font-weight: 700; font-size: 17px; }
.timeline { list-style: none; margin: 8px 0 0; padding: 0; border-left: 3px solid var(--line); }
.timeline li { margin: 0 0 10px; padding: 0 0 0 12px; position: relative; }
.timeline li::before { content: ''; position: absolute; left: -8px; top: 8px; width: 11px; height: 11px; background: var(--brand); border-radius: 50%; }
.timeline li.resched::before { background: #8a5300; }
.tl-head { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tl-body { font-size: 14px; color: #3a4252; }
.sub-panel { background: var(--sub); border-radius: 10px; padding: 12px; margin-top: 8px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.actions .btn { flex: 1 1 140px; }
.filters { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 12px; }
@media (min-width: 560px) { .filters.cols { grid-template-columns: repeat(2, 1fr); } }

/* ---- 出欠 ---- */
.roster { display: flex; flex-direction: column; gap: 6px; }
.att-row { display: flex; gap: 8px; align-items: stretch; }
.att-name { flex: 1 1 auto; min-height: var(--tap); display: flex; align-items: center; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: #fff; font-weight: 600; cursor: pointer; text-align: left; }
.att-name.on { background: #dff0e6; border-color: #7bbf98; color: #155c38; }
.att-after { flex: 0 0 96px; min-height: var(--tap); border-radius: 8px; border: 1px solid var(--line); background: #fff; font-weight: 600; cursor: pointer; }
.att-after.on { background: #e3ebf8; border-color: #8fa9d6; color: #1c4a96; }
.cat-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 10px 0 2px; }

/* ---- PC表 ---- */
.kpi-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.kpi-tools .month { display: flex; gap: 6px; align-items: center; }
.kpi-tools input[type=month] { width: 170px; }
.live { font-size: 13px; color: var(--muted); }
.live.on::before { content: '●'; color: var(--ok); margin-right: 4px; }
.live.off::before { content: '●'; color: var(--bad); margin-right: 4px; }
.table-wrap { overflow: auto; max-height: calc(100vh - 220px); border: 1px solid var(--line); border-radius: 8px; background: #fff; }
table.kpi { border-collapse: separate; border-spacing: 0; font-size: 13px; min-width: max-content; }
table.kpi th, table.kpi td { border-right: 1px solid #e3e6ec; border-bottom: 1px solid #e3e6ec; padding: 0 6px; text-align: center; white-space: nowrap; height: 32px; }
table.kpi thead th { position: sticky; background: #f0f3f9; z-index: 5; font-weight: 700; }
table.kpi thead tr:nth-child(1) th { top: 0; height: var(--h1); }
table.kpi thead tr:nth-child(2) th { top: var(--h1); }
table.kpi .name { position: sticky; left: 0; z-index: 4; background: #fff; text-align: left; min-width: 150px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; border-right: 2px solid #c7cdd9; }
table.kpi thead th.name { z-index: 8; background: #f0f3f9; }
table.kpi tr.subtotal td, table.kpi tr.subtotal .name { background: var(--sub); font-weight: 700; }
table.kpi tr.total td, table.kpi tr.total .name { background: var(--total); font-weight: 700; }
table.kpi td.num { cursor: pointer; min-width: 38px; }
table.kpi td.num:hover { background: #fff4c2; }
table.kpi td.num.zero { color: #9aa2b1; }
table.kpi td.pending { background: var(--pending); color: #7a5a1e; font-size: 11px; cursor: help; }
table.kpi th.gstart, table.kpi td.gstart { border-left: 2px solid #c7cdd9; }
.drawer { position: fixed; right: 0; top: 0; bottom: 0; width: min(460px, 100vw); background: #fff; z-index: 60; box-shadow: -4px 0 18px rgba(0, 0, 0, 0.18); display: flex; flex-direction: column; }
.drawer header { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.drawer .body { padding: 12px 16px; overflow: auto; flex: 1; }
.drawer li { margin-bottom: 10px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 84px; z-index: 80; background: #1c2230; color: #fff; padding: 10px 16px; border-radius: 8px; max-width: 90vw; }
.toast.fail { background: var(--bad); }
.setup-steps { display: flex; gap: 6px; margin-bottom: 12px; }
.setup-steps span { flex: 1; text-align: center; padding: 8px 4px; border-radius: 8px; background: #fff; border: 1px solid var(--line); font-size: 13px; font-weight: 700; }
.setup-steps span.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.match-line { border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: #fff; margin-bottom: 8px; }
.match-line .opt { display: flex; gap: 8px; align-items: center; min-height: var(--tap); }
.match-line input[type=radio], .check-row input[type=checkbox] { width: 24px; height: 24px; flex: none; }
.check-row { display: flex; align-items: center; gap: 12px; min-height: var(--tap); padding: 4px 0; border-bottom: 1px solid #eef0f4; }
.link-box { word-break: break-all; background: #f5f6f8; padding: 8px; border-radius: 6px; font-size: 13px; user-select: all; }

@media (max-width: 520px) { .topbar > .muted { display: none; } }
table.kpi tr.ghead td { background: #1f5fbf; color: #fff; font-weight: 700; text-align: left; height: 34px; }
table.kpi tr.ghead td.name { background: #174b97; }
table.kpi td.num.static { cursor: default; }
table.kpi td.num.static:hover { background: inherit; }
table.kpi tr.total td.num.static:hover { background: var(--total); }

/* ---- 推移（折れ線グラフ） ---- */
.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; margin-bottom: 8px; }
.chart-card { margin: 0; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px 6px; }
.chart-card figcaption { font-weight: 700; font-size: 15px; }
svg.chart { width: 100%; height: auto; display: block; }
svg.chart .grid { stroke: #e3e6ec; stroke-width: 1; }
svg.chart .tick { fill: #5d6677; font-size: 10px; }
svg.chart .line { fill: none; stroke: var(--brand); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
svg.chart .dot { fill: var(--brand); stroke: #fff; stroke-width: 1.5; }
svg.chart .dot.mock { fill: #fff; stroke: var(--brand); stroke-width: 2; }
svg.chart .val { fill: var(--ink); font-size: 11px; font-weight: 700; }
table.kpi th.mockcol, table.kpi td.mockcol { background: #fffaf0; }
table.kpi .mocktag { font-size: 10px; color: #8a5300; font-weight: 600; }
.analysis-card .big { font-size: 34px; font-weight: 800; line-height: 1.2; color: var(--brand); }
.analysis-card .small { font-size: 12px; margin: 2px 0 4px; }
svg.chart.spark { margin-top: 4px; }
