/* =====================================================================
   土尾站點收付管理模組專屬樣式 (tuwei.css)
   設計哲學: /design-taste-frontend 標準 (Dark Glassmorphism & High-Density UI)
   ===================================================================== */

/* 1. 土尾主要卡片結構 (Site Card - 扇子式手風琴容器) */
.tuwei-site-card {
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  overflow: hidden;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 8px 24px -6px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.tuwei-site-card:hover {
  border-color: rgba(56, 189, 248, 0.24);
  box-shadow: 0 14px 32px -6px rgba(0, 0, 0, 0.6), 0 0 18px rgba(56, 189, 248, 0.08);
}

.tuwei-site-card.is-expanded {
  border-color: rgba(56, 189, 248, 0.32);
}

/* 站點卡片頂部標題列 (Fan Header Bar - 點擊展開/收合) */
.tuwei-card-header {
  background: rgba(17, 24, 39, 0.88);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding: 0.85rem 1.15rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.2s ease;
}

.tuwei-site-card.is-collapsed .tuwei-card-header {
  border-bottom-color: transparent;
}

.tuwei-card-header:hover {
  background: rgba(30, 41, 59, 0.92);
}

.tuwei-header-main {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-width: 0;
}

.tuwei-header-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-left: auto;
}

.tuwei-fan-toggle-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(30, 41, 59, 0.75);
  color: #38bdf8;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.tuwei-fan-toggle-btn:hover {
  background: rgba(56, 189, 248, 0.2);
  border-color: #38bdf8;
  color: #fff;
}

.tuwei-site-title {
  font-size: 1.08rem;
  font-weight: 700;
  color: #f8fafc;
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.tuwei-site-title::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 18px;
  background: linear-gradient(180deg, #38bdf8 0%, #2563eb 100%);
  border-radius: 4px;
  flex-shrink: 0;
}

/* 管編代號膠囊 (Code Badge) */
.tuwei-code-badge {
  font-family: 'Outfit', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.2);
  color: #38bdf8;
  letter-spacing: 0.02em;
}

/* 地址輔助說明 (Address Text) */
.tuwei-address-text {
  font-size: 0.82rem;
  color: #94a3b8;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

/* 2. 收/付 徽章與選擇器視覺層次規範 (Receipt & Payment Badges) */
.badge-tuwei-receipt {
  background: rgba(16, 185, 129, 0.15) !important;
  color: #34d399 !important;
  border: 1px solid rgba(16, 185, 129, 0.35) !important;
  font-weight: 700 !important;
  font-size: 0.8rem !important;
  padding: 3px 9px !important;
  border-radius: 6px !important;
  display: inline-block;
  letter-spacing: 0.05em;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.15);
}

.badge-tuwei-payment {
  background: rgba(245, 158, 11, 0.15) !important;
  color: #fbbf24 !important;
  border: 1px solid rgba(245, 158, 11, 0.35) !important;
  font-weight: 700 !important;
  font-size: 0.8rem !important;
  padding: 3px 9px !important;
  border-radius: 6px !important;
  display: inline-block;
  letter-spacing: 0.05em;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.15);
}

.tuwei-cat-select {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  text-align: center;
  text-align-last: center;
  min-width: 52px;
  outline: none;
}

.tuwei-cat-select option {
  background: #0f172a;
  color: #f8fafc;
}

/* 3. 即時結算匯總膠囊群組 (未點開時包含收幾項、付幾項與合算金額) */
.tuwei-summary-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.tuwei-summary-pill {
  font-size: 0.82rem;
  font-weight: 600;
  padding: 4px 11px;
  border-radius: 9999px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(8px);
}

.tuwei-pill-divider {
  opacity: 0.4;
  margin: 0 2px;
}

.tuwei-pill-receipt {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.28);
  color: #34d399;
}

.tuwei-pill-payment {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.28);
  color: #fbbf24;
}

/* 合計金額數值動態著色規範 (F16 & R5) */
.tuwei-total-positive {
  color: #38bdf8 !important; /* 亮天藍色 / #2563eb */
  background: rgba(56, 189, 248, 0.14) !important;
  border: 1px solid rgba(56, 189, 248, 0.35) !important;
  font-weight: 800 !important;
  text-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

.tuwei-total-negative {
  color: #f87171 !important; /* 珊瑚紅 / #dc2626 */
  background: rgba(239, 68, 68, 0.14) !important;
  border: 1px solid rgba(239, 68, 68, 0.35) !important;
  font-weight: 800 !important;
  text-shadow: 0 0 12px rgba(239, 68, 68, 0.4);
}

.tuwei-total-neutral {
  color: #94a3b8 !important;
  background: rgba(148, 163, 184, 0.08) !important;
  border: 1px solid rgba(148, 163, 184, 0.2) !important;
  font-weight: 600 !important;
}

/* 4. 收付合併資料表格 (Unified Data Table - 收收收 ➔ 付付) */
.tuwei-fan-body {
  animation: tuweiFanOpen 0.18s ease-out;
  -webkit-overflow-scrolling: touch;
}

@keyframes tuweiFanOpen {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tuwei-table {
  width: 100%;
  min-width: 960px; /* 保證手機版水平滑動時各欄寬度充裕，絕不擠壓或裁剪數字 */
  margin-bottom: 0;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.875rem;
}

.tuwei-table thead th {
  background: rgba(15, 23, 42, 0.95);
  color: #94a3b8;
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  padding: 0.65rem 0.55rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  white-space: nowrap;
}

.tuwei-table tbody tr {
  transition: background-color 0.15s ease;
}

.tuwei-row-receipt {
  background: rgba(16, 185, 129, 0.02);
}

.tuwei-row-payment {
  background: rgba(245, 158, 11, 0.02);
}

/* 收與付交界分界線 (讓「收、收、收」與「付、付」視覺分群更直覺) */
.tuwei-group-divider-row td {
  border-top: 2px dashed rgba(245, 158, 11, 0.35) !important;
}

.tuwei-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.045);
}

.tuwei-table tbody td {
  padding: 0.5rem 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  vertical-align: middle;
  color: #e2e8f0;
}

.tuwei-table tbody tr:last-child td {
  border-bottom: none;
}

/* 5. 欄位輸入框與防裁剪設定 (Inputs & Checkbox) */
input.tuwei-input::-webkit-outer-spin-button,
input.tuwei-input::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input.tuwei-input[type="number"] {
  -moz-appearance: textfield;
}

.tuwei-input {
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  color: #f8fafc;
  padding: 5px 8px;
  font-size: 0.86rem;
  width: 100%;
  min-width: 72px;
  font-variant-numeric: tabular-nums;
  transition: all 0.2s ease;
}

.tuwei-num-input {
  min-width: 84px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.tuwei-input:focus {
  background: rgba(15, 23, 42, 0.95);
  border-color: #38bdf8;
  outline: none;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.22);
}

.tuwei-calc-checkbox {
  width: 1.15rem;
  height: 1.15rem;
  cursor: pointer;
  accent-color: #38bdf8;
  margin: 0 auto;
  display: block;
}

.tuwei-est-cell {
  font-weight: 700;
  color: #f1f5f9;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  white-space: nowrap;
  padding-right: 0.75rem !important;
}

.tuwei-excluded-tag {
  color: #64748b;
  font-size: 0.78rem;
  font-weight: 500;
  background: rgba(100, 116, 139, 0.12);
  padding: 2px 6px;
  border-radius: 4px;
}

/* 6. 浮動智慧下拉索引選單 (輸入+索引模式 Popup) */
.tuwei-combo-dropdown {
  position: fixed;
  z-index: 10050;
  background: rgba(15, 23, 42, 0.97);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: 10px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.06);
  max-height: 240px;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tuwei-combo-header {
  font-size: 0.72rem;
  font-weight: 700;
  color: #38bdf8;
  background: rgba(30, 41, 59, 0.9);
  padding: 5px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  letter-spacing: 0.02em;
}

.tuwei-combo-list {
  overflow-y: auto;
  max-height: 205px;
}

.tuwei-combo-option {
  padding: 6px 11px;
  font-size: 0.85rem;
  color: #e2e8f0;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  transition: background-color 0.12s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tuwei-combo-option:last-child {
  border-bottom: none;
}

.tuwei-combo-option:hover,
.tuwei-combo-option.active {
  background: rgba(56, 189, 248, 0.22);
  color: #ffffff;
}

/* 7. 唯讀身分專屬防護與遮蔽 (tuwei_viewer Read-Only Mode) */
body.role-tuwei-viewer .admin-only-action,
body.role-tuwei-viewer .tuwei-admin-only,
.role-tuwei-viewer .admin-only-action,
.role-tuwei-viewer .tuwei-admin-only {
  display: none !important;
}

body.role-tuwei-viewer .tuwei-input,
body.role-tuwei-viewer input.tuwei-input,
body.role-tuwei-viewer select.tuwei-input {
  background: transparent !important;
  border-color: transparent !important;
  pointer-events: none !important;
  color: #f1f5f9 !important;
  box-shadow: none !important;
  padding: 4px 2px !important;
  cursor: default !important;
}

body.role-tuwei-viewer .tuwei-calc-checkbox {
  pointer-events: none !important;
  cursor: not-allowed !important;
  opacity: 0.8;
}

/* 8. 工具列與搜尋列 */
.tuwei-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.tuwei-search-box {
  position: relative;
  min-width: 260px;
  max-width: 480px;
  flex-grow: 1;
}

.tuwei-search-box i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  font-size: 0.95rem;
}

.tuwei-search-input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  color: #f8fafc;
  font-size: 0.88rem;
  transition: all 0.2s ease;
}

.tuwei-search-input:focus {
  background: rgba(15, 23, 42, 0.95);
  border-color: #38bdf8;
  outline: none;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

/* 9. 手機版響應式排版防裁剪規範 (Mobile Anti-Clipping) */
@media (max-width: 768px) {
  .tuwei-card-header {
    padding: 0.75rem 0.85rem;
    gap: 0.6rem;
  }

  .tuwei-header-right {
    width: 100%;
    margin-left: 0;
    justify-content: space-between;
  }

  .tuwei-summary-group {
    width: 100%;
    gap: 0.35rem;
  }

  .tuwei-summary-pill {
    font-size: 0.78rem;
    padding: 4px 9px;
    white-space: normal;
    line-height: 1.35;
  }

  .tuwei-site-title {
    font-size: 1rem;
  }

  .tuwei-table {
    min-width: 920px;
  }

  .tuwei-input {
    font-size: 0.86rem;
    padding: 6px 8px;
  }
}

/* =====================================================================
   10. 日光模式 (Light Theme - body.light-theme) 完整白底高質感適配
   ===================================================================== */
body.light-theme .tuwei-site-card {
  background: #ffffff !important;
  border: 1px solid #cbd5e1 !important;
  box-shadow: 0 4px 16px -2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04) !important;
}

body.light-theme .tuwei-site-card:hover {
  border-color: #93c5fd !important;
  box-shadow: 0 10px 24px -4px rgba(37, 99, 235, 0.1) !important;
}

body.light-theme .tuwei-site-card.is-expanded {
  border-color: #60a5fa !important;
}

body.light-theme .tuwei-card-header {
  background: #f8fafc !important;
  border-bottom: 1px solid #e2e8f0 !important;
}

body.light-theme .tuwei-site-card.is-collapsed .tuwei-card-header {
  border-bottom-color: transparent !important;
}

body.light-theme .tuwei-card-header:hover {
  background: #f1f5f9 !important;
}

body.light-theme .tuwei-site-title {
  color: #0f172a !important;
}

body.light-theme .tuwei-code-badge {
  background: #eff6ff !important;
  border-color: #bae6fd !important;
  color: #0284c7 !important;
}

body.light-theme .tuwei-address-text {
  color: #475569 !important;
}

body.light-theme .tuwei-fan-toggle-btn {
  background: #ffffff !important;
  border-color: #cbd5e1 !important;
  color: #0284c7 !important;
}

body.light-theme .tuwei-fan-toggle-btn:hover {
  background: #eff6ff !important;
  border-color: #38bdf8 !important;
  color: #0369a1 !important;
}

/* 日光模式收付徽章與匯總膠囊 */
body.light-theme .badge-tuwei-receipt {
  background: #d1fae5 !important;
  color: #047857 !important;
  border-color: #6ee7b7 !important;
  box-shadow: none !important;
}

body.light-theme .badge-tuwei-payment {
  background: #fef3c7 !important;
  color: #b45309 !important;
  border-color: #fcd34d !important;
  box-shadow: none !important;
}

body.light-theme .tuwei-cat-select option {
  background: #ffffff !important;
  color: #0f172a !important;
}

body.light-theme .tuwei-summary-pill {
  background: #ffffff;
  border-color: #cbd5e1;
}

body.light-theme .tuwei-pill-receipt {
  background: #ecfdf5 !important;
  border-color: #6ee7b7 !important;
  color: #047857 !important;
}

body.light-theme .tuwei-pill-payment {
  background: #fffbeb !important;
  border-color: #fcd34d !important;
  color: #b45309 !important;
}

body.light-theme .tuwei-total-positive {
  color: #2563eb !important; /* 日光模式正數鮮明藍色 */
  background: #eff6ff !important;
  border: 1px solid #93c5fd !important;
  text-shadow: none !important;
}

body.light-theme .tuwei-total-negative {
  color: #dc2626 !important; /* 日光模式負數鮮明紅色 */
  background: #fef2f2 !important;
  border: 1px solid #fca5a5 !important;
  text-shadow: none !important;
}

body.light-theme .tuwei-total-neutral {
  color: #475569 !important;
  background: #f1f5f9 !important;
  border: 1px solid #cbd5e1 !important;
}

/* 日光模式表格與列底色 */
body.light-theme .tuwei-table thead th {
  background: #f1f5f9 !important;
  color: #334155 !important;
  border-bottom: 2px solid #cbd5e1 !important;
}

body.light-theme .tuwei-table tbody td {
  color: #0f172a !important;
  border-bottom: 1px solid #e2e8f0 !important;
}

body.light-theme .tuwei-row-receipt {
  background: rgba(16, 185, 129, 0.04) !important;
}

body.light-theme .tuwei-row-payment {
  background: rgba(245, 158, 11, 0.04) !important;
}

body.light-theme .tuwei-group-divider-row td {
  border-top: 2px dashed #f59e0b !important;
}

body.light-theme .tuwei-table tbody tr:hover {
  background: #f8fafc !important;
}

/* 日光模式輸入框與文字 */
body.light-theme .tuwei-input {
  background: #ffffff !important;
  border: 1px solid #cbd5e1 !important;
  color: #0f172a !important;
}

body.light-theme .tuwei-input::placeholder {
  color: #94a3b8 !important;
}

body.light-theme .tuwei-input:focus {
  background: #ffffff !important;
  border-color: #2563eb !important;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18) !important;
}

body.light-theme.role-tuwei-viewer .tuwei-input,
body.light-theme .role-tuwei-viewer .tuwei-input {
  background: transparent !important;
  border-color: transparent !important;
  color: #0f172a !important;
}

body.light-theme .tuwei-est-cell {
  color: #0f172a !important;
}

body.light-theme .tuwei-excluded-tag {
  color: #64748b !important;
  background: #e2e8f0 !important;
}

body.light-theme .tuwei-search-input {
  background: #ffffff !important;
  border: 1px solid #cbd5e1 !important;
  color: #0f172a !important;
}

body.light-theme .tuwei-search-input::placeholder {
  color: #94a3b8 !important;
}

body.light-theme .tuwei-search-input:focus {
  background: #ffffff !important;
  border-color: #2563eb !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15) !important;
}

/* 日光模式浮動下拉索引選單 */
body.light-theme .tuwei-combo-dropdown {
  background: #ffffff !important;
  border: 1px solid #93c5fd !important;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.15) !important;
}

body.light-theme .tuwei-combo-header {
  background: #eff6ff !important;
  color: #0284c7 !important;
  border-bottom: 1px solid #dbeafe !important;
}

body.light-theme .tuwei-combo-option {
  color: #1e293b !important;
  border-bottom: 1px solid #f1f5f9 !important;
}

body.light-theme .tuwei-combo-option:hover,
body.light-theme .tuwei-combo-option.active {
  background: #eff6ff !important;
  color: #1d4ed8 !important;
}

body.light-theme .tuwei-card-header .btn-outline-light {
  color: #475569 !important;
  border-color: #cbd5e1 !important;
}

body.light-theme .tuwei-card-header .btn-outline-light:hover {
  background: #e2e8f0 !important;
  color: #0f172a !important;
}

/* =====================================================================
   10. 未報價 (單價未填) 視覺警示樣式 (夜間 + 日光模式)
   ===================================================================== */
.tuwei-card.has-unpriced-items {
  border-color: rgba(239, 68, 68, 0.45);
}

.tuwei-row-unpriced {
  background: rgba(239, 68, 68, 0.08) !important;
}

.tuwei-input-unpriced {
  border-color: rgba(239, 68, 68, 0.65) !important;
  background: rgba(239, 68, 68, 0.12) !important;
  color: #fca5a5 !important;
}

.tuwei-input-unpriced::placeholder {
  color: #f87171 !important;
  font-weight: 700;
}

body.light-theme .tuwei-card.has-unpriced-items {
  border-color: #fca5a5 !important;
}

body.light-theme .tuwei-row-unpriced {
  background: #fef2f2 !important;
}

body.light-theme .tuwei-input-unpriced {
  border-color: #ef4444 !important;
  background: #fee2e2 !important;
  color: #b91c1c !important;
}

body.light-theme .tuwei-input-unpriced::placeholder {
  color: #dc2626 !important;
  font-weight: 700;
}

