/* ===== カラー・共通トークン ===== */
:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #f9f8f5;
  --text: #1d1e22;
  --muted: #6e717a;
  --faint: #a2a5ad;
  --border: #e7e5df;
  --border-strong: #d6d3cb;

  --primary: #4353c9;
  --primary-hover: #3644ad;
  --primary-soft: #eceefb;

  --amber: #b45309;
  --amber-soft: #fdf3e3;
  --green: #2f7d4f;
  --green-soft: #e8f4ec;
  --danger: #c2413a;
  --danger-soft: #fcecea;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(28, 25, 20, 0.04), 0 4px 16px rgba(28, 25, 20, 0.04);
  --ring: 0 0 0 3px rgba(67, 83, 201, 0.18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141519;
    --surface: #1c1d22;
    --surface-2: #22242a;
    --text: #e9e9ec;
    --muted: #9da0a9;
    --faint: #6c6f78;
    --border: #2b2d34;
    --border-strong: #3a3d45;

    --primary: #8391f0;
    --primary-hover: #9aa6f5;
    --primary-soft: #262a45;

    --amber: #f0a74a;
    --amber-soft: #352816;
    --green: #6cc28d;
    --green-soft: #1b3025;
    --danger: #f0817a;
    --danger-soft: #3a1e1d;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    --ring: 0 0 0 3px rgba(131, 145, 240, 0.25);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
}

p { margin: 0; }
svg { display: block; }

.shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 40px 32px 64px;
}

/* ===== ヘッダー ===== */
.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}
.eyebrow {
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}
.app-header h1 {
  margin: 2px 0 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.3;
}
.brand {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}
.brand svg { width: 18px; height: 18px; }

/* ===== ダッシュボード ===== */
.dashboard {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1.4fr;
  gap: 16px;
  margin-bottom: 16px;
}
.stat {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}
.stat-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
}
.stat-icon svg { width: 22px; height: 22px; }
.icon-memo { background: var(--primary-soft); color: var(--primary); }
.icon-task { background: var(--green-soft); color: var(--green); }
.icon-done { background: var(--green-soft); color: var(--green); }
.icon-pending { background: var(--amber-soft); color: var(--amber); }

.stat-main { flex: 1; min-width: 0; }
.stat-label { color: var(--muted); font-size: 0.82rem; }
.stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}
.stat-value small {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  margin-left: 4px;
}
.stat-done .stat-value span { color: var(--green); }
.stat-pending .stat-value span { color: var(--amber); }

.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-top: 10px;
}
.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--green);
  border-radius: inherit;
  transition: width 0.4s ease;
}
.stat-note { color: var(--muted); font-size: 0.78rem; margin-top: 6px; }

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}
.card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.card > .card-title { margin-bottom: 14px; }
.pill {
  font-size: 0.75rem;
  font-weight: 600;
  min-width: 24px;
  text-align: center;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ===== フォーム ===== */
.field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 6px;
}
.field-label + input, .field-label + textarea { margin-bottom: 14px; }

input[type="text"], textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="text"]::placeholder, textarea::placeholder { color: var(--faint); }
input[type="text"]:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}
textarea { resize: vertical; min-height: 104px; }

.btn-primary {
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  background: var(--primary);
  color: #fff;
  transition: background 0.15s, transform 0.05s;
  white-space: nowrap;
}
@media (prefers-color-scheme: dark) { .btn-primary { color: #11131f; } }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:focus-visible { outline: none; box-shadow: var(--ring); }

.form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.task-form { display: flex; gap: 8px; }

.error { color: var(--danger); font-size: 0.82rem; }
.error:empty { display: none; }
.task-form + .error { margin-top: 8px; }

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

/* ===== 空の状態 ===== */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 28px 0 18px;
  color: var(--faint);
  font-size: 0.88rem;
}
.empty svg { width: 32px; height: 32px; }
.empty[hidden] { display: none; }

/* ===== メモ一覧 ===== */
.memo-list, .task-list { list-style: none; margin: 0; padding: 0; }
.memo-list { display: flex; flex-direction: column; gap: 10px; }
.memo-list li {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.memo-title { font-weight: 700; overflow-wrap: anywhere; }
.memo-content {
  margin-top: 4px;
  color: var(--text);
  opacity: 0.85;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.92rem;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin-top: 8px;
  color: var(--faint);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
}
.meta-item { display: inline-flex; align-items: center; gap: 4px; }
.meta-item svg { width: 13px; height: 13px; }

/* ===== タスク一覧 ===== */
.task-list li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 8px;
  margin: 0 -8px;
  border-radius: 10px;
  transition: background 0.15s;
}
.task-list li + li { border-top: 1px solid var(--border); border-radius: 0; }
.task-list li:hover { background: var(--surface-2); }

.check {
  appearance: none;
  -webkit-appearance: none;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin: 3px 0 0;
  border: 1.6px solid var(--border-strong);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s, border-color 0.15s;
}
.check::after {
  content: "";
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: translateY(-1px) rotate(45deg) scale(0);
  transition: transform 0.15s;
}
.check:hover { border-color: var(--green); }
.check:checked { background: var(--green); border-color: var(--green); }
.check:checked::after { transform: translateY(-1px) rotate(45deg) scale(1); }
.check:focus-visible { outline: none; box-shadow: var(--ring); }
@media (prefers-color-scheme: dark) { .check::after { border-color: #10201a; } }

.task-body { flex: 1; min-width: 0; }
.task-title { overflow-wrap: anywhere; transition: color 0.15s; }
.task-list li.done .task-title { color: var(--faint); text-decoration: line-through; text-decoration-color: var(--faint); }
.task-list .meta { margin-top: 4px; }

.status {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0 8px;
  border-radius: 999px;
  line-height: 1.7;
  background: var(--amber-soft);
  color: var(--amber);
}
.done .status { background: var(--green-soft); color: var(--green); }

.icon-btn {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.icon-btn svg { width: 16px; height: 16px; }
.task-list li:hover .icon-btn, .icon-btn:focus-visible { opacity: 1; }
.icon-btn:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--ring); }
@media (hover: none) { .icon-btn { opacity: 1; } }

/* ===== ボタン（補助） ===== */
.btn-ghost, .btn-danger-ghost {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  background: var(--surface);
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.btn-ghost { border: 1px solid var(--border-strong); color: var(--primary); }
.btn-ghost:hover { background: var(--primary-soft); border-color: var(--primary); }
.btn-danger-ghost { border: 1px solid var(--border); color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-ghost:focus-visible, .btn-danger-ghost:focus-visible { outline: none; box-shadow: var(--ring); }
.btn-small { padding: 5px 12px; font-size: 0.8rem; }
.btn-ghost:disabled { opacity: 0.4; cursor: default; background: var(--surface); border-color: var(--border-strong); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

/* ===== ダッシュボード: 最新の振り返り ===== */
.latest-review {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 22px;
  margin-bottom: 24px;
}
.icon-review { background: #f1ecfb; color: #6d4fc2; }
@media (prefers-color-scheme: dark) { .icon-review { background: #2c2544; color: #b9a5f2; } }
.latest-review-main { flex: 1; min-width: 0; }
.latest-review-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.latest-review-text {
  margin-top: 2px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.latest-review-text.is-empty { color: var(--muted); font-size: 0.9rem; }
.week-chip {
  font-size: 0.74rem;
  font-weight: 600;
  padding: 0 8px;
  border-radius: 999px;
  line-height: 1.8;
  background: #f1ecfb;
  color: #6d4fc2;
  font-variant-numeric: tabular-nums;
}
@media (prefers-color-scheme: dark) { .week-chip { background: #2c2544; color: #b9a5f2; } }
.week-chip[hidden] { display: none; }

/* ===== 週次の振り返り ===== */
.review-card { margin-top: 24px; }
.review-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.week-nav { display: flex; align-items: center; gap: 6px; }
.nav-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-btn svg { width: 16px; height: 16px; }
.nav-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.nav-btn:disabled { opacity: 0.35; cursor: default; }
.nav-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.week-label {
  min-width: 13.5em;
  text-align: center;
  font-weight: 600;
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}
.week-label small { color: var(--primary); font-weight: 600; margin-left: 6px; font-size: 0.75rem; }

.review-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 28px;
  align-items: start;
}
.week-stats {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.week-stats li {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.76rem;
  color: var(--muted);
}
.week-stats strong {
  display: block;
  font-size: 1.15rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.review-form textarea { min-height: 148px; }
.review-status { color: var(--faint); font-size: 0.78rem; }
.form-actions { display: flex; gap: 8px; margin-left: auto; }
.review-form .error { margin-top: 8px; }

.review-history { min-width: 0; }
.review-history .card-head { margin-bottom: 10px; }
.review-history .card-title { font-size: 0.92rem; }
.review-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 420px;
  overflow-y: auto;
}
.review-item {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.review-item:hover { border-color: var(--border-strong); }
.review-item:focus-visible { outline: none; box-shadow: var(--ring); }
.review-item.is-active { border-color: var(--primary); background: var(--primary-soft); }
.review-item-week { font-weight: 700; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.review-item-text {
  margin-top: 2px;
  font-size: 0.88rem;
  opacity: 0.85;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.review-item .meta { margin-top: 6px; }

/* 振り返り欄へ移動したときの強調 */
.flash { animation: flash 1.2s ease-out; }
@keyframes flash {
  0% { box-shadow: 0 0 0 3px var(--primary); }
  100% { box-shadow: var(--shadow); }
}

@media (max-width: 860px) {
  .review-grid { grid-template-columns: 1fr; gap: 20px; }
  .review-list { max-height: none; }
}
@media (max-width: 520px) {
  .latest-review { flex-wrap: wrap; padding: 14px; gap: 10px; margin-bottom: 16px; }
  .latest-review .btn-ghost { width: 100%; }
  .review-card { margin-top: 16px; }
  .week-nav { width: 100%; }
  .week-label { flex: 1; min-width: 0; font-size: 0.85rem; }
  .week-stats li { padding: 6px 8px; }
}

/* 追加したときのアニメーション */
.enter { animation: enter 0.3s ease-out; }
@keyframes enter {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .enter { animation: none; }
  * { transition: none !important; }
}

/* ===== スマホ・狭い画面 ===== */
@media (max-width: 860px) {
  .dashboard { grid-template-columns: 1fr 1fr; }
  .columns { grid-template-columns: 1fr; gap: 16px; }
}
@media (max-width: 520px) {
  .shell { padding: 24px 16px 48px; }
  .app-header { margin-bottom: 20px; }
  .app-header h1 { font-size: 1.4rem; }
  .brand { display: none; }
  .dashboard { gap: 10px; margin-bottom: 16px; }
  .stat { padding: 14px; gap: 10px; flex-direction: column; }
  .stat-icon { width: 34px; height: 34px; border-radius: 10px; }
  .stat-icon svg { width: 18px; height: 18px; }
  .stat-value { font-size: 1.6rem; }
  .card { padding: 18px 16px; }
}
