#sleepPlanPanel { margin-top:12px; }
#sleepPlanOpen { width:100%; text-align:left; border:0; background:none; color:var(--ink); }
#sleepPlanModal > .modal-card { max-width:min(640px,100%); }
#sleepPlanTitle { margin:0 34px 12px 0; font-size:var(--fs-md); }
#sleepPlanBack:not([hidden]) { display:block; margin:0 34px 6px 0; }
#sleepPlanModal.is-fixed-date :is(.sleep-plan-calendar, .sleep-plan-date-picker) { display:none; }
#sleepPlanModal.is-fixed-date .sleep-plan-controls { justify-content:flex-start; margin-top:0; padding-top:0; border-top:0; }
#sleepPlanModal.is-fixed-date .sleep-plan-mode { margin-inline-start:0; }
.sleep-plan-calendar { padding:12px; border:1px solid var(--line); border-radius:var(--radius-lg); }
.sleep-plan-calendar-nav { display:grid; grid-template-columns:auto minmax(0,1fr) auto auto; align-items:center; gap:6px; margin-bottom:8px; }
#sleepPlanMonth { text-align:center; font-size:var(--fs-sm); }
.sleep-plan-calendar-grid { display:grid; grid-template-columns:repeat(7,minmax(0,1fr)); }
.sleep-plan-week { padding:2px 0 4px; }
.sleep-plan-week + .sleep-plan-week { border-top:1px solid var(--line); }
.sleep-plan-weekdays { margin-bottom:4px; text-align:center; color:var(--ink-soft); font-size:var(--fs-xs); }
.sleep-plan-calendar-day {
  display:grid; grid-template-rows:20px 1fr; align-content:start; box-sizing:border-box;
  min-width:0; min-height:66px; padding:2px 2px 3px; border:0; border-radius:5px;
  background:transparent; color:var(--ink); font:inherit; font-size:var(--fs-sm); cursor:pointer;
}
.sleep-plan-calendar-day.is-outside { color:var(--ink-soft); opacity:.55; }
.sleep-plan-calendar-day[aria-current="date"] { font-weight:800; box-shadow:inset 0 0 0 2px var(--selected-border); }
.sleep-plan-calendar-day[aria-pressed="true"] {
  box-shadow:inset 0 0 0 2px #D79B16; background:rgba(246,203,90,.26);
}
:root:is([data-theme="dark"], [data-theme="dark-blue"]) .sleep-plan-calendar-day[aria-pressed="true"] {
  background:rgba(246,203,90,.22);
}
.sleep-plan-calendar-sessions { display:grid; grid-template-rows:repeat(2,20px); justify-items:center; gap:1px; }
.sleep-plan-controls {
  display:flex; flex-wrap:wrap; align-items:center; justify-content:space-between; gap:6px;
  margin:12px 0 8px; padding-top:10px; border-top:1px solid var(--line);
}
.sleep-plan-date-picker { display:flex; align-items:center; gap:6px; }
.sleep-plan-mode.mode-switch { flex:0 0 auto; flex-wrap:nowrap; margin:0 0 0 auto; }
.sleep-plan-mode button { white-space:nowrap; }
#sleepPlanDate {
  min-width:0; min-height:36px; box-sizing:border-box; padding:4px 8px;
  border:1px solid var(--line); border-radius:8px; background:var(--paper); color:var(--ink); font-size:16px;
}
#sleepPlanSessions { display:grid; gap:6px; }
#sleepPlanLogLink:not([hidden]) {
  display:flex; align-items:center; justify-content:flex-end; gap:4px;
  min-height:36px; margin-top:6px; color:var(--ink); font-size:var(--fs-xs); text-underline-offset:3px;
}
.sleep-plan-session { min-width:0; padding:8px; border:1px solid var(--line); border-radius:12px; background:var(--paper); }
.sleep-plan-session-head { display:flex; align-items:center; gap:6px; min-height:24px; margin-bottom:6px; }
.sleep-plan-session h3 { margin:0; font-size:var(--fs-sm); white-space:nowrap; }
.sleep-plan-score { display:inline-flex; align-items:center; gap:4px; font-size:var(--fs-xs); color:var(--ink-soft); }
.sleep-plan-score input {
  box-sizing:border-box; width:3em; height:32px; padding:2px 4px; text-align:center;
  border:1px solid var(--line); border-radius:8px; background:var(--paper); color:var(--ink); font-size:16px;
}
.sleep-plan-choices {
  display:grid; grid-template-columns:repeat(3,minmax(0,1fr)) minmax(0,1.4fr); gap:4px;
}
.sleep-plan-type, .sleep-plan-day {
  box-sizing:border-box; min-height:36px; padding:6px 10px;
  border:1px solid var(--line); border-radius:var(--radius-pill);
  background:var(--paper); color:var(--ink-soft); font:inherit; font-size:var(--fs-xs); cursor:pointer;
}
.sleep-plan-type {
  display:flex; align-items:center; justify-content:center; gap:5px; min-height:42px; font-weight:700; white-space:nowrap;
  border-color:color-mix(in srgb, var(--sleep-type-color) 45%, var(--line));
  background:color-mix(in srgb, var(--sleep-type-color) 7%, var(--paper));
}
.sleep-plan-type::before, .sleep-plan-recorded-type::before { content:''; display:inline-block; flex:none; width:8px; height:8px; border-radius:50%; background:var(--sleep-type-color); }
.sleep-plan-type.active {
  padding:4px 8px;
  border:3px solid color-mix(in srgb, var(--sleep-type-color) 60%, var(--ink));
  background:color-mix(in srgb, var(--sleep-type-color) 14%, var(--paper));
  color:var(--ink);
}
.sleep-plan-choices[data-mode="actual"] .sleep-plan-type.active {
  background:var(--sleep-type-color); color:#101321;
}
.sleep-plan-choices[data-mode="actual"] .sleep-plan-type.active::before {
  outline:1px solid currentColor;
}
.sleep-plan-type:disabled { opacity:.55; cursor:default; }
.sleep-plan-type-column { display:grid; grid-template-rows:auto auto 1fr; align-content:start; gap:4px; min-width:0; }
.sleep-plan-ratio {
  display:grid; grid-template-columns:minmax(0,1fr) auto; align-items:center; gap:2px;
  width:100%; max-width:76px; justify-self:center; color:var(--ink-soft); font-size:var(--fs-xs);
}
.sleep-plan-ratio input {
  box-sizing:border-box; width:100%; min-width:0; height:32px; padding:2px;
  border:1px solid var(--line); border-radius:6px; background:var(--paper); color:var(--ink);
  font-size:16px; text-align:center; appearance:textfield;
}
.sleep-plan-ratio input::-webkit-inner-spin-button { appearance:none; }
.sleep-plan-ratio-caption { text-align:center; color:var(--ink-soft); font-size:var(--fs-2xs); }
.sleep-plan-ratio-hint { margin:6px 0 0; color:var(--warning); font-size:var(--fs-xs); }
.sleep-plan-ratio-hint:empty { display:none; }
.sleep-plan-session-head .sleep-plan-clear { margin-inline-start:auto; min-height:32px; padding:3px 6px; font-size:var(--fs-xs); white-space:nowrap; }
.sleep-plan-actual-actions { display:flex; align-items:center; justify-content:flex-end; flex-wrap:wrap; gap:6px; margin-top:8px; }
.sleep-plan-actual-hint { margin-inline-end:auto; color:var(--ink-soft); font-size:var(--fs-xs); }
.sleep-plan-actual-save { background:var(--success); border-color:var(--success); color:var(--paper); font-weight:700; }
.sleep-plan-actual-save:disabled { opacity:.55; cursor:default; }
.sleep-plan-recorded-result { display:flex; flex-wrap:wrap; align-items:center; justify-content:space-between; gap:10px; }
.sleep-plan-recorded-type { display:flex; align-items:center; gap:6px; font-size:var(--fs-sm); }
#sleepPlanOpen:focus-visible, #sleepPlanModal button:focus-visible { outline:2px solid var(--selected-strong-border); outline-offset:1px; }
@media(max-width:600px) {
  .sleep-plan-type { padding:6px 2px; gap:3px; font-size:11px; }
  .sleep-plan-type.active { padding:4px 0; }
}
@media(max-width:480px) {
  .sleep-plan-choices { grid-template-columns:repeat(4,minmax(0,1fr)); }
  .sleep-plan-type { flex-direction:column; justify-content:flex-start; min-height:56px; white-space:normal; line-height:1.15; }
  .sleep-plan-type > span { overflow-wrap:anywhere; }
  .sleep-plan-type.active { padding:4px 0; }
}
#sleepPlanHistory { margin-top:12px; }
.sleep-plan-history-list { margin-top:12px; min-width:0; }
.sleep-history-section + .sleep-history-section { margin-top:20px; padding-top:20px; border-top:1px solid var(--line); }
.sleep-history-heading { margin:0 0 12px; font-size:var(--fs-sm); }
.sleep-history-recent { display:grid; gap:10px; }
.sleep-history-direction { display:flex; justify-content:space-between; color:var(--ink-soft); font-size:var(--fs-xs); }
.sleep-history-direction[hidden] { display:none; }
.sleep-history-summary-chart { display:flex; height:40px; border-radius:6px; overflow:hidden; direction:ltr; }
.sleep-history-summary-segment { box-sizing:border-box; display:flex; align-items:center; justify-content:center; flex:none; color:#182332; font-size:12px; font-weight:800; }
.sleep-history-summary-segment + .sleep-history-summary-segment { border-left:1px solid var(--paper); }
.sleep-history-ratios-label { margin-bottom:6px; color:var(--ink-soft); font-size:var(--fs-xs); }
.sleep-history-ratios-columns { display:flex; height:150px; direction:ltr; background:var(--paper-dim); border-radius:4px; overflow:hidden; }
.sleep-history-date-axis { position:relative; height:calc(1.4em + 7px); color:var(--ink-soft); font-size:var(--fs-xs); line-height:1.4; }
.sleep-history-date-tick { position:absolute; padding-top:7px; white-space:nowrap; transform:translateX(-50%); }
.sleep-history-date-tick::before { content:''; position:absolute; top:0; left:50%; height:5px; border-left:1px solid currentColor; }
.sleep-history-date-tick.is-first { transform:none; }
.sleep-history-date-tick.is-first::before { left:0; }
.sleep-history-date-tick.is-last { transform:translateX(-100%); }
.sleep-history-date-tick.is-last::before { left:100%; }
.sleep-history-ratios-column { display:flex; flex-direction:column-reverse; box-sizing:border-box; flex:none; height:100%; }
.sleep-history-ratios-column + .sleep-history-ratios-column { border-left:1px solid var(--paper); }
.sleep-history-ratios-column > span { display:block; flex:none; }
.sleep-history-ratios-column.is-missing { background:repeating-linear-gradient(135deg,transparent 0 4px,var(--line) 4px 5px); }
button.sleep-history-summary-segment, button.sleep-history-ratios-column { padding:0; margin:0; border:0; border-radius:0; min-width:0; min-height:0; background:transparent; font:inherit; cursor:pointer; }
button.sleep-history-summary-segment:focus-visible, button.sleep-history-ratios-column:focus-visible { outline:2px solid var(--selected-strong-border); outline-offset:-2px; }
.sleep-history-fold { border:0; background:none; padding:0; }
.sleep-history-fold > summary { display:flex; align-items:center; gap:6px; list-style:none; cursor:pointer; font-weight:700; }
.sleep-history-fold > summary::-webkit-details-marker { display:none; }
.sleep-history-fold > summary::before { content:'›'; display:inline-block; font-size:16px; transform:rotate(0deg); }
.sleep-history-fold[open] > summary::before { transform:rotate(90deg); }
.sleep-history-fold.opt-fold[open] { padding:0; background:none; border-radius:0; }
.sleep-history-fold.opt-fold[open] > summary { margin-inline:0; padding:0; min-height:36px; background:none; }
.sleep-history-fold.opt-fold[open]::after { display:none; }
.sleep-history-tip { position:fixed; inset:auto; margin:0; box-sizing:border-box; width:280px; max-width:calc(100vw - 24px); max-height:calc(100dvh - 24px); overflow:auto; padding:14px; border:1px solid var(--line); border-radius:12px; background:var(--paper); color:var(--ink); box-shadow:0 6px 24px #0003; font-size:var(--fs-sm); z-index:10000; }
.sleep-history-tip p { margin:8px 0; color:var(--ink-soft); font-size:var(--fs-xs); }
.sleep-history-tip-ratio { display:flex; justify-content:space-between; gap:12px; padding:4px 0; font-size:var(--fs-xs); }
.sleep-history-tip-actions { display:flex; justify-content:flex-end; flex-wrap:wrap; gap:8px; margin-top:12px; }
.sleep-history-tip-edit { font-weight:700; color:var(--ink); }
.sleep-history-count-type::before, .sleep-history-legend > span::before, .sleep-history-result::before { content:''; display:inline-block; width:8px; height:8px; margin-right:5px; background:var(--history-type); border-radius:50%; }
.sleep-history-legend { display:flex; flex-wrap:wrap; gap:12px; margin:8px 0 12px; font-size:var(--fs-xs); }
.sleep-history-records { max-height:640px; overflow:auto; border:1px solid var(--line); border-radius:8px; }
.sleep-history-columns, .sleep-plan-history-session { box-sizing:border-box; display:grid; grid-template-columns:3.2em 2.6em minmax(64px,1fr) 5.3em 3.8em; gap:4px; align-items:center; min-width:0; padding:8px 6px; white-space:nowrap; }
.sleep-history-columns { background:var(--paper-dim); color:var(--ink-soft); font-size:var(--fs-xs); font-weight:700; }
.sleep-plan-history-session { width:100%; border:0; border-top:1px solid var(--line); border-radius:0; background:var(--paper); color:var(--ink); font:inherit; font-size:var(--fs-xs); text-align:left; cursor:pointer; min-height:46px; }
.sleep-plan-history-session:hover { background:var(--paper-dim); }
.sleep-plan-history-session:focus-visible { outline:2px solid var(--selected-strong-border); outline-offset:-2px; }
.sleep-history-date, .sleep-history-comparison { font-variant-numeric:tabular-nums; }
.sleep-history-comparison { font-weight:700; }
.sleep-history-ratio-bar { display:flex; height:24px; border-radius:4px; overflow:hidden; background:var(--paper-dim); }
.sleep-history-ratio-bar > span { box-sizing:border-box; display:flex; align-items:center; justify-content:center; flex:none; color:#182332; font-size:11px; font-weight:700; }
.sleep-history-ratio-bar > span + span { border-left:1px solid var(--paper); }
.sleep-history-ratio-bar.is-missing { align-items:center; justify-content:center; color:var(--ink-soft); }
.sleep-history-result, .sleep-history-comparison { overflow:hidden; text-overflow:ellipsis; }
.sleep-history-result::before { width:6px; height:6px; margin-right:3px; }
@media(max-width:600px) {
  .sleep-history-columns, .sleep-plan-history-session { font-size:11px; }
  .sleep-history-ratio-bar > span { font-size:10px; }
}

.sleep-history-breakdown.opt-fold, .sleep-history-breakdown.opt-fold[open] { padding-top:20px; border-top:1px solid var(--line); }

.sleep-history-estimate-values { display:grid; gap:10px; margin:12px 0 20px; font-size:var(--fs-xs); }
.sleep-history-estimate-values > div { display:flex; align-items:center; justify-content:space-between; gap:12px; }
.sleep-history-estimate-values strong { font-variant-numeric:tabular-nums; }
.sleep-history-estimate-note { margin:8px 0; font-size:var(--fs-xs); color:var(--ink-soft); }

.sleep-history-average-bar { display:flex; height:32px; overflow:hidden; border-radius:6px; background:var(--paper-dim); }
.sleep-history-average-bar > span { flex:none; display:flex; align-items:center; justify-content:center; min-width:0; color:#182332; font-size:11px; font-weight:700; }
.sleep-history-average-bar > span + span { border-left:1px solid var(--paper); box-sizing:border-box; }
.sleep-history-average-bar .sleep-history-average-empty { width:100%; color:var(--ink-soft); }
.sleep-history-estimate-values > .sleep-history-target-row { display:grid; grid-template-columns:minmax(0,1fr); justify-content:stretch; gap:6px; }
.sleep-history-target-row > div:first-child { display:flex; justify-content:space-between; align-items:center; gap:12px; }
.sleep-history-target-track { position:relative; height:20px; background:var(--paper-dim); border-radius:4px; border:1px solid var(--line); }
.sleep-history-target-fill { display:block; height:100%; border-radius:3px; }
.sleep-history-target-marker { position:absolute; top:-3px; bottom:-3px; width:2px; transform:translateX(-1px); background:var(--ink); }
.sleep-history-target-track.is-missing { background:repeating-linear-gradient(135deg,transparent 0 4px,var(--line) 4px 5px); }
.sleep-history-target-scale { display:flex; justify-content:space-between; color:var(--ink-soft); font-size:10px; }

