:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --border: #e2e6ee;
  --text: #1f2330;
  --text-muted: #6b7180;
  --primary: #3355dd;
  --primary-hover: #2a46bb;
  --accent: #d9682b;
  --danger: #c0392b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 60, 0.08);
  --shadow-soft: 0 2px 10px rgba(51, 85, 221, 0.08);
}

* {
  box-sizing: border-box;
}

/* display を指定した要素でも hidden 属性で確実に隠れるようにする */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, sans-serif;
  line-height: 1.6;
}

.container {
  max-width: 1040px;
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
}

/* 線画アイコン（色は文字色に合わせる） */
svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* 画面上部（タイトルとダッシュボード） ------------------------------------ */

/* 淡い水色〜ラベンダーの帯にして、下の作業エリアと分ける */
.top-area {
  background: linear-gradient(135deg, #e5ecff 0%, #efeaff 100%);
  border-bottom: 1px solid #dde3f7;
  padding: 24px 0 26px;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px 24px;
  margin-bottom: 18px;
}

.page-header h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 4px 0 0;
  color: #555c6c; /* 色付きの帯の上でも読みやすい濃さにする */
  font-size: 0.9rem;
}

.today {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 600;
}

.today-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--primary);
}

/* ダッシュボード ------------------------------------------------------- */

/* 左に最重要タスク、右に件数を並べて、ひと目で全体が見えるようにする */
.dashboard {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 14px;
}

.stats {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  gap: 12px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
}

/* 件数ごとにアイコンの色を変えて、見分けやすくする */
.stat-card.memo {
  --stat-color: var(--primary);
  --stat-tint: #e8eeff;
}

.stat-card.task {
  --stat-color: #2f8a57;
  --stat-tint: #e3f4ea;
}

.stat-card.open {
  --stat-color: var(--accent);
  --stat-tint: #fdf0e6;
}

.stat-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  color: var(--stat-color);
  background: var(--stat-tint);
}

.stat-icon svg {
  width: 22px;
  height: 22px;
}

.stat-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.stat-card.open .stat-value {
  color: var(--accent);
}

/* 最重要タスク */

.priority-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
  padding: 16px 20px 18px;
}

.priority-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 2px 12px;
  margin-bottom: 12px;
}

.priority-header h2 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.1rem;
}

.priority-icon {
  width: 20px;
  height: 20px;
  color: var(--danger);
}

.priority-count {
  padding: 1px 10px;
  border-radius: 999px;
  background: #fde4df;
  color: #b3301b;
  font-size: 0.8rem;
  font-weight: 700;
}

.priority-note {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.priority-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.priority-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 12px;
  padding: 9px 14px;
  border-radius: 10px;
  background: #f6f7fb;
}

/* 先頭の「まずはこれ」は白いカードに赤い線と影を付けて、いちばん目立たせる */
.priority-item.first {
  padding: 14px 18px 16px;
  border: 1px solid #f3c9bd;
  border-left: 4px solid var(--danger);
  background: var(--surface);
  box-shadow: 0 4px 14px rgba(192, 57, 43, 0.12);
}

.first-label {
  grid-column: 1 / -1;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--danger);
}

.priority-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.priority-item.first .priority-title {
  font-size: 1.2rem;
}

.priority-due {
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.priority-more {
  margin: 10px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* 期限の残り日数（緊急度で色を変える） ---------------------------------- */

.due-chip {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

.due-chip.overdue {
  background: var(--danger);
  color: #fff;
}

.due-chip.today {
  background: #fde4df;
  color: #b3301b;
}

.due-chip.soon {
  background: #fdf0e6;
  color: #a14b15;
}

.due-chip.later {
  background: #eaf0fd;
  color: #2f4fc4;
}

/* 作業エリア ------------------------------------------------------------ */

.content {
  padding-top: 24px;
  padding-bottom: 64px;
}

/* エラー表示 ----------------------------------------------------------- */

.error-banner {
  /* 一覧の下の方で操作したときも見えるよう、画面上部に追従させる */
  position: sticky;
  top: 8px;
  z-index: 10;
  box-shadow: var(--shadow);
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: #fdecea;
  border: 1px solid #f5c3bd;
  color: var(--danger);
  font-size: 0.9rem;
}

/* パネル --------------------------------------------------------------- */

.columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px 22px;
  min-width: 0; /* 入力欄の初期幅に引っ張られて、狭い画面ではみ出さないようにする */
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 1.1rem;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border);
}

/* 入力フォーム --------------------------------------------------------- */

.input-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

input[type="text"],
input[type="date"],
textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  color: inherit;
  background: #fbfcfe;
  resize: vertical;
}

input[type="date"] {
  width: auto;
  align-self: flex-start;
}

input[type="text"]:focus,
input[type="date"]:focus,
textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  background: var(--surface);
}

/* タスクの種類（通常／期限付き）の切り替え ------------------------------ */

.due-control {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.segmented {
  align-self: flex-start;
  display: inline-flex;
  flex-wrap: wrap;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #eef0f5;
}

.segment {
  position: relative;
  cursor: pointer;
}

/* ラジオボタン本体は見えなくし、文字の部分をボタンのように見せる */
.segment input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.segment span {
  display: block;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.segment input:checked + span {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(20, 30, 60, 0.15);
}

.segment input[value="deadline"]:checked + span {
  color: var(--danger);
}

.segment input:focus-visible + span {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.btn {
  font: inherit;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  background: #eef0f5;
  color: var(--text);
}

.btn:hover {
  background: #e3e6ee;
}

.btn.primary {
  align-self: flex-start;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.btn.primary:hover {
  background: var(--primary-hover);
}

.btn.primary:disabled {
  background: #a9b4d8;
  cursor: progress;
}

.btn.small {
  padding: 4px 10px;
  font-size: 0.8rem;
}

.btn.outline {
  background: transparent;
  border-color: var(--border);
}

.btn.outline:hover {
  background: #eef0f5;
}

.btn.danger {
  color: var(--danger);
}

.btn.danger:hover {
  background: #fdecea;
  border-color: #f5c3bd;
}

/* 一覧 ----------------------------------------------------------------- */

.list-heading {
  margin: 24px 0 8px;
  font-size: 0.95rem;
}

.count {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.85rem;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fbfcfe;
}

.item-title {
  margin: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.item-body {
  margin: 6px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.92rem;
}

.item-meta {
  margin: 6px 0 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.item-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.item-header .item-title {
  flex: 1;
  min-width: 0;
}

.item-actions {
  display: flex;
  gap: 6px;
}

/* 編集フォーム --------------------------------------------------------- */

.item.editing {
  background: var(--surface);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(51, 85, 221, 0.12);
}

.edit-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.edit-actions {
  display: flex;
  gap: 8px;
}

/* タスク項目 ----------------------------------------------------------- */

.task-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

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

.task-item.done {
  background: #f3f5f8;
}

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

/* 期限付き（最重要）の未完了タスクは、左端に色を付けて目立たせる */
.task-item.important {
  border-left: 4px solid var(--danger);
  padding-left: 9px;
}

.due-line {
  margin: 4px 0 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  font-size: 0.82rem;
}

.due-date {
  font-weight: 600;
}

.task-item.done .due-date {
  font-weight: 400;
  color: var(--text-muted);
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge.open {
  background: #fdf0e6;
  color: var(--accent);
}

.badge.done {
  background: #e6f4ea;
  color: #1e7a41;
}

.badge.important {
  background: var(--danger);
  color: #fff;
}

/* 画面の幅に合わせた調整 ------------------------------------------------ */

@media (max-width: 900px) {
  /* ダッシュボードは縦に並べ、件数は横に3つ並べる */
  .dashboard {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-rows: none;
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 760px) {
  .columns {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .container {
    padding-left: 14px;
    padding-right: 14px;
  }

  .top-area {
    padding: 20px 0 22px;
  }

  .priority-panel {
    padding: 14px;
  }

  /* 件数はアイコンを省いてコンパクトにする */
  .stat-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 10px 12px;
  }

  .stat-icon {
    display: none;
  }

  .stat-label {
    font-size: 0.72rem;
  }

  .stat-value {
    font-size: 1.6rem;
  }

  /* 「編集」「削除」を縦に並べて、タスク名と日時の表示幅を確保する */
  .item-actions {
    flex-direction: column;
  }

  /* 最重要タスクは「残り日数・期限」の下にタスク名を置く */
  .priority-item {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .priority-title {
    grid-column: 1 / -1;
    order: 1;
  }
}
