/* ─────────────────────────────────────────────────────────────
   Base & Reset
───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w:    260px;
  --sidebar-bg:   #1e2a3a;
  --sidebar-text: #94a3b8;
  --sidebar-act:  #f1f5f9;
  --accent:       #4361ee;
  --accent-h:     #3451db;
  --bg:           #f1f4f9;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --text:         #1e293b;
  --text-muted:   #64748b;
  --success:      #16a34a;
  --success-bg:   #dcfce7;
  --warning:      #d97706;
  --warning-bg:   #fef3c7;
  --danger:       #dc2626;
  --danger-bg:    #fee2e2;
  --info:         #0284c7;
  --info-bg:      #e0f2fe;
  --muted-bg:     #f1f5f9;
  --radius:       8px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:    0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
}

html, body { height: 100%; font-family: "Segoe UI", system-ui, -apple-system, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-h); text-decoration: underline; }

/* ─────────────────────────────────────────────────────────────
   App shell
───────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ─────────────────────────────────────────────────────────────
   Sidebar
───────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, #1e2a3a 0%, #1a2536 100%);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.3s ease;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.1) transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 4px; }

.sidebar.collapsed {
  width: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-brand img { max-width: 160px; height: auto; display: block; }
.brand-icon { font-size: 22px; }
.brand-name { font-size: 16px; font-weight: 700; color: #fff; letter-spacing: -.3px; }

.sidebar-nav {
  padding: 10px 10px;
  flex: 1;
}

.nav-section-label {
  padding: 18px 12px 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: rgba(148,163,184,.4);
  text-transform: uppercase;
}
.nav-section-label:first-child {
  padding-top: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 14px;
  margin: 1px 0;
  color: var(--sidebar-text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .18s ease;
  border-radius: 8px;
  border-left: none;
  text-decoration: none;
  position: relative;
}
.nav-item:hover {
  background: rgba(255,255,255,.07);
  color: #e2e8f0;
  text-decoration: none;
}
.nav-item.active {
  background: rgba(67,97,238,.15);
  color: var(--sidebar-act);
  box-shadow: inset 0 0 0 1px rgba(67,97,238,.2);
}
.nav-item.active .nav-icon { color: var(--accent); }
.nav-icon { font-size: 15px; flex-shrink: 0; opacity: .75; transition: opacity .18s, color .18s; }
.nav-item:hover .nav-icon { opacity: 1; }
.nav-item.active .nav-icon { opacity: 1; }

.nav-disabled { opacity: .35; cursor: default; }
.nav-disabled:hover { background: none; color: var(--sidebar-text); }

.nav-badge {
  margin-left: auto;
  font-size: 10px;
  background: rgba(255,255,255,.1);
  color: rgba(255,255,255,.45);
  padding: 1px 7px;
  border-radius: 20px;
}

.sidebar-footer {
  padding: 16px 20px;
  font-size: 11px;
  color: rgba(148,163,184,.3);
  border-top: 1px solid rgba(255,255,255,.05);
  background: rgba(0,0,0,.08);
}

/* ─────────────────────────────────────────────────────────────
   Main area
───────────────────────────────────────────────────────────── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: 52px;
  padding: 0 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  box-shadow: var(--shadow);
}
.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar-username {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}
.topbar-logout {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: background .15s, color .15s, border-color .15s;
}
.topbar-logout:hover {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: #fca5a5;
  text-decoration: none;
}

/* ─────────────────────────────────────────────────────────────
   Notification Bell + Panel
───────────────────────────────────────────────────────────── */
.notif-wrap { position: relative; }
.notif-bell {
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color .15s, background .15s;
}
.notif-bell:hover { color: var(--text); background: rgba(0,0,0,.05); }
.notif-badge {
  position: absolute;
  top: -2px;
  right: -4px;
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  line-height: 1;
  pointer-events: none;
}
.notif-panel {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 2000;
  width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,.15);
  overflow: hidden;
}
.notif-panel.open { display: block; }
.notif-panel-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .65rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--muted-bg);
}
.notif-panel-title { font-size: .82rem; font-weight: 700; color: var(--text); }
.notif-dismiss-all {
  background: none;
  border: none;
  font-size: .75rem;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font-weight: 500;
}
.notif-dismiss-all:hover { text-decoration: underline; }
.notif-list { max-height: 360px; overflow-y: auto; }
.notif-empty { padding: 1.5rem 1rem; font-size: .82rem; color: var(--text-muted); text-align: center; }
.notif-item {
  padding: .65rem 1rem;
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--muted-bg); }
.notif-item-type { font-size: .68rem; color: var(--text-muted); margin-bottom: .15rem; }
.notif-item-title { font-size: .82rem; font-weight: 600; color: var(--text); margin-bottom: .2rem; }
.notif-item-title a { color: inherit; text-decoration: none; }
.notif-item-title a:hover { color: var(--accent); text-decoration: underline; }
.notif-item-body { font-size: .77rem; color: var(--text-muted); line-height: 1.4; margin-bottom: .25rem; }
.notif-item-foot { display: flex; align-items: center; justify-content: space-between; }
.notif-item-time { font-size: .68rem; color: var(--text-muted); opacity: .7; }
.notif-dismiss-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: .95rem;
  color: var(--text-muted);
  line-height: 1;
  padding: 0 2px;
  opacity: .5;
  transition: opacity .12s, color .12s;
}
.notif-dismiss-btn:hover { opacity: 1; color: var(--danger); }

/* Toast notifications */
#notif-toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  pointer-events: none;
}
.notif-toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: .75rem 2.5rem .75rem 1rem;
  min-width: 260px;
  max-width: 340px;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
  pointer-events: auto;
  position: relative;
  opacity: 0;
  transform: translateX(20px);
  transition: opacity .35s ease, transform .35s ease;
}
.notif-toast.show { opacity: 1; transform: translateX(0); }
.notif-toast-type { font-size: .7rem; color: var(--text-muted); margin-bottom: .15rem; }
.notif-toast-title { font-size: .82rem; font-weight: 700; color: var(--text); margin-bottom: .15rem; }
.notif-toast-title a { color: inherit; text-decoration: none; }
.notif-toast-title a:hover { color: var(--accent); }
.notif-toast-body { font-size: .77rem; color: var(--text-muted); line-height: 1.4; }
.notif-toast-close {
  position: absolute;
  top: .35rem;
  right: .5rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text-muted);
  line-height: 1;
  opacity: .5;
}
.notif-toast-close:hover { opacity: 1; }

.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
}

/* ─────────────────────────────────────────────────────────────
   Alerts
───────────────────────────────────────────────────────────── */
.alert {
  padding: 10px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 500;
}
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #86efac; }
.alert-danger  { background: var(--danger-bg);  color: var(--danger);  border: 1px solid #fca5a5; }

/* ─────────────────────────────────────────────────────────────
   Cards
───────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-header-hint {
  margin-left: auto;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}
.card-body { padding: 16px 18px; }

.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 20px; }

/* ─────────────────────────────────────────────────────────────
   Buttons
───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background .15s, border-color .15s, box-shadow .15s;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }

.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); color: #fff; }

.btn-outline  { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn-outline:hover { background: var(--accent); color: #fff; }

.btn-ghost    { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--muted-bg); color: var(--text); }

.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }

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

.btn-warning  { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #b45309; color: #fff; }

.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; color: #fff; }

.w-full { width: 100%; justify-content: center; }

.btn-icon {
  background: none; border: none; cursor: pointer;
  font-size: 15px; padding: 2px 4px; border-radius: 4px;
  transition: background .15s;
}
.btn-icon:hover { background: var(--muted-bg); }

/* ─────────────────────────────────────────────────────────────
   Forms
───────────────────────────────────────────────────────────── */
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 5px; }
.req { color: var(--danger); }

.form-input, .form-select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.form-input:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(67,97,238,.1);
}
.form-body { font-family: "Cascadia Code", "Consolas", monospace; font-size: 13px; resize: vertical; }
.w-full { width: 100%; }

.form-group { display: flex; flex-direction: column; gap: 2px; }
.form-grid  { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.span-2     { grid-column: 1 / -1; }

/* ─────────────────────────────────────────────────────────────
   Toolbar
───────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.search-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex: 1;
}
.search-bar .form-input { min-width: 220px; }

/* ─────────────────────────────────────────────────────────────
   Tables
───────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; overflow-y: auto; max-height: calc(100vh - 220px); margin-bottom: 1rem; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--muted-bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}
.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody tr:last-child td { border-bottom: none; }

.td-id    { color: var(--text-muted); font-size: 12px; width: 40px; }
.td-task  { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); }
.td-title { min-width: 200px; }
.td-title a { font-weight: 500; color: var(--text); }
.td-title a:hover { color: var(--accent); }
.td-date  { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.td-actions { display: flex; gap: 4px; align-items: center; white-space: nowrap; }
.td-actions form { margin: 0; }

.table-footer {
  padding: 10px 16px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--muted-bg);
}

/* ─────────────────────────────────────────────────────────────
   Badges
───────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-success  { background: var(--success-bg); color: var(--success); }
.badge-warning  { background: var(--warning-bg); color: var(--warning); }
.badge-danger   { background: var(--danger-bg);  color: var(--danger); }
.badge-info     { background: var(--info-bg);    color: var(--info); }
.badge-muted    { background: var(--muted-bg);   color: var(--text-muted); }
.badge-language { background: #ede9fe; color: #6d28d9; }
.badge-week     { background: #e0f2fe; color: #0369a1; }

/* ─────────────────────────────────────────────────────────────
   Empty state
───────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 52px 20px;
  gap: 12px;
  color: var(--text-muted);
}
.empty-icon { font-size: 40px; opacity: .4; }
.empty-state p { font-size: 14px; }

/* ─────────────────────────────────────────────────────────────
   Dashboard grid
───────────────────────────────────────────────────────────── */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: box-shadow .2s;
}
.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-icon { font-size: 30px; }
.stat-value { font-size: 26px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.quick-links { display: flex; gap: 10px; flex-wrap: wrap; }

/* ─────────────────────────────────────────────────────────────
   Detail layout
───────────────────────────────────────────────────────────── */
.detail-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 20px;
  align-items: start;
}
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  align-items: start;
}
.detail-list {
  display: grid;
  grid-template-columns: 140px 1fr;
  margin: 0;
  padding: 0;
}
.detail-list dt {
  padding: 14px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--muted-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
}
.detail-list dd {
  padding: 14px 18px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  margin: 0;
  display: flex;
  align-items: center;
}
.detail-list dt:last-of-type,
.detail-list dd:last-of-type {
  border-bottom: none;
}

.detail-title-row { flex-direction: column; align-items: flex-start; gap: 8px; }
.detail-title { font-size: 18px; font-weight: 700; padding: 16px 18px 0; }
.detail-meta-pills { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 18px 14px; }

.report-resume {
  margin: 0 18px 14px;
  padding: 12px 14px;
  background: var(--muted-bg);
  border-radius: 6px;
  border-left: 3px solid var(--accent);
}
.resume-label { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--text-muted); margin-bottom: 4px; }

.report-body-content {
  padding: 4px 18px 18px;
  line-height: 1.7;
  color: var(--text);
}
.md-heading { font-size: 15px; font-weight: 700; margin: 14px 0 6px; color: var(--text); }
.md-p       { margin-bottom: 8px; }
.md-ul, .md-ol { padding-left: 22px; margin-bottom: 8px; }
.md-ul li, .md-ol li { margin-bottom: 4px; }
.md-hr      { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.img-tag    { display: inline-block; background: var(--info-bg); color: var(--info); padding: 1px 5px; border-radius: 4px; font-size: 11px; font-weight: 700; }

.report-images { padding: 0 18px 18px; }
.section-label { font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; margin-bottom: 10px; }
.image-grid { display: flex; flex-wrap: wrap; gap: 12px; }
.image-card { border: 1px solid var(--border); border-radius: 6px; overflow: hidden; max-width: 200px; }
.image-tag  { padding: 3px 8px; background: var(--muted-bg); font-size: 11px; font-weight: 700; color: var(--info); }
.report-img { display: block; width: 100%; max-height: 140px; object-fit: contain; }
.image-name { padding: 3px 8px 6px; font-size: 11px; color: var(--text-muted); }

.meta-list     { padding: 4px 0; }
.meta-row      { display: flex; gap: 8px; padding: 8px 18px; border-bottom: 1px solid var(--border); font-size: 13px; }
.meta-row:last-child { border-bottom: none; }
.meta-key      { width: 90px; flex-shrink: 0; color: var(--text-muted); font-size: 12px; }
.meta-val      { flex: 1; color: var(--text); word-break: break-all; }
.text-mono     { font-family: monospace; font-size: 11px; }
.text-muted    { color: var(--text-muted); }

.team-list     { list-style: none; padding: 8px 18px; }
.team-member   { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.team-member:last-child { border-bottom: none; }

/* ── Card collapse toggle ──────────────────────────────── */
.collapse-toggle {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  opacity: 0.4;
  flex-shrink: 0;
  transition: transform .2s ease, opacity .15s;
}
.card-header:hover .collapse-toggle { opacity: 0.9; }
.card.collapsed .collapse-toggle { transform: rotate(-90deg); opacity: 0.6; }

/* ── Small button variants ─────────────────────────────── */
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  transition: background .12s, color .12s;
  padding: 0;
}
.btn-icon-sm:hover { background: #fee2e2; color: #dc2626; border-color: #fca5a5; }
.btn-danger-sm { color: #dc2626; border-color: #fca5a5; }

/* ── Image manage list (form sidebar) ──────────────────── */
.image-manage-list { display: flex; flex-direction: column; gap: 6px; }
.image-manage-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 5px;
  background: var(--muted-bg);
  border: 1px solid var(--border);
}
.image-tag-badge {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  background: #eef2ff;
  border-radius: 3px;
  padding: 1px 5px;
  white-space: nowrap;
  flex-shrink: 0;
}
.image-manage-name {
  flex: 1;
  font-size: 11px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-buttons { display: flex; flex-direction: column; gap: 8px; }
.sticky-card { position: sticky; top: 20px; }

/* ─────────────────────────────────────────────────────────────
   Form layout
───────────────────────────────────────────────────────────── */
.form-layout {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 20px;
  align-items: start;
}
.form-layout form {
  display: contents; /* both children become direct grid children */
}

/* ─────────────────────────────────────────────────────────────
   AI Toolbar
───────────────────────────────────────────────────────────── */
.ai-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  background: linear-gradient(90deg, #f0f4ff 0%, #f8f9ff 100%);
  border-bottom: 1px solid #dde4f8;
  flex-wrap: wrap;
}
.ai-toolbar-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .5px;
  text-transform: uppercase;
  margin-right: 4px;
}
.btn-ai {
  padding: 4px 11px;
  background: white;
  border: 1px solid #c7d2fe;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
}
.btn-ai:hover { background: #eef2ff; box-shadow: 0 1px 3px rgba(67,97,238,.15); }
.ai-divider { width: 1px; height: 20px; background: #c7d2fe; margin: 0 4px; }
.ai-lang-select, .ai-prompt-select {
  padding: 4px 8px;
  font-size: 12px;
  border-color: #c7d2fe;
  border-radius: 5px;
}
.ai-lang-select { width: 60px; }
.ai-prompt-select { width: 180px; }
.ai-spinner { font-size: 14px; margin-left: 6px; animation: spin 1s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─────────────────────────────────────────────────────────────
   Rich Editor Component
───────────────────────────────────────────────────────────── */
.rich-editor-content {
  min-height: 120px;
  max-height: 400px;
  overflow-y: auto;
  padding: 12px;
  border-radius: 0 0 6px 6px;
  border: 1px solid var(--border);
  border-top: none;
  background: var(--surface);
  outline: none;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
}
.rich-editor-content:focus {
  box-shadow: inset 0 0 0 2px rgba(67,97,238,.12);
}
.rich-editor-content:empty:before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
  display: block;
}
.rich-editor-content ul {
  padding-left: 20px;
  margin: 8px 0;
}
.rich-editor-content b, .rich-editor-content strong {
  font-weight: 700;
}
.rich-editor-content i, .rich-editor-content em {
  font-style: italic;
}
.rich-editor-content u {
  text-decoration: underline;
}

.ai-result-box {
  margin: 0 18px 18px;
  border: 1px solid #c7d2fe;
  border-radius: 8px;
  background: #f8f9ff;
  overflow: hidden;
}
.ai-result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: #eef2ff;
  border-bottom: 1px solid #c7d2fe;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}
.ai-result-actions { display: flex; gap: 6px; }
.btn-sm { padding: 3px 10px; font-size: 12px; }
.btn-xs { padding: 2px 8px; font-size: 11px; }
.ai-result-text {
  padding: 12px 14px;
  font-family: "Segoe UI", sans-serif;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
}

/* ─────────────────────────────────────────────────────────────
   Timeline (2WH detail)
───────────────────────────────────────────────────────────── */
.timeline-wrap {
  padding: 16px 18px 20px;
}
.timeline-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.timeline-row {
  display: flex;
  gap: 14px;
  padding-bottom: 18px;
  position: relative;
}
.timeline-row:not(:last-child)::after {
  content: '';
  position: absolute;
  left: 7px;
  top: 16px;
  width: 2px;
  height: calc(100% - 16px);
  background: var(--border);
}
.timeline-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 2px;
  border: 2px solid;
}
.dot-accent  { background: var(--accent); border-color: var(--accent); }
.dot-warning { background: var(--warning); border-color: var(--warning); }
.dot-muted   { background: var(--border); border-color: var(--text-muted); }
.timeline-content { flex: 1; }
.timeline-title { font-size: 13px; font-weight: 600; color: var(--text); }
.timeline-dates { font-size: 13px; color: var(--text-muted); margin-top: 3px; }
.timeline-why {
  font-size: 12px;
  color: var(--text);
  background: var(--muted-bg);
  border-left: 3px solid var(--warning);
  padding: 5px 10px;
  border-radius: 4px;
  margin-top: 6px;
}
.timeline-pending { opacity: .65; }

/* ─────────────────────────────────────────────────────────────
   Misc additions
───────────────────────────────────────────────────────────── */
.form-grid-1 { display: flex; flex-direction: column; }
.mt-3 { margin-top: 12px; }

.form-hint  { font-size: 11px; color: var(--text-muted); margin-top: 4px; display: block; }
.info-box {
  background: var(--info-bg);
  color: var(--info);
  border: 1px solid #bae6fd;
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 13px;
}

.radio-group { display: flex; gap: 12px; flex-wrap: wrap; }
.radio-opt {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: border-color .15s, background .15s;
}
.radio-opt input { accent-color: var(--accent); }
.radio-opt:has(input:checked), .radio-opt.active {
  border-color: var(--accent);
  background: #eef2ff;
}
.ai-settings-form { max-width: 700px; }
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.breadcrumb a { color: var(--accent); }
.breadcrumb span { color: var(--text-muted); }

/*  Admin  */
.admin-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  padding: 1rem;
}
.admin-stat-item {
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 12px;
  text-align: center;
  transition: border-color .15s;
}
.admin-stat-item:hover { border-color: var(--accent); }
.admin-stat-missing { opacity: .5; }
.admin-stat-count {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}
.admin-stat-label {
  font-size: .8rem;
  font-weight: 600;
  margin-top: 4px;
  color: var(--text-main);
}
.admin-stat-table {
  font-size: .7rem;
  color: var(--text-muted);
  font-family: monospace;
  margin-top: 2px;
}
.card-footer {
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg-sidebar);
  border-radius: 0 0 10px 10px;
}

/* ─────────────────────────────────────────────────────────────
   Page header (title + action button row)
───────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
  margin-bottom: 2px;
}

/* ─────────────────────────────────────────────────────────────
   form-control (Bootstrap-like alias used throughout templates)
───────────────────────────────────────────────────────────── */
.form-control {
  display: block;
  width: 100%;
  padding: 7px 11px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  appearance: auto;
}
.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(67,97,238,.12);
}
.form-control:disabled, .form-control[disabled] {
  background: var(--muted-bg);
  color: var(--text-muted);
  cursor: not-allowed;
}
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }
.form-control-sm { padding: 4px 8px; font-size: 12px; }

/* ─────────────────────────────────────────────────────────────
   Spacing utilities
───────────────────────────────────────────────────────────── */
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 6px !important; }
.mb-2 { margin-bottom: 12px !important; }
.mb-3 { margin-bottom: 18px !important; }
.mb-4 { margin-bottom: 28px !important; }
.mt-1 { margin-top: 6px !important; }
.mt-2 { margin-top: 12px !important; }
.gap-1 { gap: 6px; }
.gap-2 { gap: 12px; }

/* ─────────────────────────────────────────────────────────────
   Filter bar (list page search/status row)
───────────────────────────────────────────────────────────── */
.filter-bar { margin-bottom: 12px; }
.filter-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.filter-form .form-control { width: auto; min-width: 180px; flex: 1; }
.filter-form select.form-control { flex: 0 0 auto; min-width: 140px; }

/* ─────────────────────────────────────────────────────────────
   Form action footer (submit / cancel inside a card)
───────────────────────────────────────────────────────────── */
.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: var(--muted-bg);
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
}
.form-actions { }

/* ─────────────────────────────────────────────────────────────
   Activity modal
───────────────────────────────────────────────────────────── */
.act-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(0,0,0,.55);
  padding: 2rem 1rem;
  align-items: flex-start;
  justify-content: center;
}
.act-modal-overlay.open { display: flex; }
.act-modal-box {
  background: var(--surface);
  border-radius: 12px;
  width: min(96vw, 920px);
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
  display: flex;
  flex-direction: column;
  max-height: 82vh;
  overflow: hidden;
}
.act-modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.act-modal-header strong { font-size: 15px; }
.act-modal-header .form-control { flex: 1; max-width: 340px; margin-left: auto; }
.act-modal-body { overflow-y: auto; flex: 1; }

/* ─────────────────────────────────────────────────────────────
   Responsive — mobile
───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Sidebar becomes a fixed overlay so main-area fills full viewport width */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 9000;
    width: var(--sidebar-w) !important;
    transform: translateX(0);
    transition: transform 0.3s ease !important;
  }
  .sidebar.collapsed {
    transform: translateX(-100%);
    width: var(--sidebar-w) !important; /* override desktop width:0 */
  }
  .sidebar:not(.collapsed) {
    box-shadow: 4px 0 32px rgba(0,0,0,.45);
  }
  /* Dim backdrop shown while sidebar is open on mobile */
  .mob-sidebar-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 8999;
    display: none;
  }
  .mob-sidebar-overlay.visible { display: block; }
  /* Tighten spacing */
  .page-content { padding: 14px 16px; }
  .topbar { padding: 0 14px; }
}
@media (max-width: 480px) {
  .page-content { padding: 10px 12px; }
  .topbar { padding: 0 10px; }
}

/* ═══════════════════════════════════════════════════════════════════
   CHAT WIDGET
═══════════════════════════════════════════════════════════════════ */
#chat-root {
  position: fixed; bottom: 24px; right: 24px; z-index: 3000;
  /* Draggable: left/top are set via JS when dragged */
  transition: bottom .15s, right .15s;
}
#chat-root.chat-dragging { transition: none; user-select: none; }

/* Floating Action Button */
@keyframes chat-fab-ring {
  0%,100% { transform: rotate(0deg); }
  15%      { transform: rotate(-12deg); }
  30%      { transform: rotate(11deg); }
  45%      { transform: rotate(-9deg); }
  60%      { transform: rotate(7deg); }
  75%      { transform: rotate(-5deg); }
}
@keyframes chat-fab-glow {
  0%,100% { box-shadow: 0 2px 10px rgba(0,0,0,.18), 0 0 0 0 rgba(67,97,238,.7); }
  50%     { box-shadow: 0 2px 10px rgba(0,0,0,.18), 0 0 0 10px rgba(67,97,238,.0); }
}
@keyframes chat-badge-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.5); }
  100% { transform: scale(1); }
}
#chat-fab {
  width: 56px; height: 56px; border-radius: 50%;
  background: transparent; border: 2px solid var(--accent);
  color: var(--accent); cursor: pointer; display: flex;
  align-items: center; justify-content: center; position: relative;
  transition: background .2s, color .2s, box-shadow .2s;
  box-shadow: 0 2px 10px rgba(0,0,0,.18);
}
#chat-fab:hover { background: var(--accent); color: #fff; box-shadow: 0 4px 20px rgba(67,97,238,.45); }
#chat-fab.chat-fab-unread {
  animation: chat-fab-ring 1s ease 0s, chat-fab-glow 2s ease-in-out 1s infinite;
}

.chat-fab-badge {
  position: absolute; top: -4px; right: -4px;
  background: var(--danger); color: #fff; font-size: .65rem; font-weight: 700;
  padding: 1px 5px; border-radius: 10px; min-width: 18px; text-align: center;
  border: 2px solid #fff;
}
.chat-fab-badge.pop { animation: chat-badge-pop .35s ease; }

/* Widget panel */
.chat-widget {
  position: absolute; bottom: 68px; right: 0;
  width: 400px; height: 600px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: 0 12px 40px rgba(0,0,0,.22);
  display: flex; flex-direction: column; overflow: hidden;
  transition: width .2s, height .2s, bottom .2s, right .2s, border-radius .2s;
}

/* Fullscreen mode — WhatsApp Web 2-column layout */
.chat-widget.fullscreen {
  position: fixed; inset: 0; bottom: 0; right: 0;
  width: 100vw; height: 100vh;
  border-radius: 0; z-index: 3100;
  display: grid;
  grid-template-rows: 56px 1fr;
  grid-template-columns: 320px 1fr;
}
/* Header spans both columns */
.chat-widget.fullscreen .chat-header {
  grid-column: 1 / -1; grid-row: 1;
  border-radius: 0;
}
/* List view: left column */
.chat-widget.fullscreen #chat-view-list {
  grid-column: 1; grid-row: 2;
  border-right: 1px solid var(--border);
  display: flex;
}
/* Thread view: right column */
.chat-widget.fullscreen #chat-view-thread {
  grid-column: 2; grid-row: 2;
  display: flex;
}
/* Config view: spans both columns */
.chat-widget.fullscreen #chat-view-config {
  grid-column: 1 / -1; grid-row: 2;
  display: flex;
}

/* Header */
.chat-header {
  display: flex; align-items: center; gap: 6px;
  padding: 12px 14px; background: var(--accent); color: #fff;
  border-radius: 16px 16px 0 0; flex-shrink: 0;
  transition: border-radius .2s;
  cursor: grab; /* indicate draggable */
}
.chat-header:active { cursor: grabbing; }
.chat-widget.fullscreen .chat-header { border-radius: 0; cursor: default; }
.chat-header-title {
  flex: 1; font-weight: 600; font-size: 1rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-hdr-end { display: flex; gap: 4px; margin-left: auto; }
.chat-hdr-btn {
  background: transparent; border: none; color: #fff;
  cursor: pointer; font-size: 1rem; padding: 4px 7px; border-radius: 5px;
  opacity: .85; transition: opacity .15s, background .15s; line-height: 1;
}
.chat-hdr-btn:hover { opacity: 1; background: rgba(255,255,255,.18); }

/* Views */
.chat-view { flex: 1; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }

/* Search bar */
.chat-search-bar { padding: 10px 12px; border-bottom: 1px solid var(--border); position: relative; flex-shrink: 0; }
.chat-search-bar input {
  width: 100%; padding: 8px 12px; border-radius: 8px; font-size: .9rem;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); outline: none;
  box-sizing: border-box;
}
.chat-search-bar input:focus { border-color: var(--accent); }

.chat-user-drop {
  position: absolute; top: 100%; left: 12px; right: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.12);
  z-index: 10; max-height: 220px; overflow-y: auto;
}
.chat-user-option {
  padding: 9px 14px; font-size: .88rem; cursor: pointer; color: var(--text);
  transition: background .1s;
}
.chat-user-option:hover { background: var(--muted-bg); }

/* Conversation list */
.chat-conv-list { flex: 1; overflow-y: auto; }
.chat-empty { padding: 30px 20px; text-align: center; color: var(--text-muted); font-size: .88rem; }
.chat-conv-group-header {
  padding: 6px 16px 4px; font-size: .72rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-muted); background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 1;
}
.chat-conv-item {
  padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer;
  transition: background .1s;
}
.chat-conv-item:hover { background: var(--muted-bg); }
.chat-conv-name {
  font-size: .9rem; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: 6px;
}
.chat-conv-badge {
  background: var(--accent); color: #fff; font-size: .68rem; font-weight: 700;
  padding: 1px 6px; border-radius: 10px; min-width: 18px; text-align: center;
}
.chat-conv-preview {
  display: flex; justify-content: space-between; margin-top: 3px;
  font-size: .8rem; color: var(--text-muted);
}
.chat-conv-time { flex-shrink: 0; margin-left: 8px; }

/* Message list */
.chat-msg-list {
  flex: 1; overflow-y: auto; padding: 14px 12px; display: flex;
  flex-direction: column; gap: 8px; min-height: 0;
}
.chat-bubble {
  max-width: 78%; padding: 9px 12px; border-radius: 12px; font-size: .92rem;
  line-height: 1.5; word-break: break-word; position: relative;
}
.chat-bubble.mine {
  align-self: flex-end; background: var(--chat-mine-bg, #dbeafe); color: var(--chat-mine-color, #1e3a5f);
  border-bottom-right-radius: 3px;
}
/* Color theme overrides for mine bubble */
#chat-widget.chat-theme-blue  { --chat-mine-bg: #dbeafe; --chat-mine-color: #1e3a5f; }
#chat-widget.chat-theme-slate { --chat-mine-bg: #5a6474; --chat-mine-color: #fff; }
#chat-widget.chat-theme-teal  { --chat-mine-bg: #2a9d8f; --chat-mine-color: #fff; }
.chat-bubble.theirs {
  align-self: flex-start; background: var(--muted-bg); color: var(--text);
  border-bottom-left-radius: 3px;
}
.chat-bubble-text { line-height: 1.5; }

/* ── Markdown inside chat bubbles ────────────────────────────────── */
.chat-md strong { font-weight: 700; }
.chat-md em     { font-style: italic; }
.chat-md del    { text-decoration: line-through; opacity: .75; }
.chat-md a      { color: inherit; text-decoration: underline; opacity: .9; }
.chat-md a:hover{ opacity: 1; }
.chat-md-pre {
  margin: 6px 0; padding: 8px 11px; border-radius: 7px;
  background: rgba(0,0,0,.18); overflow-x: auto;
  font-family: 'Cascadia Code', Consolas, monospace; font-size: .8rem; line-height: 1.45;
  white-space: pre;
}
.chat-bubble.theirs .chat-md-pre { background: rgba(0,0,0,.06); }
.chat-md-code {
  font-family: 'Cascadia Code', Consolas, monospace; font-size: .82em;
  background: rgba(0,0,0,.18); padding: 1px 5px; border-radius: 4px;
}
.chat-bubble.theirs .chat-md-code { background: rgba(0,0,0,.07); }
.chat-md-ul, .chat-md-ol {
  margin: 4px 0; padding-left: 18px;
}
.chat-md-ul li, .chat-md-ol li { margin-bottom: 2px; }
.chat-bubble-meta {
  display: flex; align-items: center; gap: 4px; margin-top: 4px; flex-wrap: wrap;
}
.chat-bubble-time { font-size: .72rem; opacity: .65; margin-left: auto; }
.chat-orig-btn, .chat-trans-hover-btn {
  background: transparent; border: none; font-size: .7rem; cursor: pointer;
  opacity: .7; padding: 1px 3px; color: inherit; border-radius: 3px;
}
.chat-orig-btn:hover, .chat-trans-hover-btn:hover { opacity: 1; background: rgba(0,0,0,.08); }
.mine .chat-orig-btn:hover, .mine .chat-trans-hover-btn:hover { background: rgba(0,0,0,.08); }

/* Input area */
.chat-input-area {
  border-top: 1px solid var(--border); padding: 10px 12px;
  flex-shrink: 0; position: relative; background: var(--surface);
}
.chat-textarea {
  width: 100%; resize: none; border: 1.5px solid var(--border); border-radius: 8px;
  padding: 9px 12px; font-size: .93rem; background: var(--bg); color: var(--text);
  outline: none; box-sizing: border-box; font-family: inherit; line-height: 1.45;
  min-height: 60px; max-height: 140px;
}
.chat-textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(67,97,238,.12); }
.chat-input-btns {
  display: flex; justify-content: flex-end; gap: 7px; margin-top: 7px; align-items: center;
}
.chat-suggest-btn {
  background: transparent; border: 1px solid var(--border); padding: 5px 10px;
  border-radius: 7px; cursor: pointer; font-size: .88rem; color: var(--text-muted);
  transition: border-color .15s, color .15s;
}
.chat-suggest-btn:hover { border-color: var(--accent); color: var(--accent); }
.chat-send-btn {
  background: var(--accent); color: #fff; border: none;
  padding: 6px 18px; border-radius: 7px; cursor: pointer; font-size: .93rem;
  font-weight: 600; transition: opacity .15s, box-shadow .15s;
  box-shadow: 0 2px 6px rgba(67,97,238,.3);
}
.chat-send-btn:hover { opacity: .88; box-shadow: 0 3px 10px rgba(67,97,238,.4); }

/* @mention dropdown */
.chat-mention-drop {
  position: absolute; bottom: 100%; left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px 8px 0 0; box-shadow: 0 -4px 16px rgba(0,0,0,.1);
  z-index: 5; max-height: 160px; overflow-y: auto;
}
.chat-mention-option {
  padding: 8px 14px; font-size: .88rem; cursor: pointer; color: var(--text);
  transition: background .1s;
}
.chat-mention-option:hover, .chat-mention-option.focused { background: var(--muted-bg); }

/* AI suggest bar */
.chat-ai-bar {
  display: flex; align-items: center; gap: 8px; padding: 7px 12px;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border-top: 1px solid var(--border); flex-shrink: 0;
}
.chat-ai-text {
  flex: 1; font-size: .83rem; color: var(--text); font-style: italic;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-ai-use-btn {
  background: var(--accent); color: #fff; border: none;
  padding: 4px 12px; border-radius: 6px; cursor: pointer; font-size: .8rem;
  font-weight: 600; transition: opacity .15s; flex-shrink: 0;
}
.chat-ai-use-btn:hover { opacity: .85; }

/* Config form */
.chat-cfg-form {
  padding: 18px 16px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 10px;
}
.chat-cfg-title { font-weight: 700; font-size: 1rem; color: var(--text); margin: 0 0 4px; }
.chat-cfg-section { font-weight: 600; font-size: .82rem; color: var(--text-muted); margin: 6px 0 2px; text-transform: uppercase; letter-spacing: .04em; }
.chat-cfg-label { font-size: .85rem; color: var(--text); margin: 0; }
.chat-cfg-select {
  width: 100%; padding: 7px 10px; border-radius: 7px; font-size: .88rem;
  border: 1.5px solid var(--border); background: var(--bg); color: var(--text); outline: none;
}
.chat-cfg-select:focus { border-color: var(--accent); }
.chat-cfg-toggle { display: flex; align-items: center; justify-content: space-between; cursor: pointer; padding: 2px 0; }
.chat-cfg-slider {
  display: inline-block; width: 38px; height: 22px; background: var(--border);
  border-radius: 11px; position: relative; transition: background .2s; flex-shrink: 0;
}
.chat-cfg-toggle input { display: none; }
.chat-cfg-toggle input:checked ~ .chat-cfg-slider { background: var(--accent); }
.chat-cfg-slider::after {
  content: ''; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  top: 3px; left: 3px; background: #fff; transition: left .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.chat-cfg-toggle input:checked ~ .chat-cfg-slider::after { left: 19px; }

@media (max-width: 480px) {
  .chat-widget { width: calc(100vw - 16px); height: 70vh; right: 0; }
  #chat-root { right: 8px; bottom: 8px; }
}

/* ── Chat: Drag-and-drop overlay ─────────────────────────────────── */
.chat-drop-overlay {
  position: absolute; inset: 0; z-index: 20;
  background: rgba(67,97,238,.1);
  border: 2.5px dashed var(--accent);
  border-radius: 0 0 16px 16px;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.chat-drop-label {
  font-size: 1.1rem; font-weight: 600; color: var(--accent);
  background: var(--surface); padding: 10px 22px; border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,.12);
}

/* ── Chat: Attachment preview bar ────────────────────────────────── */
.chat-attach-preview {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border-top: 1px solid var(--border); flex-shrink: 0;
  font-size: .83rem; color: var(--text);
}
.chat-attach-preview.uploading { opacity: .6; }
.chat-attach-icon { font-size: 1.1rem; flex-shrink: 0; }
.chat-attach-filename { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-attach-remove {
  background: transparent; border: none; cursor: pointer; color: var(--text-muted);
  font-size: .95rem; padding: 0 4px; flex-shrink: 0; line-height: 1;
}
.chat-attach-remove:hover { color: var(--danger); }

/* ── Chat: orig-hint (hover to see original) ─────────────────────── */
.chat-bubble-orig-hint {
  display: none;
  font-size: .73rem; font-style: italic; opacity: .75;
  margin-top: 5px; padding-top: 5px; line-height: 1.4;
  border-top: 1px solid rgba(255,255,255,.2);
  word-break: break-word;
}
.chat-bubble.theirs .chat-bubble-orig-hint { border-top-color: var(--border); }
/* Show hint on hover — but only when it's not empty (class removed by JS after translate) */
.chat-bubble:hover .chat-bubble-orig-hint:not(.chat-orig-empty) { display: block; }
/* 🌐 translate button — shown inline in meta row */
.chat-trans-hover-btn {
  background: transparent; border: 1px solid rgba(255,255,255,.3); padding: 1px 6px;
  border-radius: 5px; cursor: pointer; font-size: .78rem; color: inherit;
  opacity: .7; transition: opacity .15s, background .15s; line-height: 1.4;
}
.chat-trans-hover-btn:hover { opacity: 1; background: rgba(255,255,255,.15); }
.chat-bubble.theirs .chat-trans-hover-btn { border-color: var(--border); }
.chat-bubble.theirs .chat-trans-hover-btn:hover { background: var(--muted-bg); }

/* ── Chat: Attach button (paperclip) ─────────────────────────────── */
.chat-attach-btn {
  background: transparent; border: 1px solid var(--border); padding: 4px 8px;
  border-radius: 6px; cursor: pointer; font-size: .85rem; color: var(--text-muted);
  transition: border-color .15s, color .15s; display: inline-flex; align-items: center;
}
.chat-attach-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Chat: Attachment in bubble ──────────────────────────────────── */
.chat-bubble-attach { margin-bottom: 4px; }
.chat-attach-img {
  max-width: 200px; max-height: 180px; border-radius: 6px; display: block;
  object-fit: cover; cursor: pointer;
}
.chat-attach-file {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 6px; text-decoration: none;
  background: rgba(0,0,0,.08); color: inherit;
  transition: background .15s; font-size: .8rem; max-width: 200px;
}
.mine .chat-attach-file { background: rgba(255,255,255,.2); color: #fff; }
.chat-attach-file:hover { background: rgba(0,0,0,.15); }
.mine .chat-attach-file:hover { background: rgba(255,255,255,.3); }
.chat-attach-file-icon { font-size: .9rem; flex-shrink: 0; }
.chat-attach-file-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px;
}

/* ── Chat: resize handle ─────────────────────────────────────────── */
#chat-resize-handle {
  position: absolute; bottom: 0; left: 0;
  width: 18px; height: 18px; cursor: nesw-resize; z-index: 10;
  display: flex; align-items: flex-end; justify-content: flex-start;
  padding: 2px 0 2px 2px; opacity: .35; transition: opacity .15s;
}
#chat-resize-handle:hover { opacity: .8; }
#chat-resize-handle svg { display: block; }
.chat-widget.fullscreen #chat-resize-handle { display: none; }

/* ── Chat: conversation item actions ─────────────────────────────── */
.chat-conv-item { position: relative; }
.chat-conv-actions {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  display: none;
}
.chat-conv-item:hover .chat-conv-actions { display: flex; }
.chat-conv-menu-btn {
  background: transparent; border: none; cursor: pointer; color: var(--text-muted);
  font-size: 1rem; padding: 2px 6px; border-radius: 4px; line-height: 1;
  transition: background .1s, color .1s;
}
.chat-conv-menu-btn:hover { background: var(--muted-bg); color: var(--text); }
.chat-conv-dropdown {
  position: absolute; right: 0; top: 100%; z-index: 100;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.15);
  min-width: 140px; overflow: hidden;
}
.chat-conv-dropdown button {
  display: block; width: 100%; text-align: left; padding: 9px 14px;
  background: transparent; border: none; cursor: pointer; font-size: .85rem;
  color: var(--text); transition: background .1s;
}
.chat-conv-dropdown button:hover { background: var(--muted-bg); }
.chat-conv-dropdown button.danger { color: var(--danger); }
.chat-conv-dropdown button.danger:hover { background: rgba(239,68,68,.08); }

/* ── Chat: edit bubble button ────────────────────────────────────── */
.chat-bubble.mine { position: relative; }
.chat-edit-btn {
  position: absolute; top: 4px; left: -28px;
  background: transparent; border: none; cursor: pointer;
  color: rgba(0,0,0,.0); font-size: .85rem; padding: 2px 5px;
  border-radius: 4px; transition: color .15s, background .15s; line-height: 1;
}
.chat-bubble.mine:hover .chat-edit-btn { color: rgba(30,58,95,.5); }
.chat-edit-btn:hover { color: var(--accent) !important; background: rgba(67,97,238,.12); }

/* ── Chat: delete bubble button ──────────────────────────────────── */
.chat-delete-btn {
  position: absolute; top: 4px; left: -52px;
  background: transparent; border: none; cursor: pointer;
  color: rgba(0,0,0,.0); font-size: .85rem; padding: 2px 5px;
  border-radius: 4px; transition: color .15s, background .15s; line-height: 1;
}
.chat-bubble.mine:hover .chat-delete-btn { color: rgba(30,58,95,.5); }
.chat-delete-btn:hover { color: #e74c3c !important; background: rgba(231,76,60,.12); }

/* ── Chat settings: color swatches ──────────────────────────────── */
.chat-color-swatches { display: flex; gap: 10px; padding: 6px 0; }
.chat-color-swatch {
  width: 36px; height: 36px; border-radius: 50%; cursor: pointer;
  border: 3px solid transparent; transition: border-color .15s, transform .15s;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.chat-color-swatch:hover { transform: scale(1.12); }
.chat-color-swatch.active { border-color: var(--text); }
.chat-color-swatch.sw-blue  { background: #dbeafe; border: 2px solid #93c5fd; }
.chat-color-swatch.sw-slate { background: #5a6474; }
.chat-color-swatch.sw-teal  { background: #2a9d8f; }

/* ── Chat: edited marker ─────────────────────────────────────────── */
.chat-edited-mark {
  font-size: .68rem; opacity: .55; font-style: italic; margin-right: 4px;
}

/* ── Chat: soft-deleted bubble ───────────────────────────────────── */
.chat-bubble-deleted {
  opacity: .65; pointer-events: none;
}
.chat-bubble-deleted.mine { background: #f1f5f9 !important; color: #94a3b8 !important; }
.chat-bubble-deleted.theirs { background: #f8fafc !important; color: #94a3b8 !important; }

/* ── Chat: emoji picker panel ────────────────────────────────────── */
#chat-emoji-panel {
  position: absolute; bottom: 100%; right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.16);
  padding: 10px; z-index: 20; width: 280px;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
}
.chat-emoji-item {
  font-size: 1.35rem; padding: 4px; cursor: pointer; text-align: center;
  border-radius: 5px; transition: background .1s; line-height: 1;
  background: transparent; border: none;
}
.chat-emoji-item:hover { background: var(--muted-bg); }
.chat-emoji-btn {
  background: transparent; border: 1px solid var(--border); padding: 4px 8px;
  border-radius: 6px; cursor: pointer; font-size: .88rem; color: var(--text-muted);
  transition: border-color .15s, color .15s; display: inline-flex; align-items: center;
}
.chat-emoji-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Chat: edit-mode hint bar ────────────────────────────────────── */
.chat-edit-hint {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 12px; background: var(--primary-bg, rgba(99,102,241,.12));
  border-left: 3px solid var(--primary, #6366f1); font-size: .8rem;
  color: var(--primary, #6366f1); gap: 8px;
}
.chat-edit-hint button {
  background: transparent; border: none; cursor: pointer;
  color: var(--primary, #6366f1); font-size: .9rem; padding: 0 4px; opacity: .75;
}
.chat-edit-hint button:hover { opacity: 1; }
.chat-input-area.editing .chat-textarea {
  border-color: var(--primary, #6366f1);
}
