/* ===== 色（ライト / ダーク） ===== */
:root {
  --bg: #f6f6f3; --panel: #ffffff; --text: #1d1d1f; --muted: #6b6b70; --line: #e3e3de; --soft: #efefea;
  --accent: #2f6f5e; --accent-text: #fff; --accent-soft: #e3f0ec; --danger: #b3261e; --warn: #9a6400; --ok: #2f6f5e;
  --doing: #1f6feb; --waiting: #9a6400; --todo: #6b6b70; --unknown: #8a4fbf; --done: #2f8f4e;
  --radius: 10px; --nav-w: 248px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  --font: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, "Noto Sans Mono CJK JP", monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141517; --panel: #1c1d20; --text: #e8e8e6; --muted: #9a9aa0; --line: #2d2e33; --soft: #25262a;
    --accent: #5fb89e; --accent-text: #0e1512; --accent-soft: #1f302b; --danger: #ff8a80; --warn: #e0b050; --ok: #5fb89e;
    --doing: #6ea8ff; --waiting: #e0b050; --todo: #9a9aa0; --unknown: #c39af0; --done: #6cc98a; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #141517; --panel: #1c1d20; --text: #e8e8e6; --muted: #9a9aa0; --line: #2d2e33; --soft: #25262a;
  --accent: #5fb89e; --accent-text: #0e1512; --accent-soft: #1f302b; --danger: #ff8a80; --warn: #e0b050; --ok: #5fb89e;
  --doing: #6ea8ff; --waiting: #e0b050; --todo: #9a9aa0; --unknown: #c39af0; --done: #6cc98a; --shadow: none;
}

/* ===== 基本 ===== */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.7 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; line-height: 1.35; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; display: flex; align-items: baseline; gap: .5rem; }
h1 small, h2 small { color: var(--muted); font-weight: 400; font-size: .8rem; }
.muted { color: var(--muted); font-size: .86rem; }
.empty { color: var(--muted); padding: .75rem 0; margin: 0; }
code, kbd, pre { font-family: var(--mono); font-size: .86em; }
kbd { opacity: .7; font-size: .72em; margin-left: .25rem; }
[hidden] { display: none !important; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem; min-width: 0; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .3rem; padding: .5rem .9rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; white-space: nowrap; min-height: 40px; text-decoration: none !important; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 32px; padding: .25rem .7rem; font-size: .86rem; }
.icon-btn { background: none; border: 0; font-size: 1.25rem; width: 44px; height: 44px; display: grid; place-items: center; cursor: pointer; color: var(--text); text-decoration: none !important; }

/* ===== レイアウト ===== */
.nav { position: fixed; inset: 0 auto 0 0; width: var(--nav-w); background: var(--panel); border-right: 1px solid var(--line);
  padding: 1rem .75rem 2rem; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; z-index: 30; }
.nav a { color: var(--text); padding: .42rem .65rem; border-radius: 7px; text-decoration: none; }
.nav a:hover { background: var(--soft); }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .brand { font-weight: 700; font-size: 1.15rem; padding: .2rem .65rem .6rem; }
.brand small { color: var(--muted); font-weight: 400; font-size: .75rem; margin-left: .4rem; }
#nav-search input { width: 100%; margin-bottom: .5rem; }
.nav-projects { display: flex; flex-direction: column; margin: 0 0 .4rem .9rem; border-left: 1px solid var(--line); }
.nav-projects a { font-size: .86rem; padding: .22rem .6rem; color: var(--muted); }
#theme-btn { margin-top: auto; align-self: flex-start; }
.main { margin-left: var(--nav-w); min-height: 100vh; }
.topbar { display: none; }
.view { max-width: 1080px; margin: 0 auto; padding: 1.5rem 1.75rem 6rem; }
.scrim { display: none; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin: .75rem 0 1rem; }
.page-head .actions { margin: 0; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.grid .card { margin: 0; }
.card h3 { font-size: .92rem; margin: 1rem 0 .4rem; color: var(--muted); }
.more { margin-left: auto; font-size: .82rem; font-weight: 400; }

.bigsearch { display: flex; gap: .5rem; }
.bigsearch input { flex: 1; font-size: 1rem; padding: .65rem .85rem; }

.rows { display: flex; flex-direction: column; }
.row { display: flex; gap: .75rem; align-items: center; padding: .55rem .25rem; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none !important; }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--soft); }
.row-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta, .row-side { display: flex; gap: .5rem; flex-wrap: wrap; color: var(--muted); font-size: .8rem; align-items: center; }
.row-snip { color: var(--muted); font-size: .84rem; margin-top: .15rem; }
mark { background: #ffe58a; color: #1d1d1f; border-radius: 2px; padding: 0 1px; }

.badge { font-size: .72rem; padding: 0 .45rem; border-radius: 999px; background: var(--soft); color: var(--muted); border: 1px solid var(--line); }
.badge.k-daily { color: var(--doing); } .badge.k-board { color: var(--accent); } .badge.k-billing { color: var(--warn); }
.chip { display: inline-flex; gap: .35rem; align-items: center; font-size: .78rem; padding: .05rem .5rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); text-decoration: none !important; }
.chip.big { font-size: .86rem; padding: .3rem .7rem; }
.chip b { background: var(--accent); color: var(--accent-text); border-radius: 999px; padding: 0 .4rem; font-size: .75rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }

.counts { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; margin-bottom: .6rem; }
.count { display: flex; flex-direction: column; align-items: center; padding: .4rem; border-radius: 8px; background: var(--soft); color: var(--muted); font-size: .78rem; text-decoration: none !important; }
.count b { font-size: 1.3rem; line-height: 1.2; }
.count.g-doing b { color: var(--doing); } .count.g-waiting b { color: var(--waiting); } .count.g-todo b { color: var(--todo); } .count.g-unknown b { color: var(--unknown); }

.seg { display: inline-flex; flex-wrap: wrap; gap: 2px; background: var(--soft); padding: 3px; border-radius: 9px; margin-bottom: .75rem; }
.seg a { padding: .3rem .75rem; border-radius: 7px; color: var(--muted); font-size: .88rem; text-decoration: none !important; }
.seg a.on { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.filters { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; margin-bottom: .75rem; }
.filters .seg { margin: 0; }
.inline { display: inline-flex; gap: .35rem; align-items: center; font-size: .88rem; }

/* ===== タスク ===== */
.tasks { list-style: none; margin: 0; padding: 0; }
.task { display: flex; gap: .65rem; align-items: flex-start; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.task:last-child { border-bottom: 0; }
.task-main { min-width: 0; flex: 1; }
.task-title { font-weight: 600; line-height: 1.45; }
.task.g-done .task-title { color: var(--muted); text-decoration: line-through; }
.task-meta { display: flex; flex-wrap: wrap; gap: .25rem .6rem; font-size: .78rem; color: var(--muted); margin-top: .15rem; }
.task-meta a { color: var(--muted); }
.task input[type=checkbox] { width: 20px; height: 20px; margin: .15rem .25rem 0; accent-color: var(--accent); }
.st { font-size: .8rem; padding: .2rem .35rem; border-radius: 6px; font-weight: 600; width: 6.2em; flex: none; }
.st-doing { color: var(--doing); border-color: var(--doing); } .st-waiting { color: var(--waiting); border-color: var(--waiting); }
.st-todo { color: var(--todo); } .st-unknown { color: var(--unknown); border-color: var(--unknown); } .st-done { color: var(--done); border-color: var(--done); }

/* ===== 記録の表示 ===== */
.note-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: flex-start; border-bottom: 1px solid var(--line); padding-bottom: .75rem; margin-bottom: 1rem; }
.note-head .actions { margin: 0; }
.crumbs { font-size: .82rem; color: var(--muted); }
.toc { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .8rem; margin-bottom: 1rem; }
.toc summary { cursor: pointer; color: var(--muted); }
.toc a { display: block; font-size: .88rem; padding: .1rem 0; }
.md { overflow-wrap: anywhere; }
.md h1 { font-size: 1.35rem; } .md h2 { display: block; font-size: 1.15rem; margin: 1.6rem 0 .5rem; padding-bottom: .25rem; border-bottom: 1px solid var(--line); }
.md h3 { font-size: 1rem; margin: 1.2rem 0 .4rem; }
.md ul, .md ol { padding-left: 1.4rem; }
.md li:has(> input[type=checkbox]) { list-style: none; margin-left: -1.3rem; }
.md input[type=checkbox] { width: 17px; height: 17px; vertical-align: -3px; margin-right: .35rem; accent-color: var(--accent); }
.md code { background: var(--soft); padding: .05rem .3rem; border-radius: 4px; }
.md pre { background: var(--soft); padding: .75rem; border-radius: 8px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: .5rem 0; padding: .1rem .9rem; border-left: 3px solid var(--line); color: var(--muted); }
.table-wrap { overflow-x: auto; margin: .6rem 0 1rem; border: 1px solid var(--line); border-radius: 8px; }
.md table { border-collapse: collapse; font-size: .86rem; min-width: 100%; }
.md th, .md td { border-bottom: 1px solid var(--line); padding: .4rem .6rem; text-align: left; vertical-align: top; min-width: 5em; }
.md th { background: var(--soft); white-space: nowrap; }
.md tr:last-child td { border-bottom: 0; }

/* ===== エディタ ===== */
.editor { display: flex; flex-direction: column; gap: .6rem; }
.ed-title { font-size: 1.25rem; font-weight: 700; width: 100%; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; padding: .3rem 0; }
.ed-fields { display: flex; flex-wrap: wrap; gap: .5rem .75rem; margin-top: .5rem; }
.ed-fields label { display: flex; flex-direction: column; font-size: .75rem; color: var(--muted); gap: .15rem; }
.ed-fields label.grow { flex: 1; min-width: 160px; }
.ed-tabs { display: flex; align-items: center; gap: .25rem; border-bottom: 1px solid var(--line); }
.tab { white-space: nowrap; background: none; border: 0; padding: .45rem .9rem; border-bottom: 2px solid transparent; cursor: pointer; color: var(--muted); }
.tab.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.ed-status { margin-left: auto; font-size: .8rem; color: var(--muted); text-align: right; line-height: 1.3; }
.ed-meta summary { cursor: pointer; color: var(--muted); font-size: .82rem; margin-top: .4rem; }
.ed-status.warn { color: var(--warn); } .ed-status.ok { color: var(--ok); } .ed-status.err { color: var(--danger); font-weight: 600; }
.ed-body { width: 100%; min-height: 60vh; resize: vertical; font: 15px/1.75 var(--mono); padding: .9rem 1rem; tab-size: 2; }
.ed-preview { min-height: 60vh; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .5rem 1.1rem; }
.ed-bar { position: sticky; bottom: 0; display: flex; gap: .5rem; align-items: center; padding: .6rem 0; background: var(--bg); border-top: 1px solid var(--line); }
.spacer { flex: 1; }
.banner { background: var(--accent-soft); border-radius: 8px; padding: .6rem .8rem; font-size: .9rem; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.banner.conflict { background: var(--soft); border: 1px solid var(--danger); display: block; }
.cf-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin: .5rem 0; }
.cf-grid pre { max-height: 240px; overflow: auto; background: var(--panel); border: 1px solid var(--line); padding: .5rem; border-radius: 6px; white-space: pre-wrap; font-size: .78rem; }
.cf-grid h4 { margin: 0 0 .25rem; font-size: .85rem; }

.fab { position: fixed; right: 1.25rem; bottom: 1.25rem; width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-size: 1.8rem; box-shadow: 0 4px 14px rgba(0,0,0,.25); z-index: 20; text-decoration: none !important; }
.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 150%); background: var(--text); color: var(--bg); padding: .55rem 1rem;
  border-radius: 8px; font-size: .9rem; transition: transform .2s; z-index: 50; max-width: 90vw; pointer-events: none; visibility: hidden; }
.toast.show { transform: translate(-50%, 0); visibility: visible; }
.toast.err { background: var(--danger); color: #fff; }

/* ===== スマホ ===== */
@media (max-width: 860px) {
  .main { margin-left: 0; }
  .nav { transform: translateX(-100%); transition: transform .2s ease; width: min(82vw, 300px); box-shadow: 4px 0 24px rgba(0,0,0,.2); padding-top: calc(1rem + env(safe-area-inset-top)); }
  body.nav-open .nav { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  body.nav-open { overflow: hidden; }
  .nav a { padding: .6rem .7rem; }
  .topbar { display: flex; align-items: center; position: sticky; top: 0; z-index: 10; background: var(--panel); border-bottom: 1px solid var(--line); padding: env(safe-area-inset-top) .25rem 0; }
  .top-title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; }
  .view { padding: 1rem 1rem 6rem; }
  .grid { grid-template-columns: 1fr; }
  .card { padding: .85rem .9rem; }
  .ed-status { font-size: .72rem; }
  kbd { display: none; }
  .ed-body { font-size: 16px; min-height: 55vh; padding: .75rem; }
  .ed-fields label { flex: 1 1 40%; } .ed-fields select, .ed-fields input { width: 100%; }
  .ed-bar { padding-bottom: calc(.6rem + env(safe-area-inset-bottom)); }
  .cf-grid { grid-template-columns: 1fr; }
  .fab { bottom: calc(1.25rem + env(safe-area-inset-bottom)); }
  input, select { font-size: 16px; }
  .st { font-size: 16px; width: auto; }
}

/* ---------- ログイン ---------- */
body.signed-out .nav, body.signed-out .topbar, body.signed-out .fab, body.signed-out .scrim { display: none !important; }
body.signed-out .main { margin-left: 0; }
.login { max-width: 380px; margin: 12vh auto 0; }
.login h1 { margin: 0 0 1rem; font-size: 1.4rem; }
.login form { display: flex; flex-direction: column; gap: .8rem; }
.login label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; color: var(--muted); }
.login input { font-size: 16px; padding: .6rem .7rem; color: var(--text); }
.login .btn.primary { min-height: 44px; }
.login > .btn.ghost { margin-top: .75rem; }
.login-msg { min-height: 1.2em; margin: 0; color: var(--danger); font-size: .88rem; }

/* 取り込み・検証 */
.imp-pick { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .6rem; }
.imp-pick label.btn { cursor: pointer; }
.small { font-size: .8rem; }
.imp-sum { margin: .4rem 0 .6rem; padding-left: 1.2rem; line-height: 1.8; }
.imp-sum b.err, td.err, .warn-text { color: var(--danger); }
td.warn { color: var(--warn); }
td.muted { font-size: inherit; }
.chk { display: flex; gap: .5rem; align-items: flex-start; margin: .5rem 0; font-size: .9rem; }
.chk input { margin-top: .25rem; }
.imp-projects { columns: 2 16rem; padding-left: 1.2rem; margin: .3rem 0; line-height: 1.7; }
.imp-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.imp-table { border-collapse: collapse; font-size: .82rem; min-width: 900px; width: 100%; }
.imp-table th, .imp-table td { border-bottom: 1px solid var(--line); padding: .35rem .45rem; text-align: left; vertical-align: top; white-space: nowrap; }
.imp-table td.path { white-space: normal; word-break: break-all; min-width: 12rem; }
.imp-table td.num { text-align: right; }
.imp-table tr.off td { opacity: .5; }
.imp-list { padding-left: 1.2rem; font-size: .88rem; word-break: break-all; }
