:root {
  --bg-weekday: #ffffff;
  --bg-weekday-alt: #f5f5f5;
  --bg-sat: #e8f4ff;
  --bg-holiday-soft: #ffeef2;
  --bg-kokyu-tokkyu: #ffd3de;
  --bg-late-night: #5b2c83;
  --border-color: #dddddd;
  --text-color: #333333;
  --header-bg: #fafafa;
}

/* ページ全体 */
body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text-color);
  background-color: #ffffff;
}

#app {
  /* 画面幅ではなく、中身（表）の大きさに合わせてapp自体を広げる設定 */
  width: fit-content; 
  min-width: 100%; 
  
  margin: 0 auto;
  padding: 12px;
  padding-bottom: 120px;
  overflow: visible; /* ここをvisibleにして、スクロールバーをブラウザ全体に委ねる */
}

/* ヘッダー部分（年・月・anchor_no） */
.junkan-header {
  background-color: var(--header-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 12px;
  width: fit-content;     /* 幅を中身に合わせる */
}

.junkan-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.junkan-meta label {
  font-size: 14px;
}

.junkan-meta select,
.junkan-meta input {
  font-size: 14px;
  padding: 2px 4px;
}

#applyButton {
  padding: 4px 10px;
  font-size: 14px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background-color: #ffffff;
  cursor: pointer;
}

#applyButton:hover {
  background-color: #f0f0f0;
}

/* メインエリア */
.junkan-main {
  display: flex;
  flex-direction: column;
  gap: 24px;
  align-items: center; /* 子要素（カレンダー枠）を中央に配置 */
}

/* 月ごとのセクション */
.month-section {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 10px 12px 10px;
  width: fit-content; /* 枠の幅を、画面幅ではなく中身（表）に合わせる */
}

/* 月タイトル（例：2025年11月　加給合計：1：17） */
.month-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0;
  font-size: 18px;
  font-weight: bold;
  line-height: 1;
}

.month-title-text {
  font-weight: bold;
}

.month-extra-total {
  font-size: 14px;
  font-weight: normal;
}

/* ここがタイトルと表の余白（ユーザー編集ポイント） */
.month-title + .month-table-wrapper {
  margin-top: 0px; /* ← タイトルと表の余白：ここを調整 */
}

/* テーブルラッパー（横スクロール廃止・画面全体で動かす） */
.month-table-wrapper {
  /* 枠内スクロールをやめて、はみ出しを許可する */
  overflow-x: visible;
  
  /* 以下のタッチ制限設定を削除（または無効化）することで、
     ピンチイン・アウトや画面全体のスクロールが可能になります */
  /* -webkit-overflow-scrolling: touch; */
  /* touch-action: pan-x pan-y; */
  /* overscroll-behavior: auto; */
}

/* カレンダーテーブル */
.junkan-table {
  width: auto;
  max-width: 100%;
  min-width: 650px;
  border-collapse: collapse;  /* ← これを追加してください！ */
}


/* ヘッダー行 */
.junkan-table thead tr {
  background-color: #f2f2f2;
}

.junkan-table th,
.junkan-table td {
  border: 1px solid var(--border-color);
  padding: 2px 4px;
  text-align: center;
  vertical-align: middle;
}

/* 列幅（ユーザーが編集しやすいようコメント） */
.col-late-night {
  width: 5px;            /* 色帯としての幅 */
  padding: 0 !important;
  font-size: 0;          /* 文字を見えなくする */
  overflow: hidden;      /* はみ出し防止 */
}
.col-day {
  width: 15px; /* 日付列の幅 */
}
.col-weekday {
  width: 15px; /* 曜日列の幅 */
}
.col-type {
  width: 20px; /* 種別列の幅（甲休／祝日／休ダ） */
}
.col-weekno {
  width: 10px; /* 週番号（holiday_number）列の幅 */
}
.col-code {
  width: 50px; /* 運番列の幅（折り返し禁止） */
}
.col-work {
  width: 150px; /* 勤務列の幅（cal_text1 等） */
}
/* 以前の内容列（今は列自体は廃止済みだが、幅指定は残しておく） */
.col-text2 {
  width: 200px; /* 内容列の幅（cal_text2） */
}
.col-extra {
  width: 30px; /* 加給列の幅 */
}

/* 運番は折り返し禁止 */
.junkan-table td.col-code {
  white-space: nowrap;
}

/* cal_text1 / cal_text2 は複数行対応（JS で "\n" に変換） */
.cell-work,
.cell-text2 {
  white-space: pre-line; /* "\n" → 改行 */
  text-align: left !important;
}

/* 深夜週マーク列（1列目） */
.cell-late-night {
  background-color: transparent;
  color: #ffffff;
  font-size: 11px;
  padding: 0;
}

/* 深夜週が true のときの背景 */
.cell-late-night--active {
  background-color: var(--bg-late-night);
}

/* 行背景色（優先順位に従う） */

/* 基本：平日（後でJSからクラスを付与） */
.tr-weekday-even {
  background-color: var(--bg-weekday);
}
.tr-weekday-odd {
  background-color: var(--bg-weekday-alt);
}

/* 土曜 */
.tr-sat {
  background-color: var(--bg-sat);
}

/* 祝日・休ダ・日曜 → 薄ピンク #ffeef2 */
.tr-holiday-soft {
  background-color: var(--bg-holiday-soft);
}

/* 特休／公休 → 濃ピンク #ffd3de （最優先） */
.tr-kokyu-tokkyu {
  background-color: var(--bg-kokyu-tokkyu);
}

/* 甲休は平日扱い（背景は白／薄グレー交互） */

/* 週番号列（holiday_number）の表示を少し細く */
.col-weekno {
  font-size: 12px;
}

/* 小さい画面用 */
@media (max-width: 768px) {
  .junkan-meta {
    flex-direction: column;
    align-items: flex-start;
  }

  .month-title {
    flex-direction: column;
    gap: 4px;
  }

  .month-extra-total {
    align-self: flex-end;
  }
}

/* 年・月・循環番号をまとめるグループ */
.ym-group {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap; /* ← これがあると、画面が狭くても安全に折り返します */
}

/* スマホ表示の調整 */
@media (max-width: 768px) {
  .ym-group {
    flex-direction: row; 
    width: 100%;
  }
}

/* --- 印刷（PDF保存）用の設定（80%縮小・確実収め版） --- */
@media print {
  /* 0. 紙の余白設定 */
  @page {
    /* 余白を5mmに統一。これで下ギリギリまで表を表示できます */
    margin: 5mm;
    size: A4 portrait;
  }

  /* 1. 不要なUIを非表示 */
  .junkan-header,
  .bottom-nav,
  .drawer-menu,
  #drawer-overlay,
  #printButton,
  [data-include]
  {
    display: none !important;
  }

  body {
    background-color: #fff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    margin: 0 !important;
  }

  /* 2. レイアウト調整 */
  #app {
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  .junkan-main {
    display: block !important;
  }

  /* 3. 月セクションの調整 */
  .month-section {
    display: block !important;
    border: none !important;
    padding: 0 !important;
    margin-bottom: 0 !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    
    /* ★ご希望通り80%に設定（これで確実に入ります） */
    zoom: 0.8; 
  }

  /* 4. テーブル調整 */
  .month-table-wrapper {
    overflow: visible !important;
  }
  
  .junkan-table {
    min-width: 0 !important;
    width: 100% !important;
    font-size: 9pt; 
    table-layout: fixed;
    line-height: 1.1; 
  }

  .junkan-table tr {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  .junkan-table th,
  .junkan-table td {
    /* ★80%に合わせて余白も少しタイトに（3px） */
    padding: 3px 2px !important;
    
    height: auto !important;
    word-wrap: break-word;
    color: #000 !important;
    vertical-align: middle !important;
  }

  .junkan-table a {
    text-decoration: none !important;
    color: #000 !important;
    pointer-events: none;
    cursor: default;
  }

  /* カラム幅設定 */
  .col-late-night { width: 3% !important; }
  .col-day        { width: 5% !important; }
  .col-weekday    { width: 5% !important; }
  .col-type       { width: 8% !important; }
  .col-weekno     { width: 4% !important; }
  .col-code       { width: 14% !important; }
  .col-extra      { width: 10% !important; }
  .col-work       { width: auto !important; }

  /* 5. 強制改ページ設定 */
  #monthPrimary {
    page-break-after: always !important;
    break-after: page !important;
    margin-bottom: 0 !important; 
  }
}