:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #f2f4f7;
  --surface-accent: #eef3fb;
  --border: #d9dee7;
  --border-strong: #c4cbd7;
  --text: #172033;
  --muted: #5f6b82;
  --muted-soft: #7f8a9d;
  --blue: #325ecf;
  --green: #1f8b56;
  --red: #b24343;
  --red-soft: #fdeaea;
  --shadow: 0 18px 40px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(50, 94, 207, 0.06), transparent 28%),
    linear-gradient(180deg, #fafbfd 0%, var(--bg) 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

button:hover {
  border-color: var(--border-strong);
  background: #fafbfd;
}

button:active {
  transform: translateY(1px);
}

button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
}

button.primary:hover {
  background: #2a53ba;
}

button.subtle {
  background: var(--surface-soft);
}

button.danger {
  color: var(--red);
  background: var(--red-soft);
  border-color: #efc1c1;
}

button.toggle-button {
  border: none;
  background: transparent;
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

button.toggle-button.active {
  background: var(--text);
  color: white;
}

input[type="date"],
input[type="time"],
input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  background: var(--surface);
  color: var(--text);
}

textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgba(50, 94, 207, 0.65);
  box-shadow: 0 0 0 4px rgba(50, 94, 207, 0.12);
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px;
}

.notice {
  position: sticky;
  top: 14px;
  z-index: 30;
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 14px;
}

.notice.error {
  border-color: #efc1c1;
  background: var(--red-soft);
  color: #7a2929;
}

.notice.success {
  border-color: #bde4cd;
  background: #e5f7ee;
  color: #24583a;
}

.hidden {
  display: none !important;
}

.page-header,
.calendar-section,
.tasks-section,
.analysis-section {
  border: 1px solid rgba(217, 222, 231, 0.8);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.page-header {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
  padding: 18px;
  backdrop-filter: blur(12px);
  overflow-x: auto;
}

.header-copy h1 {
  margin: 0 0 6px 0;
  font-size: 28px;
  line-height: 1;
  letter-spacing: -0.03em;
}

.header-copy p,
.section-meta,
.analysis-meta,
.chart-caption,
.summary-subtext,
.task-status,
.day-note-preview,
.task-note-preview {
  color: var(--muted);
}

.header-copy p,
.section-meta,
.analysis-meta {
  margin: 0;
  font-size: 13px;
}

.header-controls {
  display: flex;
  flex-direction: row;
  gap: 10px;
  align-items: center;
  flex-wrap: nowrap;
  width: max-content;
}

.mode-toggle,
.calendar-toggle,
.analysis-period-toggle {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-soft);
}

.date-controls,
.tasks-toolbar,
.analysis-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}

.date-controls {
  flex-wrap: nowrap;
}

#picker {
  min-width: 142px;
}

.calendar-section,
.tasks-section,
.analysis-section {
  padding: 18px;
}

.calendar-section {
  margin-bottom: 18px;
}

.calendar-header,
.tasks-header,
.analysis-header,
.inline-editor-header,
.chart-header,
.breakdown-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.section-title,
.chart-title {
  margin: 0;
  letter-spacing: -0.02em;
}

.section-title {
  font-size: 18px;
}

.chart-title {
  font-size: 16px;
}

.calendar-grid {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.calendar-grid.week,
.calendar-grid.month {
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.dow {
  padding: 4px 0 6px 0;
  color: var(--muted-soft);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 11px;
  font-weight: 700;
}

.calendar-cell {
  position: relative;
  min-height: 76px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(242, 244, 247, 0.9));
  text-align: left;
  overflow: hidden;
}

.calendar-cell:hover {
  border-color: var(--border-strong);
}

.calendar-cell.today {
  border-color: rgba(50, 94, 207, 0.55);
  background: linear-gradient(180deg, #f9fbff, #eef3fb);
}

.calendar-cell.selected {
  border-color: var(--blue);
  background: linear-gradient(180deg, #f7faff, #e8efff);
  box-shadow: inset 0 0 0 1px rgba(50, 94, 207, 0.14);
}

.calendar-cell::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  opacity: 0;
}

.calendar-cell.has-progress::before {
  opacity: 1;
}

.calendar-cell.red::before { background: linear-gradient(180deg, #da6d6d, #b24343); }
.calendar-cell.orange::before { background: linear-gradient(180deg, #df9c42, #c97616); }
.calendar-cell.green::before { background: linear-gradient(180deg, #35a86d, #1f8b56); }

.day-number {
  font-size: 14px;
  font-weight: 700;
}

.calendar-stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 18px;
  gap: 8px;
}

.pill,
.streak {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.88);
  font-size: 11px;
  font-weight: 700;
}

.progress-text {
  color: var(--muted-soft);
  font-size: 12px;
  font-weight: 700;
}

.day-note-preview,
.inline-editor,
.summary-card,
.chart-card,
.task-card {
  border: 1px solid var(--border);
  border-radius: 16px;
}

.day-note-preview {
  margin-top: 16px;
  padding: 12px 14px;
  border-style: dashed;
  background: var(--surface-soft);
  font-size: 13px;
  line-height: 1.5;
}

.day-note-preview.has-note {
  border-style: solid;
  background: var(--surface-accent);
  color: var(--text);
}

.inline-editor {
  margin-top: 12px;
  padding: 14px;
  background: #fbfcfe;
}

.inline-editor-title,
.modal-title,
.breakdown-name,
.task-title {
  font-weight: 700;
}

.inline-editor-actions,
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.task-list,
.breakdown-list,
.filter-list {
  display: grid;
  gap: 10px;
}

.task-list,
.summary-grid,
.analysis-grid {
  margin-top: 16px;
}

.task-card {
  background: var(--surface-soft);
  overflow: hidden;
}

.task-card.completed {
  background: #edf9f2;
  border-color: #bde4cd;
}

.task-card.dragging {
  opacity: 0.55;
}

.task-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  align-items: flex-start;
}

.task-main {
  display: flex;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.drag-handle {
  padding-top: 2px;
  color: var(--muted-soft);
  cursor: move;
  user-select: none;
  font-size: 16px;
  line-height: 1;
}

.task-main input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  cursor: pointer;
  accent-color: var(--green);
}

.task-copy {
  min-width: 0;
  flex: 1;
}

.task-title-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.task-title {
  font-size: 15px;
  line-height: 1.3;
  word-break: break-word;
}

.task-card.completed .task-title {
  text-decoration: line-through;
  color: var(--muted);
}

.task-note-preview {
  margin-top: 8px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(217, 222, 231, 0.9);
  border-radius: 12px;
  padding: 8px 10px;
}

.task-metric {
  margin-top: 10px;
  display: grid;
  gap: 6px;
  max-width: 320px;
}

.task-metric-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.task-metric-row.plank {
  align-items: stretch;
}

.task-metric-label,
.task-metric-meta {
  font-size: 12px;
}

.task-metric-label {
  color: var(--muted);
  font-weight: 700;
}

.task-metric-input {
  background: rgba(255, 255, 255, 0.92);
}

.task-metric-part {
  width: 84px;
}

.task-metric-save {
  flex: 0 0 auto;
  white-space: nowrap;
}

.task-metric-unit {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.task-metric-meta {
  color: var(--muted-soft);
}

.task-actions {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.task-actions button {
  padding: 8px 10px;
  font-size: 13px;
  white-space: nowrap;
}

.task-note-editor {
  padding: 0 14px 14px 14px;
  border-top: 1px solid rgba(217, 222, 231, 0.85);
  background: rgba(255, 255, 255, 0.6);
}

.task-note-editor .inline-editor {
  margin-top: 14px;
}

.empty-state {
  padding: 36px 18px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 16px;
  background: var(--surface-soft);
}

.analysis-meta {
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.summary-card {
  padding: 14px;
  background: var(--surface-soft);
}

.summary-label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.summary-value {
  margin-top: 10px;
  font-size: 28px;
  line-height: 1;
  letter-spacing: -0.04em;
  font-weight: 700;
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.chart-card {
  padding: 16px;
  background: var(--surface);
}

.chart-card.full-width {
  grid-column: 1 / -1;
}

.chart-caption {
  font-size: 12px;
}

.chart-scroll {
  overflow-x: auto;
  padding-bottom: 4px;
}

.bar-chart {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(34px, 1fr);
  gap: 10px;
  align-items: end;
  min-height: 220px;
  min-width: fit-content;
}

.bar-chart.compact {
  grid-auto-columns: minmax(28px, 1fr);
}

.bar-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.bar-value {
  font-size: 11px;
  color: var(--muted);
  min-height: 14px;
  font-weight: 700;
}

.bar-track {
  height: 150px;
  width: 100%;
  min-width: 24px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  border-radius: 14px;
  padding: 6px;
  background: linear-gradient(180deg, #f7f9fc, #eef2f7);
  border: 1px solid rgba(217, 222, 231, 0.72);
}

.bar-fill {
  width: 100%;
  border-radius: 10px;
  background: linear-gradient(180deg, #5f83df, var(--blue));
  min-height: 0;
}

.bar-fill.rate {
  background: linear-gradient(180deg, #4fb17a, var(--green));
}

.bar-fill.metric-wake {
  background: linear-gradient(180deg, #f2b15a, #d57a1f);
}

.bar-fill.metric-plank {
  background: linear-gradient(180deg, #53b9a6, #157a72);
}

.bar-fill.metric-sleep {
  background: linear-gradient(180deg, #8d7fe3, #4d45b8);
}

.bar-fill.empty {
  min-height: 0;
}

.bar-label {
  font-size: 11px;
  color: var(--muted-soft);
  text-align: center;
  line-height: 1.2;
  max-width: 56px;
  word-break: break-word;
}

.breakdown-row {
  display: grid;
  gap: 8px;
}

.breakdown-meta {
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.breakdown-track {
  height: 12px;
  border-radius: 999px;
  background: #eef2f7;
  overflow: hidden;
  border: 1px solid rgba(217, 222, 231, 0.72);
}

.breakdown-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #5f83df, var(--blue));
  min-width: 0;
}

dialog {
  width: min(560px, calc(100vw - 24px));
  padding: 0;
  border: none;
  border-radius: 18px;
  background: white;
  box-shadow: 0 28px 80px rgba(23, 32, 51, 0.24);
}

dialog::backdrop {
  background: rgba(17, 24, 39, 0.35);
  backdrop-filter: blur(2px);
}

.modal-header,
.modal-body,
.modal-footer {
  padding: 18px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.modal-body {
  display: grid;
  gap: 14px;
}

.modal-footer {
  border-top: 1px solid var(--border);
}

.form-group {
  display: grid;
  gap: 7px;
}

.form-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.weekdays-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.weekday-label,
.filter-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  cursor: pointer;
}

.weekday-label {
  justify-content: center;
  gap: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface);
}

.weekday-label input {
  display: none;
}

.weekday-label.selected {
  border-color: var(--blue);
  background: #dfe8ff;
  color: var(--blue);
}

.interval-row {
  display: grid;
  grid-template-columns: auto 92px auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.filter-list {
  max-height: 300px;
  overflow-y: auto;
}

.filter-option input {
  margin: 0;
  accent-color: var(--blue);
}

@media (max-width: 900px) {
  .summary-grid,
  .analysis-grid {
    grid-template-columns: 1fr;
  }

  .chart-card.full-width {
    grid-column: auto;
  }
}

@media (max-width: 720px) {
  .page {
    padding: 12px;
  }

  .page-header,
  .calendar-section,
  .tasks-section,
  .analysis-section {
    border-radius: 16px;
    padding: 14px;
  }

  .calendar-header,
  .tasks-header,
  .analysis-header,
  .task-row,
  .chart-header,
  .inline-editor-header,
  .breakdown-head {
    flex-direction: column;
    align-items: stretch;
  }

  .header-controls {
    align-items: center;
  }

  .date-controls,
  .tasks-toolbar,
  .analysis-toolbar,
  .task-actions {
    justify-content: stretch;
  }

  .tasks-toolbar > *,
  .analysis-toolbar > *,
  .task-actions > * {
    flex: 1 1 auto;
  }

  .date-controls > * {
    flex: 0 0 auto;
  }

  .page-header {
    align-items: center;
  }

  .date-controls,
  .header-controls {
    flex-wrap: nowrap;
  }

  .calendar-cell {
    min-height: 68px;
    padding: 8px;
  }

  .calendar-stats {
    margin-top: 14px;
  }

  .bar-chart {
    min-height: 210px;
  }

  .interval-row {
    grid-template-columns: 1fr;
  }

  .task-metric-row {
    flex-wrap: wrap;
  }
}
