/* =====================================================================
   CICA Group 內部管理系統 — 設計系統
   依《CicaGroup 品牌系統彙整 20251220》CI 規範：
   主色 + 黑為主視覺、暖灰/淺灰為輔；歐美風簡約、靠品牌 4 色色塊帶出層次。
   標語：BUT FIRST COFFEE, AND MAKE IT AWESOME. / Total Coffee Solution
   --status-* 僅用於系統狀態提示，不可作裝飾色。
   ===================================================================== */
:root {
  /* 品牌標準色（CI 一、品牌標準色） */
  --cica-black:  #000000;  /* 輔助色1：Sidebar 背景、主標題 */
  --cica-gold:   #D4BE8F;  /* 主色（咖啡色）：Active、強調、色塊 */
  --cica-gold60: #E5D4B6;  /* 主色 60% 明度：圖表填充、Hover */
  --cica-gold20: #F5EBDF;  /* 主色 20% 明度：淺色背景區塊 */
  --cica-mid:    #A49B96;  /* 輔助色2（暖灰）：輔助文字 */
  --cica-light:  #D7D3D3;  /* 輔助色3（淺灰）：Border、分隔線 */
  --cica-white:  #FFFFFF;  /* 卡片背景 */
  --cica-ink:    #1a1a1a;  /* 內文 */

  /* 系統狀態色 */
  --status-danger:  #C0392B;  /* 鎖貨、逾期 */
  --status-warning: #D4830A;  /* 低庫存、警示 */
  --status-success: #1E6B3C;  /* 已收、正常 */

  /* 字體（CI 二、字型：中文思源黑體 = Noto Sans TC） */
  --font-en: 'Montserrat', 'Futura', sans-serif;
  --font-zh: 'Noto Sans TC', '思源黑體', sans-serif;

  --sidebar-w: 224px;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 6px 22px rgba(0,0,0,.07);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html, body { overflow-x: hidden; }  /* 防溢出保險：任何漏網元素不致把整頁撐寬 */
/* RWD 安全網（全域）：媒體元素永遠不超出容器寬，避免新功能在手機爆版。
   只限寬不動高，固定尺寸的 logo/縮圖(.mark/.ep-thumb) 不受影響。 */
img, svg, video, canvas { max-width: 100%; }
body {
  font-family: var(--font-zh);
  color: var(--cica-ink);
  background: #F4F2F0;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }

/* ---------- App 版面 ---------- */
.app { display: flex; min-height: 100vh; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { padding: 28px 32px 48px; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: #FAF8F4;            /* 暖白底（淺色配置） */
  color: #6B645E;
  border-right: 1px solid var(--cica-light);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
/* Logo 鎖定區：黑色圖標 + 黑色字標（淺底直接呈現，不反白） */
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 22px 20px 16px;
  border-bottom: 1px solid var(--cica-light);
}
.sidebar .brand .mark {
  height: 38px; width: auto;
  flex: 0 0 auto;
}
.sidebar .brand .wordmark {
  font-family: var(--font-en);
  font-weight: 700;
  color: var(--cica-black);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 16px;
  line-height: 1.1;
}
.sidebar .brand .wordmark small {
  display: block;
  font-family: var(--font-zh);
  font-weight: 400;
  letter-spacing: 0.05em;
  text-transform: none;
  color: var(--cica-mid);
  font-size: 11px;
  margin-top: 4px;
}
.sidebar nav { margin-top: 12px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 11px 20px;
  color: #5A544F;
  border-left: 3px solid transparent;
  font-size: 15px;
  letter-spacing: .01em;
  white-space: nowrap;
  cursor: pointer;
  transition: color .15s, background .15s;
}
.nav-item:hover { color: var(--cica-black); background: var(--cica-gold20); }
.nav-item.active {
  color: var(--cica-black);
  border-left: 3px solid var(--cica-gold);
  background: var(--cica-gold20);
  font-weight: 600;
}
.nav-item.alert { color: var(--status-danger); }

/* ---------- 選單工具列（全部展開 / 折疊）---------- */
.nav-tools {
  display: flex;
  justify-content: flex-end;
  gap: 2px;
  padding: 4px 12px 0;
}
.nav-tool {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  color: var(--cica-mid);
  background: transparent;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  transition: color .15s, background .15s;
}
.nav-tool:hover { color: var(--cica-black); background: var(--cica-gold20); }

/* ---------- 兩層選單（主目錄 → 子項）---------- */
.nav-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 20px;
  font-size: 15px;
  font-weight: 600;
  color: var(--cica-black);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.nav-group-head::after {
  content: '▸';
  color: var(--cica-mid);
  font-size: 12px;
  transition: transform .15s;
}
.nav-group:not(.collapsed) .nav-group-head::after { transform: rotate(90deg); }
.nav-group-head:hover { background: var(--cica-gold20); }
.nav-group.collapsed .nav-sub { display: none; }
.nav-sub .nav-item { padding-left: 38px; font-size: 14px; }
.nav-badge {
  background: var(--status-danger);
  color: #fff;
  font-family: var(--font-en);
  font-weight: 700;
  font-size: 11px;
  min-width: 19px;
  height: 19px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
}
/* 側欄底部：連線狀態 + 品牌標語 */
.sidebar .sidebar-foot { border-top: 1px solid var(--cica-light); }
.sidebar .sync-status { padding: 14px 20px 0; }
.sidebar .sync-status .pill {
  letter-spacing: normal;
  white-space: normal;
  font-size: 11px;
  line-height: 1.45;
}
/* 品牌標語（CI 五、品牌標語） */
.sidebar .slogan {
  padding: 12px 20px 22px;
  font-family: var(--font-en);
  font-size: 10px;
  letter-spacing: 0.12em;
  line-height: 1.7;
  color: var(--cica-mid);
  text-transform: uppercase;
}
.sidebar .slogan b { color: var(--cica-black); font-weight: 700; }

/* ---------- Topbar ---------- */
.topbar {
  background: var(--cica-white);
  border-bottom: 1px solid var(--cica-light);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 32px;
  position: relative;
}
/* 金色細條：色塊帶層次 */
.topbar::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, var(--cica-gold) 0%, var(--cica-gold20) 38%, transparent 70%);
}
.topbar .page-title {
  font-family: var(--font-zh);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: .02em;
  position: relative;
  padding-left: 14px;
}
.topbar .page-title::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 4px; height: 20px;
  border-radius: 2px;
  background: var(--cica-gold);
}
.topbar .right { display: flex; align-items: center; gap: 12px; }
.topbar .user { font-family: var(--font-en); font-size: 14px; color: #333; }

/* ---------- KPI 卡片 ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}
.kpi {
  position: relative;
  background: var(--cica-white);
  border: 1px solid var(--cica-light);
  border-radius: var(--radius);
  padding: 20px 18px 18px 24px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .18s, transform .18s;
}
.kpi:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kpi::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--cica-gold);
}
.kpi.danger::before  { background: var(--status-danger); }
.kpi.warning::before { background: var(--status-warning); }
.kpi .num {
  font-family: var(--font-en);
  font-weight: 700;
  font-size: 30px;
  letter-spacing: -0.01em;
  color: var(--cica-black);
}
.kpi.danger .num  { color: var(--status-danger); }
.kpi.warning .num { color: var(--status-warning); }
.kpi .label {
  font-family: var(--font-zh);
  font-size: 13px;
  color: var(--cica-mid);
  margin-top: 4px;
}

/* ---------- 鎖貨警示橫幅 ---------- */
.lock-banner {
  background: #FFF0EE;
  border-left: 4px solid var(--status-danger);
  border-radius: 8px;
  padding: 14px 18px;
  margin-top: 18px;
  font-size: 15px;
  color: #5a1f18;
}
.lock-banner b { color: var(--status-danger); }

/* ---------- 狀態 Pill ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-zh);
  font-size: 13px;
  font-weight: 500;
  padding: 3px 11px;
  border-radius: 12px;
  white-space: nowrap;
}
.pill.paid       { background: #E8F5ED; color: var(--status-success); }
.pill.due        { background: #FEF3E2; color: var(--status-warning); }
.pill.overdue    { background: #FFF0EE; color: var(--status-danger); }
.pill.locked     { background: #FFF0EE; color: var(--status-danger); border: 1px solid var(--status-danger); }
.pill.shipping   { background: #E8F0FB; color: #1A56A0; }
.pill.done       { background: #E8F5ED; color: var(--status-success); }

/* ---------- 卡片區塊 ---------- */
.card {
  background: var(--cica-white);
  border: 1px solid var(--cica-light);
  border-radius: var(--radius);
  padding: 22px;
  margin-top: 18px;
  box-shadow: var(--shadow-sm);
}
.card h2 {
  font-family: var(--font-zh);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .01em;
  margin: 0 0 16px;
  padding-left: 12px;
  position: relative;
}
.card h2::before {
  content: '';
  position: absolute;
  left: 0; top: 3px; bottom: 3px;
  width: 4px; border-radius: 2px;
  background: var(--cica-gold);
}

/* ---------- 可折疊卡片（details.card.collapsible）---------- */
details.card.collapsible > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}
details.card.collapsible > summary::-webkit-details-marker { display: none; }
details.card.collapsible > summary h2 { margin: 0; flex: 1; }
details.card.collapsible > summary::after {
  content: '▸';
  color: var(--cica-mid);
  font-size: 15px;
  transition: transform .15s;
}
details.card.collapsible[open] > summary { margin-bottom: 16px; }
details.card.collapsible[open] > summary::after { transform: rotate(90deg); }
details.card.collapsible:not([open]):hover { border-color: var(--cica-gold); }
details.card.collapsible:not([open]):hover > summary h2 { color: var(--cica-black); }

/* ---------- 資料表格 ---------- */
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.data thead th {
  background: var(--cica-black);
  color: var(--cica-gold);
  font-family: var(--font-en);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  text-align: left;
  padding: 10px 12px;
}
table.data thead th:first-child { border-top-left-radius: 6px; }
table.data thead th:last-child  { border-top-right-radius: 6px; }
table.data tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid #F0EEEC;
  font-family: var(--font-zh);
}
table.data tbody tr:nth-child(even) { background: #FAF9F8; }
table.data tbody tr:hover { background: var(--cica-gold20); }
table.data td.amount { font-family: var(--font-en); font-weight: 400; text-align: right; }
table.data td.code   { font-family: 'Courier New', monospace; font-size: 13px; }

/* 寬表格橫向捲動：表格塞進 #fTbl/#iTbl/#aTbl/#mTbl/#spTable 等容器，
   讓表格在卡片內自己左右捲，而非把整頁撐寬（手機跑版主因）。 */
.card div:has(> table.data) {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---------- 按鈕 ---------- */
.btn {
  font-family: var(--font-en);
  font-size: 14px;
  border: none;
  border-radius: 7px;
  padding: 9px 18px;
  cursor: pointer;
  transition: opacity .15s, background .15s;
}
.btn-primary   { background: var(--cica-black); color: var(--cica-gold); font-weight: 600; }
.btn-primary:hover { background: #1c1c1c; }
.btn-secondary { background: transparent; border: 1px solid var(--cica-light); color: var(--cica-black); }
.btn-secondary:hover { border-color: var(--cica-gold); background: var(--cica-gold20); }
.btn-danger    { background: var(--status-danger); color: #fff; }
.btn-ghost     { background: transparent; color: var(--cica-mid); }
.btn-ghost:hover { color: var(--cica-black); }
.btn:disabled  { opacity: 0.5; cursor: not-allowed; }

/* ---------- 表單 ---------- */
.input {
  font-family: var(--font-zh);
  font-size: 15px;
  border: 1px solid var(--cica-light);
  border-radius: 7px;
  padding: 9px 13px;
  width: 100%;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--cica-gold); box-shadow: 0 0 0 3px var(--cica-gold20); }

/* ---------- 手機抽屜選單按鈕 / 遮罩（桌機預設隱藏）---------- */
.menu-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--cica-light);
  border-radius: 7px;
  width: 40px; height: 34px;
  font-size: 18px; line-height: 1;
  color: var(--cica-black);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.menu-btn:hover { border-color: var(--cica-gold); background: var(--cica-gold20); }
.backdrop { display: none; }
.drawer-user { display: none; }  /* 桌機隱藏；手機抽屜底部顯示 */

/* ---------- 桌機側欄收合按鈕 ---------- */
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.collapse-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 32px;
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid var(--cica-light);
  border-radius: 7px;
  color: var(--cica-mid);
  cursor: pointer;
  font-size: 16px; line-height: 1;
}
.collapse-btn:hover { border-color: var(--cica-gold); color: var(--cica-black); background: var(--cica-gold20); }
.collapse-btn::before { content: '\00AB'; }            /* « 收合 */
.app.collapsed .collapse-btn::before { content: '\00BB'; } /* » 展開 */

/* 桌機：收合時整條側欄縮起，主內容滿版 */
@media (min-width: 769px) {
  .sidebar { transition: flex-basis .22s ease, width .22s ease; }
  .app.collapsed .sidebar {
    width: 0;
    min-width: 0;
    flex-basis: 0;
    border-right: none;
    overflow: hidden;
  }
}

/* ---------- 響應式（手機）：側欄改右側抽屜 ---------- */
@media (max-width: 768px) {
  .menu-btn { display: inline-flex; }
  .collapse-btn { display: none; }        /* 桌機才有收合；手機用右上抽屜 */
  .topbar .user { display: none; }
  .topbar #logoutBtn { display: none; }   /* 登出移到抽屜底部 */
  .topbar { padding: 12px 16px; }
  .content { padding: 18px 16px 36px; }

  /* 卡片不再左右吃滿造成內部表格無處可縮 */
  .card { padding: 16px 14px; }

  /* 寬表格在手機上更省空間，並維持容器內橫向捲動 */
  table.data { font-size: 13px; }
  table.data thead th { padding: 8px 9px; white-space: nowrap; }
  table.data tbody td { padding: 8px 9px; }

  /* 直接放在卡片內（無 div 包裹）的寬表格也能自身橫向捲動，不爆出視窗
     （補 .card div:has(>table.data) 抓不到的直接子表格，如員購「我的員購單」「許願清單」） */
  .card > table.data { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* KPI 數字在手機略縮，避免單卡過高 */
  .kpi { padding: 16px 14px; }
  .kpi .num { font-size: 24px; }
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }

  /* 多選下拉面板不超出視窗 */
  .invms-panel { max-width: calc(100vw - 40px); }

  /* 抽屜底部：使用者名稱 + 登出 */
  .drawer-user {
    display: block;
    padding: 14px 20px 22px;
    border-top: 1px solid var(--cica-light);
  }
  .drawer-user .duser-name {
    font-family: var(--font-en);
    font-size: 14px;
    color: var(--cica-black);
    margin-bottom: 4px;
  }

  .sidebar {
    position: fixed;
    top: 0; right: 0;
    height: 100vh; height: 100dvh;
    width: 270px; max-width: 84vw;
    flex: none;
    transform: translateX(100%);
    transition: transform .25s ease;
    z-index: 60;
    overflow-y: auto;
    border-right: none;
    border-left: 1px solid var(--cica-light);
    box-shadow: -6px 0 26px rgba(0, 0, 0, .18);
  }
  .sidebar.open { transform: translateX(0); }

  .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .42);
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
  }
  .backdrop.show { opacity: 1; pointer-events: auto; }
}
