/* Omni360 — Zalo accounts page. Plain CSS, no build step. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1f2430;
  --muted: #6b7280;
  --primary: #1867c0;
  --primary-dark: #14548f;
  --success: #2e7d32;
  --warning: #b26a00;
  --error: #c62828;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--primary); }

/* --- layout -------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 600; text-decoration: none; font-size: 16px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-chip { color: var(--muted); }
.nav-toggle { font-size: 18px; }

/* --- shell: sidebar + content -------------------------------------- */
.shell { display: flex; align-items: flex-start; min-height: calc(100vh - 56px); }

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  min-height: calc(100vh - 56px);
  padding: 12px 0;
  position: sticky;
  top: 0;
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar .nav-section {
  margin: 16px 16px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  text-decoration: none;
  color: var(--text);
  border-left: 3px solid transparent;
}
.nav-link:hover { background: var(--bg); }
.nav-link-active {
  background: #e6f0fb;
  border-left-color: var(--primary);
  color: var(--primary-dark);
  font-weight: 500;
}
.nav-link-disabled { color: #a6adba; cursor: not-allowed; }
.nav-link-disabled:hover { background: transparent; }
.nav-icon { width: 18px; text-align: center; flex: 0 0 18px; }
.nav-label { flex: 1; }
.nav-soon {
  font-size: 10px;
  text-transform: uppercase;
  background: #eef1f5;
  color: var(--muted);
  padding: 1px 5px;
  border-radius: 999px;
}

.content { flex: 1; min-width: 0; }

/* Collapsed: icons only, so a narrow screen still has the full menu. */
.nav-collapsed .sidebar { width: 56px; flex-basis: 56px; }
.nav-collapsed .nav-label,
.nav-collapsed .nav-soon,
.nav-collapsed .nav-section { display: none; }
.nav-collapsed .nav-link { justify-content: center; padding: 9px 0; }

@media (max-width: 860px) {
  .sidebar { width: 56px; flex-basis: 56px; }
  .sidebar .nav-label, .sidebar .nav-soon, .sidebar .nav-section { display: none; }
  .sidebar .nav-link { justify-content: center; padding: 9px 0; }
}

.page { padding: 24px; max-width: 1400px; margin: 0 auto; }
.analytics-page, .dashboard-page, .pipeline-page { max-width: none; margin: 0; }
.analytics-page .filter-bar, .reports-page .filter-bar { align-items: center; }

/* --- dashboard styles ----------------------------------------------- */
.dashboard-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}
.dash-kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: transform .15s ease, box-shadow .15s ease;
}
.dash-kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05);
}
.dash-kpi-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.dash-kpi-card.blue .dash-kpi-icon { background: #eff6ff; color: #2563eb; }
.dash-kpi-card.amber .dash-kpi-icon { background: #fffbeb; color: #d97706; }
.dash-kpi-card.purple .dash-kpi-icon { background: #faf5ff; color: #9333ea; }
.dash-kpi-card.emerald .dash-kpi-icon { background: #ecfdf5; color: #059669; }
.dash-kpi-card.cyan .dash-kpi-icon { background: #ecfeff; color: #0891b2; }
.dash-kpi-card.slate .dash-kpi-icon { background: #f8fafc; color: #475569; }
.dash-kpi-body { display: flex; flex-direction: column; }
.dash-kpi-val { font-size: 24px; font-weight: 700; color: #0f172a; line-height: 1.2; }
.dash-kpi-lbl { font-size: 13px; color: #64748b; font-weight: 500; margin-top: 2px; }
.page-head { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.page-head h1 { font-size: 20px; margin: 0; }
.page-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }

/* --- table --------------------------------------------------------- */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table th a { text-decoration: none; color: inherit; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #fafbfc; }
.table-compact th, .table-compact td { padding: 6px 8px; }
/* Wrapper for wide tables (super-admin lists). On desktop it is inert; the
   768px block turns it into the horizontal scroll region. */
.table-wrap { max-width: 100%; }
.col-actions { white-space: nowrap; text-align: right; }
.empty-row td { text-align: center; color: var(--muted); padding: 32px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }
.cell-name { display: flex; align-items: center; gap: 8px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.avatar-placeholder {
  background: #e2e8f0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--muted);
  user-select: none;
}
.avatar-grid {
  width: 28px !important;
  height: 28px !important;
  border-radius: 50% !important;
  overflow: hidden !important;
  display: grid !important;
  grid-template-columns: 1fr 1fr !important;
  grid-template-rows: 1fr 1fr !important;
  gap: 1px !important;
  background: #cbd5e1;
  flex: 0 0 28px !important;
  padding: 0 !important;
  box-sizing: border-box !important;
}
.avatar-grid img {
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  object-fit: cover !important;
  display: block !important;
  border-radius: 0 !important;
}
.avatar-grid-1 { grid-template-columns: 1fr !important; grid-template-rows: 1fr !important; }
.avatar-grid-2 { grid-template-columns: 1fr 1fr !important; grid-template-rows: 1fr !important; }
.avatar-grid-3 img:first-child { grid-column: span 2 !important; }

/* --- chips & badges ------------------------------------------------ */
.chip {
  display: inline-block;
  padding: 2px 8px;
  margin: 1px 2px;
  border-radius: 999px;
  background: #eef1f5;
  font-size: 12px;
}
.chip-public { background: #e6f0fb; color: var(--primary-dark); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: #eef1f5;
  color: var(--muted);
}
.badge + .badge { margin-left: 4px; }
.badge-tag {
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 9999px;
  margin: 2px 3px 2px 0;
  display: inline-block;
  line-height: 1.3;
}

.field-hint {
  font-size: 12px;
  color: var(--muted);
  margin: 4px 0 12px;
}
.badge-connected { background: #e6f4ea; color: var(--success); }
.badge-qr_pending, .badge-connecting { background: #fdf3e2; color: var(--warning); }
.badge-disconnected { background: #fdecec; color: var(--error); }

/* --- buttons ------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  background: var(--surface);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-block { width: 100%; justify-content: center; }
/* Row actions: several buttons per table cell, so they need to be compact. */
.btn-sm { padding: 4px 9px; font-size: 13px; }
.btn.btn-danger { border-color: var(--border); color: var(--error); }
.btn.btn-danger:hover { background: #fdecec; }
.btn:focus-visible, .btn-icon:focus-visible, .switch:focus-visible,
input:focus-visible, select:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn-icon {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 5px 6px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1;
}
.btn-icon:hover { background: var(--bg); }
.btn-icon.btn-danger:hover { background: #fdecec; }

/* --- switch -------------------------------------------------------- */
.switch {
  width: 40px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #d6dae1;
  position: relative;
  cursor: pointer;
  padding: 0;
  transition: background .15s;
}
.switch-knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform .15s;
}
.switch-on { background: var(--primary); }
.switch-on .switch-knob { transform: translateX(18px); }

/* --- forms --------------------------------------------------------- */
label { display: flex; flex-direction: column; gap: 6px; margin: 0 0 12px; font-size: 13px; font-weight: 600; color: #334155; }
label.checkbox, label.radio { display: inline-flex; flex-direction: row; align-items: center; gap: 8px; font-size: 14px; font-weight: 400; margin: 4px 0; color: var(--text); }
input[type="text"], input[type="email"], input[type="password"],
input[type="tel"], input[type="number"], input[type="search"],
input[type="url"], input[type="date"], input[type="time"],
input[type="datetime-local"], select, textarea {
  box-sizing: border-box;
  width: 100%;
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background-color: var(--surface);
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
input[type="datetime-local"] {
  min-height: 40px;
  line-height: 1.4;
}
textarea {
  min-height: 80px;
  resize: vertical;
  line-height: 1.5;
}
input[readonly], input:disabled, select:disabled, textarea[readonly], textarea:disabled {
  background-color: #f1f5f9;
  color: #64748b;
  cursor: not-allowed;
}
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; margin-top: 12px; }
.inline-form select { flex: 1; }

/* --- modals -------------------------------------------------------- */
.modal-host {
  position: relative;
  z-index: 1050;
}
.modal-host:empty { display: none; }
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 30, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1050;
}
.modal-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow: auto;
}
.modal-card-narrow { max-width: 380px; text-align: center; }
.modal-card h2 { margin: 0 0 4px; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
/* Pushes the remaining buttons to the right, for a secondary action such as
   "test connection" that belongs on the opposite side of the dialog footer. */
.modal-actions .action-left { margin-right: auto; }

/* --- QR ------------------------------------------------------------ */
.qr-body { min-height: 260px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.qr-image { width: 240px; height: 240px; image-rendering: pixelated; }
.qr-scanned { color: var(--success); font-weight: 500; }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 3s; }
  .switch, .switch-knob { transition: none; }
}

/* --- alerts & toasts ----------------------------------------------- */
.alert { padding: 10px 14px; border-radius: var(--radius); margin: 12px 0; }
.alert-error { background: #fdecec; color: var(--error); }
.alert-warning { background: #fdf3e2; color: var(--warning); }
.alert-info { background: #eef2ff; color: #3730a3; }

.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .10);
  max-width: 380px;
}
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--error); }
.toast-info { border-left-color: var(--primary); }
.toast-close { border: none; background: none; cursor: pointer; float: right; font-size: 16px; line-height: 1; }

/* --- auth page ----------------------------------------------------- */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: calc(100vh - 56px); }
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 380px;
}
.auth-card h1 { margin: 0 0 16px; font-size: 20px; }
.auth-card .btn { margin-top: 20px; }
.auth-hint { margin: 6px 0 16px; font-size: 13px; color: var(--muted); }
.auth-alt { margin: 16px 0 0; font-size: 13px; text-align: center; color: var(--muted); }

/* --- cards, tabs, grids -------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 16px; }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.card-head .card-actions { margin-left: auto; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab {
  padding: 9px 16px;
  text-decoration: none;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  outline: none;
}
.tab:hover { color: var(--text); }
.tab-active { color: var(--primary-dark); border-bottom-color: var(--primary); font-weight: 500; background: transparent; }

.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }
.alert-success { background: #e6f4ea; color: var(--success); }
.badge-role { background: #eef1f5; color: var(--muted); }
.badge-active { background: #e6f4ea; color: var(--success); }
.badge-inactive { background: #fdecec; color: var(--error); }

/* --- notifications ------------------------------------------------- */
.notif-wrap { position: relative; }
.notif-bell { position: relative; font-size: 17px; }
.notif-count {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 16px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--error);
  color: #fff;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
}
.notif-panel {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 320px;
  max-height: 420px;
  overflow-y: auto;
  z-index: 40;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(0 0 0 / 12%);
}
.notif-panel.open { display: block; }
.notif-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.notif-list { list-style: none; margin: 0; padding: 0; }
.notif-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
}
.notif-item:last-child { border-bottom: none; }
.notif-error { border-left-color: var(--error); }
.notif-warning { border-left-color: var(--warning); }
.notif-info { border-left-color: var(--primary); }
.notif-title { font-weight: 500; }
.notif-detail { color: var(--muted); font-size: 13px; }
.notif-empty { color: var(--muted); }
.notif-foot { padding: 8px 12px; margin: 0; border-top: 1px solid var(--border); }

/* --- utilities ----------------------------------------------------- */
.muted { color: var(--muted); }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.htmx-request { opacity: .6; }

/* --- Zalo friends & groups ------------------------------------------- */
.picker-card,
.search-card { margin-bottom: 1rem; }
.picker-card select { min-width: 18rem; }

.search-card summary {
  cursor: pointer;
  font-weight: 600;
  padding: .25rem 0;
}

.search-hit {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin: .75rem 0;
}

/* Secondary row holding the per-group inline forms. */
.row-sub > td {
  padding-top: 0;
  border-top: 0;
}
.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}
.inline-actions .inline-form { margin: 0; }

.member-list {
  list-style: none;
  margin: .5rem 0 0;
  padding: 0;
  max-height: 22rem;
  overflow-y: auto;
}
.member-list li {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .35rem 0;
  border-bottom: 1px solid var(--border);
}
.member-list li:last-child { border-bottom: 0; }

/* hx-indicator: hidden until htmx marks the request in flight. */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: block; }

/* --- shared page furniture (CRM + reporting) ------------------------ */
/* Added with the contacts/reports phases: these classes were used by the
   templates before any rule existed for them, so the pages rendered as
   unstyled HTML. Kept plain and additive — no build step, no framework. */

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: .75rem;
  margin-bottom: 1rem;
}
.filter-bar label { display: flex; flex-direction: column; gap: .25rem; font-size: 13px; }
.filter-bar input, .filter-bar select { padding: .4rem .5rem; border: 1px solid var(--border); border-radius: var(--radius); }

.flash-host:empty { display: none; }
.flash-host { margin-bottom: 1rem; }

.stack { display: flex; flex-direction: column; gap: .75rem; }
.form-actions { display: flex; justify-content: flex-end; gap: .5rem; }
.row-actions { display: flex; justify-content: flex-end; align-items: center; gap: .35rem; white-space: nowrap; }
.link-button {
  background: none;
  border: 0;
  padding: 0;
  color: var(--primary);
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.link-button:hover { text-decoration: underline; }

/* Numeric table cells read far better right-aligned and tabular. */
.num { text-align: right; font-variant-numeric: tabular-nums; }

.empty { padding: 1.5rem; text-align: center; color: var(--muted); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 1rem; }
.pager-row { display: flex; gap: .5rem; align-items: center; }

.tag {
  display: inline-block;
  padding: .1rem .4rem;
  margin: 0 .15rem .15rem 0;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 12px;
}

.tag-input-container {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg-surface, #ffffff);
  border: 1px solid var(--border, #d1d5db);
  border-radius: 8px;
  min-height: 44px;
  cursor: text;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  margin-bottom: 0.35rem;
}

.tag-input-container:focus-within {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.tag-chips {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
  font-size: 12px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 9999px;
  line-height: 1.3;
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}

.tag-chip .remove-tag {
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  color: #3b82f6;
  margin-left: 2px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  transition: all 0.15s ease;
}

.tag-chip .remove-tag:hover {
  color: #ffffff;
  background: #ef4444;
}

.tag-input-container input[type="text"] {
  border: none !important;
  outline: none !important;
  background: transparent !important;
  box-shadow: none !important;
  flex: 1 1 120px;
  min-width: 90px;
  padding: 4px 0 !important;
  margin: 0 !important;
  font-size: 13px;
  color: var(--text, #1e293b);
}

.tag-input-container input[type="text"]::placeholder {
  color: #94a3b8;
  font-size: 13px;
}

/* Dark mode support */
[data-theme="dark"] .tag-input-container,
.dark .tag-input-container,
.dark-mode .tag-input-container {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .tag-chip,
.dark .tag-chip,
.dark-mode .tag-chip {
  background: rgba(255, 255, 255, 0.12);
  color: #f1f5f9;
  border-color: rgba(255, 255, 255, 0.18);
}

[data-theme="dark"] .tag-chip .remove-tag,
.dark .tag-chip .remove-tag,
.dark-mode .tag-chip .remove-tag {
  color: #94a3b8;
}

.notes { white-space: pre-wrap; color: var(--muted); }
.detail-list { display: grid; grid-template-columns: auto 1fr; gap: .35rem .75rem; margin: 0; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .4rem 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }

.dup-group { padding: .75rem 0; border-bottom: 1px solid var(--border); }
.dup-group:last-child { border-bottom: 0; }

.check { display: inline-flex; align-items: center; gap: .35rem; margin-right: 1rem; }

/* --- drawer (detail panel) ------------------------------------------ */
.drawer-host {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  justify-content: flex-end;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: drawerFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.drawer-host:empty {
  display: none !important;
}

@keyframes drawerFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes drawerSlideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.drawer {
  position: relative;
  width: min(46rem, 100vw);
  height: 100%;
  background: var(--surface, #ffffff);
  box-shadow: -8px 0 32px rgba(15, 23, 42, 0.18);
  display: flex;
  flex-direction: column;
  animation: drawerSlideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
  border-left: 1px solid var(--border, #e2e8f0);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border, #e2e8f0);
  background: var(--surface, #ffffff);
}

.drawer-head h2 {
  font-size: 1.2rem;
  font-weight: 600;
  color: #0f172a;
  margin: 0;
}

.drawer-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border, #e2e8f0);
  background: #f8fafc;
  color: #64748b;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  transition: all 0.15s ease;
}

.drawer-close:hover {
  background: #f1f5f9;
  color: #0f172a;
  border-color: #cbd5e1;
}

.drawer-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.drawer-section {
  margin-bottom: 1.75rem;
}

.drawer-section-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #334155;
  margin: 0 0 0.85rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.detail-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 0.75rem 1rem;
}

.detail-card .label {
  font-size: 0.75rem;
  font-weight: 500;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.25rem;
}

.detail-card .value {
  font-size: 0.95rem;
  font-weight: 600;
  color: #0f172a;
}

.message-preview-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-left: 4px solid var(--primary, #2563eb);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  font-size: 0.925rem;
  line-height: 1.6;
  color: #1e293b;
  word-break: break-word;
}

.drawer-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
}

.drawer-table th {
  background: #f8fafc;
  color: #475569;
  font-weight: 600;
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid #e2e8f0;
  white-space: nowrap;
}

.drawer-table td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
  vertical-align: middle;
}

.drawer-table tr:last-child td {
  border-bottom: none;
}

.drawer-table tr:hover td {
  background: #f8fafc;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

.badge-success { background: #dcfce7; color: #15803d; }
.badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-secondary { background: #f1f5f9; color: #475569; }
.badge-info { background: #e0f2fe; color: #0369a1; }
.badge-warning { background: #fef3c7; color: #b45309; }

.drawer-actions { display: flex; gap: .5rem; margin-top: 1.5rem; pt: 1rem; border-top: 1px solid #e2e8f0; }
.modal-body { margin: 1rem 0; }

/* --- pipeline kanban ------------------------------------------------ */
.kanban {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 12px;
  align-items: stretch;
  min-height: calc(100vh - 160px);
}
.kanban-col {
  flex: 1 1 0;
  min-width: 250px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
}
.kanban-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 2px solid #e2e8f0;
}
.kanban-head h2 {
  font-size: 15px;
  font-weight: 700;
  color: #0f172a;
  margin: 0;
}
.kanban-head .badge {
  background: #e2e8f0;
  color: #334155;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
}
.kanban-cards {
  list-style: none !important;
  margin: 0 !important;
  padding: 0 !important;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}
.kanban-cards li.card {
  list-style: none !important;
  margin: 0 !important;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.kanban-cards li.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
  border-color: #94a3b8;
}
.kanban-cards .link-button {
  font-size: 14px;
  font-weight: 600;
  color: #1e293b;
  text-decoration: none;
  text-align: left;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}
.kanban-cards .link-button:hover {
  color: #2563eb;
}
.kanban-cards .hint {
  font-size: 12px;
  color: #64748b;
  display: block;
}
.kanban-cards select {
  margin-top: 4px;
  width: 100%;
  height: 32px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 500;
  color: #334155;
  background-color: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  outline: none;
  cursor: pointer;
  transition: border-color .15s ease;
}
.kanban-cards select:hover, .kanban-cards select:focus {
  border-color: #2563eb;
  background-color: #ffffff;
}
.kanban-cards li.empty {
  list-style: none !important;
  padding: 24px 12px;
  text-align: center;
  color: #94a3b8;
  font-size: 13px;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  background: #ffffff;
}

/* --- campaign progress --------------------------------------------- */
.progress {
  height: .5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  min-width: 6rem;
}
.progress-bar { height: 100%; background: var(--primary); }

/* --- dashboard KPI tiles ------------------------------------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.kpi {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.kpi-value { font-size: 24px; font-weight: 600; }
.kpi-label { color: var(--muted); font-size: 13px; }

/* --- report panels -------------------------------------------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.5rem;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.panel-head h2 { margin: 0; font-size: 16px; }
.panel-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: .5rem 0;
}
.report-config { border: 0; padding: 0; margin: 0; }
.report-config legend { padding: 0; font-size: 13px; color: var(--muted); }

/* Funnel bar: width is set inline from the computed rate. */
.bar {
  display: block;
  height: .6rem;
  min-width: 1px;
  background: var(--primary);
  border-radius: 999px;
}

/* --- Automation, integrations and AI ------------------------------------- */

/* Condition/action lists inside a table cell: no bullets and no indent, so a
   two-item list does not push the row's other columns out of alignment. */
.list-tight { margin: 0; padding: 0; list-style: none; }
.list-tight li { padding: 1px 0; }

/* Long free text in a table cell. Table layout otherwise refuses to wrap a long
   unbroken template body and stretches the whole table past the viewport. */
.cell-wrap { white-space: normal; overflow-wrap: anywhere; max-width: 32rem; }

.disclosure { margin-top: 1rem; }
.disclosure summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.disclosure h4 { margin: .75rem 0 .25rem; font-size: 13px; }
.disclosure ul { margin: 0; padding-left: 1.1rem; font-size: 13px; }
.disclosure code { font-size: 12px; }

.badge-sentiment-positive { background: #e6f4ea; color: var(--success); }
.badge-sentiment-neutral { background: #eef1f5; color: var(--muted); }
.badge-sentiment-negative { background: #fdecec; color: var(--error); }

/* AI controls sit above the composer, so they must not grow tall enough to push
   the text box off a short screen. */
.chat-ai-bar {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
  padding: .25rem .5rem 0;
}
.chat-ai-panel:empty { display: none; }
.chat-ai-panel { padding: .5rem; }

.ai-suggestion, .ai-summary, .ai-sentiment {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .6rem .75rem;
  background: var(--bg);
}
.ai-head {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  margin-bottom: .4rem;
  font-size: 13px;
}
.ai-draft {
  width: 100%;
  resize: vertical;
  font: inherit;
  padding: .4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* ====================================================================
   Mobile (<= 768px)
   ====================================================================
   Two decisions worth stating, because both look like omissions:

   1. Wide tables scroll horizontally instead of becoming cards. A card
      layout needs a `data-label` on every `<td>`, and there are 31 table
      templates — a partial rollout drops the meaning of a column silently,
      which is worse than a scrollbar. The two touch-first flows (chat and
      contacts) get their own pages under /m/ instead.
   2. The bottom nav is only drawn on those /m/ pages, so it cannot cover
      the last row of a desktop table on a narrow laptop.
   ==================================================================== */
@media (max-width: 768px) {
  .page { padding: 12px; }
  .page-head { flex-wrap: wrap; gap: 8px; }
  .page-actions { margin-left: 0; width: 100%; flex-wrap: wrap; }

  /* Stack side-by-side form fields: two inputs at 50% of 360px are unusable. */
  .form-row { flex-direction: column; gap: 8px; }
  .grid-2 { grid-template-columns: 1fr; }

  /* Full-screen sheets: a centred card with 24px of padding wastes a third
     of a phone screen, and its actions end up under the keyboard. */
  .modal { padding: 0; align-items: stretch; }
  .modal-card {
    max-width: none;
    max-height: 100vh;
    min-height: 100vh;
    border-radius: 0;
    padding: 16px;
    /* Keeps the last field clear of the home indicator. */
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; justify-content: center; }

  /* One finger-sized scroll region rather than a page that scrolls sideways. */
  .table-wrap, .table { display: block; overflow-x: auto; }
  .table { white-space: nowrap; }
  .col-actions { text-align: left; }
  .row-actions { flex-wrap: wrap; }

  /* 44px is the smallest reliably tappable target. */
  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; }
  input, select, textarea {
    /* 16px stops iOS Safari zooming the viewport on focus. */
    font-size: 16px;
    min-height: 44px;
  }

  .toasts { right: 12px; left: 12px; bottom: 12px; }
  .toast { max-width: none; }
  .notif-panel { position: fixed; left: 12px; right: 12px; width: auto; }
  .kanban-col { flex-basis: 80vw; }
  .filter-bar { flex-direction: column; align-items: stretch; }
}

/* --- mobile bottom nav ---------------------------------------------
   Only rendered by the /m/ pages. Fixed, four tabs, and padded for the
   iOS home indicator so the labels are not cut off. */
.mobile-nav { display: none; }

.mobile-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.mobile-nav ul {
  display: flex;
  margin: 0;
  padding: 0;
  list-style: none;
}
.mobile-nav li { flex: 1; }
.mobile-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0;
  min-height: 52px;
  text-decoration: none;
  color: var(--muted);
  font-size: 11px;
}
.mobile-nav a.active { color: var(--primary); }
.mobile-nav .mn-icon { font-size: 18px; line-height: 1; }

/* Body class set by the /m/ templates: makes room for the fixed bar. */
.has-mobile-nav .content { padding-bottom: 64px; }
.has-mobile-nav .mobile-nav { display: block; }
.has-mobile-nav .sidebar { display: none; }

/* --- offline indicator ---------------------------------------------
   Toggled by the script in base.html on the browser's online/offline
   events. Hidden by default so a page with JS disabled never shows a
   false warning. */
.offline-bar {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 300;
  padding: 6px 12px;
  text-align: center;
  font-size: 13px;
  background: var(--warning);
  color: #fff;
}
body.is-offline .offline-bar { display: block; }
/* Push the fixed topbar down so the warning does not cover the brand. */
body.is-offline .topbar { margin-top: 28px; }

/* --- shared utilities ----------------------------------------------
   Semantic names for the super-admin and API pages, which talk about
   success/danger rather than about a Zalo connection state. */
.badge-success { background: #e6f4ea; color: var(--success); }
.badge-danger { background: #fdecec; color: var(--error); }
.text-success { color: var(--success); }
.text-danger { color: var(--error); }

/* One-time secrets: an API key or agent key must wrap rather than overflow,
   because it has to be selectable in full to be copied by hand. */
.code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 8px 0;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

/* --- mobile list (the /m/ pages) ------------------------------------ */
.m-list { list-style: none; margin: 12px 0 0; padding: 0; }
.m-list > li { border-bottom: 1px solid var(--border); }
.m-list > li:last-child { border-bottom: none; }

.m-item {
  display: flex;
  align-items: center;
  gap: 10px;
  /* 56px: comfortably tappable without a magnifying glass. */
  min-height: 56px;
  padding: 10px 4px;
  text-decoration: none;
  color: inherit;
}
.m-item:active { background: var(--bg); }
.m-item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.m-item-title { display: flex; align-items: center; gap: 6px; font-weight: 500; }
/* Truncate rather than wrap: a two-line preview makes every row a different height. */
.m-item-sub {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.m-item-meta { font-size: 12px; white-space: nowrap; }
.m-item-actions { display: flex; gap: 6px; }

/* --- mobile thread -------------------------------------------------- */
.m-thread-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.m-thread-head h1 { font-size: 16px; margin: 0; }
.m-back { text-decoration: none; font-size: 20px; line-height: 1; color: var(--text); }
.m-thread { display: flex; flex-direction: column; gap: 8px; padding: 12px 0; }
.m-composer { display: flex; gap: 8px; align-items: flex-end; }
.m-composer textarea { flex: 1; resize: vertical; min-height: 44px; }
