:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --line: #dde1e7;
  --accent: #2f6fed;
  --working: #2f6fed;
  --working-bg: #e8f0fe;
  --review: #b45309;
  --review-bg: #fdf1e2;
  --done: #15803d;
  --done-bg: #e6f4ea;
  --chip: #f1f3f6;
  --hover: #f8f9fb;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171b;
    --card: #1f2329;
    --text: #e6e8eb;
    --muted: #9aa3ae;
    --line: #333a44;
    --accent: #6f9bff;
    --working: #8fb1ff;
    --working-bg: #22304d;
    --review: #f0b46a;
    --review-bg: #3b2c17;
    --done: #6fcf8f;
    --done-bg: #1c3526;
    --chip: #2a2f37;
    --hover: #252a31;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
}
body.drawer-open { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

/* ── 上部 ── */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--card);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand h1 { font-size: 17px; margin: 0; }
.badge-trial { font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.tabs { display: flex; gap: 4px; }
.tabs a {
  padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; font-size: 13px;
}
.tabs a:hover { background: var(--chip); text-decoration: none; }
.tabs a.active { background: var(--chip); color: var(--text); }
.tab-count { font-weight: normal; color: var(--muted); margin-left: 2px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }
.controls input, .controls select, .controls button {
  height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg);
}
.controls input { width: 200px; }
.controls button { background: var(--accent); color: #fff; border-color: var(--accent); cursor: pointer; }
.controls button:disabled { opacity: 0.6; cursor: default; }
.sync { width: 100%; margin: 0; font-size: 12px; color: var(--muted); }

/* ── 一覧（表） ── */
.list-wrap { max-width: 1280px; margin: 0 auto; padding: 16px 20px; }
.list-note { margin: 0 0 10px; color: var(--muted); font-size: 12.5px; }
.table-scroll {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  overflow-x: auto; box-shadow: var(--shadow);
}
table.tasks { width: 100%; border-collapse: collapse; min-width: 1180px; }
.tasks th, .tasks td { padding: 10px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.tasks tbody tr:last-child td { border-bottom: 0; }
.tasks th {
  position: sticky; top: 0; background: var(--chip); font-size: 12px; font-weight: 600; color: var(--muted);
  white-space: nowrap;
}
.tasks th button {
  border: 0; background: transparent; padding: 0; cursor: pointer; font-weight: 600; color: inherit; font-size: 12px;
}
.tasks th button:hover { color: var(--text); }
.tasks th button.sorted { color: var(--text); }
.tasks th button.sorted[data-dir="asc"]::after { content: " ▲"; font-size: 9px; }
.tasks th button.sorted[data-dir="desc"]::after { content: " ▼"; font-size: 9px; }
.tasks tbody tr { cursor: pointer; }
.tasks tbody tr:hover td { background: var(--hover); }
.tasks tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.c-status { width: 84px; white-space: nowrap; }
.c-title { width: 15%; min-width: 170px; }
.c-title .title { font-weight: 600; }
.c-summary { font-size: 13px; min-width: 260px; }
.c-current { width: 20%; min-width: 200px; color: var(--muted); font-size: 13px; }
.c-people { width: 150px; }
.c-requester { width: 96px; font-size: 13px; white-space: nowrap; }
.c-date { width: 76px; font-size: 13px; white-space: nowrap; color: var(--muted); }
.c-menu { width: 40px; padding-left: 0 !important; padding-right: 8px !important; }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.empty { color: var(--muted); text-align: center; padding: 40px 0 !important; cursor: default; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.badge {
  display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 999px; white-space: nowrap;
}
.badge.working { color: var(--working); background: var(--working-bg); }
.badge.review { color: var(--review); background: var(--review-bg); }
.badge.done { color: var(--done); background: var(--done-bg); }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; white-space: nowrap; }

.people { display: flex; flex-wrap: wrap; gap: 4px; }
.person {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--chip); border-radius: 999px; padding: 2px 8px 2px 2px; font-size: 12px; white-space: nowrap;
}
.avatar { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; vertical-align: middle; }
.avatar.fallback { display: inline-flex; align-items: center; justify-content: center; background: var(--line); font-size: 11px; }

/* ── 3点メニュー ── */
.menu { position: relative; }
.menu-btn {
  border: 0; background: transparent; cursor: pointer; color: var(--muted);
  font-size: 18px; line-height: 1; padding: 2px 6px; border-radius: 6px;
}
.menu-btn:hover { background: var(--chip); }
/* 表の横スクロールの箱で切れないよう、画面基準で出す（位置は board.js が開くときに決める） */
.menu-pop {
  position: fixed; z-index: 30;
  display: flex; flex-direction: column; min-width: 220px;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12); padding: 4px;
}
.menu-pop button { border: 0; background: transparent; text-align: left; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.menu-pop button:hover { background: var(--chip); }

/* ── 詳細パネル ── */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.28); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 21;
  width: min(560px, 100%); background: var(--card); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12);
}
.drawer-head {
  display: flex; justify-content: space-between; gap: 12px; align-items: flex-start;
  padding: 18px 20px 12px; border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 8px 0 0; font-size: 18px; line-height: 1.4; }
.drawer-head .tag { margin-left: 6px; }
.close { border: 0; background: var(--chip); border-radius: 8px; width: 32px; height: 32px; cursor: pointer; flex-shrink: 0; }
.drawer-body { padding: 14px 20px 28px; overflow-y: auto; }
.drawer-body section { margin-top: 18px; }
.drawer-body h4 { margin: 0 0 6px; font-size: 12px; color: var(--muted); letter-spacing: 0.04em; }
.drawer-body p { margin: 0; }
.drawer-body section.next p { background: var(--working-bg); border-radius: 8px; padding: 8px 10px; }
.facts { display: grid; grid-template-columns: 44px 1fr; gap: 8px 10px; margin: 0; align-items: center; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 0; }

.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); margin-left: 4px; }
.timeline li { display: flex; gap: 10px; padding: 0 0 12px 12px; position: relative; }
.timeline li::before {
  content: ""; position: absolute; left: -6px; top: 6px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--card); border: 2px solid var(--muted);
}
.timeline .when { font-size: 12px; color: var(--muted); width: 38px; flex-shrink: 0; padding-top: 1px; }
.timeline b { font-size: 13px; margin-right: 6px; }
.timeline p { font-size: 13.5px; }

.raw { margin-top: 18px; border: 1px solid var(--line); border-radius: 8px; }
.raw summary { cursor: pointer; padding: 8px 12px; font-size: 13px; color: var(--muted); }
.raw-body { padding: 4px 12px 10px; display: flex; flex-direction: column; gap: 10px; max-height: 420px; overflow-y: auto; }
.msg { border-left: 2px solid var(--line); padding-left: 10px; }
.msg.parent { border-left-color: var(--accent); }
.msg.deleted { opacity: 0.55; }
.msg-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.msg-head b { font-size: 13px; }
.msg p { font-size: 13px; white-space: pre-wrap; word-break: break-word; margin: 2px 0 4px; }
.links { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.links h4 { width: 100%; }
.slack-link { border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; font-size: 13px; }
.drawer-body > p.small { margin-top: 10px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 14px; border-top: 1px solid var(--line); }
.ghost { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 13px; }
.ghost:hover { background: var(--chip); }

.footnote { color: var(--muted); font-size: 12px; max-width: 1280px; margin: 0 auto; padding: 0 20px 24px; }

/* ── 狭い画面 ── */
@media (max-width: 640px) {
  .topbar { padding: 10px 16px; }
  .controls { margin-left: 0; width: 100%; }
  .controls input { flex: 1; width: auto; min-width: 0; }
  .list-wrap { padding: 12px 16px; }
  .footnote { padding: 0 16px 20px; }
  .drawer { width: 100%; border-left: 0; }
  .drawer-head, .drawer-body { padding-left: 16px; padding-right: 16px; }
}

/* ── ログイン ── */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 24px; display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { margin: 0; font-size: 18px; }
.login-card p { margin: 0; font-size: 12.5px; }
.login-card input, .login-card button { height: 38px; border-radius: 8px; border: 1px solid var(--line); padding: 0 10px; background: var(--bg); }
.login-card button { background: var(--accent); border-color: var(--accent); color: #fff; cursor: pointer; }
.error { color: #dc2626; }
