/*
 * Print feature styles: settings panel, page-split preview labels,
 * the print-only view (#print-view) and @media print rules.
 * @page (size/margin) is generated dynamically by print-renderer.js.
 */

/* ---- 印刷設定パネル（通常画面） ---- */

#printSettingsPanel {
  border-bottom: 1px solid var(--border);
  background: var(--bg-sub);
}

.print-settings-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.print-settings-head h3 {
  margin: 0;
  font-size: 15px;
}

.print-settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 6px 16px;
  margin-bottom: 10px;
}

.print-settings-grid label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}

.print-settings-grid select {
  padding: 2px 4px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  min-width: 120px;
}

.print-decl-input {
  display: flex;
  align-items: center;
  gap: 4px;
}

.print-decl-input input {
  width: 56px;
  padding: 2px 4px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}

.print-settings-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

/* ---- 地図上のページ枠プレビュー ---- */

.print-page-tooltip {
  background: transparent;
  border: none;
  box-shadow: none;
}

.print-page-no {
  display: inline-block;
  background: #1565c0;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  padding: 2px 8px;
  border-radius: 10px;
}

.print-page-no-off {
  background: #888;
  font-weight: 400;
}

/* ---- 印刷専用ビュー（画面プレビュー時はオーバーレイ） ---- */

#print-view {
  display: none;
}

#print-view.open {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 5000;
  overflow: auto;
  background: #777;
}

body.print-view-open {
  overflow: hidden;
}

.print-toolbar {
  position: sticky;
  top: 0;
  z-index: 6000;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: #333;
  color: #fff;
  flex-wrap: wrap;
}

.print-toolbar-note {
  font-size: 12px;
  color: #ffd54f;
}

/* 印刷ページは常にライトテーマで出力する */
.print-page {
  background: #fff;
  color: #000;
  margin: 12px auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

/* ダークモードの地図反転フィルターを印刷ビューでは常に解除する */
#print-view .leaflet-tile-pane {
  filter: none !important;
}

.print-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4mm;
  font-size: 10pt;
  padding: 0 1mm;
  box-sizing: border-box;
}

.print-header-title {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.print-header-no {
  font-weight: 700;
}

.print-header-band {
  white-space: nowrap;
}

.print-map {
  position: relative;
  background: #eee;
}

.print-footer {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1mm;
  font-size: 8pt;
  padding: 0 1mm;
  box-sizing: border-box;
}

.print-calibration {
  display: flex;
  align-items: center;
  gap: 3mm;
}

/* 1:25,000では1km=40mm。印刷後に定規で実測して縮尺を確認する。 */
.print-calibration-line {
  display: inline-block;
  width: 40mm;
  height: 0;
  border-top: 0.5mm solid #000;
}

.print-footer-info {
  display: flex;
  gap: 8mm;
}

.print-footer-latlon {
  color: #333;
}

/* ---- 地図上オーバーレイ（方位・スケールバー） ---- */

.print-north {
  position: absolute;
  top: 3mm;
  right: 3mm;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid #333;
  border-radius: 2px;
  padding: 1mm 2mm;
  font-size: 9pt;
  font-weight: 700;
  color: #000;
  line-height: 1.2;
  text-align: center;
}

.print-north-arrow {
  display: block;
  font-size: 11pt;
}

.print-scalebar {
  position: absolute;
  left: 3mm;
  bottom: 5mm;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid #333;
  border-radius: 2px;
  padding: 1mm 2mm;
  color: #000;
  font-size: 8pt;
  line-height: 1.2;
}

.print-scalebar-line {
  display: block;
  width: 40mm;
  height: 2mm;
  border: 0.4mm solid #000;
  border-top: none;
  box-sizing: border-box;
}

/* ---- CPラベル ---- */

.print-cp-label {
  background: transparent;
  border: none;
}

.print-cp-box {
  display: inline-block;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #c0392b;
  border-radius: 2px;
  color: #000;
  font-size: 8pt;
  line-height: 1.25;
  padding: 0.5mm 1mm;
}

/* ---- 印刷時 ---- */

@media print {
  /* 印刷専用ビュー以外の通常UIをすべて隠す */
  body > :not(#print-view) {
    display: none !important;
  }

  /* body直下に迷い込んだテキストノードは:not()で隠せず、1行分の
     行ボックスがページ送りをずらして余分なシートを生むため、
     フォントを0にして行ボックス自体を作らせない */
  body {
    font-size: 0;
    line-height: 0;
  }

  #print-view {
    font-size: medium;
    line-height: normal;
  }

  body.print-view-open {
    overflow: visible;
  }

  #print-view,
  #print-view.open {
    display: block !important;
    position: static !important;
    overflow: visible !important;
    background: #fff !important;
  }

  .print-toolbar {
    display: none !important;
  }

  .print-page {
    margin: 0;
    box-shadow: none;
    page-break-after: always;
    break-after: page;
  }

  .print-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  /* ダークモードのタイル反転を印刷では必ず解除する */
  .leaflet-tile-pane {
    filter: none !important;
  }

  /* 背景色（スケールバー等の白地）をそのまま印刷させる */
  .print-page * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
