/* オンオフノート */
:root {
  --bg: #f9f9f7;
  --card: #ffffff;
  --text: #2b2b28;
  --sub: #8a8a84;
  --line: #e8e6e0;
  --accent: #4e9e79;
  --accent-soft: #e2f3e9;
  --none: #edebe5;
  --c-on: #7ac68f;
  --c-off: #93accb;
  --c-dysk: #f2a45c;
  --c-sleep: #b3aede;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0d0d;
    --card: #1c1c1e;
    --text: #f0f0ec;
    --sub: #9a9a94;
    --line: #33332f;
    --accent: #6cbf94;
    --accent-soft: #24382e;
    --none: #2c2c2e;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  line-height: 1.55;
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}

.app-header {
  padding: calc(14px + env(safe-area-inset-top)) 20px 6px;
}
.app-title { font-size: 1.25rem; margin: 0; }

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

.card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  margin-top: 14px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .05);
}
.card-title { font-size: 1rem; margin: 0 0 10px; color: var(--sub); font-weight: 600; }
.chart-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.chart-head .card-title { margin: 0; }

/* --- 日付ナビ --- */
.day-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.day-label-wrap { text-align: center; }
.day-label { font-size: 1.15rem; font-weight: 700; }
.icon-btn {
  background: none; border: none; font-size: 1.2rem; padding: 10px 14px;
  color: var(--text); cursor: pointer; border-radius: 12px;
}
.icon-btn:disabled { opacity: .25; }
.mini-btn {
  background: var(--accent-soft); color: var(--accent); border: none;
  border-radius: 999px; padding: 6px 14px; font-size: .85rem; font-weight: 700; cursor: pointer;
}

/* --- いまの状態 --- */
.now-card { text-align: center; padding: 12px 16px; }
.now-label { font-size: .8rem; color: var(--sub); }
.now-state { font-size: 1.1rem; font-weight: 700; margin-top: 4px; }
.now-chip { padding: 4px 14px; border-radius: 999px; color: #2b2b28; }
.chip-on { background: var(--c-on); }
.chip-off { background: var(--c-off); }
.chip-dysk { background: var(--c-dysk); }
.chip-sleep { background: var(--c-sleep); }
.now-since { margin-left: 10px; font-size: .9rem; color: var(--sub); font-weight: 400; }

/* --- 状態ボタン --- */
.state-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px;
}
.state-btn {
  min-height: 76px; border-radius: 18px; border: 3px solid transparent;
  font-size: 1.15rem; font-weight: 700; cursor: pointer; color: #2b2b28;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.st-emoji { font-size: 1.5rem; }
.st-on { background: #dff2e4; }
.st-off { background: #e2eaf4; }
.st-dysk { background: #fbe8d4; }
.st-sleep { background: #e9e7f7; }
.state-btn.active { border-color: var(--accent); }
.state-btn:active { transform: scale(.97); }

.sub-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.sub-btn {
  min-height: 58px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--card); color: var(--text);
  font-size: 1.05rem; font-weight: 700; cursor: pointer;
}

/* --- タイムライン --- */
.timeline { margin-top: 4px; }
.tl-bar {
  position: relative; height: 36px; border-radius: 8px;
  background: var(--none); overflow: visible; margin-top: 14px;
}
.timeline.compact .tl-bar { height: 20px; margin-top: 8px; border-radius: 5px; }
.tl-seg { position: absolute; top: 0; height: 100%; }
.tl-seg:first-child { border-radius: 8px 0 0 8px; }
.seg-on { background: var(--c-on); }
.seg-off { background: var(--c-off); }
.seg-dysk { background: var(--c-dysk); }
.seg-sleep { background: var(--c-sleep); }
.tl-med {
  position: absolute; top: -14px; transform: translateX(-50%);
  font-size: 12px; line-height: 1;
}
.timeline.compact .tl-med { top: -10px; font-size: 9px; }
.tl-ticks {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--sub); margin-top: 3px;
}

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 12px; font-size: .8rem; color: var(--sub); }
.lg-item { display: inline-flex; align-items: center; gap: 5px; }
.lg-chip { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.lg-none { background: var(--none); border: 1px solid var(--line); }

/* --- 記録リスト --- */
.entry-list { display: flex; flex-direction: column; }
.entry-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0; border-bottom: 1px solid var(--line);
}
.entry-row:last-child { border-bottom: none; }
.entry-time { font-weight: 700; min-width: 56px; font-variant-numeric: tabular-nums; }
.entry-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-row .icon-btn { padding: 6px 8px; font-size: 1rem; }
.empty-msg { color: var(--sub); font-size: .9rem; padding: 8px 0; }

/* --- りれき --- */
.history-rows { display: flex; flex-direction: column; }
.hist-row {
  display: grid; grid-template-columns: 78px 1fr; gap: 8px; align-items: center;
  padding: 5px 0; background: none; border: none; text-align: left;
  font-size: .85rem; color: var(--text); cursor: pointer; width: 100%;
  font-family: inherit;
}
.hist-head { cursor: default; padding: 0; }
.hist-head .tl-ticks { margin: 0; }
.hist-date { font-weight: 600; }

.stats-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.stat-tile { border-radius: 14px; padding: 12px 8px; text-align: center; color: #2b2b28; }
.tile-on { background: #dff2e4; }
.tile-off { background: #e2eaf4; }
.tile-dysk { background: #fbe8d4; }
.stat-name { font-size: .8rem; font-weight: 600; }
.stat-hours { font-size: 1.5rem; font-weight: 800; margin-top: 2px; }
.stat-unit { font-size: .8rem; font-weight: 600; margin-left: 2px; }

/* --- ボタン類 --- */
.primary-btn {
  width: 100%; min-height: 56px; border: none; border-radius: 16px;
  background: var(--accent); color: #fff; font-size: 1.1rem; font-weight: 700;
  cursor: pointer; margin-top: 14px;
}
.ghost-btn {
  width: 100%; min-height: 50px; border: 1px dashed var(--sub); border-radius: 14px;
  background: none; color: var(--text); font-size: 1rem; font-weight: 600;
  cursor: pointer; margin-top: 10px;
}
.data-note { font-size: .8rem; color: var(--sub); margin: 10px 0 0; }

/* --- タブバー --- */
.tab-bar {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-btn {
  flex: 1; background: none; border: none; padding: 10px 0 8px;
  font-size: .8rem; font-weight: 700; color: var(--sub); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-family: inherit;
}
.tab-btn.active { color: var(--accent); }
.tab-emoji { font-size: 1.35rem; }

/* --- シート --- */
.sheet-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 50;
  display: flex; align-items: flex-end;
}
.sheet {
  background: var(--card); width: 100%; max-width: 640px; margin: 0 auto;
  border-radius: 20px 20px 0 0; padding: 16px 20px calc(24px + env(safe-area-inset-bottom));
  max-height: 80vh; overflow-y: auto;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h3 { margin: 0; font-size: 1.1rem; }
.sheet-note { color: var(--sub); font-size: .9rem; margin: 8px 0; }
.field-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.field-label { font-size: .9rem; color: var(--sub); font-weight: 600; min-width: 48px; }
.time-input, .text-input {
  flex: 1; font-size: 1.2rem; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--bg); color: var(--text); font-family: inherit;
}
.memo-input {
  width: 100%; min-height: 90px; margin-top: 12px; font-size: 1.05rem;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--text); font-family: inherit; resize: vertical;
}
.sheet-med-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.sheet-med-btn {
  min-height: 58px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 1.1rem; font-weight: 700;
  cursor: pointer; font-family: inherit;
}

/* --- トースト --- */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(78px + env(safe-area-inset-bottom));
  background: #2b2b28; color: #fff; border-radius: 14px; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: .9rem; z-index: 40; max-width: 600px; margin: 0 auto;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
}
.undo-btn {
  background: none; border: none; color: #ffd35c; font-weight: 700;
  font-size: .95rem; cursor: pointer; white-space: nowrap; font-family: inherit;
}

/* --- 印刷レポート --- */
#printView { display: none; }

@media print {
  body > *:not(#printView) { display: none !important; }
  body { padding: 0; background: #fff; color: #000; font-size: 12px; }
  #printView { display: block; padding: 10mm; }
  .p-title { font-size: 18px; margin: 0 0 4px; }
  .p-meta { color: #555; font-size: 11px; }
  .p-name { margin-top: 6px; font-size: 12px; border-bottom: 1px solid #999; width: 200px; padding-bottom: 2px; }
  #printView .legend { margin: 8px 0 2px; color: #333; }
  .p-meds { font-size: 11px; margin: 4px 0 8px; }
  .p-row { display: grid; grid-template-columns: 70px 1fr; gap: 8px; align-items: start; padding: 3px 0; break-inside: avoid; }
  .p-head { padding: 0; }
  .p-head .tl-ticks { margin: 0; }
  .p-date { font-size: 11px; font-weight: 600; padding-top: 8px; }
  .p-head .p-date { padding-top: 0; }
  .p-notes { font-size: 9.5px; color: #333; margin-top: 1px; }
  .p-foot { margin-top: 10px; font-size: 9px; color: #999; text-align: right; }
  #printView .tl-bar { background: #eee; }
  .tl-seg, .lg-chip, .tl-bar {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
