:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --item: #f7f9fc;
  --item-hover: #f0f4fa;
  --border: #dde3ec;
  --text: #1f2733;
  --text-soft: #3a4452;
  --muted: #6b7686;
  --primary: #3b5bdb;
  --primary-hover: #2f4bc0;
  --primary-soft: #e8edfd;
  --success: #2f9e6b;
  --success-soft: #e3f5ec;
  --danger: #d9485f;
  --danger-soft: #fdecef;
  --danger-border: #f3c4cc;
  --warning: #d97d06;
  --warning-soft: #fdf1e0;
  --done-bg: #fbfcfd;
  --topbar-a: #26324a;
  --topbar-b: #34466b;
  --focus-ring: #c9d4fa;
  --toast-bg: #1f2733;
  --toast-text: #ffffff;
  --toast-action: #9db2ff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 50, 0.06), 0 4px 16px rgba(20, 30, 50, 0.06);
}

/* ダークモード (OSの設定に合わせる) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141922;
    --surface: #1c2330;
    --item: #232b3a;
    --item-hover: #2a3345;
    --border: #334055;
    --text: #e6eaf1;
    --text-soft: #c4ccd8;
    --muted: #93a0b3;
    --primary: #7b96f5;
    --primary-hover: #93aaf8;
    --primary-soft: #2a3558;
    --success: #5cc795;
    --success-soft: #1f3a2f;
    --danger: #f07a8c;
    --danger-soft: #3d2229;
    --danger-border: #5b3039;
    --warning: #f2a23c;
    --warning-soft: #3d3020;
    --done-bg: #1f2633;
    --topbar-a: #0f141c;
    --topbar-b: #1d2840;
    --focus-ring: #3a4a7a;
    --toast-bg: #e6eaf1;
    --toast-text: #1f2733;
    --toast-action: #3b5bdb;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Yu Gothic", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* キーボード操作時のフォーカスを見えるようにする */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---- ヘッダー ---- */
.topbar {
  background: linear-gradient(120deg, var(--topbar-a), var(--topbar-b));
  color: #fff;
}
.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.15);
  font-weight: 700; font-size: 1.2rem;
}
.brand h1 { margin: 0; font-size: 1.25rem; letter-spacing: 0.02em; }
.brand-sub { margin: 0; font-size: 0.8rem; opacity: 0.75; }
.today { margin: 0; font-size: 0.9rem; opacity: 0.85; }

main { max-width: 1120px; margin: 0 auto; padding: 24px 20px 96px; }

.load-error {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px; padding: 10px 14px; border-radius: 10px;
  background: var(--danger-soft); border: 1px solid var(--danger-border); color: var(--text);
  font-size: 0.9rem;
}
.load-error span { flex: 1; min-width: 12em; }

/* ---- 秘書からのひとこと ---- */
.briefing {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 16px 24px;
  margin: -8px 0 16px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  border-top: 4px solid var(--primary);
}
.briefing-main { display: flex; gap: 14px; align-items: flex-start; }
.secretary-avatar {
  flex: none;
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--topbar-b), var(--primary));
  color: #fff; font-weight: 700; font-size: 1.1rem;
}
.briefing-body { min-width: 0; }
.briefing-greeting { margin: 0 0 6px; font-size: 1.15rem; }
.briefing-notes { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.briefing-notes li {
  position: relative; padding-left: 14px; color: var(--text-soft); font-size: 0.92rem;
}
.briefing-notes li::before {
  content: ""; position: absolute; left: 0; top: 0.65em;
  width: 6px; height: 6px; border-radius: 50%; background: var(--primary);
}
.briefing-notes .btn { margin-left: 4px; vertical-align: baseline; }

.focus-card {
  padding: 12px 14px; border-radius: 10px;
  background: var(--warning-soft); border: 1px solid var(--border);
}
.focus-card .mini-label { color: var(--warning); }
.focus-card.done { background: var(--success-soft); }
.focus-card.done .mini-label { color: var(--success); }
.focus-title { margin: 4px 0 8px; font-size: 1.1rem; font-weight: 700; word-break: break-word; }
.focus-card.done .focus-title { text-decoration: line-through; color: var(--muted); }
.focus-empty, .focus-status { margin: 4px 0 0; font-size: 0.88rem; color: var(--muted); }
.focus-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.quick-add { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 6px; }
.quick-row { display: flex; gap: 10px; }
.quick-row input { flex: 1; min-width: 0; }
kbd {
  font: inherit; font-size: 0.75rem; padding: 0 6px; border-radius: 4px;
  border: 1px solid var(--border); background: var(--item); color: var(--text);
}

@media (max-width: 800px) {
  .briefing { grid-template-columns: 1fr; padding: 16px; }
}

/* 未完了ゼロのお祝い */
.briefing.celebrate { animation: celebrate 1.2s ease-out; }
.briefing.celebrate .secretary-avatar { animation: hop 0.6s ease-out 2; }
@keyframes celebrate {
  0% { box-shadow: 0 0 0 0 var(--success); }
  40% { box-shadow: 0 0 0 8px var(--success-soft); }
  100% { box-shadow: var(--shadow); }
}
@keyframes hop {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

/* ---- ダッシュボード ---- */
.dashboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: -8px;
  margin-bottom: 24px;
}
.stat {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  border-top: 4px solid var(--primary);
}
.stat-accent { border-top-color: var(--warning); }
.stat-label { display: block; font-size: 0.85rem; color: var(--muted); }
.stat-value { font-size: 2.2rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-unit { margin-left: 4px; color: var(--muted); font-size: 0.9rem; }
.stat-accent .stat-value { color: var(--warning); }

/* ダッシュボード: 未完了タスクの一覧 */
.open-tasks, .latest-review {
  grid-column: 1 / -1;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--warning);
}
.open-tasks-title { margin: 0 0 8px; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.open-task-list { list-style: none; margin: 0; padding: 0; }
.open-task-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.open-task-list li:last-child { border-bottom: none; }
.open-task-list .task-title { flex: 1; min-width: 0; }
.open-task-list .meta { white-space: nowrap; }
.open-task-list li.empty { color: var(--muted); font-size: 0.9rem; }
.open-tasks-more { margin: 8px 0 0; font-size: 0.8rem; color: var(--muted); }

/* ダッシュボード: 最新の振り返り */
.latest-review { border-left-color: var(--success); display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.latest-review-body { flex: 1; min-width: 14em; }
.latest-review-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.latest-review-head .open-tasks-title { margin: 0; }
.latest-review-week { font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.latest-review-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px; }
.latest-review-text { margin: 2px 0 0; white-space: pre-wrap; word-break: break-word; color: var(--text-soft); font-size: 0.92rem; }
.latest-review-text.empty { color: var(--muted); }
.latest-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.latest-side a { text-decoration: none; }
.streak { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.streak strong { color: var(--success); font-size: 1.1rem; }
.reminder {
  display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 2px 10px; border-radius: 999px;
  background: var(--warning-soft); color: var(--warning);
}
.mini-label { display: block; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; color: var(--muted); }
.prio-list { margin: 2px 0 0; padding-left: 1.3em; color: var(--text-soft); font-size: 0.92rem; }

/* ---- レイアウト ---- */
.columns { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
@media (max-width: 800px) {
  .columns { grid-template-columns: 1fr; }
  .dashboard { gap: 10px; }
  .stat { padding: 14px; }
  .stat-value { font-size: 1.7rem; }
  .latest-review-grid { grid-template-columns: 1fr; }
  .latest-side { align-items: flex-start; }
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}
.panel-title {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 14px;
  font-size: 1rem;
  font-weight: 700;
}
.count {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

/* ---- フォーム ---- */
.form { display: flex; flex-direction: column; gap: 10px; }
.form-inline { display: flex; gap: 10px; }
.form-inline input { flex: 1; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.plain { border: 0; margin: 0; padding: 0; min-width: 0; }
label, .field-label { font-size: 0.85rem; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.field-label { padding: 0; margin-bottom: 4px; }
.required {
  font-size: 0.7rem; font-weight: 700; padding: 0 6px; border-radius: 4px;
  background: var(--danger-soft); color: var(--danger);
}
.hint, .hint-inline { color: var(--muted); font-size: 0.78rem; font-weight: 400; }
.hint { margin: -4px 0 0; }
.form-error { margin: 0; color: var(--danger); font-size: 0.85rem; font-weight: 600; }

input[type="text"], textarea {
  font: inherit;
  color: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--item);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
textarea { resize: vertical; }
input[type="text"]:focus, textarea:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
[aria-invalid="true"] { border-color: var(--danger) !important; }

/* ---- ボタン ---- */
.btn {
  font: inherit;
  font-weight: 600;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-success { background: var(--success-soft); color: var(--success); }
.btn-success:hover:not(:disabled) { background: var(--success); color: #fff; }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger-border); }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--item); }
.push-right { margin-left: auto; }

/* ---- 一覧 ---- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.list li.item {
  background: var(--item);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 10px;
  padding: 12px 14px;
  transition: background 0.15s, box-shadow 0.15s;
}
.list li.item:hover { background: var(--item-hover); }
.list li.empty {
  text-align: center;
  color: var(--muted);
  padding: 24px 12px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
}

.memo-title { font-weight: 700; word-break: break-word; }
.memo-content { white-space: pre-wrap; word-break: break-word; margin: 4px 0 6px; color: var(--text-soft); font-size: 0.95rem; }
.meta { color: var(--muted); font-size: 0.78rem; font-variant-numeric: tabular-nums; }

.list li.task { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.list li.task.open { border-left-color: var(--warning); }
.list li.task.done { border-left-color: var(--success); background: var(--done-bg); }
.task-body { flex: 1; min-width: 12em; }
.task-title { font-weight: 600; word-break: break-word; }
.task.done .task-title { text-decoration: line-through; color: var(--muted); font-weight: 400; }
.task-actions { display: flex; gap: 6px; margin-left: auto; }

.badge {
  display: inline-block;
  vertical-align: middle;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  margin-left: 6px;
  background: var(--warning-soft);
  color: var(--warning);
}
.badge.done { background: var(--success-soft); color: var(--success); }
.badge.stale { background: var(--danger-soft); color: var(--danger); }

/* 今日のフォーカス (星) */
.btn-star {
  padding: 2px 8px; font-size: 1rem; line-height: 1.4;
  background: transparent; color: var(--muted); border-color: transparent;
}
.btn-star:hover:not(:disabled) { color: var(--warning); background: var(--warning-soft); }
.btn-star.on { color: var(--warning); }

/* タスクの絞り込み */
.filters { display: flex; gap: 6px; margin: -4px 0 12px; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: 0.8rem; padding: 3px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: transparent; color: var(--muted);
}
.chip[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 700; }

/* ---- 週次の振り返り ---- */
.review-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 24px; align-items: start; }
@media (max-width: 800px) { .review-grid { grid-template-columns: 1fr; } }
.reviews { scroll-margin-top: 16px; }
.week-nav { display: flex; align-items: center; gap: 8px; }
.week-label { flex: 1; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.week-label small { display: block; font-weight: 400; color: var(--muted); font-size: 0.78rem; }
.week-summary {
  margin: 0; padding: 8px 12px; border-radius: 8px; background: var(--item);
  border: 1px solid var(--border); color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums;
}
.review-steps { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--item); border: 1px solid var(--border); }
.review-steps legend, .rating legend { font-size: 0.8rem; font-weight: 700; color: var(--muted); padding: 0 4px; }
.check { display: flex; align-items: flex-start; gap: 8px; font-size: 0.88rem; font-weight: 400; cursor: pointer; }
.check input { margin-top: 0.3em; accent-color: var(--success); }
.carry { margin: 0; padding: 10px 12px; border-radius: 8px; font-size: 0.88rem; background: var(--primary-soft); }
.carry .mini-label { color: var(--primary); }
.kpt {
  display: inline-block; min-width: 1.6em; text-align: center; font-size: 0.7rem; font-weight: 700;
  padding: 1px 6px; border-radius: 4px; letter-spacing: 0.04em;
}
.kpt-k { background: var(--success-soft); color: var(--success); }
.kpt-p { background: var(--danger-soft); color: var(--danger); }
.kpt-t { background: var(--primary-soft); color: var(--primary); }
.rating { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.rating-scale { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.rating-scale input { position: absolute; opacity: 0; pointer-events: none; }
.rating-scale label {
  width: 2.3em; height: 2.3em; display: grid; place-items: center; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--item); font-variant-numeric: tabular-nums;
}
.rating-scale input:checked + label { background: var(--success); border-color: var(--success); color: #fff; }
.rating-scale input:focus-visible + label { outline: 2px solid var(--primary); outline-offset: 2px; }
.rating-ends { font-size: 0.75rem; color: var(--muted); }
.prio-inputs { display: flex; flex-direction: column; gap: 6px; }
.prio-row { display: flex; align-items: center; gap: 8px; }
.prio-row span { width: 1.2em; text-align: right; color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }
.prio-row input { flex: 1; min-width: 0; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.form-actions .btn-primary { flex: 1; }
.list li.review { border-left-color: var(--success); }
.list li.review.selected { box-shadow: 0 0 0 2px var(--focus-ring); }
.review-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.review-week { font-weight: 700; font-variant-numeric: tabular-nums; }
.rating-chip {
  font-size: 0.75rem; font-weight: 700; padding: 1px 8px; border-radius: 999px;
  background: var(--success-soft); color: var(--success); font-variant-numeric: tabular-nums;
}
.review-sec { margin: 8px 0 0; }
.review-text { white-space: pre-wrap; word-break: break-word; margin: 2px 0 6px; color: var(--text-soft); font-size: 0.95rem; }

/* ---- お知らせ (トースト) ---- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px);
  display: flex; align-items: center; gap: 16px;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 12px 18px; border-radius: 10px;
  background: var(--toast-bg); color: var(--toast-text);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  font-size: 0.9rem;
  opacity: 0; visibility: hidden;
  transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
}
.toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
.toast-action {
  font: inherit; font-weight: 700; background: none; border: none; padding: 4px 6px;
  color: var(--toast-action); cursor: pointer; white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; animation: none !important; }
}
