:root {
  color-scheme: light;
  --bg: #f7f5ef;
  --ink: #172322;
  --muted: #64716f;
  --line: #d9ddd5;
  --surface: #ffffff;
  --surface-2: #eef4f2;
  --accent: #2f6f73;
  --accent-2: #b94e48;
  --gold: #b98528;
  --green: #4d7d45;
  --blue: #496fae;
  --shadow: 0 14px 34px rgba(19, 34, 33, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: "Yu Gothic UI", "Hiragino Sans", Meiryo, system-ui, sans-serif;
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar,
.section-heading,
.calendar-controls,
.topbar-actions,
.view-tabs,
.task-main,
.task-actions,
.dialog-heading,
.dialog-actions {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 16px;
}

.topbar h1,
.section-heading h2,
.dialog-heading h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(2rem, 2.6vw, 3.2rem);
  line-height: 1;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar-actions,
.calendar-controls,
.dialog-actions {
  gap: 10px;
}

.primary-action,
.quiet-button,
.danger-button,
.icon-button,
.tab-button,
.task-actions button {
  min-height: 42px;
  border-radius: 8px;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease;
}

.primary-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 18px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.quiet-button,
.tab-button,
.task-actions button {
  padding: 0 14px;
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 700;
}

.danger-button {
  margin-right: auto;
  padding: 0 14px;
  background: #f6dfdc;
  color: #96342f;
  font-weight: 700;
}

.icon-button {
  width: 42px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 1.1rem;
}

button:hover {
  transform: translateY(-1px);
}

.view-tabs {
  gap: 8px;
  margin: 24px 0;
  padding: 6px;
  overflow-x: auto;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.tab-button {
  min-width: 112px;
}

.tab-button.is-active {
  background: var(--ink);
  color: #fff;
}

.filter-bar {
  display: grid;
  grid-template-columns: minmax(220px, 1.6fr) repeat(3, minmax(140px, 1fr));
  gap: 10px;
  margin: 0 0 22px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.quick-add-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin: 0 0 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.section-heading {
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.section-heading h2 {
  font-size: clamp(1.35rem, 1.8vw, 2rem);
}

.section-heading p {
  margin: 6px 0 0;
  color: var(--muted);
}

.quick-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.stat-chip,
.category-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 700;
}

.stat-chip {
  background: var(--surface);
  border: 1px solid var(--line);
}

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

.quadrant {
  min-height: 360px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.quadrant.drag-over,
.calendar-day.drag-over {
  outline: 3px solid rgba(47, 111, 115, 0.3);
  outline-offset: 2px;
}

.quadrant-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 70px;
}

.quadrant h3,
.day-panel h3,
.today-columns h3,
.review-grid h3,
.unscheduled h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.quadrant p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.quadrant[data-quadrant="do"] {
  border-top: 5px solid var(--accent-2);
}

.quadrant[data-quadrant="schedule"] {
  border-top: 5px solid var(--accent);
}

.quadrant[data-quadrant="delegate"] {
  border-top: 5px solid var(--gold);
}

.quadrant[data-quadrant="eliminate"] {
  border-top: 5px solid var(--muted);
}

.task-list,
.time-list,
#unscheduledTasks,
#todayScheduled,
#todaySuggested,
#reviewCandidates {
  display: grid;
  gap: 10px;
}

.task-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 5px solid var(--task-color, var(--accent));
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(19, 34, 33, 0.06);
}

.task-card.is-complete {
  opacity: 0.68;
}

.task-card.is-complete h4 {
  text-decoration: line-through;
}

.task-card[draggable="true"] {
  cursor: grab;
}

.task-main {
  align-items: flex-start;
  gap: 10px;
}

.check-button {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--surface-2);
  color: transparent;
  box-shadow: inset 0 0 0 2px var(--line);
}

.task-card.is-complete .check-button {
  background: var(--green);
  color: #fff;
  box-shadow: none;
}

.task-card h4 {
  margin: 2px 0 5px;
  overflow-wrap: anywhere;
  font-size: 0.96rem;
  line-height: 1.35;
}

.task-memo-image {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: contain;
}

.task-meta,
.task-notes {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.linked-memo {
  margin: 0;
  color: var(--blue);
  font-size: 0.82rem;
  font-weight: 800;
}

.subtask-list {
  display: grid;
  gap: 6px;
}

.subtask-item {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 700;
}

.subtask-item input {
  width: 16px;
  min-height: 16px;
}

.task-actions {
  justify-content: flex-end;
  gap: 8px;
}

.task-actions button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.82rem;
}

.empty-state {
  padding: 18px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.calendar-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 380px);
  gap: 16px;
  align-items: start;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.calendar-grid-day {
  display: block;
}

.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 8px;
}

.segmented-button {
  min-height: 34px;
  padding: 0 12px;
  background: transparent;
  color: var(--ink);
  border-radius: 6px;
  font-weight: 800;
}

.segmented-button.is-active {
  background: var(--ink);
  color: #fff;
}

.weekday,
.calendar-day {
  background: var(--surface);
}

.weekday {
  padding: 10px 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
}

.calendar-day {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-height: 148px;
  padding: 9px;
  text-align: left;
}

.calendar-day-wide {
  min-height: 320px;
}

.calendar-day.is-muted {
  color: #9aa3a0;
  background: #f5f7f4;
}

.calendar-day.is-selected {
  box-shadow: inset 0 0 0 3px rgba(47, 111, 115, 0.45);
}

.calendar-day.is-today .day-number {
  background: var(--accent);
  color: #fff;
}

.calendar-day.is-holiday .day-number,
.calendar-day.is-holiday .holiday-label {
  color: #b94e48;
}

.day-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-weight: 800;
}

.day-select {
  align-self: flex-start;
  width: 32px;
  min-height: 32px;
  padding: 0;
  background: transparent;
  color: inherit;
  border-radius: 50%;
}

.holiday-label {
  margin-top: -6px;
  color: var(--accent-2);
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1.1;
}

.day-duration,
.day-total {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.day-timeline {
  display: grid;
  gap: 1px;
  overflow: hidden;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.time-slot {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 12px;
  min-height: 58px;
  padding: 10px;
  background: #fff;
}

.time-slot strong {
  color: var(--muted);
}

.time-slot-items {
  display: grid;
  gap: 8px;
}

.calendar-items {
  display: grid;
  gap: 6px;
  width: 100%;
  min-height: 32px;
}

.calendar-event {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  min-height: 30px;
  width: 100%;
  padding: 5px 7px;
  overflow: hidden;
  background: var(--event-bg, #e8f1ef);
  color: var(--ink);
  border-left: 4px solid var(--event-color, var(--accent));
  border-radius: 6px;
  text-align: left;
}

.calendar-event-do {
  border-left-color: var(--accent-2);
}

.calendar-event-schedule {
  border-left-color: var(--accent);
}

.calendar-event-delegate {
  border-left-color: var(--gold);
}

.calendar-event-eliminate {
  border-left-color: var(--muted);
}

.calendar-event[style] {
  border-left-color: var(--event-color, var(--accent));
}

.calendar-event.is-recurring-instance .calendar-event-time {
  color: var(--event-color, var(--accent));
}

.calendar-event.is-due-only {
  border-style: dashed;
}

.calendar-event.is-complete {
  opacity: 0.62;
}

.calendar-event-time {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
}

.calendar-event-title {
  min-width: 0;
  overflow: hidden;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.25;
  overflow-wrap: anywhere;
  white-space: normal;
}

.day-panel,
.today-columns section,
.review-grid section,
.standalone-memo-panel {
  padding: 16px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.standalone-memo-panel textarea {
  min-height: min(54vh, 560px);
  line-height: 1.65;
}

.memo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.standalone-notes-layout {
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.standalone-note-list {
  display: grid;
  gap: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.standalone-note-item {
  display: grid;
  gap: 5px;
  width: 100%;
  min-height: 64px;
  padding: 10px;
  background: var(--surface-2);
  color: var(--ink);
  border-left: 4px solid transparent;
  border-radius: 8px;
  text-align: left;
}

.standalone-note-item.is-active {
  background: #fff;
  border-left-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--line);
}

.standalone-note-item strong,
.standalone-note-item span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.standalone-note-item span {
  color: var(--muted);
  font-size: 0.82rem;
}

.standalone-memo-panel {
  display: grid;
  gap: 14px;
}

.unscheduled {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

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

.review-history {
  grid-column: 1 / -1;
}

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

.insights-grid section,
.settings-panel {
  padding: 16px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.insight-row {
  display: grid;
  grid-template-columns: minmax(90px, 140px) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
}

.insight-row span,
.insight-row strong {
  font-size: 0.86rem;
}

.insight-bar {
  height: 10px;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: 999px;
}

.insight-bar i {
  display: block;
  height: 100%;
  background: var(--accent);
}

.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  background: var(--surface-2);
  color: var(--ink);
  border-radius: 8px;
  font-weight: 800;
  cursor: pointer;
}

.file-button input {
  display: none;
}

.settings-note {
  color: var(--muted);
  font-size: 0.86rem;
}

.history-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.history-item span {
  color: var(--muted);
  font-size: 0.84rem;
}

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

.metric {
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric strong {
  display: block;
  font-size: 1.8rem;
}

.metric span {
  color: var(--muted);
  font-size: 0.86rem;
}

.task-dialog {
  width: min(720px, calc(100vw - 28px));
  padding: 0;
  background: var(--surface);
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.task-dialog::backdrop {
  background: rgba(23, 35, 34, 0.38);
}

.task-form {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.dialog-heading {
  justify-content: space-between;
  gap: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

textarea {
  resize: vertical;
}

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

.template-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 8px;
}

.memo-media {
  display: grid;
  gap: 12px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 8px;
}

.memo-media-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.image-editor {
  display: grid;
  gap: 10px;
  justify-items: start;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.image-editor.is-empty {
  display: none;
}

.image-editor img {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: contain;
}

.image-editor label {
  width: min(360px, 100%);
}

.image-editor output {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.checkbox-label {
  align-content: end;
  grid-template-columns: auto minmax(0, 1fr);
  min-height: 42px;
  padding: 9px 11px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
}

.checkbox-label input {
  width: 18px;
  min-height: 18px;
  padding: 0;
}

input[type="color"] {
  height: 42px;
  padding: 4px;
}

.category-pill {
  width: fit-content;
  background: #e8edf7;
  color: var(--blue);
}

@media (max-width: 980px) {
  .matrix-grid,
  .calendar-layout,
  .standalone-notes-layout,
  .filter-bar,
  .quick-add-bar,
  .insights-grid,
  .settings-grid,
  .today-columns,
  .review-grid {
    grid-template-columns: 1fr;
  }

  .quadrant {
    min-height: 240px;
  }
}

@media (max-width: 700px) {
  .app-shell {
    padding: 16px;
  }

  .topbar,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions,
  .calendar-controls {
    width: 100%;
    flex-wrap: wrap;
  }

  .primary-action {
    justify-content: center;
    flex: 1;
  }

  .tab-button {
    min-width: 96px;
  }

  .calendar-grid {
    font-size: 0.86rem;
  }

  .calendar-day {
    min-height: 116px;
    padding: 6px;
  }

  .time-slot {
    grid-template-columns: 1fr;
  }

  .calendar-event {
    grid-template-columns: 1fr;
    gap: 1px;
    padding: 4px 5px;
  }

  .calendar-event-time {
    font-size: 0.66rem;
  }

  .calendar-event-title {
    font-size: 0.72rem;
  }

  .form-grid,
  .template-row,
  .memo-media-header,
  .review-metrics {
    grid-template-columns: 1fr;
  }
}
