/* =====================================================================
 * myFIT ナビ ― 予定の画面
 * ---------------------------------------------------------------------
 * 狭いポップアップ（360px）でも広い全画面タブでも同じ部品を使う。
 * 幅で変わるのは文字の大きさとマス目の高さだけ。
 * 色はテーマの変数（--accent など）に乗せるので、テーマを変えると追従する。
 * ===================================================================== */

.pv {
  display: flex;
  flex-direction: column;
  min-height: 0;
  --pv-cell: 46px;   /* 月表示の1マスの高さ */
  --pv-bar: 15px;    /* 帯1本の高さ */
  --pv-baretop: 17px; /* 日付の数字のぶん、帯を下げる量 */
  --pv-fs: 10px;
}

/* ---------- 上のバー ----------
 * クラス名は .pv-top。帯（.pv-bar）と紛らわしい名前にすると、
 * 位置指定が効いてツールバーが消える（実際に一度そうなった） */
.pv-top {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex: none;
}
.pv-nav,
.pv-today,
.pv-mode,
.pv-add,
.pv-wide {
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  border-radius: 7px;
  border: 1px solid var(--line2, var(--line));
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  padding: 5px 8px;
  flex: none;
}
.pv-nav { padding: 4px 9px; font-size: 15px; line-height: 1; }
.pv-nav:hover, .pv-today:hover, .pv-mode:hover, .pv-wide:hover { background: var(--accent-weak); }
.pv-title {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  font-weight: 800;
  color: var(--ink);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pv-modes { display: flex; gap: 0; flex: none; }
.pv-modes .pv-mode:first-child { border-radius: 7px 0 0 7px; }
.pv-modes .pv-mode:last-child { border-radius: 0 7px 7px 0; margin-left: -1px; }
.pv-mode.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.pv-add { background: var(--accent); color: #fff; border-color: var(--accent); }
.pv-add:hover { background: var(--accent-ink, var(--accent)); }

/* ---------- 月表示 ---------- */
.pv-body { flex: 1; min-height: 0; overflow: auto; }
/* 画面が広いほど月を大きく見せる。中身の高さで固定すると、大きい端末では
 * 空っぽの詳細欄が場所を取って、肝心の月が小さいままになる（実機でそうなった） */
.pv-body-month { flex: 1 1 auto; display: flex; flex-direction: column; }
.pv-month { flex: 1; display: flex; flex-direction: column; }
.pv-week { flex: 1 1 auto; }

.pv-wd {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 3;
}
.pv-wd span {
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--sub);
  padding: 3px 0;
}
.pv-wd .w0 { color: #c0392b; }
.pv-wd .w6 { color: #2b6cb0; }

.pv-month.six { --pv-cell: 40px; }

.pv-week { position: relative; --lanes: 0; }
.pv-days { display: grid; grid-template-columns: repeat(7, 1fr); height: 100%; }
.pv-day {
  /* 帯が何段あるかで行が伸びる。決め打ちの高さにすると、2段目の帯が
   * 次の週の日付の上にはみ出してしまう */
  min-height: max(var(--pv-cell), calc(var(--pv-baretop) + var(--lanes) * (var(--pv-bar) + 2px) + 2px));
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 1px 3px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  /* 指は画面を動かす道具でもある。ふだんは縦スクロールを通し、
   * 長押しで期間選びに入ったときだけ .picking で止める */
  touch-action: pan-y;
}
.pv-day:nth-child(7n) { border-right: 0; }
.pv-day .n { font-size: 10px; font-weight: 700; color: var(--sub); }
.pv-day.out { background: var(--bg); }
.pv-day.out .n { opacity: 0.4; }
.pv-day.today .n {
  background: var(--accent);
  color: #fff;
  border-radius: 20px;
  padding: 0 5px;
}
.pv-day.sel { box-shadow: inset 0 0 0 2px var(--accent); }
/* 授業がある日は下にうっすら線を引く（時間割との重なりが分かる） */
.pv-day.hasclass { background-image: linear-gradient(to top, var(--accent-weak) 3px, transparent 3px); }
.pv-day.range { background: var(--accent-weak); }
/* 期間を選んでいる間だけスクロールを止める */
.pv-body.picking, .pv-wk-scroll.picking { touch-action: none; }
.pv-body.picking .pv-day, .pv-wk-scroll.picking .pv-slot { touch-action: none; }

/* 帯。週の行の上に浮かせて、日をまたいで1本に見せる */
.pv-bars {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--pv-baretop);
  bottom: 1px;
  pointer-events: none;
}
.pv-bar {
  position: absolute;
  left: calc(var(--from) / 7 * 100%);
  width: calc(var(--span) / 7 * 100%);
  top: calc(var(--lane) * (var(--pv-bar) + 2px));
  height: var(--pv-bar);
  margin: 0 1px;
  padding: 0 4px;
  border: 0;
  border-radius: 4px;
  background: var(--c, var(--accent));
  color: #fff;
  font-family: inherit;
  font-size: var(--pv-fs);
  font-weight: 700;
  line-height: var(--pv-bar);
  text-align: left;
  cursor: pointer;
  pointer-events: auto;
  overflow: hidden;
  white-space: nowrap;
  box-sizing: border-box;
}
.pv-bar span { display: block; overflow: hidden; text-overflow: ellipsis; }
.pv-bar:hover { filter: brightness(1.08); }
/* 週をまたぐときは、切れている側の角を落として「続き」だと分かるようにする */
.pv-bar.c0 { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: 0; }
.pv-bar.c1 { border-top-right-radius: 0; border-bottom-right-radius: 0; margin-right: 0; }
.pv-bar.done { opacity: 0.45; text-decoration: line-through; }
.pv-more {
  position: absolute;
  left: calc(var(--from) / 7 * 100%);
  width: calc(1 / 7 * 100%);
  top: calc(var(--lane) * (var(--pv-bar) + 2px));
  font-size: 9px;
  font-weight: 700;
  color: var(--faint);
  text-align: center;
}

/* 課題・テストの件数。予定の帯と混ざらないよう、日付の右に小さく置く */
.pv-cnt {
  display: inline-block;
  vertical-align: 2px;
  margin-left: 3px;
  min-width: 13px;
  height: 13px;
  line-height: 13px;
  border-radius: 20px;
  font-size: 9px;
  font-weight: 800;
  text-align: center;
  color: #fff;
  padding: 0 3px;
  background: var(--grey, #8a8f98);
}
.pv-cnt.urgent { background: #c0392b; }
.pv-cnt.soon { background: #d98000; }
.pv-cnt.future { background: #2e9e4f; }
.pv-cnt.overdue { background: #6b6b6b; }
.pv-cnt.done { background: #b9bec6; }

/* 日を選ばせているときの帯 */
.pv-pick {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: #fff;
  background: var(--accent);
  padding: 6px 10px;
  flex: none;
}
.pv-pick.hidden { display: none; }
.pv-pick span { flex: 1; min-width: 0; }
.pv-pick-x {
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.6);
  background: transparent;
  color: #fff;
  border-radius: 7px;
  padding: 3px 9px;
  cursor: pointer;
  flex: none;
}

/* ---------- 週表示 ---------- */
.pv-body-week { display: flex; }
.pv-wk { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.pv-gut { width: 30px; flex: none; font-size: 9px; color: var(--faint); text-align: center; }

.pv-wk-head {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex: none;
}
.pv-wk-d {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 10px;
  color: var(--sub);
  padding: 3px 0;
  cursor: pointer;
}
.pv-wk-d b { display: block; font-size: 9px; color: var(--faint); }
.pv-wk-d.today { color: #fff; background: var(--accent); border-radius: 6px 6px 0 0; }
.pv-wk-d.today b { color: rgba(255, 255, 255, 0.8); }
.pv-wk-d.sel { box-shadow: inset 0 -2px 0 var(--accent); }

.pv-wk-all { display: flex; border-bottom: 1px solid var(--line); flex: none; min-height: 20px; }
.pv-wk-all .pv-gut { padding-top: 3px; }
.pv-wk-all .pv-week { flex: 1; min-width: 0; min-height: 20px; }
.pv-wk-all .pv-bars { top: 2px; }

.pv-wk-scroll { flex: 1; min-height: 0; overflow-y: auto; }
.pv-wk-grid { display: flex; position: relative; }
.pv-gut-col { width: 30px; flex: none; }
.pv-h {
  display: block;
  height: var(--hh);
  font-size: 9px;
  color: var(--faint);
  text-align: right;
  padding-right: 3px;
  transform: translateY(-5px);
}
.pv-col { flex: 1; min-width: 0; position: relative; border-left: 1px solid var(--line); }
.pv-col.today { background: var(--accent-weak); }
.pv-slot {
  height: var(--hh);
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  touch-action: pan-y;
}
.pv-slot.range { background: var(--accent-weak); }

.pv-ev,
.pv-class {
  position: absolute;
  left: 1px;
  right: 1px;
  border: 0;
  border-radius: 4px;
  font-family: inherit;
  font-size: var(--pv-fs);
  font-weight: 700;
  text-align: left;
  padding: 1px 3px;
  overflow: hidden;
  cursor: pointer;
  box-sizing: border-box;
}
.pv-ev { background: var(--c, var(--accent)); color: #fff; z-index: 2; }
.pv-ev.done { opacity: 0.45; text-decoration: line-through; }
.pv-class {
  background: var(--card);
  border: 1px dashed var(--line2, var(--line));
  color: var(--sub);
  z-index: 1;
  cursor: default;
  font-weight: 600;
}
.pv-ev span, .pv-class span { display: block; overflow: hidden; }

/* 課題・テストの締切。予定のブロックと区別できるよう、線1本＋名前にする */
.pv-due {
  position: absolute;
  left: 1px;
  right: 1px;
  height: 0;
  border-top: 2px solid var(--grey, #8a8f98);
  z-index: 3;
  pointer-events: none;
}
.pv-due span {
  display: block;
  font-size: 9px;
  font-weight: 700;
  color: var(--ink);
  background: var(--card);
  padding: 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pv-due.urgent { border-top-color: #c0392b; }
.pv-due.soon { border-top-color: #d98000; }
.pv-due.future { border-top-color: #2e9e4f; }
.pv-due.done { border-top-color: #b9bec6; opacity: 0.6; }

/* ---------- 下の詳細 ---------- */
.pv-detail {
  flex: 0 0 auto;
  max-height: 46%;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 6px 8px 8px;
}
.pv-dt-head {
  display: flex;
  align-items: center;
  font-size: 11px;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 4px;
}
.pv-dt-add {
  margin-left: auto;
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  border: 1px dashed var(--accent);
  background: transparent;
  color: var(--accent);
  border-radius: 7px;
  padding: 3px 7px;
  cursor: pointer;
}
.pv-dt-sub { font-size: 9.5px; font-weight: 700; color: var(--faint); margin: 5px 0 2px; }
.pv-dt-none { font-size: 10.5px; color: var(--faint); padding: 4px 0; }
.pv-dt-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 11px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  margin-bottom: 4px;
  cursor: pointer;
}
.pv-dt-row.cls { background: transparent; border-style: dashed; cursor: default; }
.pv-dt-row.cls.tap { cursor: pointer; }
.pv-dt-row.cls.tap:hover { background: var(--card); }
/* 課題・テストは画面側が描くので、入れ物だけ用意する */
.pv-dt-items > * { margin-bottom: 4px; }
.pv-dt-row.done { opacity: 0.5; }
.pv-dt-row.done .pv-dt-n { text-decoration: line-through; }
.pv-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.pv-dt-n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.pv-dt-t { font-size: 10px; color: var(--sub); flex: none; }
.pv-rep { font-size: 10px; color: var(--accent); flex: none; }

/* ---------- 作る・直すシート ---------- */
.pv-sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 60;
}
.pv-sheet.hidden { display: none; }
.pv-sheet-in {
  width: 100%;
  max-width: 460px;
  max-height: 92dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--card);
  border-radius: 14px 14px 0 0;
  padding: 12px 13px 14px;
  box-shadow: 0 -6px 22px rgba(0, 0, 0, 0.18);
  animation: pv-up 0.2s cubic-bezier(0.2, 1, 0.4, 1) both;
}
@keyframes pv-up { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
/* 操作バー。キーボードが出てもここは隠れないので、決定はここに置く */
.pv-sh-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink);
  margin: -12px -13px 10px;
  padding: 10px 13px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  position: sticky;
  top: -12px;
  z-index: 2;
}
.pv-sh-head b { flex: 1; text-align: center; font-weight: 800; }
.pv-sh-x,
.pv-sh-head .pv-f-save {
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  border-radius: 8px;
  padding: 7px 13px;
  cursor: pointer;
  flex: none;
}
.pv-sh-x { border: 0; background: transparent; color: var(--sub); }
.pv-sh-head .pv-f-save { border: 0; background: var(--accent); color: #fff; }
/* 入力はすべて同じ見た目・同じ幅にそろえる。
 * min-width:0 が要る: 日付や選択の入力は中身に応じた最低幅を持っていて、
 * これが無いと2列に並べたとき右側がシートの外へはみ出す（実機でそうなった） */
.pv-sheet input[type="text"],
.pv-sheet textarea,
.pv-sheet select,
.pv-sheet input[type="datetime-local"],
.pv-sheet input[type="date"] {
  width: 100%;
  min-width: 0;
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line2, var(--line));
  border-radius: 9px;
  padding: 10px 10px;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
}
/* 選択には「開く」印が要る（appearance を外したので自前で描く） */
.pv-sheet select {
  background-image: linear-gradient(45deg, transparent 50%, var(--faint) 50%),
                    linear-gradient(135deg, var(--faint) 50%, transparent 50%);
  background-position: right 14px center, right 9px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 26px;
}
.pv-sheet input[type="date"],
.pv-sheet input[type="datetime-local"] { text-align: left; }
.pv-sheet textarea { resize: vertical; }
.pv-f-title { margin-bottom: 8px; font-weight: 700; }
.pv-f-allday { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--sub); margin-bottom: 8px; padding: 2px 0; }
.pv-f-allday input { width: auto; min-width: 0; flex: none; }
.pv-f-when { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.pv-f-when label,
.pv-f-row label,
.pv-f-until label {
  min-width: 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--faint);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
/* 終日のときは入力そのものが date になるので、ここでは何もしない */
.pv-f-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.pv-f-until { margin-bottom: 8px; }
.pv-f-until.hidden { display: none; }
.pv-f-place { margin-bottom: 8px; }
.pv-f-note { margin-bottom: 12px; }
.pv-f-btns { display: flex; gap: 7px; }
.pv-f-btns button {
  flex: 1;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  border-radius: 8px;
  padding: 11px 0;
  cursor: pointer;
  border: 1px solid #d9a19b;
  background: var(--bg);
  color: #8c2f26;
}

/* 繰り返しの範囲を聞く */
.pv-ask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 70;
}
.pv-ask-in {
  width: 88%;
  max-width: 320px;
  background: var(--card);
  border-radius: 12px;
  padding: 13px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.pv-ask-t { font-size: 12px; font-weight: 800; color: var(--ink); margin-bottom: 3px; }
.pv-ask-in button {
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid var(--line2, var(--line));
  background: var(--bg);
  color: var(--ink);
  border-radius: 8px;
  padding: 9px 0;
  cursor: pointer;
}
.pv-ask-in button[data-v="one"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.pv-ask-in button[data-v=""] { color: var(--faint); }

/* 縦に余裕のある端末（今どきのスマホ・全画面タブ）は、文字も帯も大きくする。
 * 360pxのポップアップに合わせた寸法のままだと、大きい画面で妙に小さく見える */
@media (min-height: 700px) {
  .pv {
    --pv-cell: 58px;
    --pv-bar: 18px;
    --pv-baretop: 21px;
    --pv-fs: 11.5px;
  }
  .pv-day .n { font-size: 12px; }
  .pv-wd span { font-size: 11.5px; padding: 5px 0; }
  .pv-cnt { min-width: 15px; height: 15px; line-height: 15px; font-size: 10px; }
  .pv-dt-row { font-size: 12.5px; padding: 7px 10px; }
  .pv-dt-head { font-size: 12.5px; }
}

/* ---------- 広い画面のとき ---------- */
/* 高さはここでは決めない。親（ポップアップなら固定値、全画面なら flex:1）が
 * 決めた高さに従う。ここで 100vh を入れると全画面側で下がはみ出す */
.pv.wide {
  --pv-cell: 92px;
  --pv-bar: 18px;
  --pv-baretop: 20px;
  --pv-fs: 11.5px;
}
.pv.wide .pv-month.six { --pv-cell: 78px; }
.pv.wide .pv-title { font-size: 15px; }
.pv.wide .pv-day .n { font-size: 12px; }
.pv.wide .pv-wd span { font-size: 11.5px; padding: 5px 0; }
.pv.wide .pv-detail { max-height: 30%; padding: 10px 14px 14px; }
.pv.wide .pv-gut, .pv.wide .pv-gut-col { width: 42px; }
.pv.wide .pv-wk-d { font-size: 12px; padding: 5px 0; }
.pv.wide .pv-dt-row { font-size: 12.5px; padding: 7px 10px; }
.pv.wide .pv-sheet { align-items: center; }
.pv.wide .pv-sheet-in { border-radius: 14px; }

@media (prefers-reduced-motion: reduce) {
  .pv-sheet-in { animation: none; }
}
