:root {
  color-scheme: light;
  --ink: #202a24;
  --muted: #667169;
  --line: #dce2dc;
  --paper: #f5f6f3;
  --surface: #fff;
  --accent: #286445;
  --accent-soft: #e7efe9;
  --danger: #a43e35;
  font: 16px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; color: var(--ink); background: var(--paper); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 224px; padding: 28px 18px; background: var(--surface); border-right: 1px solid var(--line); }
.brand, .mobile-brand, .login-brand { color: var(--ink); text-decoration: none; font-size: 26px; font-weight: 700; letter-spacing: -1.2px; }
.brand { display: inline-block; margin: 0 0 42px 10px; }
.nav { display: grid; gap: 3px; }
.nav-item { min-height: 42px; padding: 8px 12px; border: 0; border-radius: 5px; background: transparent; color: #46524a; text-align: left; font-size: 15px; }
.nav-item:hover { background: #f2f4f1; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.mobile-nav { display: none; }
.main-content { max-width: 1400px; margin-left: 224px; padding: 0 48px 48px; }
.topbar { height: 64px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.mobile-brand { display: none; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.save-status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.save-status i { width: 7px; height: 7px; border-radius: 50%; background: #6a9872; }
.page { display: none; max-width: 1080px; margin: 0 auto; padding: 32px 0 24px; }
.page.active { display: block; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: 30px; line-height: 1.2; letter-spacing: -.6px; font-weight: 650; }
h2 { margin-bottom: 3px; font-size: 17px; line-height: 1.3; font-weight: 650; }
h3 { margin-bottom: 4px; font-size: 15px; font-weight: 600; }
.subtitle, .section-head p { margin-bottom: 0; color: var(--muted); font-size: 14px; }
.date-control { display: flex; align-items: center; gap: 5px; padding: 3px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.date-control button, .calendar-top button { width: 36px; height: 36px; border: 0; border-radius: 4px; background: transparent; color: #435047; font-size: 21px; }
.date-control button:hover, .calendar-top button:hover { background: #f1f3f0; }
.date-control input { width: 148px; height: 36px; padding: 0 5px; border: 0; outline: 0; background: transparent; font-size: 14px; }
.completion-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; color: var(--muted); font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-card { min-width: 0; padding: 20px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.section-head { margin-bottom: 13px; }
.section-head p { margin-top: 3px; }
.field-block { padding: 13px 0 12px; border-top: 1px solid #edf0ed; }
.field-block.last { padding-bottom: 1px; }
.field-label { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 9px; font-size: 14px; font-weight: 550; }
.unit, .meaning { color: var(--muted); font-size: 12px; font-weight: 400; white-space: nowrap; }
.meaning.good { color: var(--accent); }
.rating { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; }
.rating-slider { width: 100%; height: 30px; margin: 0; appearance: none; background: transparent; cursor: pointer; touch-action: pan-y; }
.rating-slider:focus-visible { outline: 0; }
.rating-slider::-webkit-slider-runnable-track { height: 6px; border-radius: 4px; background: linear-gradient(to right, var(--accent) 0 var(--rating-fill), #dce2dc var(--rating-fill) 100%); }
.rating-slider::-moz-range-track { height: 6px; border-radius: 4px; background: linear-gradient(to right, var(--accent) 0 var(--rating-fill), #dce2dc var(--rating-fill) 100%); }
.rating-slider::-webkit-slider-thumb { width: 20px; height: 20px; margin-top: -7px; appearance: none; border: 2px solid var(--accent); border-radius: 50%; background: var(--surface); box-shadow: 0 1px 3px #0002; }
.rating-slider::-moz-range-thumb { width: 16px; height: 16px; border: 2px solid var(--accent); border-radius: 50%; background: var(--surface); box-shadow: 0 1px 3px #0002; }
.rating-slider:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--accent-soft), 0 1px 3px #0002; }
.rating-slider:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 4px var(--accent-soft), 0 1px 3px #0002; }
.rating.unset .rating-slider::-webkit-slider-thumb, .rating.unset .rating-slider::-moz-range-thumb { border-color: #89938b; }
.rating-meta { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 4px; color: var(--muted); font-size: 11px; line-height: 1.2; }
.rating-meta > span:first-child { justify-self: start; }
.rating-meta > span:last-child { justify-self: end; }
.rating-current { display: flex; align-items: center; justify-self: center; gap: 7px; }
.rating-meta output { min-width: 52px; color: var(--accent); font-size: 12px; font-weight: 700; text-align: center; }
.rating.unset .rating-meta output { color: var(--muted); font-weight: 400; }
.rating-clear { padding: 0 2px; border: 0; background: transparent; color: var(--muted); font-size: 11px; text-decoration: underline; }
.rating-clear[hidden] { display: none; }
.number-control { display: flex; align-items: center; gap: 8px; }
.number-control button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); font-size: 18px; }
.number-control input { width: 76px; height: 38px; border: 1px solid var(--line); border-radius: 4px; text-align: center; font-size: 14px; }
.plain-number, .plain-select { width: 100%; height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); font-size: 14px; }
.appetite-field { margin-top: 12px; }
.factors-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.factor-field { display: grid; gap: 5px; font-size: 13px; font-weight: 550; }
.factor-field span { display: flex; align-items: baseline; gap: 5px; }
.factor-field small { color: var(--muted); font-size: 12px; font-weight: 400; }
.factor-field input { width: 100%; height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); font-size: 14px; }
.toggle-list { margin-top: 14px; border-top: 1px solid #edf0ed; }
.toggle-row { min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid #edf0ed; font-size: 14px; }
.toggle-row:last-child { border-bottom: 0; }
.toggle-row input { width: 20px; height: 20px; accent-color: var(--accent); }
.notes-card textarea { width: 100%; min-height: 92px; resize: vertical; padding: 10px; border: 1px solid var(--line); border-radius: 4px; font-size: 14px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid #729a7c; outline-offset: 2px; }
.note-foot { display: flex; justify-content: space-between; margin-top: 5px; color: var(--muted); font-size: 12px; }
.primary-button, .outline-button, .danger-button { min-height: 42px; padding: 8px 15px; border: 1px solid var(--accent); border-radius: 5px; font-size: 14px; font-weight: 600; }
.primary-button { background: var(--accent); color: white; }
.primary-button:hover { background: #1f5138; }
.primary-button:disabled { opacity: .6; cursor: wait; }
.outline-button { border-color: #cbd5cc; background: var(--surface); color: #33443a; }
.outline-button:hover { background: #f2f5f2; }
.danger-button { border-color: #e2c6c3; background: white; color: var(--danger); }
.history-layout { display: grid; grid-template-columns: minmax(300px, .9fr) minmax(320px, 1.1fr); gap: 14px; }
.calendar-card, .history-detail { min-height: 330px; }
.calendar-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.calendar-top h2 { margin: 0; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; text-align: center; }
.calendar-dow { padding: 7px 0; color: var(--muted); font-size: 12px; font-weight: 600; }
.calendar-day { position: relative; min-height: 39px; border: 0; border-radius: 4px; background: transparent; color: #344239; font-size: 13px; }
.calendar-day:hover { background: #f1f3f0; }
.calendar-day.muted { color: #a0aaa2; }
.calendar-day.today { font-weight: 700; }
.calendar-day.selected { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.calendar-day.has-entry:after { content: ""; position: absolute; bottom: 3px; left: calc(50% - 3px); width: 6px; height: 6px; border-radius: 50%; background: #537c5b; }
.calendar-day.partial:after { background: #bc8743; }
.calendar-legend { display: flex; gap: 15px; margin-top: 12px; padding-top: 10px; border-top: 1px solid #edf0ed; color: var(--muted); font-size: 12px; }
.calendar-legend span { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 7px; height: 7px; border-radius: 50%; }
.legend-dot.filled { background: #537c5b; }
.legend-dot.partial { background: #bc8743; }
.empty-history { min-height: 285px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); text-align: center; }
.empty-history h2 { color: var(--ink); }
.empty-history p { margin: 0; font-size: 14px; }
.detail-date { color: var(--muted); font-size: 13px; }
.detail-title { margin: 5px 0 12px; }
.detail-values { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.detail-value { display: flex; justify-content: space-between; gap: 8px; padding: 9px; border-radius: 4px; background: #f5f6f3; color: #4f5b53; font-size: 12px; }
.detail-value strong { color: var(--ink); }
.detail-note { margin: 12px 0; color: #4f5b53; font-size: 14px; white-space: pre-wrap; }
.event-section { margin-top: 28px; }
.event-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.event-title h2 { margin: 0; }
.event-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.event-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.event-item h3 { margin: 0 0 4px; }
.event-item p { margin: 0; color: var(--muted); font-size: 13px; }
.event-item time { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; }
.event-actions { display: flex; gap: 5px; flex: none; }
.event-edit, .event-delete { min-height: 36px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 4px; background: white; color: #3e4b42; font-size: 12px; }
.event-empty { grid-column: 1 / -1; padding: 18px; border: 1px solid var(--line); border-radius: 6px; background: white; color: var(--muted); font-size: 14px; }
.range-select, .select-pair select, .lag-control select { min-height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 4px; background: white; font-size: 14px; }
.insight-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat-card { padding: 14px; border: 1px solid var(--line); border-radius: 6px; background: white; }
.stat-card span { color: var(--muted); font-size: 13px; }
.stat-card strong { display: block; margin: 5px 0 2px; font-size: 24px; font-weight: 650; }
.stat-card small { color: var(--muted); font-size: 11px; }
.insights-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(320px, .8fr); gap: 14px; }
.chart-heading { display: flex; justify-content: space-between; gap: 12px; }
.chart-heading p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 10px; }
.legend-control { display: flex; align-items: center; gap: 5px; color: #4f5b53; font-size: 12px; }
.legend-control input { accent-color: var(--accent); }
.legend-control i { width: 8px; height: 8px; border-radius: 50%; }
.legend-fatigue_am i { background: #b77956; }
.legend-fatigue_pm i { background: #a678bd; }
.legend-mood i { background: #59916b; }
.legend-sleep_quality i { background: #d5a652; }
.legend-concentration_midday i { background: #4d82a0; }
.legend-low_mood i { background: #a65c61; }
.chart-wrap { height: 230px; margin-top: 15px; border-bottom: 1px solid var(--line); }
.chart-wrap svg { width: 100%; height: 100%; }
.chart-grid { stroke: #e9ede9; stroke-width: 1; }
.chart-grid-label { fill: #68746c; font: 11px ui-monospace, monospace; }
.chart-line { fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart-fatigue_am { stroke: #b77956; }
.chart-fatigue_pm { stroke: #a678bd; }
.chart-mood { stroke: #59916b; }
.chart-sleep_quality { stroke: #d5a652; }
.chart-concentration_midday { stroke: #4d82a0; }
.chart-low_mood { stroke: #a65c61; }
.chart-average { stroke-dasharray: 4 4; opacity: .58; }
.chart-axis { display: flex; justify-content: space-between; margin-top: 6px; color: var(--muted); font-size: 12px; }
.chart-note, .small-note { margin: 10px 0 0; color: var(--muted); font-size: 12px; }
.select-pair { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: end; gap: 7px; }
.select-pair label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }
.select-pair select { width: 100%; min-width: 0; }
.select-pair > span { padding-bottom: 10px; color: var(--muted); font-size: 13px; }
.lag-control { display: grid; gap: 5px; margin-top: 12px; color: var(--muted); font-size: 12px; }
.correlation-result { min-height: 140px; display: flex; flex-direction: column; align-items: center; justify-content: center; margin-top: 12px; padding: 10px; border: 1px solid #edf0ed; border-radius: 5px; background: #fafbf9; text-align: center; }
.correlation-result p { max-width: 270px; margin: 7px 0 0; color: #4f5b53; font-size: 12px; line-height: 1.5; }
.correlation-value { color: var(--accent); font-size: 25px; font-weight: 650; }
.scatter { width: 100%; height: 105px; }
.scatter-axis { stroke: #e5ebe5; }
.event-patterns { margin-top: 14px; }
.frequency-list { display: grid; gap: 10px; }
.frequency-row { display: grid; grid-template-columns: minmax(100px, 1fr) 1.5fr 26px minmax(100px, auto); align-items: center; gap: 10px; color: #46534a; font-size: 13px; }
.frequency-row strong { text-align: right; }
.frequency-row small { color: var(--muted); font-size: 11px; }
.frequency-bar { appearance: none; width: 100%; height: 7px; border: 0; border-radius: 4px; background: #e9ede9; }
.frequency-bar::-webkit-progress-bar { border-radius: 4px; background: #e9ede9; }
.frequency-bar::-webkit-progress-value { border-radius: 4px; background: #70937a; }
.frequency-bar::-moz-progress-bar { border-radius: 4px; background: #70937a; }
.frequency-empty { padding: 14px 0; color: var(--muted); font-size: 14px; }
.settings-grid { display: grid; gap: 14px; max-width: 800px; }
.setting-row { min-height: 62px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 0; border-top: 1px solid #edf0ed; }
.setting-row strong { font-size: 14px; }
.setting-row p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.notification-status { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.notification-status.error { color: var(--danger); }
.reminder-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 50px; border-top: 1px solid #edf0ed; }
.reminder-toggle { display: flex; align-items: center; gap: 9px; font-size: 14px; }
.reminder-toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.reminder-time { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.reminder-time input { height: 38px; padding: 0 8px; border: 1px solid var(--line); border-radius: 4px; background: white; font: inherit; color: var(--ink); }
.timezone-field { display: grid; gap: 5px; margin: 12px 0; color: var(--muted); font-size: 13px; }
.timezone-field input { width: 100%; height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 4px; background: white; color: var(--ink); font: inherit; }
.notification-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.notification-actions button[hidden] { display: none; }
.notification-actions button:disabled { opacity: .55; cursor: not-allowed; }
.file-button { position: relative; display: inline-flex; align-items: center; }
.file-button input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.danger-card { border-color: #e8d5d2; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: 22px; transform: translate(-50%, 18px); opacity: 0; pointer-events: none; padding: 11px 16px; border-radius: 5px; background: #26372c; color: white; font-size: 14px; transition: opacity .15s, transform .15s; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
dialog { width: min(460px, calc(100vw - 28px)); padding: 0; border: 1px solid var(--line); border-radius: 7px; background: white; }
dialog::backdrop { background: #18231b66; }
#event-form { padding: 22px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.dialog-head h2 { margin: 0; }
.dialog-close { width: 36px; height: 36px; border: 0; background: transparent; font-size: 22px; }
#event-form > label, .dialog-row label { display: grid; gap: 5px; margin-bottom: 12px; color: #3f4b43; font-size: 13px; }
#event-form input, #event-form select, #event-form textarea { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 4px; background: white; font-size: 14px; }
#event-form textarea { resize: vertical; }
.dialog-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.muted { color: var(--muted); font-weight: 400; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--paper); }
.login-wrap { width: min(100%, 380px); }
.login-brand { display: block; margin: 0 0 22px; text-align: center; }
.login-card { padding: 26px; border: 1px solid var(--line); border-radius: 7px; background: white; }
.login-card h1 { margin-bottom: 20px; font-size: 24px; }
.login-card form > label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 550; }
.password-wrap { display: flex; height: 46px; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.password-wrap input { width: 100%; min-width: 0; padding: 0 10px; border: 0; outline: 0; font-size: 16px; }
.password-wrap button { padding: 0 12px; border: 0; background: white; color: var(--accent); font-size: 13px; }
.login-button { width: 100%; margin-top: 2px; }
.login-error { min-height: 18px; margin: 7px 0; color: var(--danger); font-size: 13px; }
.logout-button { min-height: 36px; padding: 5px 10px; font-size: 12px; }

@media (max-width: 900px) {
  .main-content { padding-right: 28px; padding-left: 28px; }
  .insights-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .sidebar { display: none; }
  .mobile-nav { position: fixed; z-index: 10; inset: auto 0 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; padding: 4px 8px calc(4px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #fff; }
  .mobile-nav .nav-item { min-height: 54px; padding: 8px 2px; border-radius: 0; color: #49554d; text-align: center; font-size: 13px; }
  .mobile-nav .nav-item.active { background: transparent; color: var(--accent); box-shadow: inset 0 2px var(--accent); }
  .main-content { margin: 0; padding: 0 16px calc(24px + 66px + env(safe-area-inset-bottom)); }
  .topbar { height: 54px; margin: 0 -16px; padding: 0 16px; background: var(--paper); }
  .mobile-brand { display: block; font-size: 22px; }
  .save-status { font-size: 12px; }
  .page { padding-top: 22px; }
  .page-heading { align-items: flex-start; flex-direction: column; gap: 12px; margin-bottom: 18px; }
  h1 { font-size: 27px; }
  .subtitle { font-size: 14px; }
  .date-control { align-self: flex-start; }
  .form-grid, .history-layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .form-card { padding: 17px 15px; border-radius: 5px; }
  .section-head { margin-bottom: 10px; }
  .section-head p { font-size: 13px; }
  .field-block { padding: 14px 0 13px; }
  .field-label { margin-bottom: 10px; font-size: 14px; }
  .meaning, .unit { font-size: 12px; }
  .rating-slider { height: 38px; }
  .rating-slider::-webkit-slider-thumb { width: 24px; height: 24px; margin-top: -9px; }
  .rating-slider::-moz-range-thumb { width: 20px; height: 20px; }
  .factor-field { font-size: 14px; }
  .factor-field input { height: 44px; font-size: 16px; }
  .toggle-row { min-height: 52px; font-size: 15px; }
  .toggle-row input { width: 22px; height: 22px; }
  .notes-card textarea { min-height: 110px; font-size: 16px; }
  .calendar-card, .history-detail { min-height: unset; }
  .calendar-day { min-height: 42px; font-size: 14px; }
  .calendar-dow { font-size: 12px; }
  .empty-history { min-height: 150px; }
  .event-list { grid-template-columns: 1fr; }
  .event-item { padding: 12px; }
  .insight-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat-card { padding: 12px; }
  .stat-card span { font-size: 12px; }
  .stat-card strong { font-size: 21px; }
  .stat-card small { font-size: 11px; }
  .chart-heading { flex-direction: column; }
  .chart-legend { gap: 8px; }
  .chart-wrap { height: 210px; }
  .frequency-row { grid-template-columns: minmax(90px, 1fr) 1fr 22px; gap: 7px; font-size: 12px; }
  .frequency-row small { display: none; }
  .setting-row { align-items: flex-start; padding: 12px 0; }
  .setting-row strong { font-size: 14px; }
  .setting-row p { font-size: 12px; }
  .primary-button, .outline-button, .danger-button { min-height: 42px; font-size: 14px; }
  .login-card { padding: 22px; }
}

@media (max-width: 380px) {
  .main-content { padding-right: 12px; padding-left: 12px; }
  .topbar { margin-right: -12px; margin-left: -12px; padding: 0 12px; }
  .form-card { padding-right: 12px; padding-left: 12px; }
}
