/* ==========================================================================
   奈平方雙牌組練習器後台 — Admin Dashboard Styles
   設計風格：shadcn/ui 精神（Zinc 中性色系 + 精準邊框 + 工程師克制美學）
   ========================================================================== */

:root {
  --bg:            #fafafa;
  --card:          #ffffff;
  --border:        #e4e4e7;
  --border-focus:  #a1a1aa;
  --text:          #09090b;
  --muted:         #71717a;
  --subtle:        #a1a1aa;
  --accent-bg:     #f4f4f5;
  --primary:       #18181b;
  --primary-fg:    #ffffff;
  --ring:          rgba(24, 24, 27, 0.12);
  --danger:        #dc2626;
  --danger-bg:     #fef2f2;
  --danger-border: #fecaca;

  --radius-card:   8px;
  --radius-inner:  6px;
  --radius-btn:    6px;

  --font:  "Inter", "Noto Sans TC", -apple-system, BlinkMacSystemFont, sans-serif;
  --mono:  "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ==========================================================================
   頂部導覽列 (Navbar)
   ========================================================================== */

.admin-navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  margin-bottom: 0;
}

.admin-nav-brand {
  display: flex;
  align-items: center;
  margin-right: auto;
}

.admin-brand-text {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.admin-nav-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.admin-nav-link {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: var(--radius-inner);
  transition: background 0.15s, color 0.15s;
  display: inline-block;
}

.admin-nav-link:hover {
  background: var(--accent-bg);
  color: var(--text);
}

.admin-nav-link.active {
  background: var(--primary);
  color: var(--primary-fg);
  font-weight: 600;
  cursor: default;
  pointer-events: none;
}

.admin-nav-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 8px;
  display: inline-block;
}

.admin-nav-logout {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-inner);
  padding: 5px 12px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
  margin-left: 6px;
}

.admin-nav-logout:hover {
  color: var(--text);
  border-color: var(--border-focus);
}

/* ==========================================================================
   頁面主容器
   ========================================================================== */

.admin-container {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

/* ==========================================================================
   頁首大標題 (Page Header)
   ========================================================================== */

.admin-header {
  margin-bottom: 28px;
}

.admin-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 4px;
}

.admin-subtitle {
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.5;
}

/* ==========================================================================
   主版面：雙欄網格
   ========================================================================== */

.admin-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

@media (max-width: 860px) {
  .admin-grid { grid-template-columns: 1fr; }
}

/* ==========================================================================
   模組卡片 (Card)
   ========================================================================== */

.admin-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  overflow: hidden;
}

.admin-card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.admin-card-body {
  padding: 20px;
}

/* 向下相容：舊版直接用 .admin-card 不含 header/body 結構的 padding */
.admin-card > .admin-card-title {
  padding: 16px 20px 0;
  border-bottom: none;
}

.admin-card-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  margin-bottom: 0;
}

.admin-card-desc {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
}

.admin-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* magic link 輸入框 */
.magic-link-input {
  font-size: 12px;
  font-family: var(--mono);
  color: var(--muted);
  background: var(--accent-bg);
}

/* SHA hash 行 */
.hash-row {
  font-size: 11px;
  color: var(--subtle);
  word-break: break-all;
  font-family: var(--mono);
  padding-top: 10px;
  border-top: 1px solid var(--border);
  margin-top: 10px;
}

.hash-row strong {
  font-family: var(--font);
  color: var(--muted);
  font-weight: 600;
}

/* 表格容器（不加 padding，讓表格貼邊） */
.admin-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ==========================================================================
   表單元件
   ========================================================================== */

.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 5px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-select,
.form-input {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-inner);
  background: var(--card);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
}

.form-select:focus,
.form-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--ring);
}

.form-input[readonly] {
  background: var(--accent-bg);
  color: var(--muted);
  cursor: default;
}

/* ==========================================================================
   模式切換 Tab（底線式）
   ========================================================================== */

.mode-tab-group {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  background: none;
  padding: 0;
  border-radius: 0;
  border-top: none;
  border-left: none;
  border-right: none;
}

.mode-tab-btn {
  flex: none;
  height: auto;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: -1px;
  border-radius: 0;
  display: flex;
  align-items: center;
  gap: 5px;
}

.mode-tab-btn:hover {
  color: var(--text);
}

.mode-tab-btn.active {
  color: var(--text);
  font-weight: 600;
  border-bottom-color: var(--text);
  background: none;
  box-shadow: none;
}

/* ==========================================================================
   成果呈現 (Code Display)
   ========================================================================== */

.result-card-inner {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.code-display-wrap {
  background: var(--accent-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-inner);
  padding: 16px 20px;
  text-align: center;
  box-shadow: none;
  position: relative;
}

.code-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}

.code-value {
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
}

.parsed-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border-radius: 0;
  padding: 0;
}

.result-note-badge {
  display: inline-block;
  margin-top: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  background: var(--accent-bg);
  border: 1px dashed var(--border);
  padding: 2px 10px;
  border-radius: 9999px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==========================================================================
   按鈕
   ========================================================================== */

.action-btn-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-primary {
  width: 100%;
  height: 38px;
  background: var(--primary);
  color: var(--primary-fg);
  border: none;
  border-radius: var(--radius-btn);
  font-size: 13.5px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: opacity 0.15s;
  box-shadow: none;
}

.btn-primary:hover {
  opacity: 0.85;
  transform: none;
}

.btn-secondary {
  width: 100%;
  height: 36px;
  background: var(--card);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s;
}

.btn-secondary:hover {
  color: var(--text);
  border-color: var(--border-focus);
  background: var(--accent-bg);
}

/* ==========================================================================
   廣播通知稿
   ========================================================================== */

.broadcast-textarea {
  width: 100%;
  flex: 1;
  min-height: 460px;
  height: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-inner);
  background: var(--accent-bg);
  font-family: var(--font);
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--text);
  resize: none;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.broadcast-textarea:focus {
  border-color: var(--border-focus);
  background: var(--card);
  box-shadow: 0 0 0 3px var(--ring);
}

/* ==========================================================================
   白名單表格
   ========================================================================== */

.whitelist-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 24px;
  padding: 12px 16px 0;
}

.whitelist-tabs { display: flex; gap: 16px; }
.whitelist-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font: 500 13px var(--font);
  cursor: pointer;
}
.whitelist-tab[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--primary);
  font-weight: 700;
}
.whitelist-count {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  padding: 1px 5px;
  border-radius: var(--radius-inner);
  background: var(--accent-bg);
}
.whitelist-search { display: flex; align-items: center; gap: 8px; flex: 0 1 360px; min-width: 0; }
.whitelist-search .form-input { min-width: 0; min-height: 40px; }
.whitelist-search-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.whitelist-clear {
  border: 0;
  background: none;
  color: var(--muted);
  font: 12px var(--font);
  min-height: 44px;
  white-space: nowrap;
  cursor: pointer;
}
.whitelist-clear[hidden] { display: none; }
.whitelist-tab:focus-visible, .whitelist-clear:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-inner);
}
.whitelist-summary { margin: 10px 16px 12px; color: var(--muted); font-size: 12px; }
.whitelist-table .whitelist-empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.whitelist-table .whitelist-row-new td { background: var(--accent-bg); }
.whitelist-new-label {
  display: inline-block;
  margin-left: 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}

@media (max-width: 680px) {
  .whitelist-toolbar { gap: 8px; }
  .whitelist-search { flex-basis: 100%; }
  .whitelist-search .form-input { min-height: 44px; }
  .whitelist-table .whitelist-code { min-width: 0; overflow-wrap: anywhere; }
  .whitelist-table .badge-master-tag { flex-shrink: 0; }
  .whitelist-table .whitelist-row-new { border-color: var(--border-focus); }
}

.whitelist-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 13px;
}

.whitelist-table th,
.whitelist-table td {
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.whitelist-table th {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  background: var(--accent-bg);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.whitelist-table tbody tr:last-child td {
  border-bottom: none;
}

.whitelist-table tbody tr:hover td {
  background: var(--accent-bg);
}

.whitelist-code-cell { overflow-wrap: anywhere; }

.whitelist-code {
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
}

.btn-copy-sm {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-copy-sm:hover {
  color: var(--text);
  border-color: var(--border-focus);
}

/* ==========================================================================
   萬用碼標籤
   ========================================================================== */

.badge-master-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  background: var(--accent-bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  margin-left: 6px;
}

/* ==========================================================================
   Toast 提示
   ========================================================================== */

.toast-notice {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(30px);
  opacity: 0;
  background: var(--primary);
  color: var(--primary-fg);
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  pointer-events: none;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 99999;
  font-family: var(--font);
}

.toast-notice.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ==========================================================================
   講師管理員門禁 (Admin Gatekeeper Overlay)
   ========================================================================== */

body.admin-locked .admin-container {
  display: none !important;
}

.admin-gatekeeper-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100000;
  padding: 20px;
}

body.admin-locked .admin-gatekeeper-backdrop {
  display: flex !important;
}

.admin-gatekeeper-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px 28px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  animation: adminModalPop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.admin-gatekeeper-card .form-input {
  height: 48px;
  font-size: 16px;
  border-radius: 8px;
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
  -webkit-appearance: none;
}

@keyframes adminModalPop {
  0%   { opacity: 0; transform: scale(0.96) translateY(6px); }
  100% { opacity: 1; transform: scale(1)    translateY(0);   }
}

.admin-gatekeeper-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}

.admin-gatekeeper-subtitle {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 24px;
}

.admin-gatekeeper-error {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger);
  padding: 8px 14px;
  border-radius: var(--radius-inner);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 14px;
}

/* ==========================================================================
   登出按鈕（nav 內）
   ========================================================================== */

/* .admin-nav-logout 已在 Navbar 區段定義 */

/* ==========================================================================
   管理後台行動與平板響應式優化 (Admin Responsive)
   ========================================================================== */
@media (max-width: 768px) {
  .admin-navbar {
    padding: 0 12px;
    height: auto;
    min-height: 48px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
  }

  .admin-nav-brand {
    flex-shrink: 0;
  }

  .admin-brand-text {
    font-size: 13px;
  }

  .admin-nav-actions {
    flex-shrink: 0;
    gap: 4px;
  }

  .admin-nav-link {
    padding: 4px 8px;
    font-size: 12px;
    white-space: nowrap;
  }

  .admin-nav-logout {
    padding: 3px 8px;
    font-size: 12px;
    white-space: nowrap;
    margin-left: 2px;
  }

  .admin-container {
    padding: 20px 12px 60px;
    max-width: 100%;
    box-sizing: border-box;
  }

  .admin-header {
    margin-bottom: 20px;
  }

  .admin-title {
    font-size: 20px;
  }

  .admin-subtitle {
    font-size: 12.5px;
  }

  .admin-card-header {
    padding: 14px 16px;
  }

  .admin-card-header > div {
    flex-wrap: wrap;
    gap: 8px;
  }

  .admin-card-body {
    padding: 16px 14px;
  }

  .broadcast-textarea {
    min-height: 300px !important;
  }

  .parsed-badge {
    display: inline-block;
    word-break: break-word;
    line-height: 1.45;
  }
}

/* 手機版專屬深雕 (Mobile <= 680px) */
@media (max-width: 680px) {
  /* 頂部導覽列：轉為上下兩層，徹底杜絕按鈕截斷或滑動出界 */
  .admin-navbar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    height: auto;
    padding: 10px 12px 10px;
    gap: 8px;
    overflow-x: hidden;
  }

  .admin-nav-brand {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-right: 0;
  }

  .admin-brand-text {
    font-size: 13.5px;
    font-weight: 700;
  }

  .admin-nav-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: var(--accent-bg);
    padding: 3px;
    border-radius: var(--radius-inner);
    gap: 2px;
    overflow-x: visible;
  }

  .admin-nav-sep {
    display: none;
  }

  .admin-nav-link {
    flex: 1 1 0;
    text-align: center;
    padding: 6px 3px;
    font-size: 11.5px;
    white-space: nowrap;
    border-radius: 4px;
    justify-content: center;
    display: inline-flex;
    align-items: center;
  }

  .admin-nav-logout {
    padding: 4px 8px;
    font-size: 11.5px;
    margin-left: 2px;
    background: var(--card);
    flex-shrink: 0;
  }

  /* 雲端通關碼清單：由 720px 寬表格轉化為原生行動卡片清單（Card List），徹底解決欄位被切掉 */
  .admin-table-wrap {
    overflow-x: visible;
    padding: 4px 0;
  }

  .whitelist-table {
    min-width: 0 !important;
    width: 100% !important;
    display: block;
  }

  .whitelist-table thead {
    display: none !important;
  }

  .whitelist-table tbody {
    display: block;
    width: 100%;
  }

  /* 單筆卡片化 */
  .whitelist-table tbody tr {
    display: block;
    margin: 10px 12px 14px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-inner);
    background: var(--card);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
  }

  .whitelist-table tbody tr:last-child {
    margin-bottom: 12px;
  }

  /* 空狀態／載入中提示文字：寬度 100% 自然換行置中，絕不超出卡片邊界 */
  .whitelist-table td[colspan="5"] {
    display: block !important;
    width: 100% !important;
    text-align: center !important;
    white-space: normal !important;
    padding: 24px 14px !important;
    box-sizing: border-box;
    font-size: 13px !important;
    line-height: 1.6;
    color: var(--muted) !important;
    border: none !important;
    background: transparent !important;
  }

  /* 單筆資料的各欄位排版 */
  .whitelist-table tbody tr td:not([colspan]) {
    display: block;
    width: 100% !important;
    padding: 0 !important;
    border: none !important;
    white-space: normal !important;
  }

  /* 第 1 欄：通關碼大字 ＋ VIP 標籤 */
  .whitelist-table tbody tr td:nth-child(1) {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
  }

  .whitelist-table .whitelist-code {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.02em;
  }

  /* 第 2 欄：開課名稱與期數 */
  .whitelist-table tbody tr td:nth-child(2) {
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.45;
    color: var(--text);
    margin-bottom: 10px;
    padding-bottom: 8px !important;
    border-bottom: 1px dashed var(--border) !important;
  }

  /* 第 3 欄：建立日期 */
  .whitelist-table tbody tr td:nth-child(3) {
    font-size: 11.5px;
    color: var(--muted);
    display: inline-block;
    width: auto !important;
    margin-right: 12px;
    margin-bottom: 8px;
  }

  .whitelist-table tbody tr td:nth-child(3)::before {
    content: "建立時間：";
    color: var(--subtle);
  }

  /* 第 4 欄：狀態 */
  .whitelist-table tbody tr td:nth-child(4) {
    display: inline-block;
    width: auto !important;
    margin-bottom: 8px;
  }

  /* 第 5 欄：操作按鈕區 */
  .whitelist-table tbody tr td:nth-child(5) {
    display: flex !important;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    text-align: right !important;
    margin-top: 4px;
    padding-top: 10px !important;
    border-top: 1px solid var(--border) !important;
  }

  .whitelist-table tbody tr td:nth-child(5) .btn-copy-sm {
    padding: 6px 14px !important;
    font-size: 12.5px !important;
    min-height: 32px;
    border-radius: 6px;
  }
}

@media (max-width: 480px) {
  .admin-card-header > div {
    flex-wrap: wrap;
    gap: 8px;
  }

  .form-row-2 {
    grid-template-columns: 1fr;
  }

  .code-display-wrap {
    padding: 12px 14px;
  }

  .code-value {
  overflow-wrap: anywhere;
    font-size: 19px;
    word-break: break-all;
  }

  .mode-tab-btn {
    padding: 8px 12px;
    font-size: 12.5px;
  }
}
