/* 見た目のテーマ。初期値は「やわらかい」、body[data-theme='simple'] で以前の見た目に戻す */
:root {
  --bg: #fdf7ef;
  --card: #ffffff;
  --text: #33302e;
  --muted: #6f6a66;
  --line: #eadfd2;
  --blue: #2a73b2;
  --blue-light: #e3f1fc;
  --blue-border: #9fcbef;
  --water: #7cc2f0;
  --ok: #5aa8e4;
  --warn: #d9a300;
  --warn-bg: #fff4cc;
  --reached: #d97200;
  --reached-bg: #ffe8cf;
  --over: #cc3340;
  --over-bg: #fde2e4;
  --green: #2f8a5b;
  --font: 'Hiragino Maru Gothic ProN', 'ヒラギノ丸ゴ ProN', 'BIZ UDPGothic', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  --card-radius: 24px;
  --card-shadow: 0 2px 0 #f1e6d8, 0 6px 16px rgba(120, 90, 60, .07);
  --btn-radius: 22px;
  --btn-font: 2.1rem;
  --btn-h: 4.8rem;
  --base: 1.25rem;
}
body[data-theme='simple'] {
  --bg: #f4f7fb;
  --text: #1a1f29;
  --muted: #5b6575;
  --line: #d5dce6;
  --blue: #1f5f99;
  --blue-light: #e3eef8;
  --blue-border: #1f5f99;
  --water: #9fc9ec;
  --ok: #2f7fc1;
  --warn: #c99700;
  --warn-bg: #fff6d6;
  --reached: #d26a00;
  --reached-bg: #ffe9d4;
  --over: #c0262d;
  --over-bg: #fde3e4;
  --green: #1e7d45;
  --font: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  --card-radius: 18px;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, .08);
  --btn-radius: 16px;
}
body[data-theme='simple'] .mascot,
body[data-theme='simple'] .overlay-mascot { display: none; }
body[data-size='normal'] { --btn-font: 1.8rem; --btn-h: 4rem; --base: 1.15rem; }
body[data-size='xlarge'] { --btn-font: 2.8rem; --btn-h: 7rem; --base: 1.4rem; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--base);
  line-height: 1.5;
}
button, input { font: inherit; }
button { touch-action: manipulation; cursor: pointer; }
.loading, .fatal { padding: 2rem; text-align: center; }

/* ---------- 患者モード ---------- */
.patient {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 3.3rem) .8rem max(1.5rem, env(safe-area-inset-bottom));
  position: relative;
  /* 長押しで文字が選択されたり拡大鏡が出たりしないようにする */
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.patient input { -webkit-user-select: text; user-select: text; }
.card {
  background: var(--card);
  border-radius: var(--card-radius);
  padding: .9rem 1rem;
  margin-bottom: .7rem;
  text-align: center;
  box-shadow: var(--card-shadow);
}
.card-tight { padding: .6rem 1rem; }
.p-title { font-size: 1.5rem; margin: 0; }
.p-date { font-size: 1.5rem; margin: 0 0 .6rem; color: var(--muted); }
.p-sub { font-size: 1.2rem; margin: 0 0 .3rem; color: var(--muted); font-weight: 600; display: flex; align-items: center; justify-content: center; gap: .3rem; }
.big-number { font-size: 2.8rem; font-weight: 700; margin: 0 0 .4rem; font-variant-numeric: tabular-nums; }
.big-number .slash { font-size: 2rem; color: var(--muted); }
.bar { height: 26px; background: #eef4fa; border-radius: 15px; overflow: hidden; border: 2px solid var(--blue-border); }
.bar-fill { height: 100%; background: var(--ok); border-radius: 0 13px 13px 0; box-shadow: inset 0 5px 0 rgba(255, 255, 255, .3); }
.level-warn .bar-fill { background: var(--warn); }
.level-reached .bar-fill { background: var(--reached); }
.level-over .bar-fill { background: var(--over); }
.rest { font-size: 1.6rem; margin: .2rem 0 0; }
.rest strong { font-size: 2.2rem; }
.level-text-warn { color: #8a6800; }
.level-text-reached { color: var(--reached); }
.level-text-over { color: var(--over); }
.notice { font-size: 1.15rem; font-weight: 700; border-radius: 12px; padding: .45rem .7rem; margin: .4rem 0 0; text-align: left; line-height: 1.35; }
.notice-none { background: var(--blue-light); }
.notice-warn { background: var(--warn-bg); border: 3px solid var(--warn); }
.notice-reached { background: var(--reached-bg); border: 3px solid var(--reached); }
.notice-over { background: var(--over-bg); border: 3px solid var(--over); }
.last-line { margin: 0; }
.last-time { font-size: 2.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.last-elapsed { font-size: 1.3rem; color: var(--muted); }
.last-none { font-size: 1.5rem; margin: .4rem 0; }

.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.quick, .quick-other, .primary-big {
  min-height: var(--btn-h);
  font-size: var(--btn-font);
  font-weight: 700;
  border-radius: var(--btn-radius);
  border: 3px solid var(--blue-border);
  background: var(--blue-light);
  color: var(--blue);
  box-shadow: 0 3px 0 var(--blue-border);
  -webkit-user-select: none;
  user-select: none;
}
.quick { display: flex; align-items: center; justify-content: center; gap: .2em; padding: 0 .3rem; }
.quick small { font-size: .55em; align-self: flex-end; margin-bottom: .55em; }
.cup { width: .85em; height: 1.05em; flex: 0 0 auto; color: var(--blue); }
.cup-water { fill: var(--water); }
.quick:active, .quick-other:active, .primary-big:active { background: var(--blue); color: #fff; box-shadow: 0 1px 0 var(--blue-border); transform: translateY(2px); }
.quick:active .cup { color: #fff; }
.quick-other { width: 100%; margin-top: .6rem; min-height: calc(var(--btn-h) * .75); font-size: calc(var(--btn-font) * .75); background: #fff; }
.primary-big { width: 100%; background: var(--blue); color: #fff; }
.link-button {
  display: block; width: 100%;
  min-height: 4rem;
  font-size: 1.5rem; font-weight: 700;
  background: #fff; color: var(--blue);
  border: 2px solid var(--line); border-radius: var(--btn-radius);
}

.staff-entry {
  position: absolute; top: calc(env(safe-area-inset-top) + .4rem); right: .4rem;
  width: 5.6rem; height: 2.6rem;
  font-size: .9rem; color: var(--muted);
  background: #fff; border: 1px solid var(--line); border-radius: 999px;
  overflow: hidden; padding: 0;
  touch-action: none; /* 押している途中に画面のスクロールと判定されないようにする */
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  z-index: 2;
}
.staff-entry.pressing { border: 2px solid var(--blue); color: var(--blue); font-weight: 700; }
.staff-entry-fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0;
  background: var(--blue-light);
}
.staff-hint {
  position: absolute; top: calc(env(safe-area-inset-top) + 3.3rem); right: .4rem; z-index: 3;
  max-width: 16rem; margin: 0; padding: .5rem .7rem;
  background: #1a1f29; color: #fff; font-size: 1rem; line-height: 1.4; border-radius: 8px;
}
.staff-entry-label { position: relative; }
.p-top {
  position: absolute; top: calc(env(safe-area-inset-top) + .25rem); left: .9rem; right: 6.6rem;
  height: 2.9rem; display: flex; align-items: center; gap: .45rem;
}
.mascot { width: 2.6rem; flex: 0 0 auto; }
.mascot svg { width: 100%; height: auto; display: block; }
.p-top-date { font-size: 1.35rem; margin: 0; white-space: nowrap; }
.icon-inline { width: 1.05em; height: 1.05em; }

.other-label { display: flex; align-items: baseline; justify-content: center; gap: .5rem; font-size: 2rem; margin: 1rem 0 .5rem; }
.other-input {
  width: 8ch; font-size: 3rem; text-align: right; font-family: inherit;
  padding: .3rem .5rem; border: 3px solid var(--blue-border); border-radius: 16px;
}
.error { color: var(--over); font-weight: 700; min-height: 1.5em; margin: .3rem 0; }

.history { list-style: none; padding: 0; margin: .5rem 0; font-size: 1.9rem; font-variant-numeric: tabular-nums; }
.history li, .history-total { display: flex; justify-content: space-between; padding: .45rem .6rem; border-bottom: 1px solid var(--line); }
.history-total { font-size: 2rem; font-weight: 700; border-bottom: none; border-top: 3px solid var(--text); margin: 0; }

.overlay {
  position: fixed; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #fff; text-align: center; padding: 2rem;
}
.overlay-ok { background: var(--green); }
.overlay-undone { background: #5d6270; }
.overlay-mascot { width: 5.5rem; margin-bottom: .6rem; }
.overlay-mascot svg { width: 100%; height: auto; display: block; }
.overlay-title { font-size: 3rem; font-weight: 800; margin: 0; }
.overlay-amount { font-size: 4rem; font-weight: 800; margin: .5rem 0 0; }
.overlay-time { font-size: 2rem; margin: 0 0 3rem; }
.overlay-undo {
  font-size: 1.3rem; padding: .9rem 1.4rem;
  background: transparent; color: #fff; border: 2px solid #fff; border-radius: 999px;
}

/* ---------- 支援者モード ---------- */
.staff { max-width: 960px; margin: 0 auto; padding: max(.8rem, env(safe-area-inset-top)) .8rem 2rem; font-size: 1rem; }
.s-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: .6rem; }
.s-header h1 { font-size: 1.4rem; margin: 0; }
.s-who { margin: 0; color: var(--muted); }
.s-card { background: var(--card); border-radius: calc(var(--card-radius) * .67); padding: 1rem; margin-bottom: .8rem; box-shadow: var(--card-shadow); }
.s-card h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
.s-note { color: var(--muted); font-size: .9rem; margin: 0 0 .6rem; }
.s-warn { background: var(--warn-bg); border: 1px solid var(--warn); border-radius: 8px; padding: .6rem .8rem; margin: 0 0 .8rem; }
.s-btn {
  min-height: 2.6rem; padding: .3rem .9rem;
  border: 1px solid var(--blue); border-radius: 8px;
  background: #fff; color: var(--blue); font-size: 1rem;
}
.s-btn:disabled { opacity: .4; }
.s-primary { background: var(--blue); color: #fff; }
.s-small { min-height: 2.2rem; padding: .2rem .6rem; font-size: .9rem; }
.s-btn-wide { min-width: 10rem; }
.s-link { border: none; background: none; color: var(--blue); text-decoration: underline; padding: 0 .3rem; }
.s-tabs { display: flex; gap: .3rem; overflow-x: auto; margin-bottom: .8rem; }
.s-tab { flex: 1 0 auto; min-height: 2.8rem; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 0 .8rem; color: var(--text); }
.s-tab.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.s-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.s-form { display: grid; gap: .7rem; max-width: 420px; }
.s-form label { display: grid; gap: .2rem; }
.s-input { min-height: 2.6rem; padding: .3rem .5rem; border: 1px solid var(--line); border-radius: 8px; font-size: 1rem; }
.s-num { width: 6rem; text-align: right; }
.s-big { font-size: 2rem; font-weight: 700; margin: 0; }
.staff-list { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.date-nav { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .8rem; }
.date-nav strong { font-size: 1.2rem; }
.s-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .5rem; margin-bottom: .6rem; }
.s-stats div { background: var(--bg); border-radius: 8px; padding: .5rem .7rem; display: grid; }
.s-stats span { color: var(--muted); font-size: .85rem; }
.s-stats strong { font-size: 1.3rem; }
.table-wrap { overflow-x: auto; }
.s-table { width: 100%; border-collapse: collapse; }
.s-table th, .s-table td { border-bottom: 1px solid var(--line); padding: .45rem .4rem; text-align: left; vertical-align: top; }
.s-table th { font-size: .85rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.s-table td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.s-table td.ops { white-space: nowrap; }
.s-table tr.deleted td:not(.ops) { color: #9aa3b0; text-decoration: line-through; }
.s-table tr.clickable { cursor: pointer; }
.s-table tr.clickable:hover { background: var(--blue-light); }
.tag { display: inline-block; padding: .05rem .45rem; border-radius: 6px; font-size: .85rem; white-space: nowrap; }
.tag-ok { background: #ddf2e5; color: var(--green); }
.tag-un { background: var(--warn-bg); color: #8a6800; }
.tag-del { background: #eceff3; color: var(--muted); text-decoration: none; }
.gaps { margin: 0; padding-left: 1.2rem; color: var(--over); font-weight: 600; }
.audit { font-size: .9rem; padding-left: 1.2rem; }
.radio { display: inline-flex; gap: .3rem; align-items: center; margin-right: 1rem; }
.file-btn { display: inline-flex; align-items: center; }

/* ---------- Phase 2 ---------- */
.s-alert {
  display: flex; gap: .6rem; align-items: flex-start;
  background: var(--over-bg); border: 2px solid var(--over); border-radius: 8px;
  padding: .6rem .8rem; margin: 0 0 .8rem; font-weight: 600;
}
.s-alert-icon {
  flex: 0 0 auto; width: 1.4rem; height: 1.4rem; border-radius: 50%;
  background: var(--over); color: #fff; font-weight: 800; text-align: center; line-height: 1.4rem;
}
.check { display: inline-flex; align-items: center; gap: .3rem; }
.s-label { display: block; margin-bottom: .2rem; }
.s-form-wide { max-width: none; margin-bottom: .6rem; }
.radio-group { gap: .2rem .4rem; }
.radio-group .radio { margin-right: .4rem; min-height: 2.2rem; }
.seg { margin-bottom: .5rem; }

.c-wrap { position: relative; }
.c-svg { width: 100%; height: auto; display: block; overflow: visible; }
.c-grid { stroke: #e6e9ee; stroke-width: 1; }
.c-axis { fill: var(--muted); font-size: 11px; }
.c-label { fill: var(--muted); font-size: 11px; }
.c-ref { fill: none; stroke: #52514e; stroke-width: 1.5; stroke-dasharray: 5 4; }
.c-bridge { fill: none; stroke-width: 1.5; stroke-dasharray: 3 4; opacity: .6; }
.c-dot { stroke: #fff; stroke-width: 2; }
.c-hit { fill: transparent; }
.c-hit.active { fill: rgba(31, 95, 153, .07); }
.c-legend { display: flex; flex-wrap: wrap; gap: .3rem 1rem; font-size: .9rem; margin-bottom: .3rem; }
.c-legend i { display: inline-block; width: .8rem; height: .8rem; border-radius: 3px; margin-right: .3rem; vertical-align: -1px; }
.c-tip {
  position: absolute; top: 0; transform: translateX(-50%);
  background: #1a1f29; color: #fff; font-size: .85rem; line-height: 1.4;
  padding: .4rem .6rem; border-radius: 6px; white-space: pre; pointer-events: none;
}
.chart-empty { color: var(--muted); }
.s-table td:first-child { white-space: nowrap; }

/* ---------- 患者版：最初の設定画面 ---------- */
.setup { max-width: 560px; }
.setup-head { display: flex; gap: .8rem; align-items: center; }
.setup-head h1 { font-size: 1.3rem; margin: 0 0 .3rem; }
.setup-head .mascot { width: 3rem; }
.staff details summary { cursor: pointer; color: var(--blue); margin: .4rem 0; }
.setup-app { margin: 0; font-size: 1rem; font-weight: 700; color: var(--blue); }

/* 上限量の出どころを添える一行と、「このアプリについて」 */
.limit-note { font-size: .95rem; color: var(--muted); margin: -.5rem 0 .35rem; white-space: nowrap; }
.about-p { margin: 0 0 .6rem; line-height: 1.6; }
.about-warn {
  margin: 0 0 .6rem; line-height: 1.6; font-weight: 700;
  background: var(--warn-bg); border: 2px solid var(--warn); border-radius: 10px; padding: .5rem .7rem;
}
