* {
  box-sizing: border-box;
}
:root {
  --row-h: 34px;
  --label-w: 200px;
  --border: #e2e8f0;
  --bg: #f1f1f4;
  --label-bg: #ffffff;
  --head-bg: #f1f5f9;
  --text: #1a1a1a;
  --muted: #626264;
  --primary: #1E293B;
}
body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 13px;
}

/* ===== トップバー ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
}
.topbar h1 {
  margin: 0 0 8px;
  font-size: 16px;
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}
.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.period-controls {
  display: flex;
  gap: 4px;
}
.period-ctl.active {
  background: #1e293b;
  color: #fff;
  border-color: #1e293b;
}
.period-ctl.active:hover {
  background: #1e293b;
}
.view-controls {
  display: flex;
  gap: 6px;
}
.ctl {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 12px;
}
.ctl:hover {
  background: var(--head-bg);
}
.ctl.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.ctl.primary:hover {
  background: #0f172a;
}

/* ===== ドロップダウンフィルタ ===== */
.dd {
  position: relative;
}
.dd-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}
.dd-btn:hover {
  background: var(--head-bg);
}
.dd-panel {
  position: absolute;
  top: 110%;
  left: 0;
  z-index: 30;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 6px;
  min-width: 180px;
  max-height: 320px;
  overflow-y: auto;
}
.dd-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
}
.dd-item:hover {
  background: var(--head-bg);
}
.dd-all {
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  font-weight: 600;
}

/* ===== 凡例 ===== */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 8px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
}
.legend-item i {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  display: inline-block;
}

/* ===== ガント本体 ===== */
.scroll {
  overflow: auto;
  height: calc(100vh - 130px);
}
.gantt {
  position: relative;
  width: calc(var(--label-w) + var(--timeline-w));
}

/* ヘッダー（上固定） */
.ghead {
  position: sticky;
  top: 0;
  z-index: 12;
  display: flex;
}
.corner {
  position: sticky;
  left: 0;
  z-index: 14;
  width: var(--label-w);
  flex-shrink: 0;
  background: var(--head-bg);
  border-right: 2px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 10px;
}
.corner-title {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}
.timeline-head {
  flex-shrink: 0;
}
.month-row {
  display: flex;
  background: var(--head-bg);
  border-bottom: 1px solid var(--border);
}
.mcell {
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  text-align: center;
  padding: 6px 2px;
  font-size: 11px;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
}
.week-row {
  display: flex;
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
}
.wcell {
  flex-shrink: 0;
  border-right: 1px solid #eef1f4;
  text-align: center;
  padding: 3px 2px;
  font-size: 10px;
  color: var(--muted);
  overflow: hidden;
  white-space: nowrap;
}

/* 行 */
.gbody {
  position: relative;
}
.grow {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.rlabel {
  position: sticky;
  left: 0;
  z-index: 6;
  width: var(--label-w);
  flex-shrink: 0;
  background: var(--label-bg);
  border-right: 2px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 10px;
  min-height: var(--row-h);
  font-size: 12px;
}
.rlabel.indent {
  padding-left: 24px;
  color: #334155;
}
.rtrack {
  flex-shrink: 0;
  position: relative;
  min-height: var(--row-h);
  background-image: linear-gradient(to right, var(--border) 1px, transparent 1px);
}
.clickable-track {
  cursor: cell;
}
.clickable-track:hover {
  background-color: rgba(30, 41, 59, 0.04);
}

/* refrear全体 / ブランド全体 / 部署 行の色 */
.row-all .rlabel {
  font-weight: 700;
  background: #eef2ff;
}
.row-all .rtrack {
  background-color: #f5f7ff;
}
.row-brandtotal .rlabel {
  font-weight: 600;
  background: #f8fafc;
}
.row-dept .rlabel {
  background: #fafafa;
}

/* ブランドヘッダー（折りたたみトグル） */
.brand-header {
  cursor: pointer;
}
.brand-header .rlabel {
  background: #1e293b;
  color: #fff;
  font-weight: 700;
  min-height: 30px;
  z-index: 6;
}
.brand-header:hover .rlabel {
  background: #334155;
}
.brand-header .rtrack {
  background: #1e293b;
  min-height: 30px;
  background-image: none;
}

/* ブランド非表示ボタン */
.brand-hide-btn {
  float: right;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 2px;
  opacity: 0.8;
  line-height: 1;
}
.brand-hide-btn:hover {
  opacity: 1;
}
.brand-hidden .rlabel {
  background: #374151 !important;
  color: rgba(255, 255, 255, 0.4) !important;
}
.brand-hidden .rtrack {
  background: #374151 !important;
}
.brand-hidden:hover .rlabel {
  color: rgba(255, 255, 255, 0.65) !important;
}
.brand-hidden-row .rlabel {
  color: rgba(0, 0, 0, 0.3);
  background: #f1f5f9 !important;
}
.brand-hidden-row .rtrack {
  opacity: 0.4;
}

/* 区切り */
.divider .rlabel {
  background: #f1f5f9;
  color: var(--muted);
  font-weight: 700;
  font-size: 11px;
  min-height: 26px;
  z-index: 6;
}
.divider .rtrack {
  background: #f1f5f9;
  min-height: 26px;
  background-image: none;
}

/* バー */
.bar {
  position: absolute;
  height: 22px;
  border-radius: 4px;
  color: #fff;
  font-size: 11px;
  line-height: 22px;
  padding: 0 6px;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
  transition: filter 0.1s;
}
.bar:hover {
  filter: brightness(1.08);
  z-index: 5;
}
.bar-label {
  pointer-events: none;
}

/* 日ビュー */
.day-row {
  display: flex;
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
}
.dcell {
  flex-shrink: 0;
  border-right: 1px solid #eef1f4;
  text-align: center;
  padding: 3px 2px;
  font-size: 10px;
  color: var(--muted);
}
.dcell-we {
  background: #f8f0f0;
  color: #c0392b;
}

/* 今日ライン */
.today-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #fe3939;
  z-index: 4;
  pointer-events: none;
}
.today-line::before {
  content: "今日";
  position: absolute;
  top: 0;
  left: 3px;
  font-size: 9px;
  color: #fe3939;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.85);
  padding: 0 2px;
}

/* ポップアップ オーバーレイ（このブランチでは非使用） */
#popupOverlay {
  display: none;
}

/* ポップアップ */
.popup {
  display: none;
  position: fixed;
  z-index: 50;
  width: 300px;
  max-height: 90vh;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  padding: 14px;
}
.popup-close {
  position: absolute;
  top: 6px;
  right: 8px;
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--muted);
}
.popup-type {
  display: inline-block;
  color: #fff;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  margin-bottom: 8px;
}
.popup-name {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 4px;
}
.popup-range {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}
.popup-memo {
  font-size: 12px;
  line-height: 1.5;
  border-top: 1px solid var(--border);
  padding-top: 6px;
  white-space: pre-wrap;
}

/* スマホ：画面下からのボトムシート */
.popup.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  top: auto;
  transform: none;
  width: 100%;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.25);
  padding: 20px 18px calc(24px + env(safe-area-inset-bottom, 0px));
  animation: sheetUp 0.18s ease-out;
}
.popup.sheet .popup-close {
  top: 12px;
  right: 14px;
  font-size: 24px;
}
.popup.sheet .popup-name {
  font-size: 16px;
}
@keyframes sheetUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

/* ===== 編集ポップアップ ===== */
.popup.edit-mode {
  width: 360px;
}

.edit-badge {
  font-size: 11px;
  color: var(--primary);
  font-weight: 700;
  margin-bottom: 10px;
}
.edit-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}
.edit-field label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}
.edit-field input,
.edit-field select,
.edit-field textarea {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  width: 100%;
  box-sizing: border-box;
}
.edit-field input:focus,
.edit-field select:focus,
.edit-field textarea:focus {
  border-color: var(--primary);
}
.edit-row {
  display: flex;
  gap: 8px;
}
.edit-row .edit-field {
  flex: 1;
}
.edit-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.edit-save-btn {
  flex: 1;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.edit-save-btn:hover {
  background: #000060;
}
.edit-cancel-btn {
  flex: 1;
  background: #fff;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  font-size: 13px;
  cursor: pointer;
}
.edit-cancel-btn:hover {
  background: var(--head-bg);
}
.edit-delete-btn {
  width: 100%;
  background: #fff;
  color: #dc2626;
  border: 1px solid #fca5a5;
  border-radius: 6px;
  padding: 7px;
  font-size: 13px;
  cursor: pointer;
}
.edit-delete-btn:hover {
  background: #fef2f2;
}
.edit-msg {
  font-size: 12px;
  margin-top: 6px;
  min-height: 16px;
  text-align: center;
}

.error {
  padding: 40px;
  color: #b91c1c;
  line-height: 1.7;
}

/* ===== 追加モーダル ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-box {
  position: relative;
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  width: 360px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.modal-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
}
.modal-box-wide {
  width: 520px;
}
@media (max-width: 640px) {
  .modal-box,
  .modal-box-wide {
    width: calc(100% - 32px);
  }
}

/* ===== 編集者選択 ===== */
.editor-hint {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 14px;
  line-height: 1.5;
}
.editor-pick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.editor-btn {
  padding: 14px 0;
  font-size: 15px;
  font-weight: 700;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  transition: all 0.12s;
}
.editor-btn:hover {
  border-color: #1e293b;
  background: #f8fafc;
}
.editor-btn.is-current {
  border-color: #1e293b;
  background: #1e293b;
  color: #fff;
}
.editor-label {
  font-weight: 600;
}

/* ===== 変更履歴 ===== */
.history-list {
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 50vh;
  overflow-y: auto;
  margin-bottom: 14px;
}
.hist-empty {
  padding: 28px 14px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.hist-item {
  display: flex;
  gap: 10px;
  padding: 11px 13px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  align-items: flex-start;
}
.hist-item:last-child {
  border-bottom: none;
}
.hist-item:hover {
  background: #f8fafc;
}
.hist-item.is-notified {
  opacity: 0.55;
  cursor: default;
}
.hist-check {
  margin-top: 3px;
  flex-shrink: 0;
}
.hist-body {
  flex: 1;
  min-width: 0;
}
.hist-top {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}
.hist-action {
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  padding: 1px 8px;
  border-radius: 10px;
  flex-shrink: 0;
}
.act-add { background: #1e3a8a; }
.act-edit { background: #0891b2; }
.act-del { background: #dc2626; }
.hist-target {
  font-size: 13px;
  font-weight: 600;
}
.hist-badge {
  font-size: 11px;
  color: #16a34a;
  font-weight: 700;
}
.hist-detail {
  font-size: 12px;
  color: #334155;
  margin-top: 3px;
  line-height: 1.5;
}
.hist-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}

/* ===== ログイン画面 ===== */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  position: fixed;
  inset: 0;
  background: #f1f5f9;
  z-index: 100;
}
.login-box {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.10);
  padding: 40px 36px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.5;
  text-align: center;
  margin-bottom: 8px;
}
.login-tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.login-tab {
  flex: 1;
  padding: 8px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  background: #fff;
  cursor: pointer;
  color: var(--muted);
}
.login-tab.active {
  background: var(--primary);
  color: #fff;
}
.login-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.login-input {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 40px 10px 12px;
  font-size: 14px;
  outline: none;
  width: 100%;
  box-sizing: border-box;
}
.login-input:focus {
  border-color: var(--primary);
}
.login-toggle {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 0;
  line-height: 1;
  color: var(--muted);
}
.login-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.login-btn:hover {
  background: #000060;
}
.login-error {
  color: #b91c1c;
  font-size: 12px;
  min-height: 16px;
  text-align: center;
}

/* ===== スマホ対応 ===== */
@media (max-width: 640px) {
  :root {
    --label-w: 124px;
  }
  .topbar {
    padding: 8px 10px;
  }
  .topbar h1 {
    font-size: 14px;
  }
  /* フィルタ・操作ボタンのタップ領域を拡大 */
  .dd-btn,
  .ctl {
    padding: 9px 12px;
    font-size: 13px;
  }
  .dd-panel {
    min-width: 160px;
  }
  /* ラベル列を詰める */
  .corner,
  .rlabel {
    padding: 0 6px;
  }
  .rlabel {
    font-size: 11px;
  }
  .rlabel.indent {
    padding-left: 14px;
  }
  .corner-title {
    font-size: 10px;
  }
  /* バーを少し高く＝タップしやすく */
  .bar {
    height: 24px;
    line-height: 24px;
  }
  /* スクロール領域の高さをツールバー実測ぶん広げる */
  .scroll {
    height: calc(100vh - 160px);
  }
}
