* {
  box-sizing: border-box;
}

/* 有設 display 的元素也要能用 hidden 屬性藏起來 */
[hidden] {
  display: none !important;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: #F5F5F5;
  margin: 0;
  padding: 16px;
  color: #333;
}

.container {
  max-width: 480px;
  margin: 0 auto;
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

header h1 {
  font-size: 20px;
  margin: 0 0 4px;
}

#producerLine {
  color: #666;
  font-size: 14px;
  margin: 0 0 16px;
}

.field {
  margin-bottom: 18px;
}

label {
  display: block;
  font-weight: bold;
  font-size: 14px;
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid #DDD;
  border-radius: 8px;
  font-size: 15px;
}

.product-block {
  border: 1px solid #C8E6C9;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 14px;
  background: #F1F8E9;
}

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

.product-title {
  font-weight: bold;
  font-size: 15px;
  color: #1B5E20;
}

.spec-title {
  font-weight: bold;
  font-size: 13px;
  color: #2E7D32;
}

.spec-row {
  border: 1px solid #E0E0E0;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
  background: #FFFFFF;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: start;
}

.sub-field {
  margin-bottom: 8px;
}

.sub-field label {
  font-weight: normal;
  font-size: 12px;
  color: #666;
  margin-bottom: 3px;
}

.sub-field input,
.sub-field textarea {
  font-size: 15px;
}


input:disabled {
  background: #EEE;
  color: #AAA;
}

.remove-product-btn,
.remove-spec-btn {
  background: #FBE9E7;
  color: #C62828;
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}

.add-spec-btn {
  margin-top: 0;
  font-size: 14px;
  padding: 8px;
}

/* 重量明細數字鍵盤 */
.numpad {
  margin-top: 6px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
}

.numpad-btn {
  padding: 10px 0;
  font-size: 15px;
  color: #1565C0;
  background: #FFFFFF;
  border: 1px solid #C8E6C9;
  border-radius: 6px;
  cursor: pointer;
}

.numpad-btn:active {
  background: #E8F5E9;
}

.numpad-ctrl {
  grid-column: span 3;
  background: #F5F5F5;
  font-size: 13px;
  color: #C62828;
}

.secondary-btn {
  width: 100%;
  padding: 10px;
  background: #E8F5E9;
  color: #2E7D32;
  border: none;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  margin-top: 4px;
}

.primary-btn {
  width: 100%;
  padding: 14px;
  background: #2E7D32;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
}

.primary-btn:disabled {
  background: #A5D6A7;
}

/* 送出 / 預覽按鈕並排 */
.form-actions {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.form-actions .secondary-btn {
  width: auto;
  flex: 0 0 30%;
  margin-top: 0;
}

.form-actions .primary-btn {
  flex: 1;
}

.form-actions .clear-btn {
  flex: 0 0 auto;
  padding: 0 14px;
  background: #F5F5F5;
  color: #555;
  border: 1px solid #DDD;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
}

/* 出貨預覽面板 */
.preview-panel {
  border: 1px solid #C8E6C9;
  border-radius: 10px;
  background: #FFFFFF;
  padding: 12px;
  margin-bottom: 12px;
}

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

.preview-close {
  background: #EEE;
  border: none;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 13px;
  cursor: pointer;
}

.preview-scroll {
  overflow-x: auto;
}

.preview-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  white-space: nowrap;
}

.preview-table th,
.preview-table td {
  border: 1px solid #E0E0E0;
  padding: 6px 8px;
  text-align: left;
}

.preview-table thead th {
  background: #F1F8E9;
  color: #1B5E20;
}

.preview-table td.num {
  text-align: right;
}

/* 品名、等級：寬度剛好放得下內容，多的空間留給後面的欄位，單價才看得到 */
.preview-table .fit {
  width: 1%;
}

/* 重量明細可換行、列高自動撐開 */
.preview-table th.detail,
.preview-table td.detail {
  white-space: normal;
  word-break: break-word;
  min-width: 120px;
  max-width: 240px;
}

.preview-table tfoot td {
  background: #FAFAFA;
  font-weight: bold;
}

#targetsContainer label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: normal;
  padding: 8px 0;
  border-bottom: 1px solid #F0F0F0;
}

#targetsContainer input[type="checkbox"] {
  width: auto;
}

.hint {
  color: #999;
  font-size: 12px;
  margin: 6px 0 0;
}

#statusMsg {
  text-align: center;
  font-size: 14px;
  min-height: 20px;
  white-space: pre-line; /* 推播失敗時逐行列出每個對象的原因 */
}

#statusMsg.success {
  color: #2E7D32;
}

#statusMsg.error {
  color: #C62828;
}

/* ---------- 首頁功能選單 ---------- */
.home-menu {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.menu-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 16px;
  border: 1px solid #C8E6C9;
  border-radius: 12px;
  background: #F1F8E9;
  text-decoration: none;
  color: inherit;
}

.menu-card:active {
  background: #E8F5E9;
}

.menu-icon {
  font-size: 28px;
  line-height: 1;
}

.menu-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.menu-title {
  font-size: 17px;
  font-weight: bold;
  color: #1B5E20;
}

.menu-desc {
  font-size: 13px;
  color: #777;
}

/* 回首頁連結 */
.back-link {
  display: inline-block;
  font-size: 13px;
  color: #2E7D32;
  text-decoration: none;
  margin-bottom: 8px;
}

/* ---------- 統計頁 ---------- */
.range-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.chip {
  padding: 6px 14px;
  border: 1px solid #C8E6C9;
  border-radius: 999px;
  background: #F1F8E9;
  color: #2E7D32;
  font-size: 13px;
  cursor: pointer;
}

/* 統計頁「查詢」：與期間快捷同一列、同尺寸 */
.query-chip {
  padding: 6px 18px;
  border: 1px solid #2E7D32;
  border-radius: 999px;
  background: #2E7D32;
  color: #fff;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
}

/* 統計頁：查詢列與結果之間不留白（狀態訊息沒內容時不佔高度） */
.stats-page .field.period {
  margin-bottom: 0;
}
.stats-page #statusMsg {
  min-height: 0;
  margin: 10px 0 0;
}
.stats-page #statusMsg:empty {
  display: none;
}
/* 貨品清單頁：沒有訊息時不佔高度，篩選列下面直接接清單 */
.products-page #statusMsg {
  min-height: 0;
  margin: 0 0 8px;
}
.products-page #statusMsg:empty {
  display: none;
}
.stats-page .summary-cards {
  margin-top: 12px;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 16px 0;
}

.summary-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  border: 1px solid #E0E0E0;
  border-radius: 10px;
  background: #FAFAFA;
}

.card-label {
  font-size: 12px;
  color: #999;
}

.card-value {
  font-size: 17px;
  font-weight: bold;
  color: #1B5E20;
  overflow-wrap: anywhere; /* 多種重量單位時在卡片內換行 */
}

.section-title {
  font-size: 15px;
  color: #1B5E20;
  margin: 20px 0 8px;
}

.stat-block {
  border: 1px solid #C8E6C9;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 12px;
  background: #FFFFFF;
}

.stat-block-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px;
  margin-bottom: 8px;
}

.stat-name {
  font-weight: bold;
  font-size: 15px;
  color: #1B5E20;
}

.stat-sum {
  font-size: 12px;
  color: #666;
}

.stat-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

.stat-table th,
.stat-table td {
  border: 1px solid #E0E0E0;
  padding: 6px 8px;
  text-align: left;
}

.stat-table thead th {
  background: #F1F8E9;
  color: #1B5E20;
}

.stat-table .num {
  text-align: right;
}

/* ---------- 出貨資料登錄（手機精簡版面） ----------
   手機畫面小、輸入時鍵盤又佔掉將近一半，能併在同一列的欄位都併成一列 */
body.entry {
  padding: 6px;
}

.entry .container {
  padding: 10px;
}

.entry input,
.entry select,
.entry textarea {
  padding: 8px;
}

.entry .field {
  margin-bottom: 12px;
}

/* 回首頁 / 標題 / 生產者 同一列 */
.entry-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  margin-bottom: 10px;
}

.entry-head .back-link {
  margin-bottom: 0;
}

.entry-head h1 {
  font-size: 17px;
  margin: 0;
}

.entry-head #producerLine {
  margin: 0;
  font-size: 13px;
}

/* 標籤與輸入框同一列（出貨日期 [日期]） */
.inline-field {
  display: flex;
  align-items: center;
  gap: 10px;
}

.inline-field > label {
  margin: 0;
  white-space: nowrap;
}

.inline-field > input,
.inline-field > select {
  flex: 1;
  min-width: 0;
}

.entry .product-block {
  padding: 8px;
  margin-bottom: 10px;
}

.entry .product-head,
.entry .spec-head {
  margin-bottom: 6px;
}

.entry .remove-product-btn,
.entry .remove-spec-btn {
  padding: 6px 8px;
  white-space: nowrap;
}

/* 品名 / 重量單位 / 計重方式 同一列 */
.name-row {
  display: flex;
  align-items: stretch;
  gap: 6px;
  margin-bottom: 8px;
}

.name-row .product-name {
  flex: 1;
  min-width: 0;
}

.name-row .weight-unit {
  flex: 0 0 58px;
  padding: 8px 2px;
}

/* 計重方式：單重 / 明細 / 整籃；明細、整籃時亮綠色 */
.name-row .wmode {
  flex: 0 0 62px;
  padding: 8px 2px;
}

.name-row .wmode.active {
  border-color: #2E7D32;
  background: #E8F5E9;
  color: #1B5E20;
}

/* 數字鍵盤 顯示 / 隱藏 小按鈕：亮綠色＝目前顯示中 */
.numpad-toggle {
  flex: 0 0 34px;
  padding: 0;
  border: 1px solid #DDD;
  border-radius: 8px;
  background: #F5F5F5;
  font-size: 16px;
  cursor: pointer;
  opacity: 0.6;
}

.numpad-toggle.active {
  border-color: #2E7D32;
  background: #E8F5E9;
  opacity: 1;
}

/* 重量明細模式：備註移到數字鍵盤下方、小計上方 */
.spec-row.detail-mode {
  display: flex;
  flex-direction: column;
}

.spec-row.detail-mode .note-line {
  order: 1;
  margin: 6px 0 0;
}

.entry .spec-row {
  padding: 8px;
  margin-bottom: 8px;
}

/* 規格列：一列放多個欄位 */
.spec-line {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

/* 等級 / 件數 / 單重 / 尾數 / 單價 同一列：欄位名稱縮小放在框內上方 */
.cell {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin: 0;
  padding: 2px 4px 0;
  border: 1px solid #DDD;
  border-radius: 8px;
  background: #FFFFFF;
  font-weight: normal;
}

.cell.c-spec {
  flex-grow: 1.2;
}

.cell > span {
  font-size: 11px;
  line-height: 14px;
  color: #888;
  white-space: nowrap;
  overflow: hidden;
}

.cell > .spec-title {
  font-size: 11px;
  color: #2E7D32;
}

.entry .cell input {
  width: 100%;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 0 0 5px;
  font-size: 14px;
}

/* 數字欄位不顯示上下箭頭，窄欄位才放得下 3~4 位數 */
.cell input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.cell input[type="number"]::-webkit-inner-spin-button,
.cell input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* 輸入中：框內的輸入欄不畫瀏覽器預設的焦點框(會壓到上方的欄位名稱)，
   改成整個格子的外框變綠 */
.cell input:focus,
.ifield input:focus {
  outline: none;
}

.cell:focus-within,
.ifield:focus-within {
  border-color: #2E7D32;
  box-shadow: 0 0 0 1px #2E7D32;
}

/* 自動計算的欄位(重量明細加總)：唯讀，灰底 */
.cell:has(input[readonly]) {
  background: #F5F5F5;
}

.cell input[readonly] {
  color: #1B5E20;
}

.entry .cell.wmode-detail-cell input {
  font-size: 13px;
}

/* 重量明細加總（例：1,436.5） */
.cell.wmode-detail-cell {
  flex-grow: 1.5;
}

.cell:has(input:disabled) {
  background: #EEE;
}

.cell input:disabled {
  color: #555;
}

.spec-cells {
  align-items: stretch;
  gap: 3px;
}

/* 欄位名稱放在框內左側，不另佔一列 */
.ifield {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 0 0 0 8px;
  border: 1px solid #DDD;
  border-radius: 8px;
  background: #FFFFFF;
  font-weight: normal;
  min-width: 0;
}

.ifield > span {
  font-size: 12px;
  color: #888;
  white-space: nowrap;
}

.entry .ifield input {
  flex: 1;
  width: 100%;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 8px 6px 8px 0;
}

.ifield:has(input:disabled) {
  background: #EEE;
}

.ifield input:disabled {
  color: #555;
}

.f-note {
  flex: 1 1 60%;
}

/* 重量明細格子：上緣欄號 1~15、左緣每列起始序號 */
.weights-grid table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  background: #FFFFFF;
  font-variant-numeric: tabular-nums;
}

.weights-grid th,
.weights-grid td {
  border: 1px solid #E0E0E0;
  padding: 0;
  height: 24px;
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
}

.weights-grid th {
  background: #F1F8E9;
  color: #888;
  font-weight: normal;
  font-size: 9px;
  height: 16px;
}

.weights-grid th.corner,
.weights-grid th.rowhead {
  width: 22px;
}

.weights-grid th.rowhead {
  font-size: 9px;
  height: 24px;
}

.weights-grid td {
  font-size: 12px;
  color: #333;
  letter-spacing: -0.3px;
}

.weights-grid td.long {
  font-size: 10px;
}

.weights-grid td.xlong {
  font-size: 8px;
}

/* 整籃：一列 5 格，格子寬，上千斤的數字用正常字級 */
.bulk-mode .weights-grid td {
  height: 30px;
  font-size: 15px;
  letter-spacing: 0;
}

.bulk-mode .weights-grid th {
  font-size: 11px;
}

/* 最後輸入的那一格 */
.weights-grid td.last {
  background: #FFF59D;
}

/* 格子裡的輸入框：看起來跟一般格子一樣，點了就能直接改 */
.entry .weights-grid .wcell {
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-align: center;
  outline: none;
}

/* 正在編輯的格子 */
.weights-grid td:focus-within {
  background: #E3F2FD;
  box-shadow: inset 0 0 0 2px #1565C0;
}

/* 1~60 數字鍵盤：一列 10 個，高度縮成一半 */
.entry .numpad {
  grid-template-columns: repeat(10, 1fr);
  gap: 3px;
}

.entry .numpad-btn {
  padding: 7px 0;
  font-size: 14px;
}

.entry .numpad-ctrl {
  grid-column: span 5;
}


/* 品名小計(靠左) + 新增規格 同一列 */
.block-foot {
  display: flex;
  align-items: center;
  gap: 8px;
}

.block-subtotal {
  flex: 1;
  margin: 0;
  font-size: 13px;
  font-weight: bold;
  color: #2E7D32;
  text-align: left;
}

.block-foot .add-spec-btn {
  flex: 0 0 auto;
  width: auto;
  margin: 0;
  padding: 8px 12px;
}

/* 取不到 LINE 身分時，原因顯示在生產者那一行下方 */
.auth-error {
  color: #C62828;
}

.auth-error-msg {
  flex-basis: 100%;
  margin: 2px 0 0;
  font-size: 12px;
  color: #C62828;
}

/* ---------- 自訂確認視窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.4);
}

.modal-box {
  width: 100%;
  max-width: 360px;
  padding: 20px;
  border-radius: 12px;
  background: #FFFFFF;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

/* 訊息字跟確定按鈕一樣大 */
.modal-msg {
  margin: 0 0 20px;
  font-size: 16px;
  line-height: 1.5;
  color: #333;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-actions button {
  padding: 10px 22px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
}

.modal-cancel {
  border: 1px solid #DDD;
  background: #F5F5F5;
  color: #555;
}

.modal-ok {
  border: none;
  background: #2E7D32;
  color: #FFFFFF;
}

/* ---------- 出貨登錄：當季貨品提示 ---------- */
.fav-hint {
  margin: 6px 0 0;
}

.fav-hint a {
  color: #2E7D32;
  white-space: nowrap;
}

/* ---------- 貨品清單頁 ---------- */
.add-product-form {
  display: flex;
  gap: 6px;
  margin: 10px 0;
}

.add-product-form input {
  flex: 1;
  min-width: 0;
}

.list-filter {
  margin: 0 0 8px;
}

.chip.active {
  background: #2E7D32;
  border-color: #2E7D32;
  color: #FFFFFF;
}

.product-card {
  border: 1px solid #E0E0E0;
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 8px;
  background: #FFFFFF;
}

.product-card.on {
  border-color: #C8E6C9;
  background: #F1F8E9;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 品名大約 5 個中文字以內，不用撐滿：斤、計重方式緊接在品名右邊，刪除靠右 */
.card-name {
  flex: 0 1 auto;
  min-width: 0;
  font-size: 16px;
  overflow-wrap: anywhere;
}

.card-wunit,
.card-wmode {
  width: auto;
  padding: 4px 6px;
  font-size: 13px;
}

.card-del {
  margin-left: auto;
  padding: 4px 10px;
  border: 1px solid #EF9A9A;
  border-radius: 6px;
  background: #FFFFFF;
  color: #C62828;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}

.star-btn {
  padding: 0 2px;
  border: none;
  background: none;
  color: #9E9E9E;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.card-opts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.card-specs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}

/* 等級一列：☆ 等級 [單重] ▲ ▼ × */
.spec-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border: 1px solid #E0E0E0;
  border-radius: 8px;
  background: #FFFFFF;
  font-size: 14px;
}

.spec-item.on {
  border-color: #FFB300;
  background: #FFF8E1;
}

.spec-item .star-btn {
  font-size: 18px;
}

.spec-name {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.uw-field {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  font-size: 13px;
  color: #666;
  white-space: nowrap;
}

.uw-input {
  width: 64px;
  padding: 4px 6px;
  font-size: 14px;
}

.order-btn {
  padding: 2px 8px;
  border: 1px solid #C8E6C9;
  border-radius: 6px;
  background: #F1F8E9;
  color: #2E7D32;
  font-size: 12px;
  cursor: pointer;
}

.order-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.spec-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px 2px 6px;
  border: 1px solid #E0E0E0;
  border-radius: 999px;
  background: #FFFFFF;
  font-size: 14px;
}

.spec-chip.on {
  border-color: #FFB300;
  background: #FFF8E1;
}

.spec-chip .star-btn {
  font-size: 17px;
}

.chip-del {
  padding: 0 6px;
  border: none;
  background: none;
  color: #9E9E9E;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

/* 首頁：出貨資料登錄卡片 + 右邊選新增方式(貨品清單 / 空白單) */
.menu-row {
  display: flex;
  gap: 8px;
}

.menu-row .menu-card {
  flex: 1;
  min-width: 0;
}

.entry-modes {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.entry-mode {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  border: 1px solid #C8E6C9;
  border-radius: 10px;
  background: #FFFFFF;
  color: #2E7D32;
  font-size: 14px;
  font-weight: bold;
  text-decoration: none;
  white-space: nowrap;
}

.entry-mode.active {
  background: #2E7D32;
  border-color: #2E7D32;
  color: #FFFFFF;
}
