/* =========================================================
   マイ秘書 — スタイル
   色・余白・角丸はすべて :root の変数にまとめています。
   ========================================================= */

:root {
  /* 下地と面 */
  --bg: #f6f7f9;
  --panel: #ffffff;
  --sunken: #fafbfc;

  /* 線 */
  --border: #e5e7ec;
  --border-strong: #d4d8e0;

  /* 文字 */
  --text: #1a1d24;
  --text-2: #565e6e;
  --muted: #868e9f;

  /* アクセント */
  --accent: #3d5afe;
  --accent-ink: #2f46d6;
  --accent-soft: #eef1ff;
  --danger: #c8453f;
  --danger-soft: #fdf0ef;
  --success: #2f7a55;
  --success-soft: #eaf5ef;

  /* メモ / タスクの色分け */
  --memo-bg: #fdf9f2;
  --memo-line: #dcbd86;
  --task-bg: #f4f7ff;
  --task-line: #7d94ff;
  --done-bg: #f7f8fa;
  --done-line: #cbd0da;
  --review-bg: #f3f8f5;
  --review-line: #6ba98b;

  /* 形 */
  --r-lg: 14px;
  --r-md: 10px;
  --r-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 26, 40, .04), 0 2px 8px rgba(20, 26, 40, .05);
  --shadow-header: 0 6px 20px rgba(32, 40, 96, .18);
  --ease: 150ms cubic-bezier(.2, .6, .3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101219;
    --panel: #171a22;
    --sunken: #13161d;

    --border: #262a35;
    --border-strong: #333845;

    --text: #e7e9ef;
    --text-2: #b0b7c6;
    --muted: #868e9f;

    --accent: #7f93ff;
    --accent-ink: #9aa9ff;
    --accent-soft: #1b2140;
    --danger: #ea8681;
    --danger-soft: #2c1b1b;
    --success: #6fc496;
    --success-soft: #16281f;

    --memo-bg: #1f1b13;
    --memo-line: #a8853f;
    --task-bg: #141a2c;
    --task-line: #4b64c8;
    --done-bg: #16181f;
    --done-line: #3a4050;
    --review-bg: #131e19;
    --review-line: #3f7d61;

    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-header: 0 6px 20px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 20px 64px;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif;
  font-size: 15px;
  line-height: 1.65;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* 数字は幅をそろえて、増減しても行がずれないようにする */
.stat-value, .meta, .count { font-variant-numeric: tabular-nums; }

/* ---------- ヘッダー ---------- */

.site-header {
  max-width: 880px;
  margin: 24px auto 20px;
  padding: 22px 26px;
  border-radius: var(--r-lg);
  background: linear-gradient(135deg, #1f2a5e 0%, #2f3f8f 55%, #3b3f86 100%);
  color: #fff;
  box-shadow: var(--shadow-header);
}
.site-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: .08em;
}
.site-header .sub {
  margin: 3px 0 0;
  font-size: 13px;
  letter-spacing: .02em;
  color: rgba(255, 255, 255, .72);
}

main { max-width: 880px; margin: 0 auto; }

/* ---------- ダッシュボード ---------- */

.dashboard {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 22px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px 15px;
  box-shadow: var(--shadow);
}
.stat-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .1em;
  color: var(--muted);
}
.stat-figure { display: flex; align-items: baseline; gap: 4px; margin-top: 2px; }
.stat-value { font-size: 30px; font-weight: 600; line-height: 1.1; letter-spacing: -.01em; }
.stat-unit { font-size: 12px; color: var(--muted); }

/* 未完了タスクだけ色を変えて視線を集める */
.stat.accent { background: var(--accent-soft); border-color: transparent; }
.stat.accent .stat-label { color: var(--accent-ink); }
.stat.accent .stat-value { color: var(--accent-ink); }
.stat.accent .stat-unit { color: var(--accent-ink); opacity: .75; }

/* 最新の振り返り（ダッシュボードの幅いっぱいに置く） */
.stat.latest { grid-column: 1 / -1; }
.latest-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.latest-week {
  font-size: 12px;
  font-weight: 600;
  color: var(--review-line);
}
.latest-comment {
  margin: 5px 0 0;
  font-size: 13.5px;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-word;
  /* 長い振り返りは3行で切る（全文は下の一覧で読める） */
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
}
.latest-comment.is-empty { color: var(--muted); }

/* ---------- パネル ---------- */

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

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}
.panel h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .06em;
}
/* 見出しの前に、その区画の色の点を置く */
.panel h2::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
}
.panel-memo h2::before { background: var(--memo-line); }
.panel-task h2::before { background: var(--task-line); }
.panel-review h2::before { background: var(--review-line); }

.count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--sunken);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 9px;
  letter-spacing: 0;
}

/* ---------- 入力欄 ---------- */

.form {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--sunken);
}
.form.row { flex-direction: row; }
.form.row input { flex: 1; }

/* 週の選択 */
.field { display: flex; align-items: center; gap: 10px; }
.field-label {
  flex: none;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  color: var(--muted);
}
select {
  flex: 1;
  min-width: 0;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 15px center, right 10px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}

.hint { margin: 0; font-size: 12px; color: var(--muted); }
.hint[hidden] { display: none; }

input[type="text"], textarea, select {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--panel);
  color: var(--text);
  resize: vertical;
  transition: border-color var(--ease), box-shadow var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input[type="text"]:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

/* ---------- ボタン ---------- */

button {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 10px 18px;
  background: var(--accent);
  color: #fff;
  white-space: nowrap;
  transition: background var(--ease), border-color var(--ease), transform var(--ease);
}
button:hover { background: var(--accent-ink); }
button:active { transform: translateY(1px); }
button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
}

/* ---------- 一覧 ---------- */

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 13px 15px 12px;
  background: var(--panel);
  overflow: hidden;
  transition: border-color var(--ease);
}
/* 左端の色帯（枠線ではなく擬似要素にして、角丸をきれいに出す） */
.card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
}

.card.memo { background: var(--memo-bg); }
.card.memo::before { background: var(--memo-line); }

.card.task { background: var(--task-bg); }
.card.task::before { background: var(--task-line); }

.card.task.is-done { background: var(--done-bg); }
.card.task.is-done::before { background: var(--done-line); }

.card.review { background: var(--review-bg); }
.card.review::before { background: var(--review-line); }

.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-title { font-weight: 600; line-height: 1.5; word-break: break-word; }
.card-body {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-word;
}
.task.is-done .card-title { text-decoration: line-through; color: var(--muted); }

.meta {
  margin-top: 9px;
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.badge {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .04em;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
}
.badge.open { color: var(--accent-ink); background: var(--accent-soft); }
.badge.done { color: var(--success); background: var(--success-soft); }

/* 行内の操作ボタンは控えめに。カードに乗せても浮かないよう枠線だけで表現する */
.actions { display: flex; gap: 6px; flex-shrink: 0; }
.actions button {
  padding: 4px 11px;
  font-size: 12px;
  font-weight: 500;
  background: var(--panel);
  border-color: var(--border-strong);
  color: var(--text-2);
}
.actions button:hover { background: var(--panel); border-color: var(--muted); color: var(--text); }
.actions .toggle:hover { border-color: var(--accent); color: var(--accent-ink); }
.actions .delete:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }

.empty {
  margin: 0;
  padding: 18px 0 6px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- エラー ---------- */

.error {
  display: flex;
  gap: 8px;
  margin: 0 0 16px;
  padding: 11px 14px;
  font-size: 13.5px;
  border-radius: var(--r-md);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  background: var(--danger-soft);
  color: var(--danger);
}
/* display 指定が hidden 属性より強いので、明示的に消す */
.error[hidden] { display: none; }

/* ---------- 狭い画面 ---------- */

@media (max-width: 720px) {
  body { padding: 0 14px 48px; }
  .site-header { margin-top: 16px; padding: 18px 20px; }
  .dashboard { grid-template-columns: 1fr; gap: 8px; }
  /* 数字のタイルだけ横並びにする（振り返りは縦のまま） */
  .stat:not(.latest) { display: flex; align-items: center; justify-content: space-between; padding: 12px 15px; }
  .stat-figure { margin-top: 0; }
  .stat-value { font-size: 22px; }
  .panel { padding: 16px; }
  .card-head { flex-direction: column; align-items: stretch; }
  .actions { justify-content: flex-end; }
}
