/* 喜翻親子感統遊戲空間 — 會員點數系統 */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --primary: #e07575;
  --primary-dark: #c45c5c;
  --primary-light: #f9eded;
  --accent: #6dba98;
  --accent-light: #eaf6f0;
  --warm: #f5c97a;
  --bg: #fdf8f2;
  --card: #ffffff;
  --text: #3d3a38;
  --muted: #8a8078;
  --border: #ede6dc;
  --green: #3aaa6a;
  --red: #e05050;
  --shadow: 0 2px 12px rgba(0,0,0,.07);
  --shadow-lg: 0 4px 24px rgba(0,0,0,.10);
  --radius: 16px;
  --radius-sm: 10px;
}
body {
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  min-height: 100vh;
}

/* ── 容器 ── */
.container { max-width: 520px; margin: 0 auto; padding: 16px; }
.container.wide { max-width: 1000px; }

/* ── 頂部導覽 ── */
header.topbar {
  background: linear-gradient(135deg, var(--primary) 0%, #d4697b 100%);
  color: #fff;
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(224,117,117,.25);
}
header.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
header.topbar .brand img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,.5);
  flex-shrink: 0;
}
header.topbar h1 {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
}
header.topbar h1 small {
  display: block;
  font-size: 0.7rem;
  font-weight: 400;
  opacity: .8;
}
header.topbar .user-info {
  font-size: 0.82rem;
  display: flex;
  gap: 8px;
  align-items: center;
}
header.topbar button {
  background: rgba(255,255,255,.22);
  border: 1px solid rgba(255,255,255,.35);
  color: #fff;
  padding: 5px 12px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.82rem;
  transition: background .15s;
}
header.topbar button:hover { background: rgba(255,255,255,.35); }

/* ── 卡片 ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(237,230,220,.6);
}
.card h2 {
  font-size: 1rem;
  margin-bottom: 14px;
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── 表單 ── */
label {
  display: block;
  font-size: 0.88rem;
  margin-bottom: 4px;
  color: var(--muted);
  font-weight: 500;
}
input, select {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  margin-bottom: 12px;
  background: #fff;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(224,117,117,.12);
}
.input { /* modal 裡的 input 用 class 方式套 */ }

/* ── 按鈕 ── */
button.btn {
  width: 100%;
  padding: 12px 16px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, transform .08s;
  letter-spacing: .03em;
}
button.btn:hover { background: var(--primary-dark); }
button.btn:active { transform: scale(.98); }
button.btn:disabled { background: #d6d3d1; cursor: not-allowed; }
button.btn.secondary {
  background: #fff;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
button.btn.secondary:hover { background: var(--primary-light); }
button.btn.accent { background: var(--accent); }
button.btn.accent:hover { background: #5aaa85; }
button.btn.small { width: auto; padding: 5px 14px; font-size: 0.82rem; font-weight: 600; }
button.btn.danger { background: var(--red); }

/* ── 訊息提示 ── */
.msg {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-size: 0.9rem;
  display: none;
  border-left: 3px solid;
}
.msg.error { background: #fef2f2; color: var(--red); border-color: var(--red); display: block; }
.msg.success { background: #f0fdf4; color: var(--green); border-color: var(--green); display: block; }

/* ── 餘額顯示 ── */
.balance-big { text-align: center; padding: 10px 0 6px; }
.balance-big .num {
  font-size: 3.2rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.1;
}
.balance-big .label { color: var(--muted); font-size: 0.88rem; margin-top: 2px; }
.expiring-note {
  text-align: center;
  font-size: 0.85rem;
  color: var(--red);
  margin-top: 6px;
  padding: 6px 12px;
  background: #fef2f2;
  border-radius: 8px;
}

/* ── QR Code ── */
#qrcode { display: flex; justify-content: center; padding: 10px 0; }
#qrcode img, #qrcode canvas {
  border: 10px solid #fff;
  border-radius: 10px;
  box-shadow: var(--shadow);
}

/* ── 表格 ── */
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; white-space: nowrap; font-size: 0.8rem; }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.pts-pos { color: var(--green); font-weight: 700; }
.pts-neg { color: var(--red); font-weight: 700; }

/* ── 分頁籤 ── */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  padding: 9px 18px;
  border: 1.5px solid var(--border);
  background: #fff;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--muted);
  white-space: nowrap;
  border-bottom: none;
  transition: background .15s, color .15s;
}
.tabs button:hover { background: var(--primary-light); color: var(--primary); }
.tabs button.active {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  border-color: var(--primary);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── 會員卡片 ── */
.member-card {
  border: 2px solid var(--primary-light);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  background: linear-gradient(135deg, #fff 60%, var(--primary-light) 100%);
  box-shadow: var(--shadow);
}
.member-card .name { font-size: 1.15rem; font-weight: 700; }
.member-card .account { color: var(--muted); font-size: 0.85rem; }
.member-card .bal {
  font-size: 1.7rem;
  color: var(--primary);
  font-weight: 800;
  margin-top: 6px;
}

/* ── 搜尋結果 ── */
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.search-result { list-style: none; }
.search-result li {
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.search-result li:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(224,117,117,.12);
}
.preview-hint { font-size: 0.9rem; color: var(--muted); margin-bottom: 12px; }
.preview-hint strong { color: var(--primary); font-size: 1.1rem; }

/* ── QR 掃碼 ── */
#video-wrap { display: none; position: relative; }
#video-wrap video { width: 100%; border-radius: var(--radius); }

/* ── 徽章 ── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge.on { background: #f0fdf4; color: var(--green); }
.badge.off { background: #fef2f2; color: var(--red); }
.badge.role { background: var(--primary-light); color: var(--primary-dark); }

/* ── 登入頁 ── */
.auth-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
  background: linear-gradient(160deg, #fdf8f2 0%, #fdf0f0 100%);
}
.auth-logo {
  margin-bottom: 24px;
  text-align: center;
}
.auth-logo img {
  width: 140px;
  height: 140px;
  object-fit: cover;
  border-radius: 50%;
  box-shadow: 0 4px 20px rgba(224,117,117,.2);
  border: 4px solid #fff;
}
.auth-logo h1 {
  margin-top: 12px;
  font-size: 1.4rem;
  color: var(--primary);
  font-weight: 800;
}
.auth-logo p { color: var(--muted); font-size: 0.88rem; margin-top: 2px; }
.auth-box { width: 100%; max-width: 420px; }
.switch-link { text-align: center; margin-top: 12px; font-size: 0.88rem; }
.switch-link a { color: var(--primary); cursor: pointer; text-decoration: underline; }

/* ── 統計磚塊 ── */
.stat-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.stat-tile {
  background: #fff;
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.stat-tile .v { font-size: 1.5rem; font-weight: 800; color: var(--primary); }
.stat-tile .k { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }

/* ── 登入頁：製作單位署名 ──
   只放在對外的登入頁；會員／店員／後台是登入後的畫面，放了只是雜訊。
   壓在 panda 裝飾與社群浮鈕之下的層級，不搶版面。 */
.site-credit {
  position: relative;
  z-index: 1;
  margin: 28px auto 18px;
  text-align: center;
  font-size: .74rem;
  color: var(--muted);
}
.site-credit a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: .18em;
  opacity: .85;
}
.site-credit a:hover { opacity: 1; }

/* ── 登入頁 panda 裝飾 ── */
.auth-panda {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 180px;
  opacity: .18;
  pointer-events: none;
  user-select: none;
}

.social-fab {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: #3a5a40;
  border-radius: 999px;
  padding: 10px 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.social-fab a {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  border-radius: 50%;
  transition: background .15s;
}
.social-fab a:hover { background: rgba(255,255,255,.15); }
.social-fab svg { width: 20px; height: 20px; }

/* ── 共用小元件 ── */
html { -webkit-text-size-adjust: 100%; }
button, [role="button"] { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button.btn, .tabs button, header.topbar button { white-space: nowrap; }
.field-hint { font-size: 0.8rem; color: var(--muted); margin: -6px 0 12px; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; list-style: none; }
.cell-actions { white-space: nowrap; }
input[type="date"], input[type="datetime-local"] {
  -webkit-appearance: none;
  appearance: none;
  min-height: 46px;
  min-width: 0;
  text-align: left;
  display: block;
}
input[type="search"] { -webkit-appearance: none; appearance: none; }
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }
.modal-box { max-height: calc(100dvh - 32px); overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ── 分段式分頁籤（平均分配寬度，不會被切掉） ── */
.tabs.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  background: #f3ebe2;
  border-radius: 14px;
  overflow: visible;
}
.tabs.seg button {
  border: none;
  border-radius: 10px;
  background: transparent;
  padding: 10px 4px;
  font-size: 0.92rem;
  color: var(--muted);
  font-weight: 600;
}
.tabs.seg button:hover { background: rgba(255,255,255,.6); color: var(--primary-dark); }
.tabs.seg button.active { background: #fff; color: var(--primary-dark); box-shadow: 0 1px 4px rgba(0,0,0,.08); }

/* ── 會員列表工具列 ── */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; align-items: stretch; }
.toolbar > .btn { width: auto; padding: 0 20px; }
.search-box { flex: 1; display: flex; gap: 8px; }
.search-box input { margin: 0; flex: 1; min-width: 0; }
.search-box .btn.small { padding: 0 18px; }

/* ── Excel 風格表格 ── */
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.xl-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid #d9d0c4;
  border-radius: 8px;
  background: #fff;
}
table.xl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.92rem; }
table.xl th, table.xl td {
  padding: 9px 12px;
  border-right: 1px solid #e6ddd1;
  border-bottom: 1px solid #e6ddd1;
  white-space: nowrap;
  text-align: left;
  vertical-align: middle;
  background: #fff;
}
table.xl th:last-child, table.xl td:last-child { border-right: none; }
table.xl tbody tr:last-child td { border-bottom: none; }
table.xl thead th {
  background: #f3ebe2;
  color: #6b625b;
  font-size: 0.82rem;
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 2;
}
table.xl tbody tr:nth-child(even) td { background: #fcfaf7; }
table.xl .num { text-align: right; font-variant-numeric: tabular-nums; }
/* 第一欄固定在左邊，左右滑時還看得到是誰 */
table.xl .sticky { position: sticky; left: 0; z-index: 1; box-shadow: 1px 0 0 #d9d0c4; }
table.xl thead .sticky { z-index: 3; }
table.xl td.empty { text-align: center; color: var(--muted); padding: 22px 12px; white-space: normal; }
.xl-link { max-width: 9em; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; color: var(--primary-dark); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; display: inline-block; padding: 4px 0; }
.xl-del {
  background: none;
  border: 1px solid #f0c9c9;
  color: var(--red);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.82rem;
  min-height: 32px;
  cursor: pointer;
}
.xl-hint { font-size: 0.78rem; color: var(--muted); margin: 6px 2px 0; }
button.btn.danger-outline { background: #fff; color: var(--red); border: 1.5px solid #f0c9c9; margin: 4px 0 20px; }

/* ── 頂端的返回／重新整理 ── */
header.topbar button.nav-btn { background: rgba(255,255,255,.95); color: var(--primary-dark); font-weight: 700; border-color: transparent; }
header.topbar button.nav-btn:disabled { opacity: .45; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; }
.pager span { color: var(--muted); font-size: 0.9rem; }

/* ── 會員詳情 ── */
#mm-detail { max-width: 640px; margin: 0 auto; }
.profile .p-name { font-size: 1.35rem; font-weight: 800; line-height: 1.3; word-break: break-all; }
.profile .p-phone { color: var(--muted); font-size: 0.9rem; }
.p-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.p-stat { border-radius: 12px; padding: 12px; text-align: center; background: var(--primary-light); }
.p-stat + .p-stat { background: var(--accent-light); }
.p-stat .v { font-size: 1.8rem; font-weight: 800; color: var(--primary); line-height: 1.1; }
.p-stat + .p-stat .v { color: var(--green); }
.p-stat .k { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.p-last { margin-top: 12px; font-size: 0.9rem; color: var(--text); }


.seg-btns { display: flex; gap: 8px; margin-bottom: 12px; }
.seg-btns .btn { flex: 1; }

/* ── 手機（iPhone 寬度約 360～440px） ── */
@media (max-width: 639px) {
  body { padding-bottom: env(safe-area-inset-bottom); }
  .container, .container.wide {
    padding: 12px max(14px, env(safe-area-inset-right)) 24px max(14px, env(safe-area-inset-left));
  }
  .card { padding: 16px; }

  /* 頂端列：一行就好，名字收起來 */
  header.topbar {
    padding: calc(8px + env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left));
  }
  header.topbar h1 small, header.topbar #user-name { display: none; }
  header.topbar .brand img { display: none; }
  header.topbar .user-info { gap: 6px; }
  table.xl { font-size: 0.9rem; }
  table.xl th, table.xl td { padding: 9px 10px; }
  header.topbar button { min-height: 36px; padding: 6px 12px; }

  button.btn.small { min-height: 44px; padding: 8px 14px; font-size: 0.92rem; }
  .tabs.seg button { font-size: 0.86rem; padding: 10px 2px; }

  /* 並排欄位改直排，標籤不會被擠到斷行 */
  .row.form-row { flex-direction: column; gap: 0; }

  .toolbar { flex-direction: column; }
  .toolbar > .btn { width: 100%; padding: 13px; }

  /* 彈窗改從底部滑出 */
  .modal { align-items: flex-end !important; }
  .modal .modal-box {
    width: 100% !important;
    max-width: none !important;
    border-radius: 18px 18px 0 0 !important;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom)) !important;
    max-height: 88dvh;
  }

  /* 報表／帳號表格改卡片 */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 10px;
    background: #fff;
  }
  table.stack td {
    border: none;
    padding: 3px 0;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 0.92rem;
    text-align: right;
  }
  table.stack td[data-label]::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.82rem;
    text-align: left;
    flex-shrink: 0;
    font-weight: 400;
  }
  table.stack td[colspan] { justify-content: center; }
  table.stack td.cell-title {
    font-weight: 700;
    font-size: 1rem;
    text-align: left;
    padding-bottom: 6px;
    margin-bottom: 4px;
    border-bottom: 1px dashed var(--border);
  }
  table.stack td.cell-actions { justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding-top: 8px; }
  /* 報表：數字兩欄並排，短一點 */
  table.stack.grid2 tr { display: grid; grid-template-columns: 1fr 1fr; column-gap: 14px; }
  table.stack.grid2 td.cell-title, table.stack.grid2 td[colspan] { grid-column: 1 / -1; }
  table.stack.grid2 td { width: auto; }
}

/* ── Desktop 增強 ── */
@media (min-width: 640px) {
  .stat-row { grid-template-columns: repeat(4, 1fr); }
  .auth-logo img { width: 160px; height: 160px; }
  .auth-logo h1 { font-size: 1.6rem; }
  header.topbar { padding: 10px 24px; }
  header.topbar h1 { font-size: 1.1rem; }
  header.topbar .brand img { width: 40px; height: 40px; }
  .auth-panda { width: 260px; opacity: .22; }
}

@media (min-width: 900px) {
  .container.wide { padding: 20px 24px; }
  .tabs button { padding: 10px 22px; font-size: 0.92rem; }
  .card { padding: 24px; }
  .auth-panda { width: 320px; }
}

@media (max-width: 479px) {
  header.topbar h1 { display: none; }
}

/* ── 頁尾版本號 ── */
.app-version { text-align: center; font-size: 0.75rem; color: var(--muted); margin: 18px 0 8px; }
