/* ====================================
   タイムバケット スタイル
   リベシティブランドカラー使用
   ==================================== */

/* Keifontローカル優先（ユーザーのMacにインストール済み） */
@font-face {
  font-family: 'Keifont Local';
  src: local('けいふぉんと'), local('Keifont');
  font-display: swap;
}

:root {
  --navy: #16214B;
  --blue: #0C45A6;
  --yellow: #FFC332;
  --cream: #FEEDC8;
  --red: #FF3131;
  --white: #ffffff;
  --gray-light: #f5f2e9;
  --gray: #c7c2b4;
  --gray-dark: #6b6657;
  --shadow: 0 2px 8px rgba(22, 33, 75, 0.12);
  --shadow-lg: 0 4px 16px rgba(22, 33, 75, 0.18);
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { overscroll-behavior-y: contain; }

body {
  font-family: 'Keifont Local', 'Yusei Magic', 'Zen Kurenaido', 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', sans-serif;
  background: var(--cream);
  color: var(--navy);
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: 90px;
}

/* ヘッダー */
header {
  background: var(--blue);
  color: var(--white);
  padding: 14px 18px 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
header h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: rgba(255,255,255,0.15);
  color: var(--white);
  font-size: 20px;
  border-radius: 50%;
  cursor: pointer;
}
.icon-btn:active { opacity: 0.7; }

.progress-bar-wrap {
  margin-top: 10px;
  background: rgba(255,255,255,0.25);
  border-radius: 6px;
  height: 10px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--yellow);
  border-radius: 6px;
  transition: width 0.35s ease;
}
.progress-text {
  margin-top: 5px;
  font-size: 13px;
  opacity: 0.95;
  text-align: right;
}

/* ビュー切替タブ */
.view-tabs {
  display: flex;
  background: var(--white);
  border-bottom: 2px solid var(--gray-light);
}
.view-tab {
  flex: 1;
  padding: 12px 8px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--gray-dark);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
  user-select: none;
}
.view-tab.active {
  color: var(--blue);
  border-bottom-color: var(--yellow);
  background: #fafaf3;
}

/* フィルタバー */
.filter-bar {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-light);
}
.filter-bar select {
  flex: 1;
  padding: 8px 10px;
  border: 1.5px solid var(--gray);
  border-radius: 8px;
  background: var(--white);
  font-family: inherit;
  font-size: 14px;
  color: var(--navy);
  outline: none;
}
.filter-bar select:focus { border-color: var(--blue); }

/* メイン */
main { padding: 14px 14px 20px; }

/* 空の状態 */
.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--gray-dark);
}
.empty-emoji { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; margin: 4px 0; }
.empty-state .sub { font-size: 13px; opacity: 0.7; }

/* ==== カード一覧ビュー ==== */
.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  border-left: 6px solid var(--yellow);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  position: relative;
}
.card:active { transform: scale(0.98); }
.card.status-done { border-left-color: #3BB273; background: #f3fbf6; }
.card.status-cancel { border-left-color: var(--gray); opacity: 0.65; }

.card-row1 {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}
.card-num {
  background: var(--blue);
  color: var(--white);
  border-radius: 50%;
  min-width: 26px;
  height: 26px;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.card-title {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
  color: var(--navy);
  word-break: break-word;
  line-height: 1.35;
}
.card.status-done .card-title { text-decoration: line-through; color: var(--gray-dark); }

.card-row2 {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.chip-bucket { background: var(--cream); color: var(--navy); border: 1.5px solid var(--yellow); }
.chip-status-open { background: #e8f0fb; color: var(--blue); }
.chip-status-done { background: #d6f1e1; color: #1f7a4b; }
.chip-status-cancel { background: #ffe1e1; color: var(--red); }
.chip-age { background: var(--yellow); color: var(--navy); }

/* ==== タイムラインビュー ==== */
.timeline-group {
  background: var(--white);
  border-radius: var(--radius);
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.timeline-header {
  background: var(--blue);
  color: var(--white);
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
}
.timeline-header .count {
  background: var(--yellow);
  color: var(--navy);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
}
.timeline-items { padding: 6px 10px 10px; }
.timeline-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 6px;
  border-bottom: 1px dashed var(--gray-light);
  cursor: pointer;
}
.timeline-item:last-child { border-bottom: none; }
.timeline-item:active { background: var(--gray-light); }
.timeline-item .ti-icon {
  font-size: 18px;
  width: 26px;
  text-align: center;
  flex-shrink: 0;
}
.timeline-item .ti-title {
  flex: 1;
  font-size: 15px;
  word-break: break-word;
}
.timeline-item.status-done .ti-title { text-decoration: line-through; color: var(--gray-dark); }
.timeline-item.status-cancel { opacity: 0.55; }
.timeline-item .ti-age {
  background: var(--yellow);
  color: var(--navy);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
}

/* ==== ガントチャート風マトリクス ==== */
/* スクロールコンテナ：縦・横両方をこのコンテナ内で処理 */
.gantt-wrap {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  /* viewportからヘッダ/タブ/フィルタ/FAB高さを差し引いた高さ。モバイルで確実に縦スクロールを発生させる */
  max-height: calc(100vh - 240px);
  max-height: calc(100dvh - 240px);
  position: relative;
}
/* 各行は独立したgrid（display:contentsを使わない＝iOS Safari対応） */
.gantt-grid {
  min-width: 100%;
  width: max-content;
  position: relative;
}
.gantt-header-row,
.gantt-row {
  display: grid;
  grid-template-columns: 140px repeat(var(--col-count), 80px);
  width: max-content;
  min-width: 100%;
}
/* ヘッダ行：上部sticky */
.gantt-header-row {
  position: sticky;
  top: 0;
  z-index: 6;
}
.gantt-title-head,
.gantt-col-head {
  background: var(--blue);
  color: var(--white);
  font-size: 12px;
  font-weight: 700;
  padding: 10px 6px;
  text-align: center;
  border-right: 1px solid rgba(255,255,255,0.15);
  border-bottom: 2px solid var(--yellow);
  white-space: nowrap;
  box-shadow: 0 2px 4px rgba(22,33,75,0.12);
}
/* 左上交差セル：縦横両方にsticky */
.gantt-title-head {
  position: sticky;
  left: 0;
  z-index: 8;
  text-align: left;
  padding-left: 10px;
  box-shadow: 2px 2px 6px rgba(22,33,75,0.18);
}
.gantt-col-head:last-child { border-right: none; }

/* タイトル列セル：左端sticky */
.gantt-title-cell {
  background: #fafaf3;
  padding: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
  border-right: 2px solid var(--yellow);
  border-bottom: 1px solid var(--gray-light);
  position: sticky;
  left: 0;
  z-index: 3;
  min-height: 48px;
  display: flex;
  align-items: center;
  /* 省略表示 */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
  cursor: pointer;
  box-shadow: 2px 0 6px rgba(22,33,75,0.10);
}
.gantt-cell {
  padding: 6px 4px;
  border-right: 1px dashed var(--gray-light);
  border-bottom: 1px solid var(--gray-light);
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--white);
  cursor: pointer;
}
.gantt-cell:last-child { border-right: none; }

.gantt-row:hover .gantt-title-cell,
.gantt-row:hover .gantt-cell {
  background: #fffdf5;
}
.gantt-row:active .gantt-cell,
.gantt-row:active .gantt-title-cell { background: var(--cream); }

/* バー */
.gantt-bar {
  width: 100%;
  min-height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  box-shadow: 0 1px 3px rgba(22,33,75,0.15);
}
.bar-open { background: #FFC332; color: var(--navy); }
.bar-done { background: #0C45A6; color: var(--white); }
.bar-cancel {
  background: var(--gray);
  color: var(--white);
  position: relative;
}
.bar-cancel::after {
  content: '';
  position: absolute;
  left: 6px;
  right: 6px;
  top: 50%;
  height: 2px;
  background: var(--navy);
  opacity: 0.7;
}
.bar-check { font-size: 13px; }
.bar-age { font-size: 11px; font-weight: 700; }

/* モバイル：タイトル列は省略、タップでフルテキスト */
@media (max-width: 480px) {
  .gantt-header-row,
  .gantt-row {
    grid-template-columns: 110px repeat(var(--col-count), 64px);
  }
  .gantt-title-cell { max-width: 110px; font-size: 12px; padding: 8px; }
  .gantt-col-head { font-size: 11px; padding: 8px 4px; }
  .gantt-bar { font-size: 10px; min-height: 26px; }
  .gantt-wrap {
    max-height: calc(100vh - 220px);
    max-height: calc(100dvh - 220px);
  }
}

/* フローティング追加ボタン */
.fab {
  position: fixed;
  bottom: 82px;
  right: 18px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--yellow);
  color: var(--navy);
  border: none;
  font-size: 32px;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  z-index: 90;
  line-height: 1;
}
.fab:active { transform: scale(0.92); }

/* アクションバー */
.action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--white);
  border-top: 1.5px solid var(--gray-light);
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  z-index: 80;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0));
}

.btn {
  padding: 11px 14px;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:active { opacity: 0.75; transform: scale(0.97); }
.btn-primary { background: var(--blue); color: var(--white); flex: 1; }
.btn-danger { background: var(--red); color: var(--white); }
.btn-sub { flex: 1; background: var(--cream); color: var(--navy); border: 1.5px solid var(--yellow); }

/* ==== モーダル ==== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(22, 33, 75, 0.55);
  z-index: 1000;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--white);
  width: 100%;
  max-width: 540px;
  max-height: 92vh;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-header {
  background: var(--blue);
  color: var(--white);
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h2 { font-size: 17px; font-weight: 700; }
.close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  border: none;
  color: var(--white);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}
.close-btn:active { opacity: 0.7; }
.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--gray-light);
  display: flex;
  gap: 8px;
  background: #fafaf3;
}
.modal-footer .btn-primary { flex: 1; }

/* フォーム */
.field {
  display: block;
  margin-bottom: 14px;
}
.field .label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--blue);
  margin-bottom: 6px;
}
.field .label em { color: var(--red); font-style: normal; }
.danger-label { color: var(--red) !important; }
.field input[type="text"],
.field input[type="number"],
.field textarea,
.field select {
  width: 100%;
  padding: 11px 12px;
  border: 1.5px solid var(--gray);
  border-radius: 10px;
  font-family: inherit;
  font-size: 16px;
  color: var(--navy);
  background: var(--white);
  outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--blue);
}
.field textarea { resize: vertical; min-height: 56px; }

.status-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.status-radio {
  flex: 1;
  min-width: 90px;
  position: relative;
  cursor: pointer;
}
.status-radio input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.status-radio span {
  display: block;
  text-align: center;
  padding: 10px 6px;
  background: var(--gray-light);
  border: 2px solid var(--gray-light);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--gray-dark);
}
.status-radio input:checked + span {
  background: var(--blue);
  color: var(--white);
  border-color: var(--blue);
}
.status-radio.done input:checked + span { background: #3BB273; border-color: #3BB273; }
.status-radio.cancel input:checked + span { background: var(--red); border-color: var(--red); }

/* バケット管理 */
.bucket-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
  min-height: 32px;
}
.bucket-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  background: var(--cream);
  border: 1.5px solid var(--yellow);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: var(--navy);
}
.bucket-item .x {
  background: var(--red);
  color: var(--white);
  border: none;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.bucket-regen, .bucket-add-row {
  background: #fafaf3;
  padding: 10px;
  border-radius: 10px;
  margin-top: 8px;
}
.bucket-regen-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.bucket-regen-row label {
  flex: 1;
  font-size: 12px;
  color: var(--gray-dark);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.bucket-regen-row input {
  padding: 6px 8px;
  border: 1.5px solid var(--gray);
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  text-align: center;
}
.bucket-add-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.bucket-add-row input {
  flex: 1;
  padding: 8px 10px;
  border: 1.5px solid var(--gray);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
}
.bucket-add-row .btn-sub { flex: 0 0 48px; }

/* ==== 読込モーダル ==== */
.import-menu {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}
.import-menu-btn {
  width: 100%;
  padding: 16px 20px;
  font-size: 16px;
  border-radius: 12px;
}
.import-hint {
  font-size: 13px;
  color: var(--gray-dark);
  text-align: center;
  line-height: 1.6;
}
.import-note {
  background: var(--cream);
  border: 1.5px solid var(--yellow);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.7;
  color: var(--navy);
  margin-top: 12px;
}
.mode-group {
  display: flex;
  gap: 10px;
}
.mode-radio {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 10px;
  border: 1.5px solid var(--gray);
  border-radius: 10px;
  cursor: pointer;
  background: var(--white);
  font-size: 14px;
  transition: all 0.15s;
}
.mode-radio input { display: none; }
.mode-radio:has(input:checked) {
  background: var(--blue);
  color: var(--white);
  border-color: var(--blue);
  font-weight: 700;
}
.btn[disabled] {
  opacity: 0.6;
  pointer-events: none;
}

/* バケットマッピングモーダル */
.bucket-map-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.bucket-map-row {
  background: var(--cream);
  border: 1.5px solid var(--yellow);
  border-radius: 12px;
  padding: 12px 14px;
}
.bucket-map-name {
  font-weight: 700;
  color: var(--navy);
  font-size: 15px;
  margin-bottom: 8px;
}
.bucket-map-name .bk-label {
  background: var(--white);
  border: 1.5px solid var(--blue);
  border-radius: 6px;
  padding: 2px 8px;
  margin: 0 2px;
  color: var(--blue);
}
.bucket-map-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.bucket-map-actions .mode-radio {
  flex: 1 1 auto;
  min-width: 92px;
  padding: 10px 8px;
  font-size: 13px;
}
.bucket-map-target {
  display: none;
  align-items: center;
  gap: 8px;
}
.bucket-map-target.show { display: flex; }
.bucket-map-target label {
  font-size: 13px;
  color: var(--navy);
  white-space: nowrap;
}
.bucket-map-target select {
  flex: 1;
  padding: 8px 10px;
  border: 1.5px solid var(--gray);
  border-radius: 8px;
  background: var(--white);
  font-size: 14px;
}

.bucket-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px;
  background: var(--cream);
  border-radius: 10px;
  min-height: 40px;
}
.wizard-intro {
  font-size: 14px;
  color: var(--navy);
  background: var(--cream);
  border-left: 4px solid var(--yellow);
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 14px;
  line-height: 1.6;
}
.wizard-preview { margin-top: 10px; }

/* レスポンシブ */
@media (min-width: 720px) {
  main { max-width: 720px; margin: 0 auto; padding: 20px; }
  .filter-bar { max-width: 720px; margin: 0 auto; }
  .action-bar { justify-content: center; }
  .action-bar .btn-sub { flex: 0 1 180px; }
  .modal-overlay { align-items: center; padding: 20px; }
  .modal { border-radius: 20px; }
}
