:root {
  --primary: #ea580c;
  --primary-dark: #c2410c;
  --bg: #f5f5f4;
  --sidebar-bg: #18181b;
  --sidebar-text: #e7e5e4;
  --card-bg: #ffffff;
  --text: #1c1917;
  --muted: #78716c;
  --border: #e7e5e4;

  /* ── 設計系統 tokens ──
     間距只准用這個階梯。禁止出現 margin:7px 這種手調數字 —— 那是高低差的來源。 */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-6: 24px;
  --sp-8: 32px;

  /* 按鈕高度固定，不由內容撐開 → 並排的按鈕永遠切齊，
     不管裡面有沒有 icon、字多字少。 */
  --btn-h-sm: 32px;
  --btn-h: 40px;
  --btn-h-lg: 48px;

  /* 所有可點擊元件共用同一組圓角 */
  --radius-sm: 6px;
  --radius: 8px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  /* 中性底色。原本是 #f5d0d4 粉紅 —— 美業時期的殘留，
     一個要賣給各行各業的產品，登入頁不能有產業色彩。 */
  background: linear-gradient(135deg, #e7e5e4 0%, #f5f5f4 100%);
}
.login-box {
  background: white;
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.08);
  width: 360px;
}
.login-box h1 {
  margin: 0 0 8px;
  font-size: 22px;
  color: var(--primary-dark);
}
.login-box .subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 24px;
}

/* Layout with sidebar */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 24px 0;
  flex-shrink: 0;
  /* 右側捲動時，左側欄固定不動 */
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .logo {
  padding: 0 24px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  font-size: 16px;
  font-weight: 600;
}
.sidebar .nav-item {
  display: block;
  padding: 12px 24px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  transition: background 0.2s;
}
.sidebar .nav-item:hover { background: rgba(255,255,255,0.05); }
.sidebar .nav-item.active {
  background: var(--primary);
  color: white;
}

/* === 群組分頁（出現在合併頁面 main-header 下方） === */
.page-tabs {
  display: flex;
  gap: 4px;
  background: #fff;
  border-radius: 12px;
  padding: 6px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  flex-wrap: wrap;
}
.page-tab {
  padding: 9px 18px;
  border-radius: 8px;
  text-decoration: none;
  color: #666;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.15s;
  white-space: nowrap;
}
.page-tab:hover {
  background: #fff7ed;
  color: var(--primary-dark);
}
.page-tab.active {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  box-shadow: 0 2px 6px rgba(234,88,12,0.3);
}
@media (max-width: 768px) {
  .page-tab { padding: 7px 12px; font-size: 13px; }
}

.main {
  flex: 1;
  padding: 32px;
  overflow-x: auto;
}
.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.main-header h1 { margin: 0; font-size: 24px; }

/* ══════════════════════════════════════════════════════════
   自助開店精靈（onboarding）
   規範同設計系統：固定高度、間距只用階梯值、零 inline style
   ══════════════════════════════════════════════════════════ */
.wiz-wrap {
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--sp-8) var(--sp-4);
  background: linear-gradient(135deg, #e7e5e4 0%, #f5f5f4 100%);
}
.wiz-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.06);
  width: 100%;
  max-width: 720px;
  padding: var(--sp-8);
}
.wiz-head { margin-bottom: var(--sp-6); }
.wiz-head h1 { margin: 0 0 var(--sp-2); font-size: 24px; }
.wiz-head p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }

/* 進度條：五個等寬節點，永遠等高 */
.wiz-steps {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--sp-2);
  margin-bottom: var(--sp-6);
}
.wiz-step {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  transition: background .2s;
}
.wiz-step.done { background: var(--primary); }

.wiz-body { min-height: 280px; }   /* 固定最小高度 → 換頁時卡片不會忽高忽低 */

/* 動作列：永遠靠兩端，按鈕等高（吃 .btn 的固定高度） */
.wiz-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  margin-top: var(--sp-6);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border);
}
.wiz-actions-right { display: flex; align-items: center; gap: var(--sp-2); }

/* 產業選擇：卡片必定等高（grid stretch + height 100%） */
.pack-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--sp-3);
  align-items: stretch;
}
.pack-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  text-align: left;
  padding: var(--sp-4);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: white;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}
.pack-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.pack-card.selected {
  border-color: var(--primary);
  background: #fff7ed;
  box-shadow: 0 0 0 3px rgba(234,88,12,.12);
}
.pack-card .pack-name { font-weight: 600; font-size: 15px; margin-bottom: var(--sp-1); }
.pack-card .pack-tag {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
  margin-top: auto;   /* 說明推到底 → 同列卡片的說明對齊同一條基線 */
}

/* 可增刪的列（服務項目 / 人員） */
.row-item {
  display: grid;
  gap: var(--sp-2);
  align-items: center;
  margin-bottom: var(--sp-2);
}
.row-item.cols-service { grid-template-columns: 1fr 110px 110px 40px; }
.row-item.cols-staff   { grid-template-columns: 1fr 1fr 40px; }
.row-item input {
  height: var(--btn-h);          /* 與按鈕同高 → 整列切齊，沒有高低差 */
  padding: 0 var(--sp-3);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  width: 100%;
}
.row-item input:focus { outline: none; border-color: var(--primary); }
.row-head {
  display: grid;
  gap: var(--sp-2);
  font-size: 12px;
  color: var(--muted);
  margin-bottom: var(--sp-1);
}
.row-head.cols-service { grid-template-columns: 1fr 110px 110px 40px; }
.row-head.cols-staff   { grid-template-columns: 1fr 1fr 40px; }

.wiz-hint {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
  margin-top: var(--sp-3);
}
.wiz-done { text-align: center; padding: var(--sp-6) 0; }
.wiz-done h2 { margin: 0 0 var(--sp-2); font-size: 22px; }
.wiz-done .wiz-summary {
  text-align: left;
  background: #fafaf9;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4);
  margin: var(--sp-4) 0;
  font-size: 14px;
  line-height: 2;
}
.wiz-err {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b94440;
  border-radius: var(--radius);
  padding: var(--sp-3);
  font-size: 13px;
  margin-bottom: var(--sp-4);
}

@media (max-width: 640px) {
  .wiz-card { padding: var(--sp-4); }
  .row-item.cols-service { grid-template-columns: 1fr 80px 80px 36px; }
  .row-head.cols-service { grid-template-columns: 1fr 80px 80px 36px; }
}

/* ══════════════════════════════════════════════════════════
   客製化頁（彈性層）— 改稱呼 / 開關功能
   ══════════════════════════════════════════════════════════ */
.section-title { margin: 0 0 var(--sp-2); font-size: 17px; }
.hint { font-size: 13px; color: var(--muted); line-height: 1.7; margin: 0 0 var(--sp-4); }
.card > .btn-row { margin-top: var(--sp-4); }
.card > .hint:last-child { margin: var(--sp-3) 0 0; }

.mod-group { margin-bottom: var(--sp-4); }
.mod-group-title {
  font-size: 12px; font-weight: 600; color: var(--muted);
  letter-spacing: .06em; margin-bottom: var(--sp-2);
}
.mod-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--sp-2);
  align-items: stretch;
}
/* 固定高度 → 每一格都等高，不管字多字少，沒有高低差 */
.mod-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: var(--btn-h);
  padding: 0 var(--sp-3);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: white;
  cursor: pointer;
  font-size: 14px;
  transition: border-color .15s, background .15s;
}
.mod-item:hover { border-color: var(--primary); }
.mod-item input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }
.mod-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mod-item.is-core { background: #fafaf9; cursor: default; }
.mod-item.is-core:hover { border-color: var(--border); }
.mod-tag {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  background: #f5f5f4;
  border-radius: 4px;
  padding: 2px 6px;
  flex-shrink: 0;
}

/* 側邊欄的登出（與上方選單拉開距離）— 用 class，不用 inline style */
.nav-logout { margin-top: var(--sp-6); }

/* 分頁列下方的角色切換鈕 */
.role-switch-row { margin: var(--sp-1) 0 var(--sp-1); }

/* Cards */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4);
  margin-bottom: var(--sp-4);
  /* 內容用縱向 flex 排 → 卡片被拉高時，內容不會擠在上緣 */
  display: flex;
  flex-direction: column;
}
.card-title {
  font-size: 14px;
  color: var(--muted);
  margin: 0 0 var(--sp-2);
}
.card-value {
  font-size: 28px;
  font-weight: 600;
  color: var(--primary-dark);
  line-height: 1.2;
  /* 把數值推到卡片底部 → 同一列卡片的數字永遠在同一條水平線上，
     不會因為上面標題長短不同而上下飄。 */
  margin-top: auto;
}

/* Stat grid — 同一列的卡片必定等高、內容基線切齊 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
  align-items: stretch;      /* 卡片撐滿列高 */
}
/* grid 已經用 gap 控間距，卡片自己的 margin-bottom 會讓縱向間距變成兩倍
   （gap 16 + margin 16 = 32），而橫向只有 16 → 縱橫不對稱。這裡歸零。 */
.stats-grid > .card {
  margin-bottom: 0;
  height: 100%;
}

/* Form */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}
.field input, .field textarea, .field select,
.modal input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=file]):not([type=range]):not([type=button]):not([type=submit]):not([type=reset]):not([type=image]),
.modal textarea,
.modal select,
input[type="text"], input[type="email"], input[type="tel"],
input[type="password"], input[type="number"], input[type="date"],
input[type="time"], input[type="datetime-local"], input[type="url"],
input[type="search"], textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.field textarea, textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
.field input:focus, .field textarea:focus, .field select:focus,
input:focus:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="file"]),
textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.15);
}
.field input::placeholder, textarea::placeholder { color: rgba(0,0,0,.32); }

/* 自訂 select 下拉箭頭
   用 !important 確保「箭頭圖 + 右側預留空間」不會被個別頁面自訂的 padding/background
   蓋掉（否則箭頭會壓到文字）。 */
select {
  appearance: none !important;
  -webkit-appearance: none !important;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='none' stroke='%23999' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1 1l5 5 5-5'/></svg>") !important;
  background-repeat: no-repeat !important;
  background-position: right 12px center !important;
  padding-right: 34px !important;
  cursor: pointer;
}

/* 美化 checkbox */
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 1.8px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  position: relative;
  vertical-align: middle;
  background: #fff;
  transition: all .15s;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  flex: none;
}
input[type="checkbox"]:hover { border-color: var(--primary); }
input[type="checkbox"]:checked {
  background: var(--primary);
  border-color: var(--primary);
}
input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid white;
  border-width: 0 2.2px 2.2px 0;
  transform: rotate(45deg);
}
input[type="checkbox"]:focus-visible {
  box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.3);
}

/* checkbox + label inline */
label > input[type="checkbox"] { margin-right: 6px; }

/* 美化 color picker */
input[type="color"] {
  width: 56px;
  height: 36px;
  padding: 4px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  background: #fff;
  vertical-align: middle;
  transition: border-color .15s;
}
input[type="color"]:hover { border-color: var(--primary); }
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 4px; }
input[type="color"]::-moz-color-swatch { border: none; border-radius: 4px; }

/* ══════════════════════════════════════════════════════════
   Buttons — 設計系統

   規則（違反就會產生高低差，不要繞過）：
   1. 高度固定（height），不靠 padding 撐開 → 並排按鈕永遠等高
   2. 每個變體都有「同寬」的 border（primary 用透明的）
      ← 原本 primary 無邊框、secondary 有 1.5px 邊框，
        高度又是內容撐開的，導致 secondary 硬是高 3px。這是舊版高低差的元兇。
   3. 尺寸只有三級：btn-sm / （預設）/ btn-lg
   4. 語意只有四種：primary / secondary / danger / ghost
      一個畫面只能有一顆 btn-primary
   5. class 順序固定：基礎 → 語意 → 尺寸  例：class="btn btn-primary btn-sm"
   6. 按鈕禁止 inline style。要新樣式就在這裡加 class
   ══════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: var(--btn-h);              /* ← 固定高度，杜絕高低差 */
  padding: 0 18px;                   /* 只給左右；高度不靠 padding */
  border: 1.5px solid transparent;   /* ← 所有變體同寬邊框，尺寸才一致 */
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  transition: all .15s;
  letter-spacing: 0.01em;
  white-space: nowrap;
  vertical-align: middle;
}

/* ── 語意變體 ── */
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  box-shadow: 0 2px 6px rgba(234, 88, 12, 0.25);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  box-shadow: 0 4px 10px rgba(234, 88, 12, 0.35);
  transform: translateY(-1px);
}
.btn-primary:active:not(:disabled) { transform: translateY(0); }

.btn-secondary {
  background: white;
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: #f5f5f4;
  border-color: var(--primary);
  color: var(--primary-dark);
}

.btn-danger {
  background: #d9534f;
  border-color: #d9534f;
  color: white;
  box-shadow: 0 2px 6px rgba(217, 83, 79, 0.25);
}
.btn-danger:hover:not(:disabled) {
  background: #b94440;
  border-color: #b94440;
  box-shadow: 0 4px 10px rgba(217, 83, 79, 0.35);
  transform: translateY(-1px);
}

/* 低調動作（取消、返回…）— 不搶視覺，但高度仍與其他按鈕一致 */
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
  background: #ebeae8;
  color: var(--text);
}

/* ── 尺寸（只有三級）── */
.btn-sm {
  height: var(--btn-h-sm);
  padding: 0 var(--sp-3);
  font-size: 12px;
  border-radius: var(--radius-sm);
  gap: var(--sp-1);
}
.btn-lg {
  height: var(--btn-h-lg);
  padding: 0 var(--sp-6);
  font-size: 15px;
}

/* 整列寬度（表單送出、手機版）*/
.btn-block { width: 100%; }

.btn:disabled, .btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* 一排按鈕：統一間距 + 垂直置中，避免各頁自己用 inline style 排 */
.btn-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

/* Table */
.table {
  width: 100%;
  background: white;
  border-collapse: collapse;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.table th, .table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.table th {
  background: #f5f5f4;
  font-weight: 600;
  color: var(--text);
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover { background: #fafaf9; }

/* Badge */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  background: #e0e0e0;
  color: #555;
}
.badge.active { background: #d4eed4; color: #2d6d2d; }
.badge.inactive { background: #f0d4d4; color: #8a2929; }

/* ============================================================
   Modal — 統一精緻設計（所有頁面共用）
   ============================================================ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(24, 24, 27, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  overflow-y: auto;
  animation: modalBackdropFade 0.2s ease;
}
@keyframes modalBackdropFade {
  from { opacity: 0; backdrop-filter: blur(0px); }
  to   { opacity: 1; backdrop-filter: blur(4px); }
}
.modal-backdrop.show { display: flex; }

.modal {
  background: white;
  padding: 0;
  border-radius: 14px;
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 32px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow:
    0 20px 60px rgba(24, 24, 27, 0.25),
    0 4px 12px rgba(0, 0, 0, 0.08);
  animation: modalSlideIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}
@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(-12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* 頂部品牌色細條（從上方延伸）*/
.modal::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 22px 26px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.01em;
}

.modal-close {
  background: none;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
  padding: 0;
  flex-shrink: 0;
}
.modal-close:hover {
  background: rgba(24, 24, 27, 0.06);
  color: var(--text);
}

/* modal 內容區 — 自動 scroll，padding 一致 */
.modal > *:not(.modal-header):not(.modal-footer) {
  padding: 18px 26px;
  overflow-y: auto;
  flex: 1;
}
/* 第一個 padding 已含於 header；body 開頭如果緊接 header 就不重複 */
.modal-header + div,
.modal-header + form { padding-top: 18px; }

.modal-footer {
  margin-top: 0;
  padding: 16px 26px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--border);
  background: #fafafa;
  border-radius: 0 0 14px 14px;
  flex-shrink: 0;
}

/* modal 內表單欄位 — 緊湊版本（各 modal 都受惠）*/
.modal .field { margin-bottom: 14px; }
.modal .field:last-child { margin-bottom: 0; }
.modal label:not(.toggle-switch) {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}
/* label 內含 checkbox / radio 時改回 inline-flex（讓 checkbox 跟文字同行）*/
.modal label:has(> input[type="checkbox"]),
.modal label:has(> input[type="radio"]) {
  display: inline-flex !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  margin-bottom: 0 !important;
}

/* modal 多列欄位 grid helper（HTML 直接用 inline grid 也 OK，這個是 utility）*/
.modal .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal .row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 480px) {
  .modal .row2, .modal .row3 { grid-template-columns: 1fr; }
}

/* 必填星號 */
.required-star { color: #d9534f; margin-left: 2px; }

/* 既有 modal HTML 沒用 .field class（直接 <div><label>...</label></div>）— 自動間距 */
.modal > *:not(.modal-header):not(.modal-footer) > div + div { margin-top: 14px; }

/* color picker 樣式：保持 inline-block 大小固定 */
.modal input[type="color"] { display: inline-block; vertical-align: middle; }

/* Toast */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: #18181b;
  color: white;
  padding: 12px 20px;
  border-radius: 6px;
  z-index: 200;
  display: none;
}
.toast.show { display: block; animation: slideIn 0.3s; }
.toast.error { background: #d9534f; }
@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

/* Quick reply chips */
.qr-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.qr-chip {
  background: #f0e0e0;
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.qr-chip button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
}

/* Empty state */
.empty {
  text-align: center;
  padding: 40px;
  color: var(--muted);
}

/* Image preview */
.img-preview {
  max-width: 200px;
  max-height: 200px;
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-top: 8px;
}

/* ===== 漢堡選單按鈕 + 遮罩（手機版）===== */
.hamburger {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 50;
  width: 40px;
  height: 40px;
  border: none;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  border-radius: 6px;
  cursor: pointer;
  font-size: 20px;
  align-items: center;
  justify-content: center;
}
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
}
.sidebar-backdrop.show { display: block; }

/* 表格水平滾動容器 */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
}

/* ===== Mobile breakpoint ===== */
@media (max-width: 768px) {
  /* Sidebar slide from left */
  .layout { display: block; }
  .hamburger { display: flex; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 45;
    width: 240px;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }

  /* Main 騰出空間 + 縮小 padding */
  .main {
    padding: 56px 16px 16px;  /* 上方留 hamburger 空間 */
  }

  /* Header 縮排 + 換行 */
  .main-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .main-header h1 {
    font-size: 18px;
  }

  /* 卡片 */
  .card { padding: 14px; }
  .card-value { font-size: 22px; }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  /* 表格：強制水平捲動 */
  .table { font-size: 13px; min-width: 600px; }
  .table th, .table td { padding: 8px 10px; }

  /* Modal 全寬 */
  .modal {
    width: 100%;
    max-height: 95vh;
    border-radius: 8px;
    margin: 8px;
  }
  .modal-wide { width: 100%; max-width: none; }

  /* edit-grid 改單欄 */
  .edit-grid { grid-template-columns: 1fr !important; gap: 16px; }

  /* 三欄表單變單欄 */
  .field input, .field textarea, .field select { font-size: 16px; } /* 避免 iOS 自動 zoom */

  /* Login box 縮 */
  .login-box {
    width: 100%;
    margin: 16px;
    padding: 28px 20px;
  }

  /* Buttons */
  /* 手機版只調左右內距 —— 高度一律吃 --btn-h，不可在此重設垂直 padding，
     否則固定高度會被打回「內容撐開」，高低差就回來了。 */
  .btn { padding: 0 16px; font-size: 14px; }
  .btn-sm { padding: 6px 10px; font-size: 12px; }

  /* Toast 全寬置中 */
  .toast {
    top: 16px;
    left: 16px;
    right: 16px;
    text-align: center;
  }

  /* RichMenu 預覽圖縮放 */
  .rm-grid { grid-template-columns: 1fr !important; }
}

/* 平板 — 中間尺寸略調整 */
@media (max-width: 1024px) and (min-width: 769px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .main { padding: 24px; }
}

/* ===== Wide modal with two-column layout ===== */
.modal-wide {
  max-width: 1100px;
  width: 95%;
}

.edit-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 24px;
}

@media (max-width: 900px) {
  .edit-grid { grid-template-columns: 1fr; }
}

/* ===== Quick Reply editor ===== */
.qr-editor {
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

.qr-cards {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.qr-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.qr-card-main {
  flex: 1;
  min-width: 0;
}

.qr-card-label {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.qr-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  font-size: 11px;
}

.qr-card-value {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.qr-type-pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
}
.qr-type-message  { background: #d4eed4; color: #2d6d2d; }
.qr-type-postback { background: #d4dbf0; color: #2d3f80; }
.qr-type-uri      { background: #f0e0d4; color: #804020; }

.qr-card-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.btn-icon {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover:not(:disabled) { background: #f5f5f5; }
.btn-icon:disabled { opacity: 0.3; cursor: not-allowed; }
.btn-icon-danger { color: #b94440; }
.btn-icon-danger:hover:not(:disabled) { background: #fee; }

/* Inline QR form */
.qr-form-card {
  background: white;
  border: 1px solid var(--primary);
  border-radius: 6px;
  padding: 12px;
  margin-top: 8px;
}
.qr-form-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.qr-form-card input, .qr-form-card select {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
}

/* ===== LINE phone preview ===== */
.preview-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  text-align: center;
}

.phone-mockup {
  background: #7a90b0;
  border-radius: 24px;
  padding: 12px 8px 18px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.phone-header {
  background: white;
  border-radius: 6px;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13px;
  color: #333;
  margin-bottom: 8px;
}

.phone-body {
  background: #8da4c1;
  min-height: 360px;
  border-radius: 4px;
  padding: 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bubble {
  padding: 10px 12px;
  border-radius: 12px;
  max-width: 78%;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.bot-bubble {
  background: white;
  align-self: flex-start;
  color: #333;
}

.bubble-image {
  max-width: 100%;
  border-radius: 6px;
  display: block;
}

.qr-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  padding: 0 4px;
}

.qr-chip-preview {
  background: white;
  color: #2c5282;
  border: 1px solid #cbd5e0;
  border-radius: 16px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Phone RWD hardening (≤600px, appended last) — desktop ≥601 untouched ===== */
@media (max-width: 600px) {
  html, body { overflow-x: hidden; max-width: 100%; }
  .main { overflow-x: hidden; }
  /* 統計卡片:2 欄緊湊磚塊 */
  .stats-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
  .stats-grid .card { padding: 12px 14px; }
  .stats-grid .card-value { font-size: 20px; }
  /* 卡片內任何元素都不得超出卡片;長字 / 網址換行 */
  .card { min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
  .card * { max-width: 100% !important; }
  .card [style*="min-width"] { min-width: 0 !important; }
  /* 卡片內的橫向 flex 列(標題+狀態、數字+進度條)在窄螢幕換行 */
  .card > div[style*="flex"] { flex-wrap: wrap !important; }
  img, canvas, video { max-width: 100%; height: auto; }
  /* 升級教學表格改成可獨立左右捲,不撐破卡片 */
  #quota-card table { display: block; overflow-x: auto; white-space: nowrap; max-width: 100%; }
  #quota-card summary { white-space: normal; }
}

