/* ================================
   2chatAI Admin Dashboard — Dark Modern
   Phase 3+: All tabs styled + Widget Settings compact + Staff
   ================================ */

:root {
  --bg-primary: #0f0f23;
  --bg-secondary: #161630;
  --bg-tertiary: #1c1c3a;
  --bg-hover: #22224a;
  --bg-active: #2a2a5a;
  --border: rgba(255, 255, 255, 0.06);
  --border-light: rgba(255, 255, 255, 0.1);
  --text-primary: #e8e8f0;
  --text-secondary: rgba(255, 255, 255, 0.55);
  --text-muted: rgba(255, 255, 255, 0.3);
  --accent: #6366F1;
  --accent-hover: #818CF8;
  --danger: #EF4444;
  --success: #22C55E;
  --warning: #F59E0B;
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary); color: var(--text-primary);
  font-size: 15px; line-height: 1.5;
}

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.08); border-radius: 3px; }

/* ---- Login ---- */
#login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg-primary); }
.login-card { background: var(--bg-secondary); border-radius: 20px; padding: 44px; width: 400px; border: 1px solid var(--border); box-shadow: 0 12px 48px rgba(0,0,0,0.3); }
.login-logo { text-align: center; margin-bottom: 36px; }
.login-logo .logo-icon { font-size: 36px; }
.login-logo h1 { font-size: 22px; margin-top: 10px; color: #fff; font-weight: 700; }
.login-logo p { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ---- Forms ---- */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 7px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.6px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--border-light); border-radius: 12px;
  font-size: 14px; outline: none; background: rgba(255,255,255,0.03); color: #fff; transition: border-color 0.15s; font-family: inherit;
}
.form-group input::placeholder, .form-group textarea::placeholder { color: var(--text-muted); }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--accent); }
.form-group input:disabled { opacity: 0.5; cursor: not-allowed; }
.form-group input[type="color"] { width: 44px; height: 36px; padding: 3px; border-radius: 8px; cursor: pointer; }

/* ---- Buttons ---- */
.btn-primary { background: var(--accent); color: #fff; border: none; border-radius: 12px; padding: 12px 20px; font-size: 14px; font-weight: 600; cursor: pointer; transition: background 0.15s; width: 100%; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; border: 1px solid var(--border-light); border-radius: 10px; padding: 6px 14px; font-size: 13px; cursor: pointer; color: var(--text-secondary); transition: all 0.12s; }
.btn-ghost:hover { border-color: var(--text-secondary); color: var(--text-primary); }
.btn-sm { padding: 6px 14px; font-size: 12px; font-weight: 600; border-radius: 8px; cursor: pointer; border: none; transition: opacity 0.12s; }
.btn-sm:hover { opacity: 0.85; }
.btn-sm.btn-primary { background: var(--accent); color: #fff; width: auto; }
.btn-sm.btn-danger { background: var(--danger); color: #fff; }
.btn-sm.btn-ghost { background: transparent; border: 1px solid var(--border-light); color: var(--text-secondary); }
.btn-icon { background: none; border: none; color: var(--text-muted); font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: 6px; transition: color 0.12s; }
.btn-icon:hover { color: var(--text-primary); }
.error-text { color: var(--danger); font-size: 13px; margin-top: 14px; text-align: center; }
.success-text { color: var(--success); font-size: 13px; margin-top: 14px; text-align: center; }

/* ---- Topbar ---- */
#topbar { background: var(--bg-secondary); border-bottom: 1px solid var(--border); padding: 12px 24px; display: flex; justify-content: space-between; align-items: center; }
.topbar-left { display: flex; align-items: center; gap: 14px; }
.logo-small { font-weight: 700; font-size: 16px; color: #fff; }
.badge { background: rgba(99,102,241,0.15); color: var(--accent); padding: 3px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-sm { background: rgba(255,255,255,0.06); color: var(--text-secondary); padding: 2px 8px; border-radius: 10px; font-size: 11px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
#admin-name { color: var(--text-secondary); font-size: 13px; }
.credit-badge { background: rgba(245,158,11,0.1); color: #F59E0B; padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.warning-banner { background: rgba(245,158,11,0.1); color: #F59E0B; padding: 10px 24px; font-size: 13px; text-align: center; border-bottom: 1px solid rgba(245,158,11,0.15); }

/* ---- Tabs ---- */
#tabs { display: flex; background: var(--bg-secondary); border-bottom: 1px solid var(--border); padding: 0 24px; }
.tab { padding: 12px 20px; background: none; border: none; border-bottom: 2px solid transparent; font-size: 13px; font-weight: 500; color: var(--text-muted); cursor: pointer; transition: all 0.12s; }
.tab:hover { color: var(--text-secondary); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-badge { background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 10px; margin-left: 6px; }

/* ---- Tab Content ---- */
#tab-content { height: calc(100vh - 110px); }
.tab-pane { height: 100%; overflow-y: auto; }
.tab-placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-muted); }
.tab-placeholder h2 { font-size: 18px; margin-bottom: 6px; color: var(--text-secondary); }

/* ============================================
   LIVE CHAT TAB
   ============================================ */
.chat-layout { display: flex; height: calc(100vh - 120px); min-height: 500px; }
.chat-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; }
.conv-sidebar { width: 300px; border-right: 1px solid var(--border); background: var(--bg-secondary); display: flex; flex-direction: column; flex-shrink: 0; }
.conv-sidebar-header, .conv-filter-row { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.conv-sidebar-header h3 { font-size: 14px; font-weight: 600; }
.conv-sidebar-header select, .conv-filter-row select { padding: 6px 10px; border: 1px solid var(--border-light); border-radius: 6px; font-size: 12px; outline: none; background: var(--bg-tertiary); color: var(--text-secondary); cursor: pointer; }
.conv-list { flex: 1; overflow-y: auto; }
.conv-empty { padding: 40px 16px; text-align: center; color: var(--text-muted); font-size: 13px; }
.conv-item { padding: 14px 18px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.08s; display: flex; flex-direction: column; gap: 5px; }
.conv-item:hover { background: var(--bg-hover); }
.conv-item.active { background: var(--bg-active); border-left: 3px solid var(--accent); }
.conv-item-top { display: flex; justify-content: space-between; align-items: center; }
.conv-item-name { font-weight: 600; font-size: 14px; color: var(--text-primary); }
.conv-item-time { font-size: 10px; color: var(--text-muted); }
.conv-item-preview { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item-bottom { display: flex; gap: 6px; align-items: center; }
.handler-badge { font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 6px; text-transform: uppercase; }
.handler-badge.ai { background: rgba(34,197,94,0.12); color: #4ADE80; }
.handler-badge.admin { background: rgba(245,158,11,0.12); color: #FBBF24; }
.handler-badge.mixed { background: rgba(99,102,241,0.12); color: #A5B4FC; }
.chat-panel { flex: 1; display: flex; flex-direction: column; background: var(--bg-primary); }
.chat-placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-muted); }
.chat-placeholder span { font-size: 42px; margin-bottom: 12px; opacity: 0.4; }
.chat-placeholder p { font-size: 14px; }
.chat-active { display: flex; flex-direction: column; height: 100%; }
.chat-header-bar { padding: 12px 20px; background: var(--bg-secondary); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.chat-header-bar div { display: flex; align-items: center; gap: 8px; }
.chat-header-bar strong { font-size: 14px; }
.chat-header-bar small { font-size: 12px; color: var(--text-secondary); }
.messages-area { flex: 1; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 8px; }
.msg-row { max-width: 70%; display: flex; flex-direction: column; }
.msg-row.visitor { align-self: flex-start; }
.msg-row.ai, .msg-row.admin { align-self: flex-end; }
.msg-bubble { padding: 11px 16px; border-radius: 14px; font-size: 15px; line-height: 1.5; word-wrap: break-word; word-break: break-word; }
.msg-row.visitor .msg-bubble { background: rgba(255,255,255,0.06); color: var(--text-primary); border-bottom-left-radius: 4px; }
.msg-row.ai .msg-bubble { background: rgba(34,197,94,0.1); color: #86EFAC; border-bottom-right-radius: 4px; }
.msg-row.admin .msg-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg-meta { font-size: 11px; color: var(--text-muted); margin-top: 4px; padding: 0 4px; }
.msg-row.ai .msg-meta, .msg-row.admin .msg-meta { text-align: right; }
.typing-display { padding: 6px 24px; font-size: 12px; color: var(--text-muted); }
.admin-input-area { padding: 14px 24px; background: var(--bg-secondary); border-top: 1px solid var(--border); display: flex; gap: 12px; align-items: center; }
.admin-input-area input, .admin-input-area textarea { flex: 1; padding: 11px 14px; border: 1.5px solid var(--border-light); border-radius: 12px; font-size: 14px; font-family: inherit; outline: none; min-height: 42px; max-height: 200px; resize: none; background: rgba(255,255,255,0.03); color: #fff; transition: border-color 0.15s; line-height: 1.4; display: block; }
.admin-input-area input::placeholder, .admin-input-area textarea::placeholder { color: var(--text-muted); }
.admin-input-area input:focus, .admin-input-area textarea:focus { border-color: var(--accent); }
.admin-input-area .btn-primary { width: auto; padding: 11px 28px; flex-shrink: 0; border-radius: 12px; }

/* ============================================
   KNOWLEDGE BASE TAB
   ============================================ */
.kb-layout { display: flex; height: 100%; }
.kb-sidebar { width: 280px; border-right: 1px solid var(--border); background: var(--bg-secondary); display: flex; flex-direction: column; flex-shrink: 0; }
.kb-sidebar-header { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.kb-sidebar-header h3, .kb-sidebar-header h4 { font-size: 14px; font-weight: 600; }
.kb-cat-list { flex: 1; overflow-y: auto; }
.kb-cat-item { padding: 12px 18px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.08s; display: flex; justify-content: space-between; align-items: center; }
.kb-cat-item:hover { background: var(--bg-hover); }
.kb-cat-item.active { background: var(--bg-active); border-left: 3px solid var(--accent); }
.kb-cat-item-name { font-size: 14px; color: var(--text-primary); }
.kb-cat-item-count { font-size: 11px; color: var(--text-muted); }
.kb-cat-item-actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.12s; }
.kb-cat-item:hover .kb-cat-item-actions { opacity: 1; }
.kb-inline-form { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.kb-inline-form input { padding: 9px 12px; border: 1.5px solid var(--border-light); border-radius: 8px; font-size: 13px; background: rgba(255,255,255,0.03); color: #fff; outline: none; }
.kb-inline-form input:focus { border-color: var(--accent); }
.kb-inline-actions { display: flex; gap: 6px; }
.kb-main { flex: 1; display: flex; flex-direction: column; }
.kb-main-header { padding: 16px 24px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; background: var(--bg-secondary); gap: 12px; }
.kb-main-header h3, .kb-main-header h4 { font-size: 15px; font-weight: 600; white-space: nowrap; }
.kb-main-actions { display: flex; gap: 10px; align-items: center; }
.input-sm { padding: 7px 12px; border: 1px solid var(--border-light); border-radius: 8px; font-size: 13px; background: rgba(255,255,255,0.03); color: #fff; outline: none; width: 200px; }
.input-sm:focus { border-color: var(--accent); }
.input-sm::placeholder { color: var(--text-muted); }
.kb-entries-list { flex: 1; overflow-y: auto; padding: 16px 24px; }
.kb-empty { text-align: center; color: var(--text-muted); padding: 40px; font-size: 14px; }
.kb-entry-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 12px; padding: 16px 20px; margin-bottom: 12px; cursor: pointer; transition: border-color 0.12s; }
.kb-entry-card:hover { border-color: var(--accent); }
.kb-entry-title { font-size: 15px; font-weight: 600; color: var(--text-primary); margin-bottom: 6px; }
.kb-entry-content { font-size: 13px; color: var(--text-secondary); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.kb-entry-meta { display: flex; gap: 10px; margin-top: 10px; align-items: center; }
.kb-entry-toggle { font-size: 11px; cursor: pointer; }

/* ============================================
   WIDGET SETTINGS — COMPACT REDESIGN
   ============================================ */
.ws-page { padding: 20px 24px; }
.ws-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.ws-header h3 { font-size: 18px; font-weight: 600; }
.ws-header-actions { display: flex; align-items: center; gap: 12px; }
.ws-status { font-size: 13px; }

.ws-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.ws-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
}
.ws-card h4 {
  font-size: 12px; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.6px;
  margin-bottom: 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.ws-card .form-group { margin-bottom: 12px; }
.ws-card .form-group:last-child { margin-bottom: 0; }

.ws-card-sm { /* default 1col span */ }
.ws-card-full { grid-column: 1 / -1; }

.ws-row-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* Color picker row */
.ws-color-row { display: flex; gap: 14px; flex-wrap: wrap; }
.ws-color-item { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.ws-color-item label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }
.ws-color-item input[type="color"] { width: 44px; height: 36px; padding: 3px; border: 1.5px solid var(--border-light); border-radius: 8px; cursor: pointer; background: rgba(255,255,255,0.03); }

/* Sound section */
.ws-sound-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.ws-sound-col { display: flex; flex-direction: column; gap: 8px; }
.ws-sound-label { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.ws-sound-select-row { display: flex; gap: 8px; align-items: center; }
.ws-sound-select-row select { flex: 1; padding: 8px 12px; border: 1.5px solid var(--border-light); border-radius: 8px; font-size: 13px; background: var(--bg-tertiary); color: var(--text-secondary); outline: none; }
.ws-sound-upload { display: none; margin-top: 4px; }
.ws-sound-upload.visible { display: flex; gap: 8px; align-items: center; }
.ws-sound-upload input[type="file"] { font-size: 12px; color: var(--text-secondary); max-width: 200px; }
.ws-sound-status { font-size: 12px; color: var(--text-muted); }

/* Embed code */
.embed-code {
  background: rgba(0,0,0,0.25); border-radius: 8px; padding: 12px;
  font-size: 12px; color: var(--accent); font-family: 'Courier New', monospace;
  line-height: 1.6; word-break: break-all; white-space: pre-wrap;
  overflow-x: auto; margin: 0;
}

@media (max-width: 900px) {
  .ws-grid { grid-template-columns: 1fr; }
  .ws-sound-grid { grid-template-columns: 1fr; }
  .ws-row-2col { grid-template-columns: 1fr; }
}

/* ============================================
   ANALYTICS TAB
   ============================================ */
.analytics-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; padding: 20px 24px 0; }
.stats-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-bottom: 28px; padding: 24px 24px 0; }
.stat-card { 
  background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 12px; 
  padding: 18px 16px; text-align: center;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  min-height: 120px;
}
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--text-primary); }
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; padding: 0 24px; }
.chart-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 12px; padding: 20px; height: 320px; position: relative; }
.chart-card h4 { font-size: 13px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 14px; }
.chart-card canvas { max-height: 250px; }

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================
   STAFF MANAGEMENT TAB
   ============================================ */
.staff-layout { padding: 24px; }
.staff-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.staff-header h3 { font-size: 18px; font-weight: 600; }
.staff-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.staff-card {
  background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px 20px; cursor: pointer; transition: border-color 0.12s;
}
.staff-card:hover { border-color: var(--accent); }
.staff-card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.staff-card-name { font-size: 15px; font-weight: 600; }
.staff-card-email { font-size: 13px; color: var(--text-secondary); margin-bottom: 10px; }
.staff-card-perms { display: flex; gap: 6px; flex-wrap: wrap; }
.staff-perm-tag { font-size: 11px; padding: 2px 8px; border-radius: 6px; background: rgba(99,102,241,0.1); color: var(--accent); }
.staff-perms { display: flex; flex-direction: column; gap: 8px; }

/* ============================================
   SETTINGS GRID (Profile, etc.)
   ============================================ */
.settings-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; padding: 28px 32px; }
.settings-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 12px; padding: 22px; }
.settings-card h4 { font-size: 13px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
@media (max-width: 800px) { .settings-grid { grid-template-columns: 1fr; } }

/* ============================================
   MODAL
   ============================================ */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 16px; width: 520px; max-height: 80vh; display: flex; flex-direction: column; }
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-body { padding: 24px; overflow-y: auto; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-footer .btn-primary { width: auto; padding: 10px 28px; }

/* ---- Toggle Switch ---- */
.toggle-row { display: flex; align-items: center; justify-content: space-between; }
.toggle-label { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; color: var(--text-primary); }
.toggle-label input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,0.15); border-radius: 24px; transition: 0.3s; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: 0.3s; }
.switch input:checked+.slider { background: #22C55E; }
.switch input:disabled+.slider { opacity: .45; cursor: not-allowed; }
.switch input:checked+.slider:before { transform: translateX(20px); }
.hint { font-size: 12px; color: rgba(255,255,255,0.4); margin-top: 6px; }

/* ---- Unread / Urgent dots ---- */
.unread-dot { display: inline-block; width: 9px; height: 9px; background: #EF4444; border-radius: 50%; margin-right: 6px; vertical-align: middle; animation: unread-pulse 1.5s infinite; }
@keyframes unread-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
.conv-item.closed { opacity: 0.5; }
.conv-item.closed:hover { opacity: 0.65; }
.urgent-dot { display: inline-block; width: 9px; height: 9px; background: #EF4444; border-radius: 50%; margin-right: 6px; vertical-align: middle; animation: urgent-flash 0.5s infinite; }
@keyframes urgent-flash { 0%,100% { opacity: 1; background: #EF4444; } 50% { opacity: 0.3; background: #FCA5A5; } }
.conv-item.urgent { border-left: 3px solid #EF4444; background: rgba(239,68,68,0.05); }
.unread-count-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #EF4444; color: #fff; font-size: 11px; font-weight: 700; margin-left: 6px; line-height: 1; }

/* Move widget bubble up so it doesn't cover Send button */
#tcai-widget-container { bottom: 100px !important; }
#tcai-window { bottom: 166px !important; }

/* ========== RESPONSIVE (MOBILE) ========== */
@media (max-width: 768px) {
    /* Login */
    .login-card { width: 90%; padding: 28px 20px; }

    /* Topbar */
    #topbar { padding: 12px 16px; flex-wrap: wrap; gap: 8px; justify-content: space-between; }
    .topbar-left { width: 100%; justify-content: space-between; }
    .topbar-right { width: 100%; justify-content: space-between; font-size: 13px; }
    
    /* Tabs */
    #tabs { padding: 0 10px; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
    .tab { padding: 12px 14px; font-size: 13px; }

    /* Content Area */
    #tab-content { height: calc(100vh - 120px); }
    .tab-pane { padding: 0; }
    
    /* Modals */
    .modal-card { width: 95%; max-width: none; margin: 10px; max-height: 90vh; display: flex; flex-direction: column; }
    .modal-body { overflow-y: auto; padding: 16px; }
    .modal-header, .modal-footer { padding: 14px 16px; }

    /* Layouts (Live Chat & Knowledge Base) */
    .chat-layout, .kb-layout { flex-direction: column; height: calc(100vh - 120px); min-height: auto; }
    
    .conv-sidebar, .kb-sidebar { width: 100%; height: 260px; flex-shrink: 0; border-right: none; border-bottom: 1px solid var(--border); }
    .chat-main, .kb-main { flex: 1; min-height: 380px; display: flex; flex-direction: column; }
    
    .chat-header-bar, .kb-main-header { flex-wrap: wrap; gap: 8px; }
    .chat-header-bar > div:last-child { display: flex; gap: 4px; width: 100%; justify-content: flex-start; }
    
    .admin-input-area { padding: 10px 14px; gap: 8px; }
    .admin-input-area input, .admin-input-area textarea { font-size: 13px; padding: 10px; }
    .admin-input-area .btn-primary { padding: 10px 16px; }
    
    .msg-row { max-width: 85%; }
    
    /* Analytics Toolbar */
    .analytics-toolbar { flex-wrap: wrap; }
    .analytics-toolbar input[type="date"] { flex: 1 1 40%; }
    .analytics-toolbar button { flex: 1 1 auto; }
    
    /* Staff & Settings Grids */
    .staff-list, .settings-grid { grid-template-columns: 1fr; }
}

/* Jalur B (Hybrid): chats assigned to this agent */
.badge-mine {
    background: rgba(99, 102, 241, 0.18);
    color: #A5B4FC;
}

/* Handover engine: "Tugas saya" strip + list badges (task-strip.js) */
.task-strip { padding: 8px 12px; border-bottom: 1px solid var(--border); background: rgba(245,158,11,0.06); }
.task-chip-topic { font-size: 10px; font-weight: 700; letter-spacing: 0.4px; padding: 1px 6px; border-radius: 8px; background: rgba(255,255,255,0.12); margin-left: 4px; }
/* The bot's card above the messages (handover brief) */
#chat-ticket-card { display: none; padding: 8px 12px 0; }
.ticket-card { background: rgba(99,102,241,0.12); border: 1px solid rgba(99,102,241,0.35); border-radius: 10px; padding: 8px 12px; font-size: 13px; }
.ticket-card.incomplete { background: rgba(245,158,11,0.12); border-color: rgba(245,158,11,0.4); }
.ticket-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.ticket-topic { font-weight: 700; letter-spacing: 0.4px; }
.ticket-flag { font-size: 11px; padding: 1px 7px; border-radius: 8px; background: rgba(245,158,11,0.25); color: #FCD34D; }
.ticket-flag.ok { background: rgba(34,197,94,0.18); color: #86EFAC; }
.ticket-copy { margin-left: auto; }
.ticket-items { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.ticket-item .ticket-label { color: var(--text-muted, #9CA3AF); }
.ticket-item.missing { color: #FCA5A5; }
.ticket-want { margin-top: 4px; color: var(--text-secondary, #D1D5DB); }
.task-strip-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-secondary); margin-bottom: 4px; }
.task-strip-overdue { color: #FCA5A5; font-weight: 700; margin-left: 6px; }
.task-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; margin: 3px 4px 3px 0; border-radius: 14px; font-size: 12px; cursor: pointer; background: rgba(245,158,11,0.15); color: #FCD34D; border: 1px solid transparent; }
.task-chip:hover { border-color: rgba(255,255,255,0.25); }
.task-chip.soon { background: rgba(249,115,22,0.2); color: #FDBA74; }
.task-chip.overdue, .task-badge.overdue { background: rgba(239,68,68,0.22); color: #FCA5A5; animation: task-pulse 1.2s ease-in-out infinite; }
.task-chip.engaged, .task-badge.engaged { background: rgba(34,197,94,0.12); color: #86EFAC; }
.task-chip.waiting, .task-badge.waiting { background: rgba(99,102,241,0.15); color: #A5B4FC; }
.task-badge.due, .task-badge.soon { background: rgba(245,158,11,0.15); color: #FCD34D; }
@keyframes task-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

/* Agent Performance cards (Tahap 3b, /admin/agent-performance.js) */
.apc-toolbar { flex-wrap: wrap; gap: 10px; align-items: center; }
.apc-seg { display: inline-flex; gap: 4px; }
.apc-h { margin: 14px 0 8px; font-size: 15px; font-weight: 600; }
.apc-store { margin-bottom: 14px; }
.apc-store-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; margin: 8px 0; }
.apc-store-warn { padding: 8px 12px; border-radius: 8px; background: rgba(239,68,68,0.12); color: #FCA5A5; font-size: 13px; }
.apc-note { font-size: 12px; margin: 6px 0; }
.apc-abuse { margin-top: 8px; font-size: 13px; }
.apc-abuse summary { cursor: pointer; color: var(--text-muted, #9CA3AF); }
.apc-abuse ul { margin: 6px 0 0 16px; padding: 0; }
.apc-abuse li { margin: 4px 0; }
.apc-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 12px; }
.apc-card { background: var(--bg-secondary, rgba(255,255,255,0.03)); border: 1px solid var(--border, rgba(255,255,255,0.08)); border-radius: 12px; padding: 14px 16px; }
.apc-card.apc-off { opacity: 0.55; }
.apc-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; font-size: 13px; }
.apc-name { font-size: 15px; }
.apc-online { color: #4ADE80; font-weight: 600; }
.apc-muted { color: var(--text-muted, #9CA3AF); font-size: 12px; }
.apc-judge { display: grid; grid-template-columns: 22px 92px 1fr; gap: 6px; align-items: baseline; padding: 6px 8px; border-radius: 8px; margin-bottom: 4px; font-size: 13px; }
.apc-judge.apc-green { background: rgba(34,197,94,0.08); }
.apc-judge.apc-yellow { background: rgba(245,158,11,0.10); }
.apc-judge.apc-red { background: rgba(239,68,68,0.12); }
.apc-judge.apc-grey { background: rgba(255,255,255,0.03); color: var(--text-muted, #9CA3AF); }
.apc-judge-title { font-weight: 600; }
.apc-problems { margin: 10px 0 6px; font-size: 13px; }
.apc-problems ul { margin: 4px 0 0 16px; padding: 0; }
.apc-problems li { margin: 4px 0; }
.apc-sub { font-weight: 600; margin-bottom: 2px; }
.apc-raw summary { cursor: pointer; font-size: 12px; color: var(--text-muted, #9CA3AF); margin-top: 6px; }
.apc-raw-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; margin-top: 8px; font-size: 12px; }
.apc-legacy { margin-top: 18px; }
.apc-legacy summary { cursor: pointer; font-size: 13px; color: var(--text-muted, #9CA3AF); }
.apc-modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; }
.apc-modal { background: var(--bg-primary, #111827); border: 1px solid var(--border, rgba(255,255,255,0.1)); border-radius: 12px; width: min(760px, 100%); max-height: 85vh; display: flex; flex-direction: column; padding: 14px 16px; }
.apc-modal-top { display: flex; justify-content: space-between; align-items: center; font-weight: 600; margin-bottom: 8px; }
.apc-modal-head { margin-bottom: 8px; font-size: 13px; }
.apc-transcript { overflow-y: auto; font-size: 13px; line-height: 1.5; }
.apc-msg { padding: 3px 0; }
.apc-msg-admin { color: #FCD34D; }
.apc-msg-ai { color: #86EFAC; }
.apc-ev { padding: 3px 8px; margin: 3px 0; border-left: 3px solid rgba(99,102,241,0.6); background: rgba(99,102,241,0.08); border-radius: 4px; }
.apc-ev-bad { border-left-color: #EF4444; background: rgba(239,68,68,0.12); }

/* ---- KB entry pictures (kb-images) ---- */
.kb-images { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0; }
.kb-image-item { width: 150px; position: relative; }
.kb-image-item img { width: 150px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-secondary); display: block; }
.kb-image-caption { width: 100%; margin-top: 4px; font-size: 12px; padding: 5px 7px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-secondary); color: var(--text-primary); }
.kb-image-del { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; border: none; background: rgba(0,0,0,0.65); color: #fff; font-size: 12px; cursor: pointer; line-height: 22px; padding: 0; }
.kb-image-del:hover { background: #EF4444; }
.kb-images-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
