/* ===============================================================
   マイ秘書アプリ - スタイル
   =============================================================== */

/* --- デザイントークン（ライト） --- */
:root {
  --bg:            #f5f6f9;
  --bg-tint:       #eceefa;
  --surface:       #ffffff;
  --surface-sunk:  #fafbfd;
  --border:        #e7e9f0;
  --border-strong: #d8dbe6;

  --text:          #171a21;
  --text-soft:     #4c5261;
  --muted:         #858b9b;

  --accent:        #5a5fd8;
  --accent-hover:  #4a4fc4;
  --accent-ring:   rgba(90, 95, 216, 0.28);

  --blue:   #4a72d8;  --blue-soft:  #e9effc;
  --green:  #2f9160;  --green-soft: #e6f4ec;
  --amber:  #b3762a;  --amber-soft: #fbf1e0;
  --violet: #7059cf;  --violet-soft:#efebfc;
  --danger: #cf4b4b;  --danger-soft:#fceded;
  --danger-line: rgba(207, 75, 75, 0.32);

  --shadow-sm: 0 1px 2px rgba(23, 26, 33, 0.05);
  --shadow-md: 0 2px 4px rgba(23, 26, 33, 0.04), 0 8px 24px rgba(23, 26, 33, 0.06);

  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 16px;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- デザイントークン（ダーク） --- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #0e1015;
    --bg-tint:       #161a27;
    --surface:       #171a22;
    --surface-sunk:  #1c2029;
    --border:        #262b36;
    --border-strong: #333947;

    --text:          #e9ebf2;
    --text-soft:     #b8bdcc;
    --muted:         #858c9e;

    --accent:        #8a8ef0;
    --accent-hover:  #9a9ef5;
    --accent-ring:   rgba(138, 142, 240, 0.35);

    --blue:   #7ea3f0;  --blue-soft:  #1b2436;
    --green:  #62c795;  --green-soft: #162a20;
    --amber:  #e0a458;  --amber-soft: #2c2314;
    --violet: #a99af0;  --violet-soft:#221f38;
    --danger: #f08585;  --danger-soft:#2e1a1c;
    --danger-line: rgba(240, 133, 133, 0.34);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.25), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

/* 注意: 色は CSS 変数で切り替えているため、色そのものは transition させていません。
   （変数を transition すると、OS のライト/ダーク切り替え時に古い色が残るブラウザがあります）
   動きをつけるのは transform / opacity / box-shadow だけにしています。 */

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN",
               "Yu Gothic UI", "Noto Sans JP", Meiryo, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
  background:
    radial-gradient(900px 420px at 12% -8%, var(--bg-tint), transparent 65%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1060px;
  margin: 0 auto;
  padding: 40px 24px 64px;
}

/* ---------------------------------------------------------------
   ヘッダー
   --------------------------------------------------------------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 26px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(140deg, var(--accent), #7d6ae4);
  box-shadow: 0 6px 16px var(--accent-ring);
}
.brand-mark svg { width: 25px; height: 25px; }

.brand-text h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}
.brand-text p {
  margin: 1px 0 0;
  font-size: 0.83rem;
  color: var(--muted);
}

.today {
  margin: 0;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 0.8rem;
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}

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

.stat {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow 0.2s var(--ease), transform 0.2s var(--ease);
}
.stat:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.stat-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 12px;
}
.stat-icon svg { width: 21px; height: 21px; }

.tone-blue   { color: var(--blue);   background: var(--blue-soft); }
.tone-green  { color: var(--green);  background: var(--green-soft); }
.tone-amber  { color: var(--amber);  background: var(--amber-soft); }
.tone-violet { color: var(--violet); background: var(--violet-soft); }

.stat-body { display: flex; flex-direction: column; min-width: 0; }
.stat-label {
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.stat-value {
  font-size: 1.85rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

/* 強調カード: 左に色の帯を付け、数字にも色を乗せる */
.stat-accent-amber, .stat-accent-green { border-color: var(--border-strong); }
.stat-accent-amber::before, .stat-accent-green::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: linear-gradient(var(--accent-color), transparent);
}
.stat-accent-amber { --accent-color: var(--amber); }
.stat-accent-green { --accent-color: var(--green); }
.stat-accent-amber .stat-value, .stat-accent-green .stat-value { color: var(--accent-color); }

/* --- ダッシュボードの「最新の振り返り」--- */
.latest-review {
  grid-column: 1 / -1;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--violet);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.latest-head {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}
.latest-icon {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  flex-shrink: 0;
}
.latest-icon svg { width: 15px; height: 15px; }

.latest-label {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--muted);
}
.latest-week {
  padding: 1px 10px;
  border-radius: 999px;
  background: var(--violet-soft);
  color: var(--violet);
  font-size: 0.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.latest-saved {
  font-size: 0.74rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.latest-comment {
  margin: 8px 0 0;
  font-size: 0.92rem;
  color: var(--text-soft);
  white-space: pre-wrap;
  word-break: break-word;
}
.latest-comment.is-empty { color: var(--muted); font-style: normal; }

/* 数字が変わったときの軽いアニメーション */
@keyframes pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.14); }
  100% { transform: scale(1); }
}
.stat-value.is-updated { animation: pop 0.32s var(--ease); }

/* ---------------------------------------------------------------
   エラーメッセージ
   --------------------------------------------------------------- */
.alert {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 20px;
  padding: 11px 16px;
  border: 1px solid var(--danger-line);
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.88rem;
}

/* ブラウザ保存モードのお知らせ */
.notice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 0 20px;
  padding: 11px 16px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--blue);
  border-radius: var(--radius);
  background: var(--blue-soft);
  color: var(--text-soft);
  font-size: 0.85rem;
  line-height: 1.55;
}
.notice svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 3px; color: var(--blue); }

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

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

/* 画面いっぱいに広げるパネル（週次の振り返り） */
.panel-wide { margin-top: 18px; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.panel-head h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.panel-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
}
.panel-icon svg { width: 16px; height: 16px; }

.count-pill {
  min-width: 26px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

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

.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-soft);
  letter-spacing: 0.01em;
}

.input-row { display: flex; gap: 8px; }
.input-row input { flex: 1; min-width: 0; }

.field-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--violet);
}

/* 振り返りフォームは「週の選択」と「コメント」を横に並べる */
.review-form {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 14px 16px;
  align-items: start;
}
.review-form .field-comment { grid-column: 2; grid-row: 1; }
.review-form .field-week    { grid-column: 1; grid-row: 1; }
.review-form .btn { grid-column: 2; justify-self: start; }

select {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-sunk);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: box-shadow 0.15s var(--ease);
}
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

input[type="text"], textarea {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-sunk);
  color: var(--text);
  font: inherit;
  transition: box-shadow 0.15s var(--ease);
}
input[type="text"]::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.75; }

input[type="text"]:focus, textarea:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
textarea { resize: vertical; min-height: 84px; line-height: 1.6; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.1s var(--ease), box-shadow 0.15s var(--ease);
}
.btn svg { width: 15px; height: 15px; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--accent-hover); }

/* ---------------------------------------------------------------
   一覧
   --------------------------------------------------------------- */
.list-heading {
  display: flex;
  align-items: center;
  margin: 22px 0 12px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  color: var(--muted);
}
.list-heading::after {
  content: "";
  flex: 1;
  height: 1px;
  margin-left: 12px;
  background: var(--border);
}

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

.item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-sunk);
  padding: 14px 16px;
  transition: box-shadow 0.18s var(--ease);
  animation: rise 0.25s var(--ease);
}
.item:hover {
  border-color: var(--border-strong);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

.item-title {
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.005em;
  word-break: break-word;
}
.item-body {
  margin: 6px 0 0;
  font-size: 0.9rem;
  color: var(--text-soft);
  white-space: pre-wrap;
  word-break: break-word;
}
.item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 9px;
  font-size: 0.75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.item-meta svg { width: 13px; height: 13px; flex-shrink: 0; opacity: 0.8; }
.meta-sep { opacity: 0.45; }

/* 空のとき */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 30px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.86rem;
  text-align: center;
}
.empty svg { width: 26px; height: 26px; opacity: 0.55; }

/* --- 振り返りの行 --- */
.review-row { display: flex; align-items: flex-start; gap: 12px; }
.review-main { flex: 1; min-width: 0; }

.review-week {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}
.week-tag {
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--violet-soft);
  color: var(--violet);
  font-size: 0.7rem;
  font-weight: 700;
}
.review-comment {
  margin: 7px 0 0;
  font-size: 0.9rem;
  color: var(--text-soft);
  white-space: pre-wrap;
  word-break: break-word;
}

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

/* チェックボックスを丸いカスタムデザインに */
.check {
  position: relative;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  cursor: pointer;
}
/* 本物のチェックボックスは見た目だけ隠す
   （display:none や opacity:0 にすると、キーボードや読み上げから使えなくなるため） */
.check input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.check-box {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 1.8px solid var(--border-strong);
  border-radius: 50%;
  background: var(--surface);
  color: transparent;
  transition: box-shadow 0.18s var(--ease);
  pointer-events: none;
}
.check-box svg { width: 12px; height: 12px; }
.check:hover .check-box { border-color: var(--green); }
.check input:focus-visible + .check-box { box-shadow: 0 0 0 3px var(--accent-ring); }
.check input:checked + .check-box {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  padding: 1px 9px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  vertical-align: 2px;
  white-space: nowrap;
}
.badge-open { background: var(--amber-soft); color: var(--amber); }
.badge-done { background: var(--green-soft); color: var(--green); }

/* 削除ボタン（ふだんは control 色、ホバーで赤く）
   opacity で隠すとキーボードや読み上げから見えなくなるので、常に表示します */
.btn-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.btn-icon svg { width: 15px; height: 15px; }
.item:hover .btn-icon, .btn-icon:hover, .btn-icon:focus-visible { opacity: 1; }
.btn-icon:hover {
  background: var(--danger-soft);
  border-color: var(--danger-line);
  color: var(--danger);
}
.btn-icon:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }

/* ---------------------------------------------------------------
   フッター
   --------------------------------------------------------------- */
.app-footer {
  margin-top: 34px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
}
.app-footer code {
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.95em;
}

/* ---------------------------------------------------------------
   レスポンシブ
   --------------------------------------------------------------- */
@media (max-width: 860px) {
  .columns { grid-template-columns: 1fr; }
  /* 4枚のカードは 2×2 に */
  .dashboard { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
  /* 振り返りフォームは縦に積む */
  .review-form { grid-template-columns: 1fr; }
  .review-form .field-week,
  .review-form .field-comment,
  .review-form .btn { grid-column: 1; grid-row: auto; }
  .review-form .btn { justify-self: stretch; }
}
@media (max-width: 620px) {
  .app { padding: 26px 16px 48px; }
  .dashboard { grid-template-columns: 1fr; gap: 10px; }
  .stat { padding: 14px 16px; }
  .stat-value { font-size: 1.6rem; }
  .app-header { gap: 12px; }
  /* スマホではホバーがないので、削除ボタンをはっきり表示 */
  .btn-icon { opacity: 1; transition: none; }
}

/* 動きを減らす設定の人向け */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
