:root {
  --bg: #f4f1ec;
  --paper: #ffffff;
  --ink: #1f2a37;
  --ink-2: #5b6573;
  --line: #e3ddd3;
  --fixed: #1f2a37;
  --fixed-ink: #ffffff;
  --block: #dfe6ee;
  --block-ink: #34485e;
  --alt: #c2410c;
  --alt-soft: #fff1e8;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #a16207;
  --warn-soft: #fdf6dc;
  --danger: #b91c1c;
  --shadow: 0 1px 2px rgba(31, 42, 55, .06), 0 4px 14px rgba(31, 42, 55, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #13171c; --paper: #1c2229; --ink: #eef1f4; --ink-2: #9aa5b1; --line: #2c343d;
    --fixed: #eef1f4; --fixed-ink: #13171c; --block: #26313d; --block-ink: #b8c7d8;
    --alt: #fb923c; --alt-soft: #33231a; --ok: #4ade80; --ok-soft: #17301f;
    --warn: #facc15; --warn-soft: #2f2a14; --danger: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #13171c; --paper: #1c2229; --ink: #eef1f4; --ink-2: #9aa5b1; --line: #2c343d;
  --fixed: #eef1f4; --fixed-ink: #13171c; --block: #26313d; --block-ink: #b8c7d8;
  --alt: #fb923c; --alt-soft: #33231a; --ok: #4ade80; --ok-soft: #17301f;
  --warn: #facc15; --warn-soft: #2f2a14; --danger: #f87171;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:active { transform: scale(.97); }
button[disabled] { opacity: .5; pointer-events: none; }

#app { max-width: 640px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(132px + env(safe-area-inset-bottom)); }

/* ---------- 上の帯 ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: 48px 1fr 48px; align-items: center;
  padding: calc(8px + env(safe-area-inset-top)) 8px 8px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
}
.nav-btn { font-size: 30px; line-height: 1; height: 44px; border-radius: 12px; color: var(--ink-2); }
.date-title { font-weight: 800; font-size: 20px; letter-spacing: .02em; height: 44px; border-radius: 12px; }
.date-title small { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-top: -4px; }

main { padding: 4px 16px 0; animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- お知らせ ---------- */
.notice {
  background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  border-radius: var(--radius); padding: 12px 14px; margin: 4px 0 14px;
}
.notice h3 { margin: 0 0 6px; font-size: 14px; color: var(--warn); }
.notice .row { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 6px 0; border-top: 1px dashed color-mix(in srgb, var(--warn) 30%, transparent); }
.notice .row:first-of-type { border-top: 0; }
.notice .row span { font-size: 14px; }
.notice .acts { display: flex; gap: 6px; flex-shrink: 0; }

/* ---------- 1日の並び ---------- */
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.slot { display: grid; grid-template-columns: 52px 1fr; gap: 10px; align-items: stretch; }
.slot .time { font-variant-numeric: tabular-nums; font-size: 14px; font-weight: 700; color: var(--ink-2); padding-top: 12px; text-align: right; }
.slot .time small { display: block; font-weight: 500; font-size: 12px; }

.card {
  position: relative; background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px 12px 18px; overflow: hidden;
  display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: left;
}
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--bar, var(--b-multi)); }
.card .body { flex: 1; min-width: 0; }
.card .title { font-weight: 700; word-break: break-word; }
.card .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; font-size: 12px; color: var(--ink-2); }
.chip { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 1px 9px; font-weight: 700; font-size: 12px; background: color-mix(in srgb, var(--bar, var(--b-multi)) 14%, transparent); color: var(--bar, var(--b-multi)); }
.chip.alt { background: var(--alt); color: #fff; }
.chip.conflict { background: var(--danger); color: #fff; }

.card.fixed { background: var(--fixed); color: var(--fixed-ink); }
.card.fixed .meta { color: color-mix(in srgb, var(--fixed-ink) 70%, transparent); }
.card.fixed .lock { font-size: 11px; font-weight: 800; letter-spacing: .08em; border: 1px solid currentColor; border-radius: 6px; padding: 0 6px; opacity: .85; }

.card.alt { background: var(--alt-soft); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--alt) 55%, transparent); }
.card.is-done { opacity: .62; }
.card.is-done .title { text-decoration: line-through; text-decoration-thickness: 1.5px; }
.card.conflict { opacity: .55; }
.card.now { box-shadow: 0 0 0 2.5px var(--ink), var(--shadow); }

.block-band {
  border-radius: var(--radius); padding: 10px 14px;
  background: repeating-linear-gradient(-45deg, var(--block), var(--block) 10px, color-mix(in srgb, var(--block) 70%, var(--paper)) 10px, color-mix(in srgb, var(--block) 70%, var(--paper)) 20px);
  color: var(--block-ink); font-weight: 700; font-size: 14px;
}

.done-btn {
  flex-shrink: 0; min-width: 72px; padding: 0 10px; height: 40px; border-radius: 12px; font-weight: 800; font-size: 13px; white-space: nowrap;
  border: 1.5px solid var(--line); background: var(--paper); color: var(--ink-2);
  transition: background .15s, color .15s, border-color .15s;
}
.done-btn.on { background: var(--ok); border-color: var(--ok); color: #fff; }

.empty { text-align: center; color: var(--ink-2); padding: 40px 0; }
.summary { display: flex; gap: 8px; flex-wrap: wrap; margin: 2px 0 12px; font-size: 13px; color: var(--ink-2); }
.summary b { color: var(--ink); }

/* ---------- 週 ---------- */
.week { display: grid; gap: 10px; }
.wday { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; text-align: left; width: 100%; }
.wday.today { box-shadow: 0 0 0 2px var(--ink), var(--shadow); }
.wday h3 { margin: 0 0 6px; font-size: 16px; display: flex; justify-content: space-between; align-items: baseline; }
.wday h3 span { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.wday ul { list-style: none; margin: 0; padding: 0; font-size: 14px; display: grid; gap: 3px; }
.wday li.f { font-weight: 700; }
.wday li.b { color: var(--block-ink); }
.wday .bar { height: 6px; border-radius: 3px; background: var(--line); margin-top: 8px; overflow: hidden; }
.wday .bar i { display: block; height: 100%; background: var(--ok); }

/* ---------- メモ ---------- */
.memo-box { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; }
.memo-box textarea { width: 100%; min-height: 150px; border: 0; outline: none; resize: vertical; background: transparent; font-size: 17px; }
.memo-box .acts { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pending { font-size: 13px; color: var(--warn); font-weight: 700; }
.memo-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 8px; }
.memo-list li { background: var(--paper); border-radius: 12px; padding: 10px 12px; white-space: pre-wrap; word-break: break-word; font-size: 15px; }
.memo-list time { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 2px; }
.memo-list .wait { border: 1.5px dashed var(--warn); }

/* ---------- AIと埋める ---------- */
.ai + .ai { margin-top: 14px; }
.ai h2 { margin: 0 0 6px; font-size: 16px; }
.steps { margin: 0 0 12px; padding-left: 1.3em; font-size: 14px; color: var(--ink-2); }
.steps li { margin: 2px 0; }
.ai textarea { min-height: 120px; font-size: 14px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.preview { margin-top: 12px; border-radius: 12px; padding: 12px; background: var(--ok-soft); }
.preview.bad { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.preview p { margin: 0 0 8px; font-weight: 700; }
.preview ul { margin: 0 0 10px; padding-left: 1.2em; font-size: 13px; }
.kit-out { width: 100%; min-height: 160px; font-size: 12px; margin-top: 10px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--bg); color: var(--ink); padding: 8px; }

/* ---------- 履歴 ---------- */
h2.sec { font-size: 15px; margin: 18px 0 8px; color: var(--ink-2); }
.hist { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 14px; }
.hist li { background: var(--paper); border-radius: 12px; padding: 9px 12px; display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.hist time { font-size: 12px; color: var(--ink-2); display: block; }
.who { font-size: 11px; font-weight: 800; border-radius: 6px; padding: 0 6px; margin-right: 4px; background: var(--line); }

/* ---------- ボタン ---------- */
.btn { border-radius: 12px; padding: 10px 16px; font-weight: 800; background: var(--ink); color: var(--bg); min-height: 44px; }
.btn.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: 13px; }
.btn.wide { width: 100%; }

.fab {
  position: fixed; right: max(16px, calc(50% - 304px)); bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 6;
  background: var(--ink); color: var(--bg); font-weight: 800; border-radius: 999px; padding: 12px 18px; box-shadow: 0 6px 20px rgba(0, 0, 0, .22);
}

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--paper); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { height: 58px; font-weight: 700; color: var(--ink-2); font-size: 15px; position: relative; }
.tabs button.on { color: var(--ink); }
.tabs button.on::after { content: ""; position: absolute; left: 30%; right: 30%; top: 0; height: 3px; border-radius: 0 0 3px 3px; background: var(--ink); }

/* ---------- 下から出る画面 ---------- */
.sheet-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 20; animation: fade .18s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-width: 640px; margin: 0 auto;
  background: var(--paper); border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto; animation: up .24s cubic-bezier(.2, .8, .2, 1);
}
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
.sheet h2 { margin: 0 0 12px; font-size: 18px; }
.sheet .acts { display: grid; gap: 8px; margin-top: 14px; }
.field { display: grid; gap: 4px; margin-bottom: 10px; font-size: 13px; font-weight: 700; color: var(--ink-2); }
.field input, .field select { font-size: 17px; padding: 10px 12px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--bg); color: var(--ink); width: 100%; }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.field input { min-width: 0; }
.field input[type="date"], .field input[type="time"] { font-size: 16px; padding: 10px 8px; }

.toast {
  position: fixed; left: 50%; bottom: calc(140px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 700; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 30; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--danger); color: #fff; }

/* ---------- ログイン ---------- */
.login { max-width: 360px; margin: 18vh auto 0; padding: 0 16px; text-align: center; }
.login h1 { font-size: 24px; margin: 0 0 18px; }
.login input { width: 100%; font-size: 18px; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--paper); margin-bottom: 10px; }

.card.tentative{border:2px dashed #ad7a25}.collapsed{list-style:none;margin:0 0 12px 64px}.collapsed summary{cursor:pointer;font-size:13px;padding:8px}.collapsed .timeline{padding-top:8px}
/* Imported candidates and non-blocking date markers */
.date-marks { display:flex; gap:8px; flex-wrap:wrap; margin:8px 0; }
.candidate-group { border:1px solid #d7ddd6; border-radius:10px; margin:16px 0; padding:12px; }
.candidate-group legend { font-weight:700; padding:0 6px; }
.candidate-row { display:flex; align-items:flex-start; gap:12px; padding:12px 4px; border-bottom:1px solid #e5e9e4; }
.candidate-row input { flex:0 0 22px; width:22px; height:22px; margin:0; }
.candidate-row span { overflow-wrap:anywhere; }
.candidate-row small,.candidate-row strong { display:block; margin-top:4px; }
.needs-check { background:#fff5df; color:#42330f; }
.candidate-actions { display:flex; flex-wrap:wrap; gap:8px; margin:12px 0; }
