/* ---- デザイントークン ---- */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-2: #4b5563;
  --muted: #9ca3af;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --ring: 0 0 0 3px rgba(79, 70, 229, .18);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1d212a;
    --border: #262b36;
    --border-strong: #353b48;
    --text: #e5e7eb;
    --text-2: #aab1bd;
    --muted: #6b7280;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-soft: rgba(129, 140, 248, .12);
    --success: #34d399;
    --success-soft: rgba(52, 211, 153, .12);
    --warn: #fbbf24;
    --warn-soft: rgba(251, 191, 36, .12);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, .12);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --ring: 0 0 0 3px rgba(129, 140, 248, .25);
    color-scheme: dark;
  }
}

/* ---- ベース ---- */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--text-2); }

/* ---- トップバー ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .01em; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
}
.today { font-size: .85rem; color: var(--text-2); }

main { max-width: 1120px; margin: 0 auto; padding: 32px 24px 48px; }

/* ---- あいさつ ---- */
.greeting h1 { margin: 0; font-size: 1.6rem; font-weight: 700; letter-spacing: -.01em; }
.greeting p { margin: 4px 0 24px; }

/* ---- ダッシュボード ---- */
.dashboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.stat-head { display: flex; justify-content: space-between; align-items: center; }
.stat-label { font-size: .85rem; color: var(--text-2); font-weight: 500; }
.stat-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
}
.stat-value {
  font-size: 2.1rem;
  font-weight: 700;
  line-height: 1.1;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}
.stat-accent .stat-icon { background: var(--warn-soft); color: var(--warn); }
.progress {
  height: 6px;
  margin-top: 12px;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: var(--success);
  border-radius: inherit;
  transition: width .4s ease;
}
.stat-note { margin-top: 6px; font-size: .78rem; color: var(--text-2); }

/* 最新の振り返り（ダッシュボード） */
.stat-review { grid-column: 1 / -1; }
.review-latest-week { margin-left: 6px; color: var(--muted); font-weight: 400; }
.review-latest-text {
  margin: 8px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.link { font-size: .85rem; font-weight: 600; color: var(--accent); text-decoration: none; white-space: nowrap; }
.link:hover { text-decoration: underline; }

/* ---- レイアウト ---- */
.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: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  font-size: 1rem;
  font-weight: 650;
}
.chip {
  font-size: .75rem;
  font-weight: 600;
  padding: 1px 9px;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
}

/* ---- フォーム ---- */
.form { display: flex; flex-direction: column; gap: 10px; }
.form-inline { flex-direction: row; }
.form-inline input { flex: 1; min-width: 0; }
.form-actions { display: flex; justify-content: flex-end; }

input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, textarea:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: var(--ring);
}
textarea { resize: vertical; min-height: 96px; }

.btn {
  font: inherit;
  font-weight: 600;
  font-size: .9rem;
  padding: 9px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
@media (prefers-color-scheme: dark) { .btn-primary { color: #0f1115; } }

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

.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: .9rem;
}

/* メモ */
.memo {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 12px 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
}
.memo-main { flex: 1; min-width: 0; }
.memo-title { font-weight: 650; word-break: break-word; }
.memo-body { white-space: pre-wrap; word-break: break-word; color: var(--text-2); margin: 4px 0 8px; font-size: .92rem; }
.memo-body:empty { display: none; }

.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: .78rem; color: var(--muted); }
.meta > span { white-space: nowrap; }

/* タスク */
.task {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 12px 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: background .15s, border-color .15s;
}
.task:hover { border-color: var(--border-strong); }
.task-main { flex: 1; min-width: 0; }
.task-text { word-break: break-word; font-weight: 500; }
.task.done { background: var(--surface-2); }
.task.done .task-text { text-decoration: line-through; color: var(--muted); font-weight: 400; }

.check {
  flex: none;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: transparent;
  color: transparent;
  cursor: pointer;
  transition: all .15s;
}
.check:hover { border-color: var(--success); color: var(--success); }
.check:focus-visible { outline: none; box-shadow: var(--ring); }
.task.done .check { background: var(--success); border-color: var(--success); color: #fff; }

.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  opacity: .6;
  transition: all .15s;
}
.task:hover .icon-btn, .memo:hover .icon-btn, .icon-btn:focus-visible { opacity: 1; }
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* 並び替え */
.grip {
  flex: none;
  display: grid;
  place-items: center;
  width: 20px;
  height: 28px;
  margin: -2px -6px 0 -8px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: grab;
  touch-action: none; /* タッチでのドラッグ中に画面がスクロールしないように */
  opacity: .5;
  transition: opacity .15s, background .15s, color .15s;
}
.memo:hover .grip, .task:hover .grip, .grip:focus-visible { opacity: 1; }
.grip:hover { background: var(--surface-2); color: var(--text-2); }
.grip:focus-visible { outline: none; box-shadow: var(--ring); }

.sorting, .sorting * { cursor: grabbing !important; user-select: none; }
.dragging {
  position: relative;
  z-index: 1;
  border-color: var(--accent) !important;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .14), var(--ring);
  opacity: .95;
}
.dragging .grip { opacity: 1; color: var(--accent); }

.item-actions { flex: none; display: flex; gap: 2px; margin: -4px -4px 0 0; }

/* 編集中 */
.memo.editing, .task.editing {
  display: block;
  padding: 12px;
  background: var(--surface);
  border-color: var(--accent);
  border-left-width: 1px;
  box-shadow: var(--ring);
}
.edit-form { display: flex; flex-direction: column; gap: 8px; }
.edit-form input, .edit-form textarea { background: var(--surface); }
.edit-actions { display: flex; justify-content: flex-end; gap: 8px; }
.edit-actions .btn { padding: 6px 14px; font-size: .85rem; }
.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--ring); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: .72rem;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 99px;
  background: var(--warn-soft);
  color: var(--warn);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.done { background: var(--success-soft); color: var(--success); }

/* ---- 週次の振り返り ---- */
.review-section { margin-top: 24px; scroll-margin-top: 72px; }
.review-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 16px;
}
.review-header .card-title { margin: 0; }
.week-nav { display: flex; align-items: center; gap: 4px; }
.nav-btn { opacity: 1; font-size: 1.3rem; line-height: 1; color: var(--text-2); }
.nav-btn:disabled { opacity: .3; cursor: default; background: transparent; color: var(--text-2); }
.week-label { min-width: 12em; text-align: center; font-weight: 600; font-size: .92rem; font-variant-numeric: tabular-nums; }
.week-label { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 2px 6px; }
.week-range { white-space: nowrap; }
.week-tag {
  font-size: .7rem;
  font-weight: 600;
  padding: 0 7px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
}
.review-status { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-sm { padding: 5px 12px; font-size: .8rem; margin-left: 6px; }
.btn:disabled { opacity: .4; cursor: default; }

.review-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 24px; align-items: start; }

.week-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.week-stat {
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.week-stat-value { font-size: 1.3rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.week-stat-label { font-size: .75rem; color: var(--text-2); }

.review-actions { display: flex; align-items: center; gap: 8px; }
.review-status { flex: 1; font-size: .78rem; color: var(--muted); }
.btn-danger-text:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }

.subhead { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: .9rem; font-weight: 650; color: var(--text-2); }
.review-history .list { max-height: 360px; overflow-y: auto; }

.review-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.review-item:hover { border-color: var(--border-strong); background: var(--surface-2); }
.review-item:focus-visible { outline: none; box-shadow: var(--ring); }
.review-item.active { border-color: var(--accent); background: var(--accent-soft); }
.review-item-week { font-size: .78rem; font-weight: 600; color: var(--text-2); }
.review-item-text {
  font-size: .88rem;
  white-space: pre-wrap;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---- レスポンシブ ---- */
@media (max-width: 800px) {
  .columns, .review-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  main { padding: 20px 16px 40px; }
  .topbar-inner { padding: 10px 16px; }
  .dashboard { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-accent { grid-column: span 2; }
  .stat { padding: 14px 16px; }
  .stat-value { font-size: 1.7rem; }
  .icon-btn, .grip { opacity: 1; }
  .week-nav { width: 100%; }
  .week-label { flex: 1; min-width: 0; font-size: .85rem; }
  .btn-sm { margin-left: 2px; }
  .review-actions { flex-wrap: wrap; justify-content: flex-end; }
  .review-status { flex-basis: 100%; }
}
