/* ============================================================
   Social Bot 控制台 — Synergis AI CRM 視覺統一
   規格：SA-BOT-UI-2026-001 v1.0
   Design tokens 抄自 AICRM static/aicrm/styles.css?v=19
   純前端換皮：只改配色與視覺，唔改任何功能邏輯 / class / DOM
   ============================================================ */

:root {
  /* 主色系：深海軍藍 */
  --navy:   #0e3355;   /* 側欄底、logo 方塊、登入漸層起點 */
  --navy2:  #14456f;   /* 卡片標題列、彈窗標題列、主按鈕 */
  --navy3:  #1b5686;   /* 主按鈕 hover */

  /* 輔色：藍／青 */
  --teal:   #1a86bd;   /* 連結、次按鈕、focus 邊框 */
  --cyan:   #25a7dd;   /* 選中指示條、頭像、focus ring */

  /* 語意色 */
  --gold:   #a9790b;
  --ok:     #1f9d57;
  --ok2:    #188047;
  --warn:   #c9781a;
  --danger: #c62828;

  /* 中性色 */
  --line:   #dbe4ee;   /* 主邊框 */
  --line2:  #eef2f7;   /* 表格列分隔線 */
  --bg:     #eef2f7;   /* 頁面底色 */
  --ink:    #12283d;   /* 主文字 */
  --muted:  #5d7186;   /* 次文字 */

  /* 形狀 */
  --radius: 10px;
  --shadow:    0 2px 10px rgba(14, 51, 85, 0.08);
  --shadow-lg: 0 12px 40px rgba(14, 51, 85, 0.22);
  --side-w: 232px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  font-family: "PingFang TC", "Noto Sans CJK TC", "Noto Sans TC",
    "Microsoft JhengHei", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* 等寬字（工單號、ID、Base URL、金鑰預覽類） */
code { font-family: ui-monospace, Menlo, Consolas, monospace; }

/* ── Sidebar ── */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--side-w);
  padding: 16px 0 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: var(--navy);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 16px 16px; }
.brand-logo {
  height: 34px; width: auto; max-width: 120px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: #fff; border-radius: 8px; padding: 4px 7px;
  box-shadow: 0 1px 2px rgba(0,0,0,.12);
}
.brand-logo img { height: 100%; width: auto; max-width: 100%; object-fit: contain; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-weight: 900; font-size: 14.5px; color: #fff; }
.brand-sub { font-size: 11px; opacity: .65; color: #fff; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 18px; border: none; background: transparent; color: #fff;
  opacity: .86; border-radius: 0; cursor: pointer; font-size: 13.5px; text-align: left;
  font-family: inherit;
  transition: background 0.15s, opacity 0.15s;
}
.nav-item span { width: 18px; text-align: center; flex: 0 0 18px; font-size: 15px; }
.nav-item:hover { background: rgba(255,255,255,.07); opacity: 1; }
.nav-item.active {
  background: rgba(255,255,255,.13); font-weight: 800; opacity: 1;
  box-shadow: inset 3px 0 0 var(--cyan);
}

.sidebar-footer { display: flex; flex-direction: column; gap: 8px; padding: 0 16px; color: #fff; }
.connection { display: flex; align-items: center; gap: 8px; font-size: 12.5px; opacity: .6; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 0 rgba(201,120,26,0.5); animation: pulse 2s infinite; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 0 rgba(31,157,87,0.5); }
.dot.off { background: var(--danger); animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(201,120,26,0.5);} 70% { box-shadow: 0 0 0 8px rgba(201,120,26,0);} 100% { box-shadow: 0 0 0 0 rgba(201,120,26,0);} }
.hint { font-size: 11px; opacity: .6; }

/* ── Main ── */
.main { margin-left: var(--side-w); background: #f4f7fa; padding: 0; min-height: 100vh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  background: #fff; border-bottom: 1px solid var(--line); padding: 14px 22px; margin-bottom: 0;
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 900; color: var(--ink); }
.topbar-right { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; flex: 1 1 auto; min-width: 0; }

/* pill 狀態章（引擎 / LLM / 渠道 / 連線） */
.badge {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; flex: none;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; border: 0;
}
.engine-badge { background: #e3f1fb; color: #16608f; }
.llm-badge.on, .tg-badge.on { background: #e3f6ea; color: #188047; }
.llm-badge.off, .tg-badge.off { background: #eceff3; color: #62748a; }
.conn-badge { display: inline-block; margin-left: 8px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; vertical-align: middle; }
.conn-badge.on { background: #e3f6ea; color: #188047; }
.conn-badge.off { background: #eceff3; color: #62748a; }
.conn-badge.err { background: #fde6e6; color: #c62828; }

.section { display: none; padding: 18px 22px 40px; }
.section.active { display: block; animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── Stats (KPI 卡) ── */
.stats-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--teal);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px;
  transition: transform 0.15s, box-shadow 0.15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-label { font-size: 13px; font-weight: 700; color: #4b6376; margin-bottom: 8px; }
.stat-label small { color: var(--muted); font-size: 11px; font-weight: 400; }
.stat-value { font-size: 30px; line-height: 1.1; font-weight: 900; font-variant-numeric: tabular-nums; color: var(--ink); }
/* 6 張 KPI 卡冇語意 class，用 nth-child 分色（規格 §4.3 語意色） */
.stat-card:nth-child(1) { border-left-color: #12608f; } .stat-card:nth-child(1) .stat-value { color: #12608f; }
.stat-card:nth-child(2) { border-left-color: #188047; } .stat-card:nth-child(2) .stat-value { color: #188047; }
.stat-card:nth-child(3) { border-left-color: #12608f; } .stat-card:nth-child(3) .stat-value { color: #12608f; }
.stat-card:nth-child(4) { border-left-color: #b5730d; } .stat-card:nth-child(4) .stat-value { color: #b5730d; }
.stat-card:nth-child(5) { border-left-color: #0e3355; } .stat-card:nth-child(5) .stat-value { color: #0e3355; }
.stat-card:nth-child(6) { border-left-color: #c62828; } .stat-card:nth-child(6) .stat-value { color: #c62828; }

/* ── Panels ── */
.dash-columns { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.panel {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; margin-bottom: 18px;
  padding: 0 16px 16px;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  background: var(--navy2); color: #fff; padding: 11px 16px;
  margin: 0 -16px 16px;
  font-weight: 800; font-size: 13.5px;
}
.panel-title { color: #fff; font-weight: 800; font-size: 13.5px; display: flex; align-items: center; gap: 8px; }
.count { color: #fff; opacity: .75; font-size: 12px; margin-left: 4px; }
.panel-head .muted, .panel-head .muted small { color: rgba(255,255,255,.75); }
/* 主按鈕喺深藍標題列上改用白底 CTA（保持可見） */
.panel-head .btn.primary { background: #fff; color: var(--navy2); }
.panel-head .btn.primary:hover { background: #eef2f7; }

.muted { color: var(--muted); font-size: 12.5px; }
.small { font-size: 12px; }
.divider { border: none; border-top: 1px solid var(--line); margin: 20px 0; }
.subtitle { font-size: 13px; color: var(--muted); font-weight: 700; margin-bottom: 12px; }

/* ── Feed ── */
.feed { display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; }
.feed-item {
  display: flex; align-items: flex-start; gap: 10px; padding: 9px 11px; border-radius: 8px;
  background: #fff; border: 1px solid var(--line2); border-left: 3px solid var(--teal); font-size: 13px;
}
.feed-item .icon { flex: none; }
.feed-item .time { color: var(--muted); font-size: 11px; margin-left: auto; font-variant-numeric: tabular-nums; }
.feed-item .body { overflow: hidden; }
.feed-item .body b { display: block; font-size: 12.5px; font-weight: 700; color: var(--ink); }
.feed-item .body span { color: var(--muted); word-break: break-word; }
.feed-item.t-message { border-left-color: var(--teal); }
.feed-item.t-reply { border-left-color: var(--ok); }
.feed-item.t-handoff { border-left-color: var(--warn); }
.feed-item.t-job_order { border-left-color: var(--navy2); }
.feed-item.t-settings { border-left-color: #c9d3de; }
.feed-item.t-faq { border-left-color: var(--teal); }
.empty { color: var(--muted); font-size: 13px; padding: 46px 20px; text-align: center; }

/* ── Channels ── */
.channels { display: flex; flex-direction: column; gap: 12px; }
.ch-row { display: flex; flex-direction: column; gap: 6px; }
.ch-row .ch-top { display: flex; justify-content: space-between; font-size: 13px; }
.ch-row .ch-top b { font-weight: 600; color: var(--ink); }
.ch-bar { height: 8px; border-radius: 99px; background: var(--line2); overflow: hidden; }
.ch-bar > div { height: 100%; background: var(--teal); border-radius: 99px; transition: width 0.4s ease; }

/* ── Forms ── */
.form-panel { max-width: 680px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field-wide { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink); }
.field > span { font-size: 12.5px; font-weight: 800; color: #33506b; margin-bottom: 5px; }
.field input, .field textarea, .field select {
  background: #fff; border: 1px solid var(--line); color: var(--ink);
  border-radius: 8px; padding: 9px 12px; font-size: 13.5px; outline: none; font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(26,134,189,.13);
}
.field textarea { resize: vertical; }
.form-actions { margin-top: 22px; display: flex; justify-content: flex-end; gap: 8px; }

/* ── Switch ── */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; font-size: 14px; color: var(--ink); }
.switch-row b { font-weight: 600; }
.switch { appearance: none; width: 46px; height: 26px; border-radius: 99px; background: #c9d3de; position: relative; cursor: pointer; transition: background 0.2s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.switch:checked { background: var(--ok); }
.switch:checked::after { transform: translateX(20px); }

/* ── Buttons ── */
.btn {
  border: 1px solid transparent; cursor: pointer; border-radius: 8px; padding: 9px 16px; font-size: 13.5px;
  font-weight: 700; transition: background 0.15s, border-color 0.15s, opacity 0.15s; font-family: inherit;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--navy2); color: #fff; }
.btn.primary:hover { background: var(--navy3); }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: #f4fafe; border-color: var(--teal); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { background: #a51f1f; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Engines ── */
.engines { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.engine-card {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  background: #fff; position: relative; transition: border-color 0.2s, box-shadow 0.2s;
}
.engine-card.active { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(26,134,189,.13); }
.engine-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 8px; }
.engine-name { font-weight: 700; color: var(--ink); }
.engine-kind { font-size: 11px; color: var(--muted); padding: 3px 8px; border-radius: 6px; background: var(--line2); }
.engine-card .field { margin-bottom: 10px; }
.engine-actions { display: flex; gap: 8px; margin-top: 6px; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 11px 13px; vertical-align: top; }
.table th { background: #f6f9fc; color: #33506b; padding: 11px 13px; font-weight: 800; border-bottom: 1px solid var(--line); }
.table td { border-bottom: 1px solid var(--line2); }
.table tbody tr:nth-child(even) { background: #fafcfe; }
.table tbody tr:hover { background: #eef7fd; }
.th-actions { text-align: right; white-space: nowrap; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions .btn { margin-left: 5px; }

/* pill 標籤（語言 / 分類 / 狀態 / 公司 / 渠道） */
.tag { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: #e3f1fb; color: #16608f; }
.lang-yue { background: #e3f1fb; color: #16608f; }
.lang-eng { background: #e3f6ea; color: #188047; }
.human-tag { background: #fdf0dc; color: #a9790b; }
.company-tag { background: #e3f1fb; color: #16608f; }
.company-badge { background: #e3f1fb; color: #16608f; }
.channel-badge { background: #e3f1fb; color: #16608f; }
.handoff-badge { background: #fdf0dc; color: #a9790b; }
.assigned-badge { background: #e3f1fb; color: #16608f; }

.filter-select {
  background: #fff; border: 1px solid var(--line); color: var(--ink); border-radius: 8px;
  padding: 8px 12px; font-size: 13px; outline: none; font-family: inherit;
}
.filter-select:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(26,134,189,.13); }

.company-add { display: flex; gap: 10px; margin-bottom: 16px; }
.company-add input { flex: 1; background: #fff; border: 1px solid var(--line); color: var(--ink); border-radius: 8px; padding: 9px 12px; font-size: 13.5px; outline: none; font-family: inherit; }
.company-add input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(26,134,189,.13); }
.company-list { display: flex; flex-direction: column; gap: 8px; }
.company-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.company-name { font-weight: 600; color: var(--ink); }

/* ── Form 設計器 ── */
.form-editor { display: grid; grid-template-columns: 240px 1fr; gap: 16px; }
.form-list-panel { border-right: 1px solid var(--line); padding-right: 12px; }
.form-list { display: flex; flex-direction: column; gap: 6px; }
.form-item { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); cursor: pointer; font-size: 13.5px; background: #fff; color: var(--ink); }
.form-item:hover { background: #f4fafe; }
.form-item.active { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(26,134,189,.13); }
.form-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 12px; }
.field-row { display: grid; grid-template-columns: 1fr 110px 90px 1fr 40px; gap: 8px; align-items: center; margin-bottom: 8px; }
.field-row input, .field-row select { background: #fff; border: 1px solid var(--line); color: var(--ink); border-radius: 8px; padding: 8px 10px; font-size: 13px; outline: none; font-family: inherit; }
.field-row input:focus, .field-row select:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(26,134,189,.13); }
.f-req { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--danger); white-space: nowrap; }
.f-del { justify-self: center; }

/* ── 工作單 ── */
.wo-fields { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.wo-field { font-size: 13px; color: var(--ink); }
.wo-field b { display: inline-block; min-width: 120px; color: var(--muted); font-weight: 600; }
.kw { color: var(--muted); font-size: 12px; word-break: break-word; }

/* ── Modal ── */
.modal {
  position: fixed; inset: 0; background: rgba(10,32,54,.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 14px; overflow-y: auto; z-index: 50;
}
.modal-card {
  width: 620px; max-width: 100%; background: #fff; border-radius: 13px;
  box-shadow: var(--shadow-lg); overflow: hidden;
  display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--navy2); color: #fff; padding: 13px 20px; font-weight: 800; flex-shrink: 0;
}
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 800; }
.modal-close { background: none; border: none; color: #fff; font-size: 20px; cursor: pointer; line-height: 1; padding: 0; }
.modal-body { padding: 18px 20px; max-height: 66vh; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 13px 20px; border-top: 1px solid var(--line); background: #fafcfe; display: flex; gap: 10px; justify-content: flex-end; flex-shrink: 0; }
.company-modal-card { width: min(820px, 94vw); }
.company-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
.company-box { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; background: #fafcfe; display: flex; flex-direction: column; gap: 11px; }
.company-box-title { font-weight: 800; color: var(--navy2); font-size: 13.5px; }
.company-box-wide { grid-column: 1 / -1; }
@media (max-width: 640px) { .company-grid { grid-template-columns: 1fr; } }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; right: 24px; padding: 13px 18px; border-radius: 10px;
  background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow-lg);
  font-size: 13.5px; z-index: 100; animation: slidein 0.25s ease; color: var(--ink);
}
.toast.ok { background: #e6f7ee; color: #12693c; border: 1px solid #bfe6d1; }
.toast.err { background: #fdecec; color: #8f1d1d; border: 1px solid #f3c9c9; }
@keyframes slidein { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ── Conversations ── */
.conv-layout { display: grid; grid-template-columns: 320px 1fr; gap: 16px; height: calc(100vh - 150px); min-height: 420px; }
.conv-list-panel, .conv-detail-panel { display: flex; flex-direction: column; overflow: hidden; margin-bottom: 0; }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.conv-item {
  padding: 12px 13px; border-radius: var(--radius); border: 1px solid var(--line);
  background: #fff; cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.conv-item:hover { background: #f4fafe; }
.conv-item.active { background: #e3f1fb; box-shadow: inset 3px 0 0 var(--cyan); }
.conv-item.handoff { box-shadow: inset 3px 0 0 var(--warn); }
.conv-item-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.conv-name { font-weight: 600; font-size: 13.5px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1 1 auto; min-width: 0; }
.conv-badges { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; flex: 0 0 auto; max-width: 55%; }
.conv-item .badge { padding: 3px 8px; font-size: 11px; gap: 4px; }
.conv-last { color: var(--muted); font-size: 12.5px; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-meta { color: var(--muted); font-size: 11px; margin-top: 4px; }
.conv-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 2px; }
.msg { display: flex; flex-direction: column; max-width: 78%; }
.msg-user { align-self: flex-start; }
.msg-bot { align-self: flex-end; }
.msg-human { align-self: flex-end; }
.msg-bubble { padding: 9px 13px; border-radius: 10px; font-size: 13.5px; line-height: 1.45; word-break: break-word; }
.msg-user .msg-bubble { background: #eceff3; color: var(--ink); }
.msg-bot .msg-bubble { background: var(--navy2); color: #fff; }
.msg-human .msg-bubble { background: var(--teal); color: #fff; }
.msg-time { color: var(--muted); font-size: 11.5px; margin-top: 3px; padding: 0 4px; }
.msg-bot .msg-time, .msg-human .msg-time { text-align: right; }
.conv-reply { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; }
.conv-reply textarea { width: 100%; background: #fff; border: 1px solid var(--line); color: var(--ink); border-radius: 8px; padding: 9px 12px; font-size: 13.5px; outline: none; font-family: inherit; resize: vertical; }
.conv-reply textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(26,134,189,.13); }
.conv-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

@media (max-width: 1100px) { .stats-grid { grid-template-columns: repeat(3, 1fr); } .dash-columns { grid-template-columns: 1fr; } .conv-layout { grid-template-columns: 1fr; height: auto; } .conv-list-panel { max-height: 300px; } }
@media (max-width: 760px) {
  .sidebar { position: static; width: 100%; flex-direction: column; align-items: stretch; gap: 6px; padding: 10px 0 10px; }
  .brand { padding: 0 14px 8px; }
  .brand-name { font-size: 15px; }
  .nav { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 4px; padding: 0 10px; }
  .nav-item { flex: 0 0 auto; padding: 11px 14px; min-height: 42px; border-radius: 8px; white-space: nowrap; }
  .nav-item.active { box-shadow: inset 0 -3px 0 var(--cyan); }
  .sidebar-footer { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 6px 14px; padding: 2px 14px; font-size: 11px; }
  .sidebar-footer .hint { width: 100%; }
  .main { margin-left: 0; padding: 0; }
  .topbar { padding: 11px 14px; gap: 8px; }
  .topbar h1 { font-size: 17px; }
  .section { padding: 14px 12px 32px; }
  .panel { padding: 0 12px 12px; }
  .panel-head { margin: 0 -12px 12px; padding: 11px 12px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .form-grid { grid-template-columns: 1fr; }
  .engines { grid-template-columns: 1fr; }
  .form-actions { flex-wrap: wrap; }
  .btn { min-height: 40px; }
  .field input, .field textarea, .field select { font-size: 16px; }
}

@media (max-width: 480px) {
  .topbar h1 { font-size: 16px; }
  .section { padding: 12px 10px 28px; }
  .stats-grid { gap: 8px; }
  .modal-card { padding: 18px 14px; }
}

/* ── 登入畫面 ── */
.login-overlay {
  position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--navy), var(--navy2));
}
.login-card {
  width: 360px; max-width: 92vw; background: #fff; border: 1px solid var(--line);
  border-radius: 13px; padding: 34px 30px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 14px;
}
.login-logo { font-size: 44px; text-align: center; }
.login-card h2 { margin: 0; text-align: center; font-size: 20px; font-weight: 800; color: var(--ink); }
.login-card input { width: 100%; background: #fff; border: 1px solid var(--line); color: var(--ink); border-radius: 8px; padding: 9px 12px; font-size: 14px; outline: none; font-family: inherit; }
.login-card input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(26,134,189,.13); }
.login-err { color: var(--danger); font-size: 13px; text-align: center; min-height: 18px; }

/* ── 分派 / 相片 / 用戶 / 範本 ── */
.photo-link { color: var(--teal); text-decoration: none; font-weight: 600; }
.photo-link:hover { text-decoration: underline; }
.out-photos { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 5px; }
.out-photo { display: block; line-height: 0; }
.out-photo img { width: 140px; height: 140px; object-fit: cover; border-radius: 8px; border: 1px solid rgba(0,0,0,0.14); background: #fff; }
.user-add { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.user-add input, .user-add select { flex: 1; min-width: 120px; background: #fff; border: 1px solid var(--line); color: var(--ink); border-radius: 8px; padding: 9px 12px; font-size: 13.5px; outline: none; font-family: inherit; }
.user-add input:focus, .user-add select:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(26,134,189,.13); }
.user-list { display: flex; flex-direction: column; gap: 8px; }
.user-row { display: flex; align-items: center; gap: 12px; padding: 11px 13px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; flex-wrap: wrap; }
.user-name { font-weight: 600; flex: 1; color: var(--ink); }
.user-name code { color: var(--muted); font-weight: 400; }
.user-meta { display: flex; gap: 4px; flex-wrap: wrap; }
.user-multi { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 14px; }
.user-multi-group { flex: 1; min-width: 200px; }
.user-multi-title { color: var(--muted); font-size: 12px; margin-bottom: 6px; font-weight: 600; }
.check-group { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--ink); cursor: pointer; }
.check input { accent-color: var(--teal); }
.spacer { flex: 1; }
.aicrm-map-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 6px 0; }
.aicrm-map-row select { background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 13px; }
.tpl-row { display: flex; flex-direction: column; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.tpl-row b { color: var(--ink); }
.tpl-row textarea, .tpl-row input { background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font-size: 13px; width: 100%; box-sizing: border-box; }
#st-tbody input { background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 13px; width: 100%; box-sizing: border-box; }
