/* ── 全域 ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:      #0A1E4F;
  --primary-dark: #061530;
  --primary-light:#3A5490;
  --primary-bg:   #EBEEF7;
  --accent:       #B8965A;
  --bg:           #F7F8FB;
  --card:         #ffffff;
  --border:       #DDE2EC;
  --text:         #3A3F4A;
  --text-title:   #0A1E4F;
  --text-2:       #656B78;
  --text-3:       #9CA3AF;
  --danger:       #A94442;
  --danger-bg:    #fdf0ef;
  --success:      #2F855A;
  --success-bg:   #EAF7F0;
  --radius:       7px;
  --shadow:       0 1px 4px rgba(0,0,0,.06);
}

html, body { height: 100%; font-family: 'Noto Sans TC', 'Inter', sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg); }

button {
  font-family: inherit; font-size: 14px; cursor: pointer;
  border: none; border-radius: var(--radius); padding: 9px 18px;
  transition: background .15s, opacity .15s;
}
button:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-ghost { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); }

.btn-sm { padding: 6px 12px; font-size: 13px; }

input, select, textarea {
  font-family: inherit; font-size: 14px; color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 9px 12px; width: 100%; background: #fff;
  transition: border-color .15s, box-shadow .15s; outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(10,30,79,.12);
}

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

.field { margin-bottom: 16px; }

.alert {
  padding: 10px 14px; border-radius: var(--radius); font-size: 13px;
  margin-bottom: 14px; display: none;
}
.alert.show { display: block; }
.alert-error   { background: var(--danger-bg); color: var(--danger); }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-info    { background: var(--primary-bg); color: var(--primary-dark); }

/* ── 認證頁 ───────────────────────────────────────────────── */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center;
  justify-content: center; padding: 24px;
}
.auth-card {
  background: var(--card); border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,.08);
  padding: 40px 36px; width: 100%; max-width: 400px;
}
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo .logo-name { font-size: 18px; font-weight: 600; color: var(--primary); display: block; }
.auth-title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 20px; }
.auth-hint { font-size: 12px; color: var(--text-3); margin-top: 16px; text-align: center; }
.auth-link { color: var(--primary); cursor: pointer; text-decoration: underline; }

/* ── 主佈局（骨架，Phase D 後續階段補完整功能）─────────────── */
#app-shell { display: none; height: 100vh; flex-direction: column; }
#app-shell.active { display: flex; }
.topbar {
  height: 56px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; background: var(--card); border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 600; color: var(--text-title); }
.shell-body { flex: 1; overflow: auto; padding: 24px; }
/* 客服對話 tab 內容自己管理版面（sidebar + chat-area 佔滿），不要外層 padding/scroll。
   app.js 的 switchTab() 會在切到 chat tab 時把 #tab-body className 換成 "" 套用這個規則。 */
#tab-body.tab-body-flush { padding: 0; overflow: hidden; display: flex; }

/* ===== Tabs Bar ===== */
.tabs-bar {
  display: flex;
  height: 44px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  align-items: stretch;
  flex-shrink: 0;
}
.tab-btn {
  background: none;
  border: none;
  padding: 0 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 0;
}
.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ===== 開發中 placeholder（其餘 6 個尚未搬遷的分頁）===== */
.coming-soon {
  max-width: 480px;
  margin: 80px auto;
  text-align: center;
  padding: 48px 24px;
  background: var(--card);
  border-radius: 12px;
  border: 1px dashed var(--border);
}
.coming-soon-icon { font-size: 56px; margin-bottom: 16px; }
.coming-soon-title { font-size: 20px; color: var(--text); font-weight: 600; margin-bottom: 8px; }
.coming-soon-desc { font-size: 14px; color: var(--text-2); line-height: 1.6; }

/* ===== 客服對話 tab ===== */
.main { display: flex; flex: 1; min-height: 0; }

/* Sidebar (Customer List) */
.sidebar {
  width: 320px;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-header { padding: 12px 16px; border-bottom: 1px solid var(--border); }
#customer-list { flex: 1; overflow-y: auto; }

.customer-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--bg);
  transition: background .15s;
}
.customer-item:hover { background: var(--bg); }
.customer-item.active { background: var(--primary-bg); }
.customer-item.unread { background: #F0FAF3; }
.customer-item:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; background: var(--primary-bg); }

.customer-avatar {
  width: 44px; height: 44px; border-radius: 50%; background: var(--border);
  margin-right: 12px; flex-shrink: 0; object-fit: cover;
}
.customer-info { flex: 1; min-width: 0; }
.customer-name { font-weight: 600; font-size: 14px; color: var(--text); display: flex; align-items: center; gap: 6px; }
.unread-badge {
  background: var(--success); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px; display: flex; align-items: center;
  justify-content: center; padding: 0 5px; flex-shrink: 0;
}
.handoff-badge { font-size: 12px; margin-left: 4px; flex-shrink: 0; }
.customer-preview {
  font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; margin-top: 2px;
}
.customer-item.unread .customer-preview { color: var(--text); font-weight: 500; }
.customer-time { font-size: 11px; color: var(--text-3); flex-shrink: 0; margin-left: 8px; align-self: flex-start; margin-top: 2px; }
.customer-item.unread .customer-time { color: var(--success); }
.customer-tags { display: flex; gap: 4px; margin-top: 3px; flex-wrap: wrap; }
.tag { font-size: 10px; padding: 1px 6px; border-radius: 4px; background: var(--success-bg); color: var(--success); }

/* Chat Area */
.chat-area { flex: 1; display: flex; flex-direction: column; background: var(--bg); min-width: 0; }
.chat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-3); font-size: 16px; gap: 8px;
}
.chat-empty-icon { font-size: 48px; opacity: .3; }

.chat-header {
  background: var(--card); padding: 10px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.chat-header-left { display: flex; align-items: center; gap: 12px; }
.chat-header-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--border); object-fit: cover; }
.chat-header-info h2 { font-size: 15px; font-weight: 600; color: var(--text); }
.chat-header-info .tags-inline { display: flex; gap: 4px; margin-top: 2px; }
.chat-header-actions { display: flex; gap: 8px; }

.btn-icon {
  background: var(--bg); border: 1px solid var(--border); padding: 6px 12px; border-radius: var(--radius);
  cursor: pointer; font-size: 13px; color: var(--text-2); transition: all .15s;
}
.btn-icon:hover { background: var(--border); }
.btn-icon.active {
  background: var(--success); color: #fff; border-color: var(--success);
  box-shadow: inset 0 2px 4px rgba(0,0,0,.18); transform: translateY(1px);
}
.btn-icon:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.ai-pause-status { font-size: 12px; color: var(--text-2); white-space: nowrap; }
.ai-exempt-inline {
  display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-2);
  white-space: nowrap; cursor: pointer; user-select: none;
}
.ai-exempt-inline input { cursor: pointer; }

/* Chat Messages */
.chat-messages { flex: 1; overflow-y: auto; padding: 16px 20px; }
.message-row { display: flex; margin-bottom: 10px; }
.message-row.customer { justify-content: flex-start; }
.message-row.staff, .message-row.forward, .message-row.ai { justify-content: flex-end; }
.message-row.system { justify-content: center; }

/* max-width 掛在這層（訊息真正的 flex 子項）才會對到 .message-row 的實際寬度 */
.message-content { max-width: 65%; }
.message-bubble {
  min-width: 40px; padding: 10px 14px; border-radius: 16px; font-size: 14px; line-height: 1.5;
  word-break: keep-all; overflow-wrap: break-word; box-sizing: content-box;
}
.message-row.customer .message-bubble { background: var(--card); color: var(--text); border-bottom-left-radius: 4px; box-shadow: var(--shadow); }
.message-row.staff .message-bubble, .message-row.forward .message-bubble {
  background: var(--primary); color: #fff; border-bottom-right-radius: 4px;
}
.message-row.system .message-bubble { background: rgba(0,0,0,.08); color: var(--text-2); font-size: 12px; padding: 4px 12px; border-radius: 12px; }
/* AI 自動回覆：跟真人職員明顯區分用淡紫色（純顯示，不含任何 AI 控制 UI） */
.message-row.ai .message-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.message-time { font-size: 11px; color: var(--text-3); margin-top: 4px; }
.message-row.staff .message-time, .message-row.forward .message-time, .message-row.ai .message-time { text-align: right; }

/* Transfer mode + 「轉回客戶」(SPEC §8) */
.transfer-mode-banner {
  background: linear-gradient(180deg, var(--primary), var(--primary-dark));
  color: #fff; padding: 10px 16px; font-size: 13px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-shrink: 0;
}
.transfer-mode-banner[hidden] { display: none; }
.transfer-mode-banner-actions { display: flex; gap: 6px; }
.transfer-mode-banner-actions .btn-secondary { background: rgba(255,255,255,.2); color: #fff; border-color: rgba(255,255,255,.4); }
.transfer-mode-banner-actions .btn-secondary:hover { background: rgba(255,255,255,.3); }
.transfer-mode-banner-actions .btn-primary { background: #fff; color: var(--primary); border: none; }
.transfer-mode-banner-actions .btn-primary:disabled { background: rgba(255,255,255,.5); color: #888; cursor: not-allowed; }
.btn-mini { padding: 4px 10px; font-size: 12px; }

body.transfer-mode .message-bubble { cursor: pointer; transition: outline .15s, box-shadow .15s; }
body.transfer-mode .message-bubble:hover { box-shadow: 0 0 0 2px rgba(10,30,79,.3); }
body.transfer-mode .message-row.selected .message-bubble {
  outline: 2px solid var(--primary); outline-offset: 2px; box-shadow: 0 0 0 4px rgba(10,30,79,.2);
}
body.transfer-mode .message-row.system { opacity: .4; pointer-events: none; }
body.transfer-mode .chat-input-area { opacity: .4; pointer-events: none; }

.reply-fwd-banner {
  display: inline-flex; align-items: center; gap: 6px; background: var(--success-bg); color: var(--success);
  border: 1px solid #B7E3C5; border-radius: 12px; padding: 4px 10px; font-size: 12px; margin-bottom: 4px;
}
.reply-fwd-banner .reply-fwd-quote { color: var(--text-2); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.relay-btn {
  display: inline-flex; align-items: center; gap: 4px; margin-top: 4px; background: var(--success);
  color: #fff; border: none; border-radius: 14px; padding: 5px 12px; font-size: 12px; cursor: pointer;
  transition: background .15s;
}
.relay-btn:hover { background: #256e49; }
.relay-btn:disabled { background: var(--border); color: var(--text-2); cursor: not-allowed; }
.relay-btn.relayed { background: var(--bg); color: var(--text-2); border: 1px solid var(--border); }

/* Chat Input */
.chat-input-area { background: var(--card); border-top: 1px solid var(--border); position: relative; flex-shrink: 0; }

.template-popover {
  position: absolute; bottom: calc(100% + 4px); left: 16px; right: 16px; max-height: 280px;
  overflow-y: auto; background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12); z-index: 100; padding: 4px 0;
}
.template-popover[hidden] { display: none; }
.template-popover-empty { padding: 12px 16px; color: var(--text-3); font-size: 13px; text-align: center; }
.template-popover-item { padding: 8px 14px; cursor: pointer; border-radius: 4px; margin: 0 4px; }
.template-popover-item:hover, .template-popover-item.active { background: var(--primary-bg); }
.template-popover-item-head { display: flex; gap: 8px; align-items: baseline; font-size: 13px; }
.template-popover-shortcut { color: var(--primary); font-weight: 600; font-family: monospace; }
.template-popover-title { color: var(--text); font-weight: 500; }
.template-popover-preview { font-size: 12px; color: var(--text-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-input { display: flex; padding: 12px 16px; gap: 10px; align-items: flex-end; }
.chat-input textarea {
  flex: 1; padding: 8px 14px; border: 1px solid var(--border); border-radius: 20px; font-size: 14px;
  font-family: inherit; resize: none; outline: none; max-height: 50vh; min-height: 40px; line-height: 1.4;
}
.chat-input textarea:focus { border-color: var(--primary); }

.chat-input-resize {
  height: 8px; cursor: ns-resize; background: transparent; position: relative; user-select: none;
  flex-shrink: 0; transition: background .15s;
}
.chat-input-resize::before {
  content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 36px; height: 3px; background: var(--border); border-radius: 2px; opacity: 0; transition: opacity .15s;
}
.chat-input-resize:hover, .chat-input-resize.dragging { background: var(--bg); }
.chat-input-resize:hover::before, .chat-input-resize.dragging::before { opacity: 1; }
body.chat-input-resizing { cursor: ns-resize; user-select: none; }
body.chat-input-resizing * { cursor: ns-resize !important; }

.btn-send {
  background: var(--primary); color: #fff; border: none; width: 36px; height: 36px; border-radius: 50%;
  cursor: pointer; font-size: 16px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.btn-send:hover { background: var(--primary-dark); }
.btn-send:disabled { background: var(--border); cursor: default; }
.btn-send:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(100px);
  background: #333; color: #fff; padding: 10px 24px; border-radius: 8px; font-size: 14px;
  z-index: 200; transition: transform .3s ease;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ============================================================
   Phase D 段落4b：客戶清單／範本管理／設定 三個分頁
   移植自舊版 public/index.html 前段 <style> 區塊，只挑三個分頁實際用到
   的 class，變數改用這份檔案既有的 --primary/--border 等（舊檔用寫死的
   #06c755 綠色，這裡維持沿用寫死色碼以求跟舊版視覺一致，不強行套色票）。
   ============================================================ */

/* ===== 範本管理 tab ===== */
.templates-view {
  display: none; flex: 1; min-height: 0; background: var(--bg);
  flex-direction: column; overflow: hidden;
}
.templates-view[data-active="true"] { display: flex; }
.templates-toolbar {
  display: flex; align-items: center; gap: 12px; padding: 16px 24px;
  background: var(--card); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.templates-toolbar h2 { font-size: 18px; color: var(--text); margin-right: auto; }
.templates-toolbar input[type="search"] {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; width: 240px; outline: none;
}
.templates-toolbar input[type="search"]:focus { border-color: #06c755; }
.templates-body { flex: 1; overflow-y: auto; padding: 20px 24px; }

.template-form {
  background: var(--card); border-radius: 12px; padding: 20px; margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05); border: 2px solid #06c755;
}
.template-form[hidden] { display: none; }
.template-form h3 { font-size: 16px; color: var(--text); margin-bottom: 16px; }
.form-row { margin-bottom: 12px; }
.form-row label {
  display: block; font-size: 12px; font-weight: 600; color: var(--text-2);
  margin-bottom: 4px; text-transform: uppercase;
}
.form-row input, .form-row textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; font-family: inherit; outline: none;
}
.form-row input:focus, .form-row textarea:focus { border-color: #06c755; }
.form-row textarea { min-height: 100px; resize: vertical; }
.form-hint { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.template-card {
  background: var(--card); border-radius: 10px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  border: 1px solid var(--border); transition: box-shadow 0.15s; display: flex; flex-direction: column;
}
.template-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.template-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; gap: 8px; }
.template-card-title {
  font-size: 15px; font-weight: 600; color: var(--text); flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.template-card-shortcut {
  background: #e8f5e9; color: #2e7d32; padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-family: monospace; flex-shrink: 0;
}
.template-card-content {
  color: var(--text-2); font-size: 13px; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
  margin-bottom: 12px; flex: 1; overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 4; -webkit-box-orient: vertical;
}
.template-card-actions {
  display: flex; gap: 6px; justify-content: flex-end; border-top: 1px solid var(--bg); padding-top: 10px;
}
.btn-card {
  background: none; border: 1px solid var(--border); color: var(--text-2);
  padding: 4px 12px; border-radius: 4px; font-size: 12px; cursor: pointer;
}
.btn-card:hover { background: var(--bg); color: var(--text); }
.btn-card.danger:hover { background: #ffebee; color: #c62828; border-color: #ef9a9a; }

.templates-empty { text-align: center; color: var(--text-3); padding: 60px 20px; font-size: 14px; }
.templates-empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.4; }

/* ===== 客戶清單 tab ===== */
.customers-view {
  display: none; flex: 1; min-height: 0; background: var(--bg); flex-direction: row; overflow: hidden;
}
.customers-view[data-active="true"] { display: flex; }
.customers-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.customers-toolbar {
  display: flex; align-items: center; gap: 10px; padding: 14px 20px; background: var(--card);
  border-bottom: 1px solid var(--border); flex-shrink: 0; flex-wrap: wrap;
}
.customers-toolbar h2 { font-size: 18px; color: var(--text); margin-right: auto; }
.customers-toolbar input[type="search"], .customers-toolbar select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px;
  outline: none; background: var(--card);
}
.customers-toolbar input[type="search"] { width: 220px; }
.customers-toolbar input:focus, .customers-toolbar select:focus { border-color: #06c755; }
.customers-body { flex: 1; overflow-y: auto; padding: 16px 20px; }

.customers-table {
  width: 100%; background: var(--card); border-radius: 10px; overflow: hidden;
  border-collapse: separate; border-spacing: 0; box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.customers-table thead { background: var(--bg); }
.customers-table th {
  text-align: left; padding: 12px 14px; font-size: 12px; color: var(--text-3); font-weight: 600;
  text-transform: uppercase; border-bottom: 1px solid var(--border);
}
.customers-table td {
  padding: 12px 14px; border-bottom: 1px solid var(--bg); font-size: 13px; color: var(--text); vertical-align: middle;
}
.customers-table tr:hover td { background: var(--bg); cursor: pointer; }
.customers-table tr.active td { background: var(--primary-bg); }
.customers-table tr:last-child td { border-bottom: none; }

.cust-avatar-sm {
  width: 32px; height: 32px; border-radius: 50%; background: var(--border); object-fit: cover;
  display: inline-block; vertical-align: middle; margin-right: 8px;
}

.status-badge { display: inline-block; padding: 2px 10px; border-radius: 10px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.status-badge.status-active   { background: #e8f5e9; color: #2e7d32; }
.status-badge.status-paused   { background: #fff3e0; color: #e65100; }
.status-badge.status-blocked  { background: #ffebee; color: #c62828; }
.status-badge.status-archived { background: #f5f5f5; color: #757575; }

.role-chip { background: #e3f2fd; color: #1565c0; padding: 2px 8px; border-radius: 10px; font-size: 11px; display: inline-block; }

.patient-chips { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.patient-chip { background: #fff8e1; color: #f57f17; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 500; }

/* Detail Drawer */
.detail-drawer {
  width: 0; background: var(--card); border-left: 1px solid var(--border);
  overflow-y: auto; transition: width 0.2s; flex-shrink: 0;
}
.detail-drawer[data-open="true"] { width: 400px; }
.detail-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center;
  justify-content: space-between; position: sticky; top: 0; background: var(--card); z-index: 1;
}
.detail-header h3 { font-size: 16px; color: var(--text); }
.detail-close { background: none; border: none; font-size: 22px; color: var(--text-3); cursor: pointer; }
.detail-body { padding: 16px 20px; }
.detail-section { margin-bottom: 22px; }
.detail-section-title {
  font-size: 11px; font-weight: 700; color: var(--text-3); text-transform: uppercase;
  letter-spacing: 0.5px; margin-bottom: 8px; padding-bottom: 4px; border-bottom: 1px solid var(--bg);
}
.detail-avatar-box { text-align: center; margin-bottom: 12px; }
.detail-avatar { width: 72px; height: 72px; border-radius: 50%; background: var(--border); object-fit: cover; }
.detail-row { display: grid; grid-template-columns: 90px 1fr; gap: 8px; margin-bottom: 10px; align-items: center; }
.detail-row label { font-size: 12px; color: var(--text-3); font-weight: 600; }
.detail-row input, .detail-row select, .detail-row textarea {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 5px; font-size: 13px;
  font-family: inherit; outline: none; width: 100%;
}
.detail-row textarea { min-height: 60px; resize: vertical; }
.detail-row input:focus, .detail-row select:focus, .detail-row textarea:focus { border-color: #06c755; }
.detail-row-mono { font-family: monospace; font-size: 11px; color: var(--text-3); word-break: break-all; }

.patient-list { display: flex; flex-direction: column; gap: 6px; }
.patient-row {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px;
  background: #fffdf5; border: 1px solid #ffe082; border-radius: 6px;
}
.patient-row-main { flex: 1; font-size: 13px; color: var(--text); }
.patient-row-sub { font-size: 11px; color: var(--text-3); }
.patient-row button { background: none; border: none; color: #c62828; cursor: pointer; font-size: 14px; }

.btn-add-small {
  background: var(--card); border: 1px dashed #06c755; color: #06c755; padding: 6px 12px;
  border-radius: 5px; font-size: 12px; cursor: pointer; margin-top: 6px;
}
.btn-add-small:hover { background: #f0fbf3; }

.role-options { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.role-option {
  font-size: 11px; color: #1565c0; background: #e3f2fd; padding: 3px 8px;
  border-radius: 10px; cursor: pointer; border: 1px solid transparent;
}
.role-option:hover { border-color: #1565c0; }

.detail-actions {
  display: flex; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border);
  background: var(--bg); position: sticky; bottom: 0;
}

/* ===== 設定 tab ===== */
.generic-view {
  display: none; flex: 1; min-height: 0; background: var(--bg); flex-direction: column; overflow: hidden;
}
.generic-view[data-active="true"] { display: flex; }
.generic-view-header { padding: 16px 24px; background: var(--card); border-bottom: 1px solid var(--border); }
.generic-view-header h2 { font-size: 18px; color: var(--text); margin: 0; }
.generic-view-body { flex: 1; overflow-y: auto; padding: 24px; }
.settings-body { max-width: none; width: 100%; padding: 0 24px; box-sizing: border-box; margin: 0 auto; }
.settings-section {
  background: var(--card); border-radius: 8px; padding: 20px 24px; margin-bottom: 16px; border: 1px solid var(--border);
}
.settings-section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.settings-section-head h3 { margin: 0; font-size: 16px; color: var(--text); }
.settings-section-desc { font-size: 13px; color: var(--text-2); margin-bottom: 16px; line-height: 1.6; }

.whitelist-table {
  width: 100%; table-layout: fixed; border-collapse: collapse; background: var(--card);
  font-size: 13px; border: 1px solid var(--border); border-radius: 6px;
}
.whitelist-table th {
  background: var(--bg); color: var(--text); font-weight: 700; padding: 10px 10px; text-align: left;
  border-bottom: 1px solid var(--border); white-space: nowrap; box-sizing: border-box; min-width: 60px;
}
.whitelist-table th:last-child { width: 260px; }
.whitelist-table td { padding: 6px 8px; border-bottom: 1px solid var(--bg); vertical-align: middle; overflow: hidden; }
.whitelist-table td:last-child { white-space: nowrap; }
.whitelist-table tr:hover { background: var(--bg); }
.whitelist-table input[type="text"], .whitelist-table input[type="email"], .whitelist-table select {
  width: 100%; padding: 5px 8px; border: 1px solid var(--border); border-radius: 4px;
  font-size: 13px; box-sizing: border-box; outline: none; background: var(--card);
}
.whitelist-table input:focus, .whitelist-table select:focus {
  border-color: #06c755; box-shadow: 0 0 0 2px rgba(6,199,85,0.15);
}
.whitelist-table input[readonly] { background: var(--bg); color: var(--text-2); border-color: var(--border); }
.whitelist-table .btn-tbl {
  padding: 4px 10px; font-size: 12px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--bg); color: var(--text); cursor: pointer; margin-right: 4px; transition: all 0.15s ease;
}
.whitelist-table .btn-tbl:hover { background: var(--border); }
.whitelist-table .btn-tbl.save { background: var(--card); color: var(--text); border-color: var(--border); }
.whitelist-table .btn-tbl.save:hover { background: #e6f9ee; border-color: #06c755; color: #049d42; }
.whitelist-table .btn-tbl.danger { color: #c63b3b; border-color: #f5c6c6; }
.whitelist-table .btn-tbl.danger:hover { background: #fdecea; }
.new-row-editing { background: #f0fdf4 !important; }
