/* ============== 基礎與重設 ============== */
* { box-sizing: border-box; }
html, body { height: 100%; }

/* HTML5 [hidden] 必須強制 display:none，
   否則 .login-section / .loading-state / .tab-nav / .admin-info / .drawer
   等明確設定 display: flex 的 selector 會 override 掉 [hidden] 屬性，
   造成「明明 element.hidden = true 卻仍然顯示」的 bug。 */
[hidden] { display: none !important; }
body {
  font-family: "Microsoft JhengHei", "PingFang TC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin: 0;
  padding: 0;
  background: #f5f5f7;
  color: #1f2329;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; }
button { font-family: inherit; }

/* ============== 顏色與設計變數 ============== */
:root {
  --shopee: #ee4d2d;
  --shopee-dark: #d73c1e;
  --shopee-light: #fff1ed;
  --border: #e8e8ec;
  --border-strong: #d9d9de;
  --text: #1f2329;
  --text-muted: #6b7180;
  --text-faint: #9ba1ab;
  --bg-card: #ffffff;
  --bg-hover: #f8f8fa;
  --success: #2eb872;
  --warning: #ff9800;
  --danger: #f5222d;
  --info: #1890ff;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --radius: 8px;
  --radius-sm: 4px;
}

/* ============== Header ============== */
.app-header {
  background: linear-gradient(90deg, var(--shopee) 0%, var(--shopee-dark) 100%);
  color: #fff;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.25);
}
.brand h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

/* Tabs */
.tab-nav {
  display: flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.15);
  padding: 4px;
  border-radius: var(--radius);
}
.tab-btn {
  background: transparent;
  color: rgba(255, 255, 255, 0.9);
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s;
}
.tab-btn:hover { background: rgba(255, 255, 255, 0.15); }
.tab-btn.active {
  background: #fff;
  color: var(--shopee);
}

/* Admin info */
.admin-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.admin-email {
  background: rgba(255, 255, 255, 0.18);
  padding: 5px 12px;
  border-radius: 999px;
  font-weight: 500;
}

/* Buttons */
.btn-ghost {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35);
  padding: 5px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.3); }

/* 工具列裡的 btn-ghost 是深色 */
.toolbar .btn-ghost,
.page-header .btn-ghost,
.pagination .btn-ghost {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border-strong);
}
.toolbar .btn-ghost:hover,
.page-header .btn-ghost:hover,
.pagination .btn-ghost:hover {
  background: var(--bg-hover);
  border-color: var(--shopee);
  color: var(--shopee);
}
.toolbar .btn-ghost:disabled,
.pagination .btn-ghost:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ============== Main ============== */
.app-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

/* ============== 登入畫面 ============== */
.login-section {
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: #fff;
  padding: 40px 48px;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  max-width: 380px;
  width: 100%;
}
.login-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--shopee), var(--shopee-dark));
  color: #fff;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
}
.login-card h2 {
  font-size: 22px;
  margin-bottom: 8px;
}
.login-sub {
  color: var(--text-muted);
  margin: 0 0 24px;
}
.btn-google {
  background: #4285f4;
  color: #fff;
  border: none;
  padding: 11px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s;
}
.btn-google:hover { background: #3367d6; }
.login-hint {
  margin: 16px 0 0;
  color: var(--text-faint);
  font-size: 12px;
}

/* ============== 統計卡片 ============== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--bg-card);
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--shopee);
}
.stat-card[data-tone="trial"]::before { background: var(--warning); }
.stat-card[data-tone="active"]::before { background: var(--success); }
.stat-card[data-tone="disabled"]::before { background: var(--danger); }
.stat-card[data-tone="expired"]::before { background: var(--text-faint); }
.stat-card[data-tone="expiring"]::before { background: #ff5722; }
.stat-card[data-tone="new"]::before { background: var(--info); }
.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

/* ============== 工具列 ============== */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.search-input,
.select {
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-input { min-width: 220px; }
.search-input:focus,
.select:focus {
  border-color: var(--shopee);
  box-shadow: 0 0 0 3px rgba(238, 77, 45, 0.15);
}
.result-count {
  color: var(--text-muted);
  font-size: 13px;
}

/* ============== Page header (logs 頁) ============== */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.page-header h2 {
  font-size: 18px;
  color: var(--text);
}

/* ============== 表格 ============== */
.table-wrapper {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  position: relative;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th,
.data-table td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th {
  background: #fafafa;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.data-table th.sortable {
  cursor: pointer;
  user-select: none;
}
.data-table th.sortable:hover { color: var(--shopee); }
.sort-ind {
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 4px;
  vertical-align: middle;
}
.data-table th.sort-asc .sort-ind {
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 5px solid var(--shopee);
}
.data-table th.sort-desc .sort-ind {
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--shopee);
}
.data-table tbody tr {
  transition: background 0.1s;
  cursor: pointer;
}
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .col-email {
  color: var(--text);
  font-weight: 500;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.data-table .col-actions { white-space: nowrap; }
.data-table .col-actions button { margin-right: 4px; }

/* ============== 狀態 Badge ============== */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
}
.badge-trial    { background: #fff4e0; color: #d77a00; }
.badge-active   { background: #e6f7ec; color: #0d9852; }
.badge-disabled { background: #ffeded; color: #cf1322; }
.badge-expired  { background: #efeff2; color: #666; }
.badge-expiring { background: #fff1ed; color: #d73c1e; }

/* ============== 動作按鈕 ============== */
.btn {
  border: 1px solid transparent;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s;
  background: #fff;
}
.btn-primary {
  background: var(--shopee);
  color: #fff;
  border-color: var(--shopee);
}
.btn-primary:hover { background: var(--shopee-dark); border-color: var(--shopee-dark); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { filter: brightness(0.92); }
.btn-danger  { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { filter: brightness(0.92); }
.btn-info    { background: var(--info); color: #fff; border-color: var(--info); }
.btn-info:hover { filter: brightness(0.92); }
.btn-outline {
  background: #fff;
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-outline:hover { border-color: var(--shopee); color: var(--shopee); }
.btn-icon {
  background: transparent;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text); }

/* ============== 載入 / 空狀態 / 錯誤 ============== */
.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px;
  color: var(--text-muted);
}
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--shopee);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-faint);
  font-size: 14px;
}
.error-state {
  padding: 16px;
  margin: 16px;
  background: #fff1f0;
  border: 1px solid #ffccc7;
  color: #cf1322;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

/* ============== 分頁 ============== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px 0;
}
.page-info {
  color: var(--text-muted);
  font-size: 13px;
}

/* ============== 抽屜 ============== */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 90;
  animation: fadeIn 0.15s ease;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(520px, 100vw);
  background: #fff;
  z-index: 100;
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.16);
  display: flex;
  flex-direction: column;
  animation: slideIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.drawer-header h3 {
  font-size: 16px;
  color: var(--text);
}
.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.detail-section {
  margin-bottom: 20px;
}
.detail-section h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.detail-grid {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 8px 12px;
  font-size: 13px;
}
.detail-grid dt { color: var(--text-muted); }
.detail-grid dd { margin: 0; color: var(--text); word-break: break-all; }

.action-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin: 6px 0;
  flex-wrap: wrap;
}
.action-row input[type="number"],
.action-row input[type="date"] {
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13px;
  width: 100px;
}
.action-row input:focus {
  outline: none;
  border-color: var(--shopee);
  box-shadow: 0 0 0 3px rgba(238, 77, 45, 0.15);
}

.note-area {
  width: 100%;
  min-height: 80px;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  resize: vertical;
}
.note-area:focus {
  outline: none;
  border-color: var(--shopee);
  box-shadow: 0 0 0 3px rgba(238, 77, 45, 0.15);
}

.logs-list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.logs-list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.logs-list li:last-child { border-bottom: none; }
.log-action {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 4px;
  background: var(--shopee-light);
  color: var(--shopee);
  font-size: 11px;
  font-weight: 600;
  margin-right: 6px;
}
.log-time { color: var(--text-muted); font-size: 12px; }
.log-payload {
  color: var(--text-muted);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  margin-top: 4px;
  word-break: break-all;
}

/* ============== Toast ============== */
.toast-container {
  position: fixed;
  top: 80px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: #1f2329;
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  min-width: 200px;
  max-width: 360px;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn 0.2s ease;
  pointer-events: auto;
}
.toast.toast-success { background: var(--success); }
.toast.toast-error   { background: var(--danger); }
.toast.toast-info    { background: var(--info); }
@keyframes toastIn {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.toast.fade-out { animation: toastOut 0.2s ease forwards; }
@keyframes toastOut {
  to { transform: translateX(20px); opacity: 0; }
}

/* ============== Responsive ============== */
@media (max-width: 768px) {
  .app-main { padding: 16px; }
  .header-inner { padding: 12px 16px; }
  .brand h1 { font-size: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-value { font-size: 20px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-left, .toolbar-right { width: 100%; }
  .search-input { flex: 1; min-width: 0; }
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 8px 10px; }
  .drawer { width: 100vw; }
  .detail-grid { grid-template-columns: 90px 1fr; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .admin-info { font-size: 12px; }
  .admin-email { padding: 3px 8px; }
}
