/* ---------- 色・影・フォント ---------- */
[hidden] { display: none !important; }

:root {
  --bg: #efede8;
  --surface: #ffffff;
  --panel: #dfe3e8;
  --ink: #1b2530;
  --text: #25303b;
  --muted: #56616d;
  --line: #d8dbdf;
  --accent: #1f6a67;
  --accent-strong: #17524f;
  --accent-soft: #dcecea;
  --danger: #a93a35;
  --danger-soft: #f7e4e2;
  --done: #2f7350;
  --done-soft: #e0efe6;
  --shadow-sm: 0 1px 2px rgba(27, 37, 48, 0.1);
  --shadow: 0 1px 2px rgba(27, 37, 48, 0.06), 0 8px 24px rgba(27, 37, 48, 0.08);
  --font-sans: "Yu Gothic UI", "Hiragino Sans", "Meiryo", sans-serif;
  --font-display: "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
}

/* ---------- ヘッダー ---------- */
header {
  background: var(--ink);
  color: #f4f1ea;
  padding: 18px 0;
}
header h1 {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px;
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: 0.08em;
}
header.hero { padding: 26px 0 92px; }
header.hero h1 { max-width: 1280px; font-size: 1.5rem; }

main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 56px; }

/* ---------- ダッシュボード（ヘッダーに重ねた1枚のカード） ---------- */
.dashboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: -84px 0 24px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.stat {
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
}
.stat + .stat { border-left: 1px solid var(--line); }
.stat-label { color: var(--muted); font-size: 0.82rem; letter-spacing: 0.05em; }
.stat-value {
  font-family: var(--font-display);
  font-size: 2.6rem;
  font-weight: 600;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.stat.accent .stat-value { color: var(--accent); }
.stat.done-stat .stat-value { color: var(--done); }

/* ---------- レイアウト ---------- */
.columns { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
.column { display: flex; flex-direction: column; gap: 24px; min-width: 0; }

.card {
  background: var(--surface);
  border-radius: 14px;
  padding: 22px 24px;
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.05em;
}

/* ---------- フォーム ---------- */
label { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 4px; letter-spacing: 0.03em; }
input, textarea {
  width: 100%;
  font: inherit;
  color: inherit;
  padding: 9px 12px;
  background: #fbfaf7;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 14px;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}
input:focus, textarea:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder { color: var(--muted); }
textarea { resize: vertical; }

button {
  font: inherit;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 9px 22px;
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
button:hover { background: var(--accent-strong); }
button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.inline-form { display: flex; gap: 8px; }
.inline-form input { margin-bottom: 0; }
.inline-form button { flex-shrink: 0; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- 一覧（色つきの枠に白い行を並べる） ---------- */
.list-card { background: var(--panel); box-shadow: none; }
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  background: var(--surface);
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 8px;
  box-shadow: var(--shadow-sm);
}
.list li:first-child { margin-top: 0; }
.list li.task.done { background: #f6f6f3; }
.list li.empty {
  background: transparent;
  box-shadow: none;
  border: 1px dashed #9aa5b1;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

/* メモの行 */
.memo-row { display: flex; align-items: center; gap: 6px; }
.memo-row .memo-title { flex: 1; min-width: 0; user-select: none; }
.memo-title { font-weight: 600; overflow-wrap: anywhere; }
.memo-body { white-space: pre-wrap; overflow-wrap: anywhere; margin: 2px 0; }
.meta { color: var(--muted); font-size: 0.78rem; }

/* 一覧の小さなボタン（表示・編集・削除） */
.button-link { display: inline-block; text-decoration: none; }
.memo-btn, .delete-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 3px 11px;
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1.6;
  box-shadow: none;
  flex-shrink: 0;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.memo-btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); }
.memo-btn.danger, .delete-btn { color: var(--danger); }
.memo-btn.danger:hover, .delete-btn:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

/* タスクの行 */
.task { display: flex; align-items: flex-start; gap: 12px; }
.task input[type="checkbox"] {
  width: 18px; height: 18px;
  margin: 4px 0 0;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--accent);
}
.task-main { flex: 1; min-width: 0; }
.task-text { overflow-wrap: anywhere; font-weight: 500; }
.task.done .task-text { text-decoration: line-through; color: var(--muted); font-weight: 400; }

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0 9px;
  border-radius: 999px;
  margin-right: 8px;
}
.badge.open { color: var(--accent-strong); background: var(--accent-soft); }
.badge.done { color: var(--done); background: var(--done-soft); }

/* ---------- 表示・編集画面（別画面） ---------- */
main.narrow { max-width: 960px; padding-top: 12px; }
.back-link { color: var(--accent); font-size: 0.9rem; text-decoration: none; }
.back-link:hover { text-decoration: underline; }
.memo-detail { padding: 32px 36px; }
.memo-detail h2 { font-size: 1.5rem; margin-bottom: 18px; overflow-wrap: anywhere; }
#view h2 { padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.memo-detail .memo-body { margin-bottom: 24px; line-height: 1.95; }
.memo-body.empty { color: var(--muted); }
#edit-form textarea { margin-bottom: 6px; }
#edit-form .meta { margin-bottom: 20px; }
.edit-actions { display: flex; gap: 8px; align-items: center; }

.secondary-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  transition: background-color 0.15s;
}
.secondary-btn:hover { background: var(--bg); }
a.secondary-btn { padding: 8px 20px; font-weight: 600; letter-spacing: 0.04em; }

/* ---------- 週次の振り返り ---------- */
header.wide h1 { max-width: 1280px; }
main.reviews-page { padding-top: 12px; }

.dashboard { grid-template-columns: repeat(4, 1fr) 2.4fr; }
.stat-review { justify-content: flex-start; min-width: 0; }
.review-head { display: flex; align-items: center; gap: 12px; }
.review-head .stat-label { flex: none; }
.review-head .meta { flex: 1; min-width: 0; white-space: nowrap; }
.review-link { color: var(--accent); font-size: 0.82rem; font-weight: 600; text-decoration: none; flex: none; }
.review-link:hover { text-decoration: underline; }
.review-text {
  margin: 8px 0 0;
  font-size: 0.9rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}
.review-text.empty { color: var(--muted); }

.week-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px 6px; flex-wrap: wrap; margin-bottom: 16px; }
.week-current {
  flex: 1 0 100%;
  order: -1; /* 週の表示を1段目に、移動ボタンを2段目に並べる */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  font-weight: 600;
  font-size: 0.92rem;
  text-align: center;
}
.week-current .badge { margin-right: 0; }
#next-week { flex-direction: row-reverse; }
.memo-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.memo-btn:disabled:hover { background: var(--surface); border-color: var(--line); color: var(--text); }

#review-form textarea { margin-bottom: 6px; }
#review-form .meta { min-height: 1.3em; margin-bottom: 14px; }
.save-status { color: var(--done); font-size: 0.85rem; font-weight: 600; }

.list li.review-item { padding: 0; }
.review-row {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: inherit;
  box-shadow: none;
  border-radius: 10px;
  padding: 12px 14px;
  font-weight: 400;
  letter-spacing: 0;
}
.review-row:hover { background: var(--accent-soft); }
.review-row[aria-current="true"] { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.review-row-week { font-weight: 600; font-size: 0.92rem; }
.review-preview {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

/* 横幅が足りないときは、最新の振り返りを次の段に送る */
@media (max-width: 1100px) {
  .dashboard { grid-template-columns: repeat(4, 1fr); }
  .stat + .stat.stat-review { grid-column: 1 / -1; border-left: none; border-top: 1px solid var(--line); }
}

/* ---------- アイコン ---------- */
.icon { display: inline-flex; width: 1.05em; height: 1.05em; flex-shrink: 0; }
.icon svg { width: 100%; height: 100%; display: block; }

[data-icon] { display: inline-flex; align-items: center; justify-content: center; gap: 0.4em; }
h1[data-icon], h2[data-icon], .stat-label[data-icon] { display: flex; justify-content: flex-start; }

header h1 .icon { color: #8fd0c9; width: 1.1em; height: 1.1em; }
.card h2 .icon { color: var(--accent); width: 1.15em; height: 1.15em; }
.badge .icon { width: 1em; height: 1em; }
.badge[data-icon] { gap: 0.3em; vertical-align: 1px; }
.memo-btn[data-icon], .delete-btn[data-icon] { gap: 0.3em; }

.stat-label[data-icon] { gap: 8px; }
.stat-label .icon {
  width: 30px;
  height: 30px;
  padding: 6px;
  border-radius: 8px;
  color: var(--accent);
  background: var(--accent-soft);
}
.done-stat .stat-label .icon { color: var(--done); background: var(--done-soft); }

/* ---------- スマホ幅 ---------- */
@media (max-width: 760px) {
  .stat-label[data-icon] { flex-direction: column; align-items: flex-start; gap: 4px; }
  /* スマホ幅では件数を2列×2段に並べる */
  .dashboard { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(3) { border-left: none; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
  .memo-btn .icon { display: none; }
  .review-head { flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; }
  .review-head .stat-label[data-icon] { flex-direction: row; align-items: center; gap: 8px; font-size: 0.8rem; }
  .review-head .meta { flex: 1 0 100%; order: 3; }
  .columns { grid-template-columns: 1fr; }
  .stat { padding: 14px 14px; }
  .stat-label { font-size: 0.72rem; letter-spacing: 0; }
  .stat-value { font-size: 1.9rem; }
  .card { padding: 18px 16px; }
  .memo-detail { padding: 24px 20px; }
  .list-card { padding: 14px 10px; }
  .list-card h2 { padding: 0 6px; }
  .list li { padding: 10px 10px; }
  .memo-btn, .delete-btn { padding: 3px 8px; }
}

/* ---------- PC幅（左右の余白をそろえる） ---------- */
@media (min-width: 761px) {
  header h1 { padding: 0 24px; }
  main { padding-left: 24px; padding-right: 24px; }
}

/* ---------- 1280×1024 などのPC画面：ページ全体を1画面に収める ----------
   画面の高さいっぱいに広げ、件数が増えたら一覧の中だけをスクロールする */
@media (min-width: 1101px) and (min-height: 800px), (min-width: 761px) and (min-height: 900px) {
  body {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  header { flex: none; }
  main {
    flex: 1;
    min-height: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    padding-bottom: 24px;
  }
  .dashboard { flex: none; }

  .columns { flex: 1; min-height: 0; grid-template-rows: minmax(0, 1fr); align-items: stretch; }
  .column { min-height: 0; }
  .column > .card:not(.list-card) { flex: none; }
  .list-card { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .list-card h2 { flex: none; }
  .list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: thin;
    /* 行の影が切れないように少し余白を持たせる */
    padding: 2px;
    margin: -2px;
  }

  /* 表示・編集画面 */
  main.narrow > p { flex: none; }
  #view:not([hidden]) { flex: 0 1 auto; min-height: 0; display: flex; flex-direction: column; }
  #view .memo-body { flex: 0 1 auto; min-height: 0; overflow-y: auto; }
  #view h2, #view .meta { flex: none; }
  #edit:not([hidden]) { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  #edit-form { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  #edit-form textarea { flex: 1; min-height: 80px; }

  /* 週次の振り返り画面 */
  main.reviews-page > p { flex: none; }
  .column > .card.review-editor { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  #review-form { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  #review-form textarea { flex: 1; min-height: 80px; }
}

/* ブラウザのツールバーの分だけ高さが減る場合は、入力欄を低くしてメモ一覧の場所を確保 */
@media (min-width: 761px) and (min-height: 800px) and (max-height: 960px) {
  #memo-body { height: 76px; }
}
