/* =========================================
   Root 變數
========================================= */
:root{
  --bg:#f5f6f8;
  --card:#ffffff;
  --primary:#111827;
  --primary-blue:#2563eb;
  --border:#e5e7eb;
  --text:#1f2937;
  --muted:#6b7280;
  --radius:12px;
  --shadow:0 4px 12px rgba(0,0,0,0.06);

  --loading-bg:#e5e7eb;
  --loading-fill:#3b82f6;
}

/* =========================================
   Body
========================================= */
body{
  margin:0;
  padding:24px;
  background:var(--bg);
  font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
  color:var(--text);
  max-width:980px;
  margin:0 auto;
}

h1{margin:0 0 4px;}
.subtitle{
  color:var(--muted);
  margin-bottom:18px;
  font-size:14px;
  font-weight: 500;
  letter-spacing: 0.5px;
}

/* =========================================
   Top Bar
========================================= */
.top-bar{
  display:flex;
  justify-content:space-between;
  align-items:center;
  margin-bottom:14px;
}
.user-badge{
  background:#eef0f4;
  padding:6px 14px;
  border-radius:999px;
  font-size:13px;
  transition: all 0.3s ease;
  border: 1px solid transparent;
}
.badge-lv0 { color: #666; border-color: #ddd; background: #f3f4f6; }
.badge-lv1 { background: #dbeafe; color: #1e40af; }
.badge-lv2 { background: #dcfce7; color: #15803d; }
.badge-lv3 { background: #fef3c7; color: #92400e; }
.badge-lv4 { background: #f3e8ff; color: #6b21a8; }
/* VIP Badge */
.badge-vip { background: #fce7f3; color: #be185d; border-color: #fbcfe8; }

.logout-btn{
  padding:6px 14px;
  border-radius:999px;
  border:1px solid var(--border);
  cursor:pointer;
  background:white;
  font-size:12px;
}

/* =========================================
   Toolbar
========================================= */
.toolbar{
  display:flex;
  gap:8px;
  align-items:stretch;
  margin:10px 0 6px;
  flex-wrap: wrap;
  width: 100%;
  box-sizing: border-box;
  background: white;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  padding: 10px 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

/* Each direct child of toolbar stretches to fill the row evenly */
.toolbar-btn-pill {
  flex: 1;
  padding: 9px 12px;
  border-radius: 999px;
  border: 1px solid #e5e7eb;
  background: white;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
  font-weight: 500;
  color: #374151;
  text-align: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.toolbar-btn-pill:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
}
.toolbar-btn-pill:disabled {
  color: #d1d5db;
  cursor: not-allowed;
  border-color: #f1f5f9;
  background: #fafafa;
}
.toolbar-btn-more {
  color: #6b7280;
}

/* Level switch wrap also expands to fill space */
#levelSwitchWrap {
  flex: 1;
  /* visibility controlled by auth.js via inline style */
}
#levelSwitchWrap select.toolbar-btn-pill {
  width: 100%;
  flex: 1;
  text-align: left;
}

/* More options wrapper expands and the button inside fills it */
.more-options-wrapper {
  position: relative;
  flex: 1;
}
.more-options-wrapper #moreOptionsBtn {
  width: 100%;
}

/* Mobile: force 3 items per row */
@media (max-width: 700px) {
  .toolbar-btn-pill,
  .more-options-wrapper,
  #levelSwitchWrap {
    flex: 0 0 calc(33.333% - 6px);
  }
  #levelSwitchWrap select.toolbar-btn-pill {
    width: 100%;
  }
}


/* 工具列懸浮樣式 */
.toolbar.fixed-active {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  bottom: auto;
  
  z-index: 2000;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  padding: 12px 20px;
  
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  border: 1px solid rgba(0,0,0,0.1);
  
  width: calc(100% - 48px);
  max-width: 980px;
  border-radius: 12px;
  
  justify-content: flex-start;
  animation: popDown 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popDown {
  from { transform: translate(-50%, -120%); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

#toolbarSpacer { height: 70px; display: none; }

.quote-toolbar-btn{
  padding:10px 16px;
  border-radius:999px;
  border:1px solid var(--border);
  background:white;
  cursor:pointer;
  font-size:14px;
  white-space:nowrap;
  display:none;
}

/* =========================================
   搜尋區塊
========================================= */
.search-box{
  background:var(--card);
  padding:18px;
  border-radius:var(--radius);
  box-shadow:0 8px 28px rgba(0,0,0,0.15);
  margin-bottom:12px;
}
.search-row {margin-bottom:14px;}
label{
  font-weight:600;
  margin-bottom:6px;
  display:block;
  font-size:14px;
}
/* 輸入框聚焦光暈特效 */
input, select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 15px;
  box-sizing: border-box;
  border: 1px solid #e2e8f0;
  background: #fff;
  transition: all 0.2s ease;
}

/* 當滑鼠點擊輸入框時的效果 */
input:focus, select:focus {
  outline: none;
  border-color: #3b82f6;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15); 
}

/* 複合式搜尋列 (分類 + 關鍵字) */
.combo-search {
    display: flex;
    gap: 10px;
}
.combo-search select {
    width: 35%;
    min-width: 130px;
    background-color: #f9fafb;
    border: 1px solid #cbd5e1;
}
.combo-search input {
    flex: 1;
}

/* =========================================
   Buttons
========================================= */
.btn-primary{
  background:var(--primary);
  color:white;
  border:none;
  border-radius:999px;
  padding:12px 20px;
  font-weight:600;
  cursor:pointer;
  width:100%;
}
.btn-secondary{
  background:white;
  border:1px solid var(--border);
  padding:10px 16px;
  border-radius:999px;
  cursor:pointer;
  font-size:14px;
  white-space:nowrap;
}
.btn-secondary:disabled { color: #ccc; cursor: not-allowed; }
.btn-outline-add{
  padding:6px 12px;
  border-radius:6px;
  border:1px solid #2563eb;
  background:#eff6ff;
  color:#2563eb;
  font-size:12px;
  cursor:pointer;
  font-weight:600;
}
.btn-outline-add:hover{background:#dbeafe;}

/* =========================================
   表格
========================================= */
table{
  width:100%;
  border-collapse:collapse;
  background:white;
  border-radius:var(--radius);
  box-shadow:0 8px 28px rgba(0,0,0,0.15);
}
/* 表格寬鬆化設定 */
th, td {
  padding: 16px 12px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 14px;
  vertical-align: middle;
}

th {
  background: #f8fafc;
  color: #64748b;
  font-weight: 700;
  text-align: left;
  letter-spacing: 0.5px;
}

.product-img{
  width:110px;height:110px;
  object-fit:cover;
  border-radius:14px;
  border:1px solid #e5e7eb;
  cursor: pointer;
}
.model-cell { cursor: pointer; }
.model-cell:hover { color: var(--primary-blue); text-decoration: underline; }

/* 價格標籤 - 藥丸化 */
.price-tag {
  padding: 4px 12px;
  font-size: 12px;
  border-radius: 50px;
  display: inline-block;
  margin-right: 6px;
  margin-bottom: 6px;
  font-weight: 700;
  white-space: nowrap;
  border: none;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  transition: transform 0.2s;
}
.price-tag:hover {
  transform: scale(1.05);
}
.tag50{background:#dbeafe;color:#1e40af;}
.tag100{background:#e0f2fe;color:#0369a1;}
.tag300{background:#dcfce7;color:#15803d;}
.tag500{background:#ffedd5;color:#ea580c;}
.tag1000{background:#fee2e2;color:#b91c1c;}

/* 分類標籤 - 藥丸化 */
.category-badge {
  display: inline-block;
  font-size: 11px;
  padding: 3px 10px;
  background: #f1f5f9;
  color: #64748b;
  border-radius: 50px;
  margin-bottom: 4px;
  border: 1px solid #e2e8f0;
  font-weight: 600;
}

/* 庫存文字標籤 - 藥丸化 */
.stock-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 50px;
  font-size: 11px;
  font-weight: 700;
  margin-left: 0; 
  vertical-align: middle;
  border: 1px solid transparent;
}

/* 1. 小於 30 (紅色 - 警戒) */
.st-crit { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
/* 2. 小於 100 (橘紅 - 少量) */
.st-low  { background: #ffedd5; color: #9a3412; border-color: #fdba74; }
/* 3. 小於 400 (橘黃 - 普通) */
.st-warn { background: #fff7ed; color: #b45309; border-color: #fed7aa; }
/* 4. 小於 800 (草綠 - 充足) */
.st-mid  { background: #ecfccb; color: #3f6212; border-color: #bef264; }
/* 5. 小於 1200 (綠色 - 豐富) */
.st-good { background: #dcfce7; color: #166534; border-color: #86efac; }
/* 6. 大於 1200 (深綠 - 極多) */
.st-high { background: #ccfbf1; color: #0f766e; border-color: #5eead4; }
.st-zero { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }


/* =========================================
   Loading
========================================= */
#centerLoadingBox{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,0.35);
  display:none;
  align-items:center;
  justify-content:center;
  z-index:2000;
}
#centerLoadingCard{
  background:rgba(255,255,255,0.65);backdrop-filter:blur(14px);
  width:280px;
  padding:20px;
  border-radius:12px;
  box-shadow:0 8px 28px rgba(0,0,0,0.15);
}
.loading-title{
  font-size:15px;
  font-weight:700;
  margin-bottom:12px;
}
.loading-bar .fill{
  height:100%;
  width:0%;
  background:var(--loading-fill);
  transition:width .15s linear;
}

/* =========================================
   Detail Card
========================================= */
#detailCard{
  position:fixed;
  right:20px;
  top:120px;
  width:360px;
  max-height:78vh;
  overflow-y:auto;
  background:white;
  padding:18px;
  border-radius:var(--radius);
  box-shadow:0 8px 28px rgba(0,0,0,0.15);
  display:none;
  z-index:999;
}
.card-close-btn {
  position: absolute; 
  top: 12px; 
  right: 12px; 
  width: 32px; 
  height: 32px; 
  border-radius: 50%; 
  background: #f3f4f6; 
  border: 1px solid #e5e7eb;
  color: #6b7280; 
  font-size: 20px; 
  cursor: pointer; 
  display: flex; 
  align-items: center; 
  justify-content: center;
  z-index: 20;
  transition: all 0.2s;
}
.card-close-btn:hover {
  background: #e5e7eb;
  color: #ef4444;
  transform: scale(1.1);
}

/* =========================================
   網路圖 grid
========================================= */
.net-gallery{
  display:grid;
  grid-template-columns:repeat(3,1fr);
  gap:6px;
  margin-top:10px;
}
.net-gallery img{
  width:100%;
  border-radius:6px;
  border:1px solid #e5e7eb;
  object-fit:cover;
  cursor: pointer;
  transition: transform 0.2s;
}
.net-gallery img:hover { transform: scale(1.05); }

/* =========================================
   Mobile Sheet
========================================= */
.sheet-backdrop{
  position:fixed;inset:0;
  background:rgba(0,0,0,0.45);
  z-index:1000;
}
.sheet{
  position:fixed;left:0;right:0;bottom:0;
  height:80vh;background:#fff;
  border-radius:16px 16px 0 0;
  transform:translateY(100%);
  transition:transform .25s ease;
  display:flex;flex-direction:column;
  z-index:1001;
}
.sheet.open{transform:translateY(0);}
.sheet-header{
  padding:12px 16px;
  border-bottom:1px solid var(--border);
  font-weight:700;
  display:flex;justify-content:space-between;align-items:center;
}
.sheet-close{
  background:none;border:none;
  font-size:26px;cursor:pointer;line-height:1;
}
.sheet-content{
  padding:16px;overflow-y:auto;font-size:15px;flex:1;
}
.hidden{display:none!important;}

.quote-item{
  display:flex;justify-content:space-between;align-items:center;
  padding:12px 0;border-bottom:1px solid #eee;
}
.quote-info{font-size:14px;color:#666;}
.quote-price{font-weight:700;color:#2563eb;}
.quote-del{color:#999;cursor:pointer;padding:6px;font-size:16px;}
.quote-del:hover{color:#ef4444;}

/* =========================================
   Login Overlay
========================================= */
#loginOverlay {
  position: fixed;
  inset: 0;
  background: #f5f6f8;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
.login-card {
  background: white;
  padding: 30px;
  border-radius: 16px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.1);
  width: 90%;
  max-width: 400px;
  text-align: center;
}
.login-card h2 { margin-top: 0; color: var(--primary); }
.login-input {
  width: 100%;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-sizing: border-box;
}
.login-btn {
  width: 100%;
  padding: 12px;
  background: var(--primary-blue);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  margin-top: 10px;
}
.login-btn:hover { background: #1d4ed8; }
.login-error {
  color: #ef4444;
  margin-top: 10px;
  font-size: 14px;
  display: none;
}

/* =========================================
   RWD
========================================= */
@media (max-width:900px){
  #detailCard{display:none!important;}
}

/* =========================================
   More Options Floating Dropdown
========================================= */
.more-options-wrapper {
  position: relative;
  display: inline-block;
}

#moreOptionsBtn {
  color: #4b5563;
  white-space: nowrap;
}

.options-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 3000;
  background: white;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.16);
  border: 1px solid #e5e7eb;
  padding: 16px;
  min-width: 280px;
  flex-direction: column;
  gap: 14px;
  animation: fadeInDown 0.18s ease;
}

.options-dropdown.open {
  display: flex;
}

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

.options-dropdown-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.options-dropdown-section select {
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  background: #f9fafb;
  color: #374151;
  cursor: pointer;
}

.options-dropdown-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: #9ca3af;
}

.options-dropdown-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.dropdown-action-btn {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid #e5e7eb;
  background: white;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
  color: #374151;
}
.dropdown-action-btn:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
}
.dropdown-action-btn:disabled {
  color: #d1d5db;
  cursor: not-allowed;
  border-color: #f3f4f6;
  background: #fafafa;
}

/* Close dropdown when clicking outside */
.options-dropdown-divider {
  height: 1px;
  background: #f1f5f9;
  margin: 2px 0;
}

/* 9. 手機版適配 (Card View) - 4欄結構專用版 */
@media (max-width: 600px) {
  body { padding: 16px; background: #f8fafc; }
  
  /* 隱藏原本的表頭 */
  thead { display: none; }
  /* 表格轉塊狀 */
  table, tbody, tr, td { display: block; width: 100%; }
  
  tr {
    background: white;
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 16px;
    /* 手機版卡片陰影 */
    box-shadow: 0 2px 8px rgba(0,0,0,0.04) !important;
    border: 1px solid rgba(0,0,0,0.03);
    position: relative;
    box-sizing: border-box;
  }
  
  /* 移除電腦版的懸浮上浮特效，手機不需要 */
  tbody tr:hover { transform: none; box-shadow: 0 2px 8px rgba(0,0,0,0.04); }

  td { border: none; padding: 4px 0; text-align: left; }
  
  /* --- 格子對應邏輯 --- */

  /* 格子1: 勾選框 (定位在左上角) */
  td:nth-of-type(1) { 
    position: absolute; top: 12px; left: 12px; width: auto; z-index: 10; 
  }
  
  /* 格子2: 型號+圖片 (置中顯示) */
  td:nth-of-type(2) { 
    display: flex; flex-direction: column; align-items: center; padding-bottom: 12px; 
  }
  /* 手機版把圖片上方的小型號隱藏 */
  td:nth-of-type(2) .model-cell { display: none; } 
  .product-img { width: 100%; max-width: 200px; height: 180px; }
  
  /* 格子3: 商品資訊 (保持原樣) */
  td:nth-of-type(3) { padding-bottom: 12px; }

  /* 格子4: 價格區 (改成左右橫排) */
  td:nth-of-type(4) {
    background: #f8fafc; 
    padding: 10px 12px; 
    border-radius: 12px; 
    margin-top: 8px;
    display: flex; 
    justify-content: space-between; 
    align-items: center;
  }
  
  /* 用 CSS 在價格前面補上文字標籤 */
  td:nth-of-type(4) div:first-child::before { 
    content: "末售: "; 
    color: #64748b; font-weight: normal; font-size: 13px; margin-right: 4px; 
  }
  td:nth-of-type(4) div:last-child::before { 
    content: "賣場: "; 
    color: #94a3b8; font-weight: normal; font-size: 12px; margin-right: 4px;
  }
  
  /* 修復能量條在手機版的寬度 */
  .stock-bar-container { width: 100%; }
}

/* =========================================
   Preview Overlay
========================================= */
#previewOverlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5); 
    display: none; align-items: center; justify-content: center; z-index: 4000;
}
.preview-card {
    background: white; width: 90%; max-width: 900px; max-height: 80vh;
    border-radius: 12px; padding: 20px; display: flex; flex-direction: column;
}
.preview-header { font-weight: bold; font-size: 18px; margin-bottom: 10px; border-bottom: 1px solid #eee; padding-bottom: 10px;}
.preview-body { flex: 1; overflow-y: auto; margin-bottom: 10px; font-size: 13px; }
.preview-footer { display: flex; justify-content: flex-end; gap: 10px; }
.preview-table { width: 100%; border-collapse: collapse; }
.preview-table th, .preview-table td { border: 1px solid #ddd; padding: 6px; text-align: left; }
.preview-table th { background: #f3f4f6; }
.field-badge {
    background: #e0f2fe; color: #0284c7; padding: 2px 6px; border-radius: 4px; font-size: 11px; margin-right: 4px;
}

/* =========================================
   Gift Excel Report Form Overlay
========================================= */
#giftFormOverlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    display: none; align-items: center; justify-content: center; z-index: 4500;
}
.gift-form-card {
    background: white; width: 92%; max-width: 480px; max-height: 90vh;
    border-radius: 12px; padding: 20px; display: flex; flex-direction: column;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.gift-form-header {
    font-weight: bold; font-size: 17px; margin-bottom: 12px;
    border-bottom: 1px solid #eee; padding-bottom: 10px; color: #111827;
}
.gift-form-body { flex: 1; overflow-y: auto; margin-bottom: 14px; }
.gift-form-row { display: flex; gap: 10px; }
.gift-form-row .gift-form-field { flex: 1; }
.gift-form-field { margin-top: 10px; }
.gift-form-field label {
    display: block; font-size: 13px; font-weight: 600;
    color: #374151; margin-bottom: 4px;
}
.gift-form-field input,
.gift-form-field textarea,
.gift-form-field select {
    width: 100%; padding: 8px 10px;
    border: 1px solid #e5e7eb; border-radius: 6px;
    font-size: 14px; box-sizing: border-box; background: #fff;
    font-family: inherit;
}
.gift-form-field input:focus,
.gift-form-field textarea:focus,
.gift-form-field select:focus {
    outline: none; border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.gift-form-hint {
    font-size: 12px; color: #6b7280;
    margin-top: 14px; padding: 8px 10px;
    background: #f9fafb; border-radius: 6px;
}
.gift-form-footer {
    display: flex; justify-content: flex-end; gap: 10px;
    padding-top: 12px; border-top: 1px solid #eee;
}

/* =========================================
   庫存能量條 (Inventory Bar) 樣式
========================================= */
.stock-bar-container {
  width: 100%;
  height: 6px;
  background: #e5e7eb;
  border-radius: 3px;
  margin-top: 4px;
  overflow: hidden;
  position: relative;
}
.stock-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}

/* 能量條顏色定義 */
.fill-crit { background: #ef4444; }
.fill-low  { background: #f97316; }
.fill-mid  { background: #eab308; }
.fill-good { background: #22c55e; }
.fill-high { background: #10b981; }

/* =========================================
   LINE 按鈕專屬樣式 (強制綠色)
========================================= */
.line-share-btn {
  background-color: #06C755 !important;
  color: white !important;
  border: 1px solid #06C755 !important;
  box-shadow: 0 2px 6px rgba(6, 199, 85, 0.3) !important;
  transition: all 0.2s ease;
}

.line-share-btn:hover {
  background-color: #059640 !important;
  transform: translateY(-2px);
}

/* =========================================
   Scroll To Top Button
========================================= */
#scrollToTopBtn {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: var(--primary-blue);
  color: white;
  border: none;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#scrollToTopBtn.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

#scrollToTopBtn:hover {
  background-color: #1d4ed8;
  transform: translateY(-5px);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.4);
}

@media (max-width: 600px) {
  #scrollToTopBtn {
    bottom: 20px;
    right: 20px;
    width: 45px;
    height: 45px;
    font-size: 20px;
  }
}

