/* ===== カラートークン（ライト） ===== */
:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --surface-hover: #f2f4fa;
  --text: #1b1e28;
  --text-muted: #5f6678;
  --border: #dfe2ec;
  --border-soft: #e9ebf3;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-contrast: #ffffff;
  --accent-ring: rgba(79, 70, 229, 0.22);
  --accent-tint: rgba(79, 70, 229, 0.08);

  --danger: #b4342c;
  --danger-tint: rgba(180, 52, 44, 0.1);
  --done: #4a7a52;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(20, 24, 40, 0.05);
  --shadow-md: 0 6px 20px rgba(20, 24, 40, 0.09);
}

/* ===== カラートークン（ダーク） ===== */
/* OS設定に追従。ただし手動でライトを選んだ場合は除外する */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0f1117;
    --surface: #181b24;
    --surface-2: #1e222d;
    --surface-hover: #232734;
    --text: #e9ebf2;
    --text-muted: #9aa2b6;
    --border: #2c3140;
    --border-soft: #242936;

    --accent: #8b87f5;
    --accent-hover: #a5a1f8;
    --accent-contrast: #14121f;
    --accent-ring: rgba(139, 135, 245, 0.28);
    --accent-tint: rgba(139, 135, 245, 0.14);

    --danger: #f08a80;
    --danger-tint: rgba(240, 138, 128, 0.14);
    --done: #7fbf8c;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
  }
}

/* 手動でダークを選んだ場合（OS設定より優先） */
:root[data-theme='dark'] {
  --bg: #0f1117;
  --surface: #181b24;
  --surface-2: #1e222d;
  --surface-hover: #232734;
  --text: #e9ebf2;
  --text-muted: #9aa2b6;
  --border: #2c3140;
  --border-soft: #242936;

  --accent: #8b87f5;
  --accent-hover: #a5a1f8;
  --accent-contrast: #14121f;
  --accent-ring: rgba(139, 135, 245, 0.28);
  --accent-tint: rgba(139, 135, 245, 0.14);

  --danger: #f08a80;
  --danger-tint: rgba(240, 138, 128, 0.14);
  --done: #7fbf8c;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 32px 20px 72px;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI Variable Text", "Segoe UI", "Yu Gothic UI",
    "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  accent-color: var(--accent);
}

.container {
  max-width: 1000px;
  margin: 0 auto;
}

/* ===== ヘッダー ===== */
.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.app-header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.theme-toggle {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.theme-toggle:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
}

.theme-toggle:active {
  transform: scale(0.94);
}

/* ===== ダッシュボード ===== */
.dashboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px 20px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}

/* 未完了タスクのカードは、塗りではなく上端のバーと色付きの数値で区別する */
.stat-card.accent::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent);
}

.stat-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.stat-value {
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

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

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

/* ===== 最新の振り返り（ダッシュボード直下の帯） ===== */
.review-highlight {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px 20px 18px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

.review-highlight-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 6px;
}

.review-highlight-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.review-week {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.review-highlight-body {
  margin: 0;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.review-highlight-body.is-empty {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ===== 週次の振り返りパネル ===== */
.panel.wide {
  margin-top: 18px;
}

.week-picker {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

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

.week-picker input[type='date'] {
  width: auto;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface-2);
  color-scheme: light dark;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.week-picker input[type='date']:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

/* ===== エラー表示 ===== */
.error-banner {
  margin: 0 0 18px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--danger-tint);
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 0.875rem;
}

/* ===== パネル ===== */
.columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 20px 22px 24px;
  box-shadow: var(--shadow-sm);
}

.panel h2 {
  margin: 0 0 16px;
  font-size: 0.95rem;
  font-weight: 650;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  text-transform: none;
}

/* ===== 入力フォーム ===== */
.input-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 22px;
}

.input-form input,
.input-form textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.92rem;
  color: var(--text);
  background: var(--surface-2);
  resize: vertical;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.input-form input::placeholder,
.input-form textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.75;
}

.input-form input:focus,
.input-form textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.input-form button {
  align-self: flex-start;
  padding: 10px 22px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-contrast);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.input-form button:hover {
  background: var(--accent-hover);
}

.input-form button:active {
  transform: translateY(1px);
}

.input-form button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

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

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

.item {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--surface-2);
  transition: background-color 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.item:hover {
  background: var(--surface-hover);
  box-shadow: var(--shadow-sm);
}

.item-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.item-title {
  font-weight: 600;
  font-size: 0.95rem;
  word-break: break-word;
}

.item-body {
  margin-top: 5px;
  font-size: 0.9rem;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
}

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

/* ===== タスク ===== */
.task-row {
  display: flex;
  align-items: flex-start;
  gap: 11px;
}

.task-row input[type='checkbox'] {
  margin-top: 3px;
  width: 18px;
  height: 18px;
  cursor: pointer;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.task-main {
  flex: 1;
  min-width: 0;
}

/* 未完了タスクは左端のアクセントバーで一覧の中から立ち上がらせる */
#task-list .item:not(.done) {
  border-left: 3px solid var(--accent);
  background: var(--surface);
}

#task-list .item:not(.done):hover {
  background: var(--surface-hover);
}

/* 完了済みは色も装飾も後退させる */
.item.done {
  background: transparent;
  border-style: dashed;
}

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

/* ===== バッジ ===== */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  /* 未完了は塗りつぶし。地との境界がはっきり出るようにする */
  background: var(--accent);
  color: var(--accent-contrast);
  border: 1px solid var(--accent);
}

.badge.done {
  /* 完了済みは枠線のみの控えめな表現にする */
  background: transparent;
  color: var(--done);
  border-color: var(--done);
  font-weight: 500;
}

/* ===== 削除ボタン ===== */
.delete-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 6px;
  flex-shrink: 0;
  transition: color 0.15s ease, background-color 0.15s ease;
}

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

.delete-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-ring);
}

/* ===== レスポンシブ ===== */
@media (max-width: 700px) {
  body {
    padding: 24px 14px 56px;
  }

  .columns {
    grid-template-columns: 1fr;
  }

  .dashboard {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .stat-card {
    flex-direction: row;
    align-items: baseline;
    gap: 10px;
    padding: 14px 18px;
  }

  .stat-label {
    flex: 1;
  }

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

/* ===== モーションを減らす設定への配慮 ===== */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
