:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1d2733;
  --muted: #6b7785;
  --line: #dde3ea;
  --primary: #2f5d8a;
  --primary-text: #ffffff;
  --accent: #e8f0f8;
  --done: #9aa5b1;
  --danger: #c0392b;
  --bot: #eef3f8;
  --me: #2f5d8a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12171d;
    --card: #1b222b;
    --text: #e4e9ef;
    --muted: #8e9aa7;
    --line: #2c3540;
    --primary: #5b8fc4;
    --accent: #23303e;
    --done: #5d6873;
    --bot: #232c37;
    --me: #3d6c9c;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
h1 { font-size: 1.1rem; margin: 0; }
h3 { font-size: .95rem; margin: 1.4rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.err { color: var(--danger); min-height: 1.2em; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: .5rem; margin: .5rem 0; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: .5rem; }

input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .55rem .7rem;
  width: 100%;
}
select { width: auto; }
textarea { resize: vertical; }
button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  padding: .55rem 1rem;
  cursor: pointer;
}
button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
button.ghost, .ghost { background: transparent; }
button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
button.small, .small.ghost { padding: .35rem .7rem; font-size: .82rem; }
button:disabled { opacity: .5; cursor: default; }
.file-btn { border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.danger-h { color: var(--danger); }

/* ロック画面 */
.lock { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.lock-box {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 2rem 1.5rem; width: min(360px, 100%); text-align: center;
}
.lock-box h1 { margin: .6rem 0 .3rem; }
.lock-box form { display: flex; flex-direction: column; gap: .6rem; margin-top: 1rem; }

/* メイン */
#app { max-width: 760px; margin: 0 auto; padding: 0 16px 40px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + .8rem) 0 .6rem;
}
.tabs {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  position: sticky; top: 0; background: var(--bg); padding: .4rem 0; z-index: 5;
}
.tabs button { padding: .5rem .2rem; font-size: .85rem; border-radius: 8px; }
.tabs button.active { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.tab { padding-top: .6rem; }

/* カテゴリチップ */
.cat-chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .3rem; }
.cat-chips button { white-space: nowrap; border-radius: 999px; padding: .35rem .9rem; font-size: .85rem; }
.cat-chips button.active { background: var(--accent); border-color: var(--primary); color: var(--primary); font-weight: 600; }
.cat-chips .badge { font-size: .72rem; color: var(--muted); margin-left: .25rem; }

/* チェックリスト */
.checklist { list-style: none; padding: 0; margin: .4rem 0; display: flex; flex-direction: column; gap: .4rem; }
.checklist li {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  display: flex; align-items: flex-start; gap: .6rem; padding: .7rem .8rem;
}
.checklist li input[type=checkbox] { width: 1.3rem; height: 1.3rem; margin-top: .1rem; flex: none; accent-color: var(--primary); }
.checklist li .txt { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.checklist li.done .txt { color: var(--done); text-decoration: line-through; }
.checklist .meta { font-size: .72rem; color: var(--muted); display: block; margin-top: .15rem; }
.checklist .count { background: var(--accent); color: var(--primary); border-radius: 999px; padding: 0 .5rem; font-size: .72rem; font-weight: 600; }
.icon-btn { border: none; background: transparent; padding: .1rem .3rem; color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 1.5rem 0; }
.inline-form { display: flex; gap: .4rem; margin-top: .6rem; }
.inline-form input { flex: 1; }
.inline-form button { flex: none; }

/* BOT */
.chat { display: flex; flex-direction: column; gap: .6rem; min-height: 200px; padding-bottom: .6rem; }
.msg { max-width: 88%; padding: .6rem .8rem; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--me); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--bot); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.proposal { background: var(--card); border: 1px solid var(--primary); border-radius: 12px; padding: .8rem; align-self: stretch; }
.proposal label { display: block; font-size: .78rem; color: var(--muted); margin-top: .5rem; }
.proposal .row { margin-top: .7rem; }
.bot-form { display: flex; flex-direction: column; gap: .5rem; position: sticky; bottom: 0; background: var(--bg); padding: .5rem 0; }

/* 履歴 */
.filters { display: flex; flex-wrap: wrap; gap: .6rem; font-size: .85rem; }
.filters label { display: flex; align-items: center; gap: .3rem; flex-wrap: wrap; }
.filters input[type=date] { width: auto; padding: .35rem .5rem; }
.history { list-style: none; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
.history li { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .8rem; }
.history .h-head { display: flex; gap: .5rem; align-items: center; font-size: .78rem; color: var(--muted); }
.history .tag { background: var(--accent); color: var(--primary); border-radius: 999px; padding: 0 .5rem; }
.history .h-sum { margin: .2rem 0 0; overflow-wrap: anywhere; }
.history details { font-size: .8rem; color: var(--muted); margin-top: .2rem; }
#exportText { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .82rem; }

/* 設定 */
.cat-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .3rem; }
.cat-list li { display: flex; align-items: center; gap: .4rem; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .3rem .6rem; }
.cat-list li span { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%);
  background: #1d2733; color: #fff; padding: .6rem 1.1rem; border-radius: 999px; font-size: .88rem; z-index: 50;
  max-width: calc(100% - 32px);
}
