:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e3e6eb;
  --line-strong: #c9ced6;
  --text: #1f2933;
  --muted: #6b7684;
  --accent: #2f6fde;
  --accent-weak: #e8f0fd;
  --off: #f1f2f5;
  --holiday: #fdeeee;
  --phase-bg: #f3f5f9;
  --today: #e0453a;
  --row-h: 32px;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 13px; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- ツールバー ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 14px; letter-spacing: .02em; }
.tb-group { display: flex; align-items: center; gap: 6px; }
.tb-spacer { flex: 1; }
#projectSelect { min-width: 160px; max-width: 260px; height: 30px; border: 1px solid var(--line-strong); border-radius: 6px; padding: 0 6px; background: #fff; }

.btn {
  height: 30px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 6px;
  background: #fff; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f4f6f9; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #255fc4; }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.seg button { height: 28px; width: 34px; border: 0; background: #fff; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--accent); color: #fff; }

.chk { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; white-space: nowrap; }
.chk.small { font-size: 12px; color: var(--muted); }

.save-status { color: var(--muted); font-size: 12px; }
.save-status.error { color: var(--today); }
.save-status .badge { background: #fff4d6; color: #8a6200; border-radius: 4px; padding: 2px 6px; margin-right: 6px; }

/* ---------- メニュー ---------- */
.menu-wrap { position: relative; }
.menu {
  position: absolute; z-index: 50; min-width: 200px; padding: 4px; background: #fff;
  border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: 0 8px 24px rgba(20, 30, 50, .14);
}
.menu-wrap .menu { top: 34px; left: 0; }
.menu button { display: block; width: 100%; text-align: left; padding: 6px 10px; border: 0; background: none; border-radius: 5px; cursor: pointer; }
.menu button:hover { background: var(--accent-weak); }
.menu button.danger { color: #c0392b; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.row-menu { position: fixed; }

/* ---------- ワークスペース ---------- */
.workspace { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 10px 14px 0; }
.gantt {
  flex: 1; min-height: 0; overflow: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; position: relative; outline: none;
}
.addbar { display: flex; align-items: center; gap: 6px; padding: 8px 0 10px; flex-wrap: wrap; }
.addbar .hint { color: var(--muted); font-size: 12px; margin-left: 8px; }

/* グリッド */
.g-inner { position: relative; }
.g-head {
  position: sticky; top: 0; z-index: 20; display: flex; background: #fff;
  border-bottom: 1px solid var(--line-strong);
}
.g-left-head, .g-left {
  position: sticky; left: 0; z-index: 10; display: flex; flex: none; background: inherit;
  border-right: 1px solid var(--line-strong);
}
.g-left-head { z-index: 30; background: #fff; align-items: flex-end; }
.g-left-head .c { font-weight: 600; color: var(--muted); font-size: 12px; padding: 0 6px 6px; }
.g-time-head { position: relative; flex: none; }
.g-time-head .hc {
  position: absolute; border-left: 1px solid var(--line); font-size: 11px; color: var(--muted);
  display: flex; align-items: center; justify-content: center; overflow: hidden; white-space: nowrap;
}
.g-time-head .hc.top { justify-content: flex-start; padding-left: 6px; color: var(--text); font-weight: 600; }
.g-time-head .hc.sat { color: #2d6cc9; }
.g-time-head .hc.sun, .g-time-head .hc.hol { color: #d0392b; }
.g-time-head .hc.today { background: var(--today); color: #fff; border-radius: 3px; }

.g-body { position: relative; }
.g-bg { position: absolute; top: 0; bottom: 0; pointer-events: none; z-index: 0; }
.g-bg .off { position: absolute; top: 0; bottom: 0; background: var(--off); }
.g-bg .off.hol { background: var(--holiday); }
.g-bg .vline { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--line); }
.g-bg .today-line { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--today); opacity: .75; }

.g-row { display: flex; height: var(--row-h); position: relative; }
.g-row > .g-left { background: #fff; border-bottom: 1px solid var(--line); }
.g-row.phase > .g-left { background: var(--phase-bg); }
.g-row.selected > .g-left { background: var(--accent-weak); }
.g-row.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.g-row.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }
.g-time { position: relative; flex: none; border-bottom: 1px solid var(--line); z-index: 1; overflow: hidden; }

.c { flex: none; display: flex; align-items: center; height: 100%; padding: 0 4px; overflow: hidden; }
.c input, .c select {
  width: 100%; height: 24px; border: 1px solid transparent; border-radius: 4px; background: transparent; padding: 0 4px; font-size: 12px;
}
.c input:hover { border-color: var(--line); }
.c input:focus { border-color: var(--accent); background: #fff; outline: none; }
.c input:disabled { color: var(--muted); }
.c.num { justify-content: flex-end; color: var(--muted); font-size: 12px; }
.c.handle { cursor: grab; color: #a3abb7; justify-content: center; user-select: none; font-size: 12px; }
.c.handle:active { cursor: grabbing; }
.c.name { gap: 4px; }
.c.name .type-mark { flex: none; width: 10px; height: 10px; border-radius: 2px; }
.c.name .type-mark.milestone { transform: rotate(45deg) scale(.85); }
.c.name .type-mark.phase { border-radius: 1px; height: 6px; width: 12px; }
.g-row.task .c.name { padding-left: 18px; }
.g-row.milestone .c.name { padding-left: 18px; }
.g-row.phase .c.name input { font-weight: 700; }
.c.menu-btn button { width: 22px; height: 22px; border: 0; background: none; border-radius: 4px; cursor: pointer; color: var(--muted); }
.c.menu-btn button:hover { background: #e9ecf1; color: var(--text); }
.c.note-flag::after { content: ""; }

/* バー */
.bar { position: absolute; top: 7px; height: 18px; cursor: grab; }
.bar .bseg {
  position: absolute; top: 0; bottom: 0; border-radius: 4px; overflow: hidden;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .08);
}
.bar.phase .bseg { border-radius: 2px; }
.bar.faded .bseg { opacity: .4; }
.bar .prog { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(0, 0, 0, .22); }
.bar .h { position: absolute; top: 0; bottom: 0; width: 7px; cursor: ew-resize; z-index: 2; }
.bar .h.l { left: 0; } .bar .h.r { right: 0; }
.bar.phase { top: 11px; height: 10px; border-radius: 2px; }
.bar.dragging { opacity: .85; cursor: grabbing; }
.ms {
  position: absolute; top: 8px; width: 16px; height: 16px; transform: rotate(45deg); cursor: grab; border-radius: 2px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .15);
}
.bar-label { position: absolute; top: 0; height: var(--row-h); display: flex; align-items: center; font-size: 11px; color: #3c4652; white-space: nowrap; pointer-events: none; }
.drag-tip {
  position: fixed; z-index: 100; background: #1f2933; color: #fff; font-size: 11px; padding: 3px 7px; border-radius: 4px; pointer-events: none;
}

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

/* ---------- ダイアログ ---------- */
.dlg { border: 0; border-radius: 12px; padding: 0; width: min(640px, 94vw); box-shadow: 0 20px 60px rgba(20, 30, 50, .25); }
.dlg::backdrop { background: rgba(20, 28, 40, .35); }
.dlg form { padding: 20px 22px 18px; }
.dlg h2 { margin: 0 0 14px; font-size: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 14px; }
.form-grid > label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form-grid > label.chk { flex-direction: row; color: var(--text); font-size: 13px; }
.form-grid input[type=text], .form-grid input[type=date], .form-grid input[type=number], .form-grid select, .form-grid textarea {
  height: 32px; border: 1px solid var(--line-strong); border-radius: 6px; padding: 0 8px; color: var(--text); font-size: 13px; background: #fff;
}
.form-grid textarea { height: auto; padding: 6px 8px; resize: vertical; }
.form-grid fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px 10px; display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.form-grid legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.span2 { grid-column: span 2; } .span3 { grid-column: span 3; }
.color-row { display: flex; align-items: center; gap: 10px; height: 32px; }
.color-row input[type=color] { width: 44px; height: 30px; border: 1px solid var(--line-strong); border-radius: 6px; padding: 2px; background: #fff; }
.range-inputs { display: inline-flex; align-items: center; gap: 6px; }
.range-inputs input { height: 30px; border: 1px solid var(--line-strong); border-radius: 6px; padding: 0 6px; }
.note { margin: 0; color: var(--muted); font-size: 12px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
code { background: #f1f3f6; padding: 1px 4px; border-radius: 3px; font-size: 12px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200;
  background: #1f2933; color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
}

.muted { color: var(--muted); font-size: 12px; }
.btn.icon { width: 30px; padding: 0; font-size: 10px; color: var(--muted); }
.period input[type=date], .period select { height: 30px; border: 1px solid var(--line-strong); border-radius: 6px; padding: 0 6px; background: #fff; font-size: 12px; }
.form-grid fieldset.col { flex-direction: column; align-items: flex-start; }
.form-grid fieldset input[type=date], .form-grid fieldset select { height: 28px; border: 1px solid var(--line-strong); border-radius: 6px; padding: 0 6px; background: #fff; }

#colorBy { height: 30px; border: 1px solid var(--line-strong); border-radius: 6px; padding: 0 6px; background: #fff; font-size: 12px; }
.legend { display: inline-flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-left: 10px; font-size: 12px; }
.legend .lg { display: inline-flex; align-items: center; gap: 5px; }
.legend i { display: inline-block; width: 16px; height: 10px; border-radius: 2px; }
.legend i.lg-ms { width: 9px; height: 9px; transform: rotate(45deg); border-radius: 1px; }
.ac-list { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.ac-item { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); }
.ac-item input[type=color] { width: 36px; height: 26px; border: 1px solid var(--line-strong); border-radius: 5px; padding: 1px; background: #fff; }
.btn.icon2 { width: 34px; padding: 0; font-size: 16px; }
.save-status { white-space: nowrap; }

.dlg.wide { width: min(880px, 96vw); }
.tpl-list { max-height: 52vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 4px 12px 12px; background: #fafbfc; }
.tpl-group h3 { font-size: 12px; color: var(--muted); margin: 12px 0 6px; font-weight: 600; }
.tpl-group { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tpl-group h3 { grid-column: 1 / -1; }
.tpl { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; background: #fff; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.tpl:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; background: #f7faff; }
.tpl input { margin-top: 3px; }
.tpl-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tpl-title { font-weight: 600; }
.tpl-meta { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 11px; color: var(--muted); }
.tpl-meta .tag { background: #eef1f5; color: #4a5562; border-radius: 4px; padding: 1px 6px; }
.tpl-meta .span { margin-left: 4px; }
.tpl-desc { font-size: 12px; color: var(--muted); line-height: 1.5; }
.copy-src { margin-top: 4px; height: 28px; border: 1px solid var(--line-strong); border-radius: 6px; padding: 0 6px; background: #fff; max-width: 100%; }
.new-opts { margin-top: 14px; }
.dlg-actions .tb-spacer { flex: 1; }

[hidden] { display: none !important; }
.legend:not([hidden]) + .hint { display: none; }

.drive-status { font-size: 12px; color: #2e7d4f; white-space: nowrap; }
.drive-status.warn { color: #b26a00; }
.drive-status.muted-s { color: var(--muted); }
.drive-btn { border-color: #9bb8e8; color: #2457b3; }
.drive-list { max-height: 50vh; overflow: auto; margin-top: 10px; }
.drive-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.drive-table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line-strong); }
.drive-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
.drive-list .err { color: #c0392b; }

.status-stack { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.35; }
.status-stack .save-status, .status-stack .drive-status { font-size: 11px; }
#colorBy { width: auto; }
.topbar { gap: 8px; }
#projectSelect { min-width: 140px; max-width: 200px; }
#colorBy { width: 112px; }
#rangeStart { width: 128px; }
#rangeMonths { width: 78px; }
.tb-group { gap: 5px; }
@media (max-width: 1680px) { .brand { display: none; } }
@media (max-width: 1480px) { .status-stack .save-status { display: none; } }
