body {
  font-family: "Microsoft JhengHei", Arial, sans-serif;
  background-color: #f5f5f5;
  margin: 20px;
  line-height: 1.6;
  padding-top: 90px; /* ★ 新增這行：把網頁內容整體往下推 90px，留出導覽列的空間 */
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  background: #fff;
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

h2 {
  text-align: center;
  color: #333;
  border-bottom: 2px solid #555; /* 深灰底線 */
  padding-bottom: 10px;
}

.top-section {
  background-color: #fafafa; /* 淺灰底 */
  padding: 15px;
  border-radius: 5px;
  margin-bottom: 20px;
  border: 1px solid #ddd;
}

.input-group {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.input-group label {
  width: 130px;
  font-weight: bold;
}

.input-group input {
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  flex: 1;
  min-width: 150px;
}

.calc-item {
  background-color: #fff;
  border: 1px solid #ddd;
  padding: 15px;
  margin-bottom: 15px;
  border-radius: 5px;
  position: relative;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  border-left: 4px solid #b3a2c7; /* 淡紫飾條 */
}

.calc-item h4 {
  margin-top: 0;
  margin-bottom: 10px;
  color: #555;
  font-size: 1em;
  border-bottom: 1px dashed #ccc;
  padding-bottom: 5px;
}

.calc-row {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
}

.calc-field {
  flex: 1;
  min-width: 160px;
  display: flex;
  flex-direction: column;
}

.calc-field label {
  font-size: 0.9em;
  margin-bottom: 4px;
  font-weight: bold;
}

.calc-field input,
.calc-field select {
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  height: 38px;
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

.btn-remove {
  position: absolute;
  top: 10px;
  right: 10px;
  background-color: #bbb; /* 淺灰 */
  color: white;
  border: none;
  border-radius: 8px; /* 圓角 */
  padding: 5px 10px;
  cursor: pointer;
  font-size: 0.8em;
}

.btn-remove:hover {
  background-color: #999;
}

.action-buttons {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
/*新增請求大項*/
.btn-add {
  flex: 1;
  padding: 12px;
  background-color: #d9d5e4; /* 淡紫底 */
  color: #4a3b6c; /* 深紫字 */
  border: none;
  border-radius: 8px; /* 圓角 */
  font-size: 16px;
  cursor: pointer;
}

.btn-add:hover {
  background-color: #c4bcd6;
}

.btn-calc {
  flex: 2;
  padding: 12px;
  background-color: #444; /* 深灰底 (主按鈕) */
  color: white;
  border: none;
  border-radius: 8px; /* 圓角 */
  font-size: 16px;
  cursor: pointer;
}

.btn-calc:hover {
  background-color: #222;
}

.result-area {
  margin-top: 30px;
  border-top: 2px solid #eee;
  padding-top: 20px;
  display: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 0.95em;
}

table th,
table td {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: center;
  vertical-align: middle;
}

table th {
  background-color: #f5f5f5;
  color: #333;
}

.text-right {
  text-align: right;
}

.text-left {
  text-align: left;
}

.highlight {
  color: #4a3b6c; /* 深紫色 */
  font-weight: bold;
}

.summary-box {
  background-color: #efebfb;
  border: 1px solid #eee;
  padding: 20px;
  margin-top: 20px;
  border-radius: 5px;
}

.summary-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 1.1em;
}

.summary-item.grand-total {
  border-top: 2px solid #555;
  padding-top: 10px;
  margin-top: 10px;
  font-weight: bold;
  font-size: 1.3em;
  color: #333;
}

.hint {
  font-size: 0.8em;
  color: #666;
  margin-top: 2px;
}

#loading {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.8);
  z-index: 999;
  text-align: center;
  padding-top: 200px;
  font-size: 2em;
  color: #555;
}

.group-container {
  background-color: #fdfdfd;
  border: 1px solid #eaeaea;
  border-radius: 8px;
  margin-bottom: 25px;
  padding: 15px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 2px solid #555; /* 深灰 */
}

.group-title {
  font-size: 1.2em;
  font-weight: bold;
  color: #333;
}

.btn-remove-group {
  background-color: #bbb; /* 淺灰 */
  color: white;
  border: none;
  padding: 5px 12px;
  border-radius: 8px; /* 圓角 */
  cursor: pointer;
}

.btn-remove-group:hover {
  background-color: #999;
}

.btn-add-item {
  width: 100%;
  padding: 8px;
  background-color: #e6e0f8; /* 淡紫底 */
  color: #4a3b6c; /* 深紫字 */
  border: none;
  border-radius: 8px; /* 圓角 */
  margin-top: 10px;
  cursor: pointer;
}
.btn-add-item:hover {
  background-color: #d1c7eb;
}

.btn-remove-item {
  background-color: #eee;
  color: #555;
  border: none;
  padding: 2px 8px;
  border-radius: 6px; /* 圓角 */
  font-size: 0.8em;
  cursor: pointer;
}

.btn-remove-item:hover {
  background-color: #ccc;
}

/* 結果區樣式 */
.result-group-block {
  margin-bottom: 30px;
  border: 1px solid #ccc;
  border-radius: 5px;
  overflow: hidden;
}

.result-group-header {
  background-color: #f5f5f5;
  padding: 10px;
  font-weight: bold;
  border-bottom: 1px solid #ccc;
  color: #333;
}

.result-group-footer {
  background-color: #fafafa;
  padding: 10px;
  text-align: right;
  font-size: 1.1em;
}

.date-wrapper {
  display: flex; /* 讓內部的起算日、終止日橫向排列 */
  gap: 10px; /* 兩個欄位中間的間距 */
  flex: 2; /* 讓這個區塊佔用比一般欄位多一點的寬度 (本金是 flex:1) */
  min-width: 300px; /* 防止太窄時擠在一起 */
}

/* 手機版適應：螢幕太窄時自動變回垂直排列 */
@media (max-width: 600px) {
  .date-wrapper {
    flex-wrap: wrap;
  }
}
/* --- 列印按鈕樣式 --- */
.btn-print {
  background-color: #666;
  color: white;
  border: none;
  padding: 8px 15px;
  border-radius: 8px; /* 圓角 */
  cursor: pointer;
  font-size: 1em;
  font-weight: normal; /* ★ 改為 normal (一般粗細) */
}
.btn-print:hover {
  background-color: #444;
}

/* static/calculator/style.css 新增這段 */

/* 設定標題表格撐滿寬度，並移除預設框線與間距 */
.header-table {
  width: 100%;
  border-collapse: collapse;
  border: none;
  margin: 0;
  padding: 0;
}

/* 標題表格的儲存格樣式 (繼承原本的粗體與顏色) */
.header-table td {
  border: none;
  padding: 0;
  vertical-align: middle;
}

/* 左側文字靠左，寬度佔 10% */
.header-left {
  text-align: left;
  width: 10%;
  white-space: nowrap; /* 確保「大項 #1」不會被擠到換行 */
}

/* 右側文字靠左，寬度佔 90%，並讓文字更明顯 */
.header-right {
  text-align: left;
  width: 90%;
  font-size: 1.15em;
  color: #4a3b6c; /* 深紫字 */
  font-weight: 900;
  padding-left: 15px !important;
}

/* --- 免責聲明區塊樣式 --- */
.legal-disclaimer {
  margin-top: 25px;
  padding: 15px;
  background-color: #fafafa;
  color: #666;
  border: 1px solid #eee;
  border-radius: 5px;
  font-size: 0.9em;
  line-height: 1.6;
}
/* --- ★ 列印時專用的 CSS 規則 ★ --- */
@media print {
  /* 1. 隱藏不必要的元素 */
  h2,
  .top-section,
  .hint,
  #groupsWrapper,
  .action-buttons,
  .btn-print {
    display: none !important;
  }

  /* 2. 調整背景、邊距與【整體字型大小】 */
  body {
    background-color: #fff;
    margin: 0;
    padding: 0;
    font-size: 12px !important;
  }

  .container {
    box-shadow: none;
    margin: 0;
    padding: 0;
    max-width: 100%;
    border: none;
  }

  /* 3. 調整表格，讓畫面更緊湊 */
  table {
    page-break-inside: auto;
    font-size: 11px !important;
  }

  table th,
  table td {
    padding: 4px 6px !important;
  }

  tr {
    page-break-inside: avoid;
    page-break-after: auto;
  }

  /* 縮小標題與結尾小計的字型與間距 */
  h3 {
    font-size: 16px !important;
    margin-bottom: 10px !important;
  }

  .result-group-footer {
    font-size: 12px !important;
    padding: 6px !important;
  }

  .summary-box {
    padding: 10px !important;
    margin-top: 10px !important;
  }

  .summary-item {
    font-size: 12px !important;
    margin-bottom: 4px !important;
  }

  .summary-item.grand-total,
  #globalFinalExeFee {
    font-size: 14px !important;
  }

  /* 4. 確保強制列印出背景色 */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .legal-disclaimer {
    margin-top: 15px !important;
    padding: 8px !important;
    font-size: 11px !important;
  }
}

/* 銀行專區專屬按鈕 - 最終版：比例對齊、無粗體 */
.btn-bank-action {
  /* 不設定 font-size，自動繼承網頁預設大小 */
  font-weight: normal;
  /* 這裡的 8px 是上下間距，確保高度與原本的按鈕一致 */
  padding: 8px 16px;
  background-color: #f0ebf5;
  color: #4a3b6c;
  border: 1px solid #d1c7eb;
  border-radius: 8px;
  cursor: pointer;
  line-height: 1.2; /* 確保行高穩定，不撐開框框 */
  transition: all 0.2s ease;
  margin-right: 8px;
  vertical-align: middle; /* 確保跟前面的文字在同一水平線上 */
}

.btn-bank-action:hover {
  background-color: #e2d6ed;
  border-color: #b595cd;
}

.btn-bank-action:active {
  background-color: #b595cd;
  color: white;
  transform: scale(0.95);
}

/* --- ★ 列印時專用的 CSS 規則 ★ --- */
@media print {
  /* 1. 隱藏不必要的元素 (導覽列、標題、所有輸入題型、按鈕、說明) */
  nav,
  #navbar,
  h2,
  .top-section,
  .hint,
  #groupsWrapper,
  .action-buttons,
  .btn-print,
  .btn-snapshot, /* ★ 新增這行：讓截圖分享按鈕在列印時隱藏 */
  .calc-item,
  .btn-calculate,
  #q4_calculator_section h4 {
    display: none !important;
  }

  /* 2. 調整背景、邊距與【整體字型大小】 */
  body {
    background-color: #fff !important;
    margin: 0 !important;
    padding: 0 !important; /* 消除原本給導覽列留的 90px 空白 */
    font-size: 12px !important;
  }

  .container {
    box-shadow: none !important;
    margin: 0 !important;
    padding: 0 !important;
    max-width: 100% !important;
    border: none !important;
  }

  /* 去除附屬計算器外框，讓列印畫面完全融入白紙 */
  #q4_calculator_section {
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* 3. 調整表格，讓畫面更緊湊 */
  table {
    page-break-inside: auto;
    font-size: 11px !important;
  }

  table th,
  table td {
    padding: 4px 6px !important;
  }

  tr {
    page-break-inside: avoid;
    page-break-after: auto;
  }

  /* 縮小標題與結尾小計的字型與間距 */
  h3 {
    font-size: 16px !important;
    margin-bottom: 10px !important;
  }

  .result-group-footer {
    font-size: 12px !important;
    padding: 6px !important;
  }

  .summary-box {
    padding: 10px !important;
    margin-top: 10px !important;
  }

  .summary-item {
    font-size: 12px !important;
    margin-bottom: 4px !important;
  }

  .summary-item.grand-total,
  #globalFinalExeFee,
  #result_fee_text {
    font-size: 14px !important;
  }

  /* 4. 確保強制列印出背景色與精美框線 */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .legal-disclaimer {
    margin-top: 15px !important;
    padding: 8px !important;
    font-size: 11px !important;
  }
}
/* ==========================================
   彈出式說明視窗 (Modal) 樣式
   ========================================== */
.custom-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5); /* 半透明黑背景 */
    display: none; /* 預設隱藏 */
    justify-content: center;
    align-items: center;
    z-index: 2000; /* 確保在最上層，蓋過導覽列 */
    opacity: 0;
    animation: fadeIn 0.2s forwards;
}

.custom-modal-overlay[style*="display: flex"] {
    opacity: 1;
}

.custom-modal-content {
    background-color: #fff;
    padding: 25px;
    border-radius: 10px;
    width: 90%;
    max-width: 500px; /* 限制最大寬度 */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    transform: translateY(-20px);
    animation: slideDown 0.3s forwards;
    position: relative;
}

@keyframes fadeIn {
    to { opacity: 1; }
}

@keyframes slideDown {
    to { transform: translateY(0); }
}
/* ==========================================
   📱 手機版 (Mobile) 響應式排版優化
   ========================================== */
@media (max-width: 768px) {
  /* 1. 調整整體內距，讓手機螢幕兩側不會太擠 */
  body { margin: 10px; padding-top: 70px; }
  .container { padding: 15px; }

  /* 2. 輸入框與標題：從「左右並排」改為「上下排列」 */
  .input-group { flex-direction: column; align-items: flex-start; }
  .input-group label { width: 100%; margin-bottom: 5px; }
  .input-group input, .input-group select { width: 100%; min-width: 100%; }

  /* 3. 頂部選項區塊滿版 */
  .top-section { flex-direction: column !important; align-items: stretch !important; gap: 10px !important; }
  
  /* 4. 按鈕自動滿版、好點擊 */
  .action-buttons { flex-direction: column; }
  .btn-add, .btn-calc { width: 100%; margin-bottom: 10px; margin-left: 0 !important; }
  
  /* 5. 銀行快速新增按鈕：變成一列一顆，不會超出螢幕 */
  .bank-section { display: flex; flex-direction: column; gap: 8px; }
  .btn-bank-action { width: 100%; margin: 0; text-align: center; }

  /* 6. ★ 核心修復：計算結果表格 (讓表格可以左右滑動，保護版面不破裂) */
  .result-group-block {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* 讓 iPhone 滑動更順暢 */
  }
  table { min-width: 650px; /* 強制維持寬度，讓它保有排版被滑動 */ }

  /* 7. 選擇題選項 (單選/複選) 變成上下排列，加大點擊範圍 */
  .radio-group { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
  .radio-group label { margin-right: 0; padding: 10px; background: #f9f9f9; border-radius: 8px; border: 1px solid #eee; }

  /* 8. 結算清單：讓金額靠右對齊 */
  .summary-item { flex-direction: column; align-items: flex-start; gap: 5px; }
  .summary-item span:last-child { align-self: flex-end; font-size: 1.1em; }
}
