/* ---------- カラー・共通設定 ---------- */
:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-sunken: #f8f7f4;
  --item-bg: #fbfaf8;
  --item-border: #e7e4dd;
  --border: #ebe8e1;
  --text: #1c1b19;
  --text-sub: #57534e;
  --muted: #8a857c;

  --primary: #3f51b5;
  --primary-hover: #34449c;
  --primary-soft: #eceefa;
  --accent: #c2410c;
  --accent-soft: #fdf0e8;
  --done: #15803d;
  --done-soft: #e8f5ec;
  --danger: #b91c1c;
  --danger-soft: #fdecec;

  --radius-lg: 16px;
  --radius-md: 10px;
  --shadow-card: 0 1px 2px rgba(28, 27, 25, 0.04), 0 4px 16px rgba(28, 27, 25, 0.04);
  --shadow-item: 0 1px 2px rgba(28, 27, 25, 0.05);
  --focus-ring: 0 0 0 3px rgba(63, 81, 181, 0.18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141412;
    --surface: #1d1c1a;
    --surface-sunken: #171715;
    --item-bg: #242320;
    --item-border: #34322e;
    --border: #2c2b28;
    --text: #eeece8;
    --text-sub: #bdb8af;
    --muted: #8f8a82;

    --primary: #8c9cf0;
    --primary-hover: #a5b2f5;
    --primary-soft: #262a42;
    --accent: #f59e6b;
    --accent-soft: #3a2a20;
    --done: #6fcf8f;
    --done-soft: #1f3226;
    --danger: #f28b8b;
    --danger-soft: #3b2222;

    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-item: none;
    --focus-ring: 0 0 0 3px rgba(140, 156, 240, 0.25);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  letter-spacing: 0.02em;
  -webkit-font-smoothing: antialiased;
}

/* ---------- ヘッダー ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.3;
}

.greeting { margin: 0; font-size: 0.8rem; color: var(--muted); line-height: 1.4; }

.today {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-sub);
  font-variant-numeric: tabular-nums;
}

/* ---------- レイアウト ---------- */
.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

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

.column { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px 24px;
  box-shadow: var(--shadow-card);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.card-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.count {
  min-width: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  color: var(--text-sub);
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
  line-height: 20px;
  font-variant-numeric: tabular-nums;
}

/* ---------- ダッシュボード ---------- */
.dashboard {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

.stat-value {
  margin: 0;
  font-size: 2.1rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.stat-value small {
  margin-left: 4px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
}

.stat-sub { font-size: 0.75rem; color: var(--muted); }

.stat-accent { background: var(--accent-soft); border-color: transparent; }
.stat-accent .stat-label,
.stat-accent .stat-value { color: var(--accent); }

.progress {
  height: 4px;
  margin: 8px 0 4px;
  border-radius: 999px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--done);
  border-radius: inherit;
  transition: width 0.4s ease;
}

/* ---------- フォーム ---------- */
.stack-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }

.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }

label { font-size: 0.8rem; font-weight: 600; color: var(--text-sub); }

:is(input[type="text"], input[type="search"], input[type="date"], textarea) {
  font: inherit;
  color: var(--text);
  width: 100%;
  padding: 10px 12px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

:is(input[type="text"], input[type="search"], textarea)::placeholder { color: var(--muted); }

:is(input[type="text"], input[type="search"], input[type="date"], textarea):hover { border-color: var(--item-border); }

:is(input[type="text"], input[type="search"], input[type="date"], textarea):focus {
  outline: none;
  background: var(--surface);
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

textarea { resize: vertical; min-height: 96px; }

.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }

button {
  font: inherit;
  cursor: pointer;
  border: none;
  white-space: nowrap;
}

button:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.btn-primary {
  padding: 10px 20px;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.15s, transform 0.05s;
}

.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: translateY(1px); }

@media (prefers-color-scheme: dark) {
  .btn-primary, .brand-mark { color: #141412; }
}

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

.list li {
  background: var(--item-bg);
  border: 1px solid var(--item-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-item);
  animation: fade-in 0.25s ease;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(-3px); }
  to { opacity: 1; transform: none; }
}

.list li.empty {
  background: transparent;
  border: 1px dashed var(--item-border);
  box-shadow: none;
  padding: 24px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* メモ */
.memo-title {
  margin: 0;
  font-weight: 700;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

.memo-body {
  margin: 4px 0 0;
  color: var(--text-sub);
  font-size: 0.9rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.memo-item .meta {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* タスク */
.task-item { display: flex; align-items: flex-start; gap: 12px; }
.task-main { flex: 1; min-width: 0; }

.task-text {
  margin: 0 0 4px;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
  transition: color 0.2s;
}

.list li.task-item.done { background: var(--surface-sunken); box-shadow: none; }
.task-item.done .task-text { color: var(--muted); text-decoration: line-through; }

.task-item input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin: 3px 0 0;
  border: 1.5px solid var(--item-border);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s, border-color 0.15s;
}

.task-item input[type="checkbox"]:hover { border-color: var(--done); }
.task-item input[type="checkbox"]:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.task-item input[type="checkbox"]::after {
  content: "";
  width: 5px;
  height: 9px;
  margin-top: -2px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0);
  transition: transform 0.15s ease;
}

.task-item input[type="checkbox"]:checked {
  background: var(--done);
  border-color: var(--done);
}

.task-item input[type="checkbox"]:checked::after { transform: rotate(45deg) scale(1); }

.badge {
  display: inline-block;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 18px;
  background: var(--accent-soft);
  color: var(--accent);
}

.badge.done { background: var(--done-soft); color: var(--done); }

.btn-delete {
  flex-shrink: 0;
  padding: 4px 10px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  transition: background 0.15s, color 0.15s;
}

.btn-delete:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- 週次の振り返り ---------- */
.latest-review { grid-column: 1 / -1; gap: 6px; }

.latest-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.text-link {
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
}

.text-link:hover { text-decoration: underline; }

.latest-week, .review-week {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-weight: 700;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.latest-comment {
  margin: 2px 0 4px;
  color: var(--text-sub);
  font-size: 0.9rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

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

.review-section { margin-top: 24px; scroll-margin-top: 88px; }

.review-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.review-comment {
  margin: 6px 0 0;
  color: var(--text-sub);
  font-size: 0.9rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.review-item .meta {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.item-actions { margin-left: auto; display: flex; gap: 4px; }

.badge.current { background: var(--primary-soft); color: var(--primary); }

.form-hint { margin: 0; font-size: 0.8rem; color: var(--accent); }

select {
  font: inherit;
  color: var(--text);
  width: 100%;
  padding: 10px 36px 10px 12px;
  background-color: var(--surface-sunken);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%238a857c' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

.btn-ghost {
  flex-shrink: 0;
  padding: 4px 10px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  transition: background 0.15s, color 0.15s;
}

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

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--item-border);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s;
}

.btn-secondary:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-secondary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-small { padding: 6px 14px; font-size: 0.85rem; }

.shortcut-hint { margin-right: auto; font-size: 0.75rem; color: var(--muted); }

.form-note { margin: 8px 0 0; font-size: 0.75rem; color: var(--muted); }

/* ---------- ダッシュボード：今日やること ---------- */
.stat-detail { font-size: 0.75rem; color: var(--muted); }
.stat-detail b { color: var(--text-sub); font-weight: 700; }
.stat-detail .alert, .stat-detail .alert b { color: var(--danger); }

/* ---------- 検索・絞り込み ---------- */
.search-field { margin-bottom: 12px; }
.search-result { margin: -4px 0 10px; font-size: 0.75rem; color: var(--muted); }

.task-add-form input[type="date"] { flex: 0 0 auto; width: 150px; }

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  margin-bottom: 12px;
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
}

.segmented button {
  padding: 4px 12px;
  border-radius: 7px;
  background: transparent;
  color: var(--text-sub);
  font-size: 0.8rem;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}

.segmented button:hover { color: var(--text); }

.segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(28, 27, 25, 0.08);
}

.seg-count {
  margin-left: 6px;
  color: var(--muted);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* ---------- 完了済みタスクのまとまり ---------- */
.done-group { margin-top: 18px; }
.list[hidden] + .done-group { margin-top: 0; }

.group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.group-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-sub);
}

/* ---------- 一覧の項目：ピン留め・期限 ---------- */
.item-head { display: flex; align-items: center; gap: 8px; }
.item-head .memo-title { min-width: 0; }

.badge.pin { flex-shrink: 0; background: var(--primary-soft); color: var(--primary); }
.list li.pinned { border-color: color-mix(in srgb, var(--primary) 35%, var(--item-border)); }

.due { font-weight: 600; color: var(--text-sub); }
.due.today, .due.soon { color: var(--accent); }
.due.overdue { color: var(--danger); }

.list li.task-item.overdue { border-color: color-mix(in srgb, var(--danger) 40%, var(--item-border)); }

.task-item .item-actions { margin-left: 0; }

/* ---------- 編集フォーム ---------- */
.list li.editing {
  display: block;
  background: var(--surface);
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
  animation: none;
}

.edit-form { display: flex; flex-direction: column; gap: 8px; }
.edit-row { display: flex; flex-wrap: wrap; gap: 8px; }
.edit-row input[type="text"] { flex: 1 1 220px; }
.edit-row input[type="date"] { flex: 0 1 160px; }

.edit-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}

/* ---------- 振り返り：この週の記録 ---------- */
.week-activity {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
}

.activity-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.activity-title { font-size: 0.8rem; font-weight: 700; color: var(--text-sub); }

.activity-group h3 {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 4px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}

.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 132px;
  overflow-y: auto;
  font-size: 0.85rem;
}

.activity-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
  border-top: 1px dashed var(--border);
}

.activity-list li:first-child { border-top: none; }
.activity-text { min-width: 0; overflow-wrap: anywhere; }
.activity-date { flex-shrink: 0; font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.activity-list li.activity-empty { display: block; font-size: 0.8rem; color: var(--muted); }

/* ---------- バックアップ ---------- */
.backup-section {
  margin-top: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px 24px;
}

.backup-section h2 { margin: 0 0 4px; font-size: 0.95rem; }
.backup-text { margin: 0; font-size: 0.85rem; color: var(--text-sub); }
.backup-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- 通知 ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  background: var(--text);
  color: var(--bg);
  font-size: 0.875rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

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

/* ---------- スマホ ---------- */
@media (max-width: 760px) {
  .header-inner { padding: 12px 16px; }
  .today { font-size: 0.75rem; text-align: right; }
  .container { padding: 20px 16px 48px; }
  .columns { grid-template-columns: 1fr; gap: 20px; }
  .dashboard { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 20px; }
  .task-add-form { flex-wrap: wrap; }
  .task-add-form input[type="text"] { flex: 1 1 100%; }
  .task-add-form input[type="date"] { flex: 1 1 auto; width: auto; }
  .backup-section { flex-direction: column; align-items: stretch; }
  .stat { padding: 14px; }
  .stat-value { font-size: 1.6rem; }
  .stat-sub { display: none; }
  .card { padding: 18px; }
  .review-grid { grid-template-columns: 1fr; gap: 20px; }
}
