/* ══════════════════════════════════════════════════════════════
   identity.css — 帳號系統專屬樣式
   刻意不重複定義 body / .container / .card / .btn / .badge 這些
   style.css 已經有的基礎元件，全部沿用網站既有的設計語彙
   （--brand / --surface / --border / --radius / --shadow ...），
   這裡只放「帳號系統才有」的元件：頂欄、分頁籤、九宮格手勢、
   知識庫卡片、Modal、表格在手機上的卡片化。
   ══════════════════════════════════════════════════════════════ */

/* ── 置中版面（登入 / 註冊 / 管理者登入）── */
.id-center-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}
.id-auth-card { width: 100%; max-width: 400px; }
.id-auth-card h1 { text-align: center; }
.id-auth-switch { text-align: center; font-size: 14px; margin-top: 16px; }

/* ── 頂欄（登入後的頁面：/dashboard、/admin）── */
.id-topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 64px; padding: 0 4px;
}
.id-topbar .id-topbar-title { font-weight: 800; font-size: 20px; }
.id-topbar a { color: var(--brand); font-weight: 600; }

/* ── 分頁籤 ── */
.id-tabs {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px;
  overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px;
}
.id-tabs button {
  white-space: nowrap; background: #fff; color: var(--ink);
  border: 1px solid var(--border);
}
.id-tabs button.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ── 訊息提示 ── */
.id-msg {
  margin-top: 14px; padding: 10px 14px; border-radius: 12px;
  font-size: 13px; display: none; border: 1px solid transparent;
}
.id-msg.ok  { background: #ecfdf3; color: #067647; border-color: #abefc6; }
.id-msg.err { background: #fef3f2; color: #b42318; border-color: #fecdca; }

/* ── 小按鈕變體 ── */
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-danger { background: #dc2626; color: #fff; box-shadow: none; }
.btn-danger:hover { background: #b91c1c; }

/* ── 標籤 / 狀態 chip（沿用 .chip，額外補顏色變體）── */
.chip-status-active  { background: #ecfdf3 !important; color: #067647 !important; border-color: #abefc6 !important; }
.chip-status-disabled{ background: #fef3f2 !important; color: #b42318 !important; border-color: #fecdca !important; }

/* ── 表單元件橫向排列（桌面兩欄，手機自動變一欄）── */
.id-row { display: flex; gap: 12px; align-items: flex-end; }
.id-row > .field { flex: 1; min-width: 0; }
.id-row > button { flex: 0 0 auto; }

/* ── Radio 選項式 chip（平台選擇用，取代原本的 <select>）──
   2026-09-12：「平台綁定」跟「我的客服 Bot」這兩處原本都是 <select>
   下拉選單，選項少（2~4 個）又要常常切換，改成一排像 .chip 一樣的
   圓角選項，選到哪個一眼就看到、也少一次「點開下拉」的動作。 */
.id-radio-group { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0 4px; }
.id-radio-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border: 1px solid var(--border); border-radius: 999px;
  background: #fff; color: var(--ink); font-size: 14px; cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.id-radio-pill input { margin: 0; accent-color: var(--brand); cursor: pointer; }
.id-radio-pill.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.id-radio-pill.active input { accent-color: #fff; }

/* ── 對話 / 記憶預覽 ── */
.id-bubble { padding: 10px 14px; border-radius: 14px; margin: 6px 0; font-size: 14px; max-width: 85%; }
.id-bubble.user { background: var(--brand); color: #fff; margin-left: auto; border-bottom-right-radius: 4px; }
.id-bubble.assistant { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.id-bubble-meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.id-empty { color: var(--muted); font-size: 14px; padding: 16px 0; text-align: center; }

/* ══════════════════════════════════════════════
   九宮格連線手勢
   ══════════════════════════════════════════════ */
.pattern-lock-wrap { display: flex; flex-direction: column; align-items: center; margin: 20px 0 8px; }
.pattern-lock-svg {
  width: 100%; max-width: 260px; aspect-ratio: 1/1; touch-action: none; user-select: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.pattern-dot { fill: var(--border); stroke: var(--muted); stroke-width: 1; transition: r .1s ease; }
.pattern-dot-active { fill: var(--brand); stroke: var(--brand); }
.pattern-line { stroke: var(--brand); stroke-width: 5; stroke-linecap: round; opacity: .85; }
.pattern-lock-hint { font-size: 13px; color: var(--muted); margin-top: 10px; min-height: 18px; text-align: center; }
.pattern-lock-error .pattern-lock-svg { border-color: #dc2626; animation: pattern-shake .3s; }
.pattern-lock-error .pattern-dot-active { fill: #dc2626; stroke: #dc2626; }
.pattern-lock-error .pattern-line { stroke: #dc2626; }
.pattern-lock-disabled .pattern-lock-svg { opacity: .45; pointer-events: none; }
@keyframes pattern-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ══════════════════════════════════════════════
   知識庫管理
   ══════════════════════════════════════════════ */
.rag-chunk-card {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
  margin-bottom: 10px; background: #fff;
}
.rag-chunk-meta {
  font-size: 12px; color: var(--muted); display: flex; justify-content: space-between;
  flex-wrap: wrap; gap: 6px; margin-bottom: 8px;
}
.rag-chunk-preview { font-size: 14px; color: var(--ink); white-space: pre-wrap; max-height: 60px; overflow: hidden; }
.rag-vector-preview { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; color: #b0a08a; }
.rag-chunk-actions { margin-top: 10px; display: flex; gap: 8px; }

.rag-hover-preview {
  display: none; position: fixed; z-index: 999; max-width: 480px; max-height: 400px;
  overflow-y: auto; background: var(--ink); color: #f8fafc; padding: 16px; border-radius: var(--radius);
  box-shadow: var(--shadow); font-size: 13px; line-height: 1.6;
}
.rag-hover-preview h1, .rag-hover-preview h2, .rag-hover-preview h3 { color: #fff; margin: 8px 0 4px; }
.rag-hover-preview p { margin: 4px 0; color: #e5e7eb; opacity: 1; }
.rag-hover-preview table { border-collapse: collapse; width: 100%; font-size: 12px; }
.rag-hover-preview th, .rag-hover-preview td { border: 1px solid #475569; padding: 4px 8px; }
.rag-hover-preview code { background: #334155; padding: 1px 4px; border-radius: 4px; }
@media (max-width: 640px) {
  .rag-hover-preview { display: none !important; } /* 手機沒有 hover，改靠點擊「編輯」看全文 */
}

/* ══════════════════════════════════════════════
   Modal
   ══════════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .55);
  display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px;
}
.modal-box {
  background: #fff; border-radius: var(--radius); padding: 24px; width: 520px; max-width: 100%;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal-box textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
}

/* ══════════════════════════════════════════════
   表格在手機上改卡片式呈現（管理者帳號列表）
   ══════════════════════════════════════════════ */
.id-table-wrap { overflow-x: auto; }
@media (max-width: 720px) {
  table.id-responsive-table thead { display: none; }
  table.id-responsive-table, table.id-responsive-table tbody, table.id-responsive-table tr, table.id-responsive-table td {
    display: block; width: 100%;
  }
  table.id-responsive-table tr {
    border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; padding: 12px;
  }
  table.id-responsive-table td {
    border: none; padding: 6px 0;
  }
  table.id-responsive-table td[data-label]::before {
    content: attr(data-label); display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px;
  }
  table.id-responsive-table td[data-label=""]::before { display: none; }
  table.id-responsive-table input { max-width: 100% !important; }
}

/* ══════════════════════════════════════════════
   小螢幕整體微調
   ══════════════════════════════════════════════ */
@media (max-width: 640px) {
  .id-auth-card { max-width: 100%; }
  .id-row { flex-direction: column; align-items: stretch; }
  .id-topbar { flex-wrap: wrap; height: auto; padding: 12px 0; gap: 8px; }
  .rag-chunk-actions button { flex: 1; }
  .modal-box { padding: 18px; }
}

/* ══════════════════════════════════════════════
   長字串防撐破（Webhook 網址、LINE UID、綁定碼）
   一條沒有空白的長網址會把整頁撐出橫向捲動，
   這裡讓它在卡片裡自己換行，表格維持原本的捲動方式。
   ══════════════════════════════════════════════ */
/* 用 break-word 不用 anywhere：anywhere 會把「最小寬度」也算成一個字寬，
   卡片裡的膠囊鈕（例如平台 LINE／WeChat／Telegram）會被擠成一字一行。
   break-word 只在真的放不下時才斷，不影響其他元件的排版。 */
.card { min-width: 0; overflow-wrap: break-word; }
.id-radio-pill { white-space: nowrap; flex: none; }
.id-row > * { min-width: 0; }
.id-row .chip { max-width: 100%; overflow-wrap: anywhere; word-break: break-all; white-space: normal; }

.code-copy { display: flex; gap: 8px; align-items: stretch; margin-top: 6px; }
.code-box {
  flex: 1 1 auto; min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px; line-height: 1.5;
  padding: 10px 12px;
  background: var(--surface-2, #f6f7f9);
  border: 1px solid var(--border, #e3e5ea);
  border-radius: 10px;
  overflow-wrap: anywhere; word-break: break-all;
  user-select: all; -webkit-user-select: all;
}
.code-copy-btn {
  flex: none; padding: 0 14px; min-height: 40px;
  border: 1px solid var(--border, #e3e5ea); border-radius: 10px;
  background: var(--surface, #fff); color: var(--brand, #2563eb);
  font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.code-copy-btn:active { transform: scale(.97); }
.code-copy-btn.ok { color: #16a34a; border-color: #16a34a; }
#bindingCodeText { font-size: 20px; letter-spacing: .12em; text-align: center; }
/* 表單欄位（特別是 type=date）有自己的最小寬度，字放大時會把格子撐出卡片外 */
.card input, .card select, .card textarea { max-width: 100%; min-width: 0; }
.card .field { min-width: 0; }
