/*
 * 利用者日報MVP — スタイル
 *
 * 決定事項 D-08: スマホ幅で動かすことが最優先。20〜30項目の巨大フォームにしない。
 *
 * 現場条件（docs/04_SCREENS_DRAFT.md §9）:
 *   ・夜勤帯に暗い場所で使う      → ダークテーマ対応
 *   ・手袋・急いでいる            → タップ領域 最小44px、主要ボタン56px以上
 *   ・高齢の職員も使う            → 本文16px以上。小さい灰色文字を使わない
 *   ・片手で持って入力する        → 主要操作は画面下部
 */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #16181d;
  --text-muted: #565b66;
  --border: #d3d7de;
  --primary: #1b5fb3;
  --primary-text: #ffffff;
  --trial-bg: #8a4b00;
  --trial-text: #ffffff;
  --danger: #a3231d;
  --accent-handover: #8a4b00;
  --tap-min: 44px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1e2126;
    --surface-2: #262a31;
    --text: #f0f2f5;
    --text-muted: #b3b9c4;
    --border: #3a3f48;
    --primary: #4d94e8;
    --primary-text: #0d1015;
    --trial-bg: #b8792a;
    --trial-text: #1a1208;
    --danger: #ef8a84;
    --accent-handover: #d9a05b;
  }
}

* { box-sizing: border-box; }

/*
 * hidden 属性は必ず非表示にする。
 * ★これが無いと、display: flex を指定した要素（.vital-row / .choice-row / .occurred-row）で
 *   hidden が効かず、血糖の欄が対象外の人にも出たり、緊急用の「起きた時刻」「その後」が
 *   通常の記録画面に出たりしていた（2026-09-11 実画面で発見）。
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
               "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

/* ---- 試用バナー：閉じられない・常時表示 ---------------------------- */

.trial-banner {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 100;
  padding: 8px 12px;
  background: var(--trial-bg);
  color: var(--trial-text);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
}

/* ---- 画面の骨格 ---------------------------------------------------- */

.view {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding-top: var(--banner-height, 0px);
}

.view[hidden] { display: none; }

.topbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.topbar-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar-title {
  font-size: 18px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-context {
  font-size: 13px;
  color: var(--text-muted);
}

.scroll-area {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 12px;
}

.sticky-footer {
  flex: 0 0 auto;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

/* ---- ボタン -------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 17px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}

.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:disabled { opacity: .55; cursor: default; }
.btn-block { width: 100%; }

.btn-plain {
  min-height: var(--tap-min);
  min-width: var(--tap-min);
  padding: 0 10px;
  border: 0;
  background: none;
  color: var(--primary);
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
}

.btn-back { font-size: 24px; line-height: 1; }

/* ---- ログイン ------------------------------------------------------ */

.login-box {
  margin: auto;
  padding: 20px;
  width: 100%;
  max-width: 380px;
}

.login-title { margin: 0 0 24px; font-size: 24px; }
.login-sub {
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--trial-bg);
  color: var(--trial-text);
  font-size: 13px;
  vertical-align: middle;
}

.field { display: block; margin-bottom: 16px; }
.field-label { display: block; margin-bottom: 6px; font-size: 14px; color: var(--text-muted); }

.field input {
  width: 100%;
  min-height: var(--tap-min);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px; /* iOSで自動ズームさせないため16px以上 */
  font-family: inherit;
}

.hint { margin: 14px 0 0; font-size: 13px; color: var(--text-muted); text-align: center; }
.error-text { margin: 12px 0 0; color: var(--danger); font-size: 15px; font-weight: 700; }
.empty-text, .loading-text {
  margin: 24px 0;
  color: var(--text-muted);
  font-size: 15px;
  text-align: center;
}

/* ---- 利用者一覧 ---------------------------------------------------- */

.resident-list { margin: 0; padding: 0; list-style: none; }

.resident-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 76px;      /* 大きなタップ領域 */
  margin-bottom: 10px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}

.resident-name { font-size: 19px; font-weight: 700; }
.resident-meta { margin-top: 2px; font-size: 14px; color: var(--text-muted); }
.resident-meta.is-missing { color: var(--danger); font-weight: 700; }
.resident-chevron { color: var(--text-muted); font-size: 20px; flex: 0 0 auto; }

/* ---- タイムライン -------------------------------------------------- */

.date-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 10px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 700;
}
.date-heading::before,
.date-heading::after {
  content: "";
  flex: 1 1 auto;
  height: 1px;
  background: var(--border);
}
.date-heading:first-child { margin-top: 0; }

.entry {
  margin-bottom: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.entry.is-handover { border-left-color: var(--accent-handover); }

.entry-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 14px;
  color: var(--text-muted);
}

.entry-time { font-size: 16px; font-weight: 700; color: var(--text); }

.tag {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 700;
}
.tag-handover { background: var(--accent-handover); color: var(--trial-text); }

.entry-text { margin: 0; white-space: pre-wrap; word-break: break-word; }
.entry-sub {
  margin: 8px 0 0;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  font-size: 14px;
  color: var(--text-muted);
}

/* ---- 記録する ------------------------------------------------------ */

.compose-text {
  display: block;
  width: 100%;
  min-height: 40vh;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 17px;
  font-family: inherit;
  line-height: 1.7;
  resize: vertical;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap-min);
  margin: 14px 0 6px;
  font-size: 16px;
  cursor: pointer;
}
.toggle input { width: 22px; height: 22px; }

.choices { margin-top: 8px; }

.choice-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.choice-label {
  flex: 0 0 56px;
  font-size: 15px;
  color: var(--text-muted);
}

.choice-options { display: flex; flex: 1 1 auto; gap: 6px; }

.choice-btn {
  flex: 1 1 0;
  min-height: 48px;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}

.choice-btn[aria-pressed="true"] {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 700;
}

.vitals {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.vitals > summary {
  min-height: var(--tap-min);
  padding: 12px 14px;
  font-size: 15px;
  cursor: pointer;
}

.vitals-body { padding: 0 14px 14px; }

.vital-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.vital-label { flex: 0 0 48px; font-size: 15px; color: var(--text-muted); }
.vital-unit { flex: 0 0 auto; font-size: 14px; color: var(--text-muted); }
.vital-sep { color: var(--text-muted); }

.vital-row input {
  flex: 1 1 0;
  min-width: 0;
  min-height: var(--tap-min);
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}

/* ---- 広い画面 ------------------------------------------------------ */

@media (min-width: 700px) {
  .scroll-area, .sticky-footer, .topbar { padding-inline: max(12px, calc((100% - 640px) / 2)); }
}
