/* =========================================
   1. 全域 CSS 變數 (CSS Variables)
   ========================================= */
:root {
  --color-bg: #F7F5F0;          /* 柔和米白色 */
  --color-card-bg: #FFFFFF;     /* 白色卡片底色 */
  --color-primary: #DBCFB0;     /* 燕麥色主色調 */
  --color-border: #EAEAEA;      /* 淺灰邊框 */
  --color-focus: #AF6A31;       /* 擷取自圖片的活潑橘褐色 */
  --color-text: #4A3B32;        /* 深褐色文字 */
  --color-text-light: #7A6A5A;  /* 次要文字色 */

  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --radius-md: 8px;
}

/* =========================================
   2. 基礎元素重置與全域設定 (Reset & Base)
   ========================================= */
*, *::before, *::after { box-sizing: border-box; }
body {
  font-family: system-ui, -apple-system, sans-serif;
  background-color: var(--color-bg);
  color: var(--color-text);
  max-width: 800px;
  margin: 0 auto;
  padding: var(--spacing-md);
  line-height: 1.6;
}
h1, h2, h3, h4, h5, h6 { color: var(--color-text); }
header {
  text-align: center;
  margin-bottom: var(--spacing-lg);
  padding: var(--spacing-lg) 0;
}
header p {
  color: var(--color-text-light);
}

/* =========================================
   3. 輸入元件與表單 (Form Elements)
   ========================================= */
.form-group { margin-bottom: var(--spacing-md); }
.group-label {
  display: block;
  font-weight: 700;
  color: #555;
  font-size: 0.85em;
  margin-bottom: 8px;
  text-align: center; /* 標題文字置中 */
  white-space: nowrap !important; /* 強制不換行 */
}

input[type="number"],
input[type="time"],
input[type="datetime-local"],
select {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 1.1rem;
  background-color: #FFFFFF;
  color: var(--color-text);
  font-family: inherit;
  text-align: center; /* 圖片皆為置中對齊 */
  font-weight: 500;
  transition: all 0.2s ease;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--color-focus);
  box-shadow: 0 0 0 2px rgba(175, 106, 49, 0.1);
}
input:disabled {
  opacity: 0.6;
  background-color: #F9F9F9;
  cursor: not-allowed;
  border-color: #F0F0F0;
}

.row {
  display: flex;
  gap: var(--spacing-md);
  flex-wrap: wrap; /* RWD: 空間不夠時自動換行 */
}
.row > div {
  flex: 1;
  min-width: 90px;
}
.hidden { display: none !important; }

/* =========================================
   4. 視覺翻新：計算模式切換 (Segmented Control)
   ========================================= */
.segmented-control {
  display: flex;
  background-color: #F4F4F4;
  border-radius: 8px;
  padding: 4px;
}
.segmented-control input[type="radio"] { display: none; }
.segment-btn {
  flex: 1;
  text-align: center;
  padding: 8px 2px;
  border-radius: 6px;
  cursor: pointer;
  color: #999;
  font-weight: 600;
  font-size: 0.82em;
  transition: all 0.2s ease;
  margin: 0;
  word-break: keep-all; /* 不在中文字間斷行 */
  overflow-wrap: break-word;
}
.segmented-control input[type="radio"]:checked + .segment-btn {
  background-color: #FFFFFF;
  color: var(--color-focus);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  font-weight: 700;
}

/* =========================================
   5. 區塊屬性專屬排版 (Block Layout)
   ========================================= */
.calc-section {
  background-color: var(--color-card-bg);
  padding: var(--spacing-lg);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.03);
  margin-bottom: var(--spacing-lg);
}
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 0;
  padding-bottom: var(--spacing-sm);
  margin-bottom: var(--spacing-md);
  border-bottom: 1px solid #F0F0F0;
  font-size: 1.25em;
}

.calc-grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--spacing-lg);
  align-items: start;
}

.calc-grid-3col {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--spacing-md);
}

.calc-grid-4col {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-lg);
}

/* 提示與公式資訊相關 */
.formula-info-container {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-lg);
  font-size: 0.9em;
}

.formula-text {
  flex: 1;
  color: #777;
  margin: 0;
  line-height: 1.4;
}

.advice-box {
  flex: 1;
  background-color: #FFF9E6; /* 淺黃色背景 */
  color: #856404;            /* 褐色文字 */
  padding: 12px;
  border-radius: var(--radius-md);
  line-height: 1.5;
  border-left: 4px solid #FFEEBA;
}

.result-highlight-box {
  background-color: #FFF9E6;
  text-align: center;
  padding: 16px;
  border-radius: var(--radius-md);
  font-size: 1.25em;
  font-weight: 700;
  color: #856404;
  margin-top: var(--spacing-md);
}

.result-highlight-box span {
  font-size: 1.5em;
  font-weight: 800;
  margin: 0 4px;
  color: #AF5E22; /* 符合設計圖的土橘色 / 磚紅色 */
}

.section-divider {
  border: 0;
  border-top: 1px solid #F0F0F0;
  margin: var(--spacing-lg) 0;
}

/* 調合水溫專屬排版 */
#req-total-water {
  border: 2px solid #EED792; /* 明顯的暖黃色邊框 */
  background-color: #FEFDF2; /* 淺黃色背景 */
  font-weight: 700;
  font-size: 1.2rem;
}
#req-total-water:focus {
  border-color: #DAB459;
  box-shadow: 0 0 0 2px rgba(238, 215, 146, 0.3);
}

.blending-layout {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: var(--spacing-lg);
  align-items: start;
}

.blending-card {
  background-color: #FFFFFF;
  border: 1px solid #F0F0F0;
  border-radius: 12px;
  padding: var(--spacing-md);
  box-shadow: 0 2px 8px rgba(0,0,0,0.02);
}

.blending-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #F8F8F8;
}

.blending-row:last-of-type { border-bottom: none; }

.blending-row .label {
  color: var(--color-text-light);
  font-size: 0.95em;
}

.blending-row .value {
  font-size: 1.4em;
  font-weight: 800;
}

.hot-value { color: #D9534F; } /* 紅色 */
.cold-value { color: #337AB7; } /* 藍色 */

.blending-footer {
  text-align: right;
  color: #AAA;
  font-size: 0.8em;
  margin-top: 12px;
  font-style: italic;
}

.required {
  color: #D9534F;
  font-size: 0.8em;
  margin-left: 4px;
}

.error-text {
  color: #D9534F;
  background-color: #F8D7DA;
  padding: 12px;
  border-radius: var(--radius-md);
  margin-top: 12px;
  font-size: 0.9em;
  text-align: center;
}

.full-width { grid-column: span 3; }

/* 運算結果區塊 */
.output-box {
  background-color: #FAFAFA;
  border: 1px solid #EAEAEA;
  border-radius: 12px;
  padding: var(--spacing-sm) var(--spacing-md);
}

.recipe-table {
  width: 100%;
  border-collapse: collapse;
}
.recipe-table th, 
.recipe-table td {
  padding: 12px 6px;
  border-bottom: 1px solid #EFEFEF; /* 分隔列線 */
}
.recipe-table th {
  color: var(--color-text-light);
  font-weight: 700;
  font-size: 0.9em;
}
.recipe-table td { font-size: 0.95em; }

.recipe-table tr.total-row {
  background-color: #FDF6EE;
  color: #9B5526;
}
.recipe-table tr.total-row td {
  font-weight: 700;
  font-size: 1.05em;
  border-bottom: none;
}
/* 讓總麵團重的顏色背景更平滑接合邊緣 */
.recipe-table tr.total-row td:first-child { border-radius: 6px 0 0 6px; }
.recipe-table tr.total-row td:last-child { border-radius: 0 6px 6px 0; }

/* =========================================
   6. 區塊三：排程設定與佈局 (Schedule Settings)
   ========================================= */
.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--spacing-md);
  border-bottom: 1px solid #F0F0F0;
  padding-bottom: var(--spacing-sm);
}
.section-header-row .section-title {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}
.inherited-info {
  font-size: 0.9em;
  color: #A0A0A0;
}

.sleep-container {
  background-color: #F2F6FC;
  border-radius: var(--radius-md);
  padding: var(--spacing-md);
  margin-bottom: var(--spacing-lg);
}

.sleep-title {
  margin-top: 0;
  margin-bottom: var(--spacing-md);
  color: #335588;
  font-size: 1.1em;
}

.input-with-icon-right {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-icon-right input {
  padding-right: 36px;
}

.icon-right {
  position: absolute;
  right: 12px;
  pointer-events: none;
}

.custom-ratio-box {
  background-color: #FFF9E6;
  border: 1px solid #FFEEBA;
  border-radius: var(--radius-md);
  padding: var(--spacing-sm) var(--spacing-md);
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.custom-ratio-box label {
  font-size: 0.9em;
  color: var(--color-text-light);
  white-space: nowrap;
}

.custom-ratio-box input {
  flex: 1;
  min-width: 0; /* 防止 input 撐破容器 */
}

.input-with-icon {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-icon input {
  padding-left: 36px;
}

.input-icon {
  position: absolute;
  left: 12px;
  pointer-events: none;
}

.readonly-input {
  background-color: #F2F4F7 !important;
  color: #555 !important;
  cursor: default;
  border-color: #DDD !important;
}

.slider-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.vigor-slider {
  flex: 1;
  appearance: none;
  -webkit-appearance: none;
  height: 6px;
  background-color: #DDE5F4;
  border-radius: 4px;
  outline: none;
  padding: 0 !important;
  border: none !important;
}

.vigor-slider::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #3B82F6;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.vigor-info-box {
  background-color: #FFF6EC;
  border-left-color: #FFDFB3;
  color: #8C6A3C;
}

/* =========================================
   7. 區塊四：製作時程表 (Timeline Display)
   ========================================= */

.timeline-divider {
  border-bottom: 2px dashed #EAEAEA;
  margin: var(--spacing-sm) 0 var(--spacing-lg) 0;
}

.validation-container {
  padding: 6px 12px;
  border-radius: 20px;
  font-weight: bold;
  font-size: 0.9em;
}
.validation-container.success {
  background-color: #E5F3EB;
  color: #2E8055;
}
.validation-container.warning {
  background-color: #F8ECEE;
  color: #D9534F;
}

.timeline-day-header {
  background-color: #EAEAEA;
  color: #555;
  font-size: 0.8em;
  font-weight: bold;
  padding: 2px 8px;
  border-radius: 4px;
  display: inline-block;
  margin: 16px 0 8px 32px;
}

.timeline-node {
  display: flex;
  margin-bottom: 0;
}

.timeline-icon-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-right: 16px;
  width: 32px;
}

.timeline-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid #CCC;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: white;
  z-index: 2;
  font-size: 14px;
}

.timeline-icon.mix-icon {
  border-color: #EAC66F;
  border-width: 2px;
  background-color: #FCF7EE;
}

.timeline-icon.bake-icon {
  background-color: #333;
  border-color: #333;
  color: white;
}

.timeline-line {
  flex: 1;
  width: 1px;
  background-color: #DDD;
  margin: 4px 0;
  min-height: 24px;
}

.timeline-content {
  flex: 1;
  padding-bottom: 24px;
  padding-top: 4px;
}

.timeline-title {
  color: #444;
  font-size: 1.05em;
  margin-bottom: 4px;
}

.timeline-desc {
  color: #888;
  font-size: 0.9em;
}

/* =========================================
   8. 贊助卡片 & 頁尾 (Sponsorship & Footer)
   ========================================= */
.sponsorship-card {
  text-align: center;
  padding: var(--spacing-lg) var(--spacing-lg);
}

.sponsorship-icon {
  font-size: 2.5rem;
  margin-bottom: var(--spacing-sm);
  line-height: 1;
}

.sponsorship-title {
  font-size: 1.3rem;
  color: var(--color-text);
  margin: 0 0 var(--spacing-sm) 0;
  border-bottom: none;
}

.sponsorship-desc {
  color: var(--color-text-light);
  line-height: 1.8;
  max-width: 520px;
  margin: 0 auto var(--spacing-lg) auto;
  font-size: 0.95em;
  padding: 0 var(--spacing-md);
}

.qr-code-wrapper {
  display: flex;
  justify-content: center;
}

#linepay-qr {
  width: 200px;
  height: 200px;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  border: 2px dashed var(--color-primary);
}

#site-footer {
  text-align: center;
  margin-top: var(--spacing-lg);
  padding: var(--spacing-md) 0 var(--spacing-lg) 0;
  color: var(--color-text-light);
  font-size: 0.85em;
}

/* =========================================
   9. 響應式設計 (RWD) 斷點
   ========================================= */
@media (max-width: 600px) {
  /* 由 Tailwind 接管 Grid 響應式行為 */
  .formula-info-container { flex-direction: column; }
  .row { gap: var(--spacing-sm); }
  .calc-section { padding: var(--spacing-md); }

  /* 自訂比例框手機端優化 */
  .custom-ratio-box {
    flex-direction: column;
    padding: 8px;
    gap: 4px;
    align-items: center;
  }
  .custom-ratio-box label {
    margin-bottom: 2px;
  }
  .custom-ratio-box input {
    width: 100%;
    text-align: center;
    padding: 6px;
  }

  /* 就寢/起床時間：手機端單欄填滿 */
  .sleep-container > div {
    grid-template-columns: 1fr !important;
  }
  .sleep-container .input-with-icon-right {
    width: 100%;
    display: flex;
  }
  .sleep-container .input-with-icon-right input[type="time"] {
    flex: 1;
    width: 100%;
    min-width: 0;
  }

  /* 餵養比例：手機端單列垂直排列 */
  .feed-ratios-container {
    grid-template-columns: 1fr !important;
  }
}

@media print {
  body {
    background-color: white !important;
    padding: 0 !important;
    margin: 0 !important;
    color: #000 !important;
  }
  
  /* 隱藏不必要的輸入區塊與元件 */
  header, 
  #site-footer,
  #sponsorship,
  #temp-calculator, 
  #schedule-settings, 
  .calc-inputs-col,
  #btn-print-schedule,
  .section-title {
    display: none !important;
  }

  /* 保留配方名稱作為列印抬頭 */
  #recipe-calculator .section-title {
    display: block !important;
    text-align: left;
    margin-bottom: 20px;
    color: #000 !important;
  }
  
  /* 在列印時覆寫區塊四標題顯示 */
  #block-4 .section-title {
    display: block !important;
    margin-bottom: 20px;
    color: #000 !important;
  }

  /* 取消列印時的背景色與陰影，節省墨水 */
  .calc-section, 
  .result-card {
    box-shadow: none !important;
    border: none !important;
    background: transparent !important;
    padding: 0 !important;
    margin-bottom: 30px !important;
  }

  .calc-grid-2col {
    display: block !important;
  }

  .results-table th {
    background-color: #F0F0F0 !important;
    color: #000 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .timeline-section {
    page-break-inside: auto;
  }
  
  .timeline-node {
    page-break-inside: avoid;
  }
}

