:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --line: #e3e8ef;
  --text: #1b2434;
  --muted: #6b7789;
  --brand: #2f6df6;
  --brand-dark: #2354c8;
  --todo: #8a94a6;
  --doing: #eaa60c;   /* CVD検証済み: 完了(緑)と識別できる琥珀 */
  --done: #1f9d63;
  --danger: #d93a3a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 20px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }
.hidden { display: none !important; }

/* ---------- ログイン ---------- */
#login {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: linear-gradient(160deg, #1e2c47, #2f6df6);
  padding: 20px; z-index: 100;
}
.login-card {
  width: 100%; max-width: 380px; background: #fff; border-radius: 16px;
  padding: 32px 26px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card p.sub { margin: 0 0 22px; color: var(--muted); font-size: 13px; }
.login-card label { display: block; margin-bottom: 6px; font-size: 12px; color: var(--muted); }
.login-card input { width: 100%; margin-bottom: 16px; }

/* ---------- 共通パーツ ---------- */
input[type=text], input[type=password], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px;
  background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(47, 109, 246, .13); }
textarea { resize: vertical; min-height: 76px; }

.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 9px;
  padding: 8px 14px; font-weight: 600; white-space: nowrap;
}
.btn:hover { background: #f7f9fc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--danger); border-color: #f2c9c9; }
.btn.danger:hover { background: #fdf2f2; }
.btn.wide { width: 100%; justify-content: center; }
.btn.sm { padding: 5px 10px; font-size: 12px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px;
  border-radius: 999px; font-size: 11px; font-weight: 700; line-height: 1.7;
}
.badge.todo { background: #eef0f4; color: #5b6577; }
.badge.doing { background: #fdf1de; color: #a86206; }
.badge.done { background: #e6f6ee; color: #157a4c; }
.badge.high { background: #fdeaea; color: #b12727; }
.badge.overdue { background: #fdeaea; color: #b12727; }

/* ---------- ヘッダー ---------- */
header.top {
  position: sticky; top: 0; z-index: 20; background: var(--panel);
  border-bottom: 1px solid var(--line); padding: 10px 16px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.brand { font-weight: 800; font-size: 16px; letter-spacing: .02em; margin-right: 4px; }
.brand span { color: var(--brand); }
.spacer { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 8px 14px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--brand); color: #fff; }
.who { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none;
}

.filters {
  display: flex; gap: 8px; padding: 10px 16px; flex-wrap: wrap;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.filters select, .filters input { width: auto; min-width: 130px; flex: 0 1 auto; }
.filters input[type=search] { min-width: 180px; flex: 1 1 200px; }

/* ---------- カンバン ---------- */
main { padding: 16px; }
.board { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; align-items: start; }
.col { background: #eceff4; border-radius: var(--radius); padding: 10px; min-height: 160px; }
.col.dragover { background: #dbe6ff; outline: 2px dashed var(--brand); outline-offset: -4px; }
.col > h2 {
  margin: 2px 4px 10px; font-size: 13px; display: flex; align-items: center; gap: 8px;
}
.col .count { color: var(--muted); font-weight: 600; }
.dot { width: 9px; height: 9px; border-radius: 50%; }
.col[data-status=todo] .dot { background: var(--todo); }
.col[data-status=doing] .dot { background: var(--doing); }
.col[data-status=done] .dot { background: var(--done); }

.card {
  background: #fff; border-radius: 10px; padding: 11px 12px; margin-bottom: 9px;
  box-shadow: var(--shadow); border-left: 4px solid var(--todo); cursor: pointer;
}
.card[data-status=doing] { border-left-color: var(--doing); }
.card[data-status=done] { border-left-color: var(--done); opacity: .78; }
.card.dragging { opacity: .4; }
.card .title { font-weight: 700; line-height: 1.45; margin-bottom: 6px; word-break: break-word; }
.card[data-status=done] .title { text-decoration: line-through; text-decoration-color: #b9c1cd; }
.card .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--muted); font-size: 11.5px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; background: #f2f4f8;
  border-radius: 6px; padding: 2px 7px; font-size: 11px;
}
.chip .sq { width: 8px; height: 8px; border-radius: 2px; }
.card .foot { display: flex; align-items: center; gap: 6px; margin-top: 9px; }
.statusbtns { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.statusbtns button {
  border: 0; background: #fff; padding: 4px 8px; font-size: 11px; font-weight: 700; color: var(--muted);
}
.statusbtns button.on[data-s=todo] { background: var(--todo); color: #fff; }
.statusbtns button.on[data-s=doing] { background: var(--doing); color: #fff; }
.statusbtns button.on[data-s=done] { background: var(--done); color: #fff; }

/* ---------- 一覧 ---------- */
.tablewrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
table { border-collapse: collapse; width: 100%; min-width: 720px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: #f8fafc; font-size: 12px; color: var(--muted); position: sticky; top: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f7f9fd; }
td.due.over { color: var(--danger); font-weight: 700; }

.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* ---------- モーダル ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(20, 28, 42, .45);
  display: flex; justify-content: flex-end; z-index: 50;
}
.sheet {
  background: var(--panel); width: min(560px, 100%); height: 100%; overflow: auto;
  padding: 18px 20px 60px; box-shadow: -8px 0 40px rgba(0, 0, 0, .18);
}
.modal.center { align-items: center; justify-content: center; padding: 16px; }
.modal.center .sheet { height: auto; max-height: 90vh; border-radius: 14px; width: min(560px, 100%); }
.sheet h2 { margin: 0 0 14px; font-size: 17px; }
.sheet h3 { margin: 22px 0 8px; font-size: 13px; color: var(--muted); }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.sheet-head .close { margin-left: auto; border: 0; background: transparent; font-size: 22px; color: var(--muted); line-height: 1; }
.actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }

.comment { border-top: 1px solid var(--line); padding: 11px 0; }
.comment .head { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.comment .body { white-space: pre-wrap; line-height: 1.6; word-break: break-word; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.thumbs a { display: block; }
.thumbs img { width: 92px; height: 92px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.filechip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 8px; font-size: 12px; text-decoration: none;
}
.log { font-size: 12px; color: var(--muted); line-height: 1.9; }

.adm-tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.adm-tabs button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 12px; font-weight: 600; }
.adm-tabs button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.list-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line);
}
.list-item .grow { flex: 1; min-width: 0; }
.list-item .name { font-weight: 600; }
.list-item .sub { font-size: 12px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #1b2434; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; z-index: 200; box-shadow: 0 8px 30px rgba(0, 0, 0, .3);
}
.toast.err { background: var(--danger); }

@media (max-width: 780px) {
  .board { grid-template-columns: 1fr; }
  .filters select, .filters input { flex: 1 1 40%; min-width: 0; }
  main { padding: 12px; }
  .brand { font-size: 15px; }
}

/* ---------- グラフ・レポート ---------- */
:root {
  --todo-strong: #5b6577;
  --doing-strong: #9a6a09;
  --done-strong: #157a4c;
  --chart-doing: var(--doing);
}
.statusbtns button.on[data-s=todo] { background: var(--todo-strong); }
.statusbtns button.on[data-s=doing] { background: var(--doing-strong); }
.statusbtns button.on[data-s=done] { background: var(--done-strong); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: block; }
.lg-todo { background: var(--todo); }
.lg-doing { background: var(--chart-doing); }
.lg-done { background: var(--done); }

/* 積み上げバー */
.pbar { display: flex; gap: 2px; height: 14px; background: #e7ebf1; border-radius: 7px; overflow: hidden; }
.pbar > i { display: block; }
.pbar > i:first-child { border-radius: 7px 0 0 7px; }
.pbar > i:last-child { border-radius: 0 7px 7px 0; }
.pbar > i:only-child { border-radius: 7px; }

.prow { display: grid; grid-template-columns: minmax(110px, 210px) 1fr auto; gap: 12px; align-items: center; padding: 7px 0; }
.prow .pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow .pval { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; white-space: nowrap; }
.prow .pval b { color: var(--text); font-size: 13px; }

/* ボード上部のサマリー */
.summary {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 14px;
}
.summary .head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.summary .head h2 { font-size: 13px; margin: 0; }
.summary .head .link { margin-left: auto; font-size: 12px; }

/* レポート */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.tile .lab { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.tile .num { font-size: 28px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile .num small { font-size: 14px; font-weight: 700; color: var(--muted); margin-left: 3px; }
.tile .sub { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.tile.warn .num { color: var(--danger); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.panel > h2 { font-size: 14px; margin: 0 0 4px; }
.panel > p.note { font-size: 12px; color: var(--muted); margin: 0 0 12px; }

/* 週次推移（縦棒） */
.trend { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 18px; }
.trend .tcol { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 4px; }
.trend .tbar { width: 100%; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; }
.trend .tbar.zero { background: #dfe4ec; }
.trend .tval { font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }
.trend .tlab { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.trend-axis { border-top: 1px solid var(--line); margin-top: 2px; }

/* 担当者別（横棒） */
.hrow { display: grid; grid-template-columns: minmax(80px, 150px) 1fr; gap: 10px; align-items: center; padding: 5px 0; }
.hrow .hname { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar { display: flex; align-items: center; gap: 8px; }
.hbar i { display: block; height: 12px; background: var(--brand); border-radius: 4px; min-width: 3px; }
.hbar span { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }

.rangebar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.rangebar .btn.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.rangebar input[type=date] { width: auto; }

#chartTip {
  position: fixed; z-index: 300; background: #1b2434; color: #fff; padding: 6px 10px;
  border-radius: 8px; font-size: 12px; pointer-events: none; white-space: nowrap;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
@media (max-width: 780px) {
  .prow { grid-template-columns: 1fr; gap: 4px; }
  .prow .pval { text-align: right; }
  .trend .tlab { font-size: 9px; }
}
