/* ── Olivv Hub design tokens ──────────────────────────────────────── */
:root {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  --bg: #fbfbf9;
  --surface: #ffffff;
  --bg-subtle: #f3f3ee;
  --text: #111110;
  --text-muted: #5f5f58;
  --text-faint: #8f8f86;
  --border: #eaeae4;
  --accent: #111110;
  --accent-bg: #f1f1ed;
  --accent-hover: #2e2e2b;
  --brand-bright: #2dd736;
  --sidebar-w: 248px;
  --sidebar-w-collapsed: 68px;
  --green: #1a7f4b;
  --green-bg: #e9f5ee;
  --yellow: #e37400;
  --yellow-bg: #fef3e2;
  --red: #d93025;
  --red-bg: #fce8e6;
  --shadow-sm: 0 1px 2px rgba(17,17,16,.06), 0 1px 3px rgba(17,17,16,.06);
  --shadow-md: 0 2px 6px rgba(17,17,16,.07), 0 1px 3px rgba(17,17,16,.05);
  --shadow-lg: 0 8px 24px rgba(17,17,16,.12), 0 2px 6px rgba(17,17,16,.06);
  --r-sm: 4px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 24px;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); color: var(--text); background: var(--bg); font-size: 14px; line-height: 1.5; }
a { color: var(--accent); }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ── Topbar ─────────────────────────────────────────────────────────────── */
.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  gap: 16px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 18px; font-weight: 500; color: var(--text);
  text-decoration: none;
}
.brand-icon { color: var(--accent); font-size: 22px; }
.brand-logo { height: 24px; width: auto; display: block; }
.brand-sub { font-size: 13px; color: var(--text-muted); font-weight: 400; padding-left: 8px; border-left: 1px solid var(--border); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
/* ── User menu ─────────────────────────────────────────────────────────── */
.user-menu { position: relative; }
.user-chip {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text-muted);
  background: var(--bg-subtle); border: 1px solid var(--border);
  padding: 5px 12px; border-radius: var(--r-xl);
  cursor: pointer; user-select: none; transition: all 120ms;
}
.user-chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  min-width: 220px; z-index: 300; overflow: hidden;
  display: none;
}
.user-dropdown.open { display: block; }
.user-dropdown-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.user-dropdown-email { font-size: 13px; font-weight: 500; color: var(--text); }
.user-dropdown-role {
  display: inline-block; margin-top: 4px;
  font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: var(--r-xl); background: var(--accent-bg); color: var(--accent);
}
.dropdown-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  font-size: 13px; color: var(--text);
  cursor: pointer; transition: background 80ms;
  border: none; background: none; width: 100%; text-align: left;
}
.dropdown-item:hover { background: var(--bg-subtle); }
.dropdown-item.danger { color: var(--red); }
.dropdown-item.danger:hover { background: var(--red-bg); }
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ── Modals ────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.35);
  z-index: 400; display: none; align-items: center; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 16px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 18px; font-weight: 500; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--text-muted); cursor: pointer; padding: 4px; border-radius: var(--r-sm); }
.modal-close:hover { background: var(--bg-subtle); }
.modal-body { padding: 20px 24px; }
.modal-footer { padding: 12px 24px 20px; display: flex; gap: 10px; justify-content: flex-end; }
.form-field { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--text-muted); margin-bottom: 6px; }
.form-input {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  font-size: 14px; font-family: inherit; color: var(--text); background: var(--bg);
  outline: none; transition: border-color 150ms;
}
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(17,17,16,.12); }
.form-select {
  width: 100%; height: 40px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  font-size: 14px; font-family: inherit; color: var(--text); background: var(--bg);
}
.form-error { font-size: 12px; color: var(--red); margin-top: 4px; }
.form-success { font-size: 12px; color: var(--green); margin-top: 4px; }

/* ── Users table in admin panel ─────────────────────────────────────────── */
.users-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.users-table th { padding: 8px 12px; font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing:.04em; border-bottom: 1px solid var(--border); text-align: left; }
.users-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.users-table tbody tr:last-child td { border-bottom: none; }
.role-badge { display: inline-block; padding: 2px 8px; border-radius: var(--r-xl); font-size: 11px; font-weight: 600; }
.role-badge.admin   { background: #fce8e6; color: var(--red); }
.role-badge.analyst { background: var(--accent-bg); color: var(--accent); }
.role-badge.sales_manager { background: #e6f4ea; color: #1a7f4b; }
.role-badge.sales { background: var(--bg-subtle); color: #1a7f4b; }
.role-badge.viewer  { background: var(--bg-subtle); color: var(--text-muted); }
.role-badge.super_admin { background: #1f1147; color: #fff; }

/* ── Audit log ───────────────────────────────────────────────────────────── */
.log-table tbody tr { cursor: default; }
.log-table tbody tr:hover { background: transparent; }
.audit-action {
  display: inline-block; font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: var(--r-xl);
  background: #1f1147; color: #fff;
}
.mode-link {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text-muted);
  background: transparent; border: 1px solid var(--border);
  padding: 6px 14px; border-radius: var(--r-xl);
  text-decoration: none; transition: all 120ms;
}
.mode-link:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-bg); }
.refresh-info { font-size: 12px; color: var(--text-faint); display: flex; align-items: center; gap: 6px; }
.refresh-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--border); display: inline-block;
}
.refresh-dot.spinning { background: var(--accent); animation: spin 1s linear infinite; }

/* ── Tab nav ────────────────────────────────────────────────────────────── */
.tab-nav {
  display: flex; align-items: center;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  gap: 0;
}
.tab-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 14px 16px;
  background: none; border: none;
  font-size: 13px; font-weight: 500; color: var(--text-muted);
  border-bottom: 3px solid transparent;
  cursor: pointer; white-space: nowrap;
  transition: color 120ms;
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--accent); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── View panels ────────────────────────────────────────────────────────── */
.view { display: none; padding: 24px; }
.view.active { display: block; }

/* ── Cards & KPIs ────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.kpi-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
  cursor: default;
  transition: box-shadow 120ms;
}
.kpi-card.clickable { cursor: pointer; }
.kpi-card.clickable:hover { box-shadow: var(--shadow-md); border-color: var(--accent); }
.kpi-label { font-size: 12px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px; }
.kpi-value { font-size: 28px; font-weight: 700; color: var(--text); line-height: 1; }
.kpi-sub { font-size: 12px; color: var(--text-faint); margin-top: 4px; }

/* ── Panels ──────────────────────────────────────────────────────────────── */
.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 20px; margin-bottom: 24px;
}
.panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.panel-header {
  padding: 16px 20px 0;
  display: flex; align-items: center; gap: 8px;
}
.panel-header h3 { margin: 0; font-size: 14px; font-weight: 500; color: var(--text); }
.panel-body { padding: 16px 20px 20px; }
.chart-wrap { position: relative; height: 220px; }

/* ── Table ─────────────────────────────────────────────────────────────── */
.data-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-md); }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table thead { position: sticky; top: 0; background: var(--bg-subtle); z-index: 10; }
.data-table th {
  padding: 12px 16px; text-align: left;
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background 80ms; cursor: pointer; }
.data-table tbody tr:hover { background: var(--accent-bg); }
.th-sort { background: none; border: none; font: inherit; color: inherit; cursor: pointer; display: flex; align-items: center; gap: 4px; }
.sort-icon { color: var(--text-faint); font-size: 10px; }

/* ── Data pipeline funnel ────────────────────────────────────────────────── */
.pipeline-funnel {
  display: flex;
  align-items: stretch;
  gap: 0;
  overflow-x: auto;
}
.pipeline-step {
  flex: 1;
  min-width: 140px;
  display: flex;
  flex-direction: column;
  position: relative;
}
.pipeline-step + .pipeline-step::before {
  content: "";
  position: absolute;
  left: 0; top: 50%; transform: translateY(-50%);
  width: 0; height: 0;
  border-top: 28px solid transparent;
  border-bottom: 28px solid transparent;
  border-left: 16px solid var(--border);
  z-index: 1;
}
.pipeline-step + .pipeline-step::after {
  content: "";
  position: absolute;
  left: 1px; top: 50%; transform: translateY(-50%);
  width: 0; height: 0;
  border-top: 27px solid transparent;
  border-bottom: 27px solid transparent;
  border-left: 15px solid var(--bg);
  z-index: 2;
}
.pipeline-inner {
  flex: 1;
  padding: 16px 20px 16px 28px;
  border: 1px solid var(--border);
  border-right: none;
  background: var(--bg);
}
.pipeline-step:first-child .pipeline-inner { border-radius: var(--r-md) 0 0 var(--r-md); padding-left: 20px; }
.pipeline-step:last-child .pipeline-inner  { border-right: 1px solid var(--border); border-radius: 0 var(--r-md) var(--r-md) 0; }
.pipeline-stage  { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); margin-bottom: 6px; }
.pipeline-count  { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1; margin-bottom: 4px; }
.pipeline-pct    { font-size: 12px; font-weight: 600; margin-bottom: 6px; }
.pipeline-label  { font-size: 12px; color: var(--text-muted); line-height: 1.4; }
.pipeline-step.step-ingest  .pipeline-pct { color: var(--text-muted); }
.pipeline-step.step-matched .pipeline-pct { color: var(--yellow); }
.pipeline-step.step-phone  .pipeline-pct { color: var(--accent); }
.pipeline-step.step-email  .pipeline-pct { color: #7b1fa2; }
.pipeline-step.step-ready  .pipeline-pct { color: var(--green); }
.pipeline-step.step-ready  .pipeline-inner { background: var(--green-bg); border-color: #a8d5b5; }
.pipeline-step.step-ready  .pipeline-count { color: var(--green); }

/* ── Filters & controls ─────────────────────────────────────────────────── */
.filter-row {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-bottom: 16px;
}
.search-input {
  height: 36px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  font-size: 14px; min-width: 240px; background: var(--bg);
  transition: border-color 120ms;
}
.search-input:focus { outline: none; border-color: var(--accent); }
.select-input {
  height: 36px; padding: 0 8px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  font-size: 13px; background: var(--bg); color: var(--text);
}
.btn {
  height: 36px; padding: 0 16px; border-radius: var(--r-md);
  font-size: 13px; font-weight: 500; border: none; transition: all 120ms;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-subtle); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; align-items: center; }
.chip-label { font-size: 12px; color: var(--text-muted); }
.chip {
  padding: 5px 14px; border-radius: var(--r-xl);
  border: 1px solid var(--border); font-size: 12px; font-weight: 500;
  cursor: pointer; background: var(--bg); color: var(--text-muted);
  transition: all 120ms;
}
.chip:hover { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }

/* ── Pagination ──────────────────────────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; gap: 8px;
  padding: 16px 0; justify-content: center;
}
.pagination span { font-size: 13px; color: var(--text-muted); }

/* ── Map ───────────────────────────────────────────────────────────────── */
.map-canvas { height: calc(100vh - 120px); border-radius: var(--r-md); overflow: hidden; }
.map-controls {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-bottom: 12px;
}

/* ── Enrichment bars ─────────────────────────────────────────────────────── */
.enrich-bars { display: flex; flex-direction: column; gap: 10px; }
.enrich-bar-row { display: flex; flex-direction: column; gap: 4px; }
.enrich-bar-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); }
.enrich-track { height: 6px; background: var(--bg-subtle); border-radius: 3px; overflow: hidden; }
.enrich-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width 600ms ease; }

/* ── Quality cards ─────────────────────────────────────────────────────── */
.quality-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-top: 20px; }
.quality-card {
  border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 16px 20px; background: var(--bg);
}
.quality-card.fixable { border-left: 3px solid var(--accent); }
.quality-card.flag { border-left: 3px solid var(--yellow); }
.quality-count { font-size: 24px; font-weight: 700; }
.quality-title { font-size: 13px; font-weight: 500; margin: 4px 0; }
.quality-detail { font-size: 12px; color: var(--text-muted); }
.quality-fix { font-size: 12px; color: var(--accent); margin-top: 6px; }

/* ── Pills ──────────────────────────────────────────────────────────────── */
.pill { display: inline-block; padding: 2px 8px; border-radius: var(--r-xl); font-size: 11px; font-weight: 500; }
.pill.green { background: var(--green-bg); color: var(--green); }
.pill.yellow { background: var(--yellow-bg); color: var(--yellow); }
.pill.red { background: var(--red-bg); color: var(--red); }
.pill.blue { background: var(--accent-bg); color: var(--accent); }
.pill.grey { background: var(--bg-subtle); color: var(--text-faint); }

/* ── Detail drawer ───────────────────────────────────────────────────────── */
.drawer {
  position: fixed; right: 0; top: 0; bottom: 0; width: 420px;
  background: var(--bg); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg); z-index: 200;
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform 200ms ease;
}
.drawer.open { transform: translateX(0); }
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.2); z-index: 199;
  opacity: 0; pointer-events: none; transition: opacity 200ms;
}
.drawer-overlay.visible { opacity: 1; pointer-events: auto; }
.drawer-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-edited-by { font-size: 11px; color: var(--text-faint); margin-top: 2px; }

/* ── Conflict banner ─────────────────────────────────────────────────────── */
.drawer-conflict {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; font-size: 12px;
  background: var(--yellow-bg); color: var(--yellow);
  border-bottom: 1px solid #f5c842; flex-shrink: 0;
}
.drawer-conflict.hidden { display: none; }

/* ── Edit mode — field inputs ────────────────────────────────────────────── */
.edit-field-wrap { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.edit-field-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.edit-field-input {
  width: 100%; height: 38px; padding: 0 10px;
  border: 1.5px solid var(--border); border-radius: var(--r-md);
  font-size: 14px; font-family: inherit; color: var(--text); background: var(--bg);
  outline: none; transition: border-color 150ms;
}
.edit-field-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(26,115,232,.1); }
.edit-field-input.changed { border-color: var(--accent); background: var(--accent-bg); }
.edit-actions { display: flex; gap: 8px; padding: 12px 0 0; border-top: 1px solid var(--border); margin-top: 4px; }
.edit-readonly { font-size: 13px; color: var(--text-faint); font-style: italic; padding: 6px 0; }
.edit-field-textarea { height: auto; min-height: 72px; padding: 8px 10px; line-height: 1.4; resize: vertical; }
select.edit-field-input { cursor: pointer; appearance: auto; }
.edit-checkbox-wrap { margin-top: 4px; }
.edit-check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); cursor: pointer; }
.edit-check-input { width: 16px; height: 16px; flex: 0 0 auto; cursor: pointer; accent-color: var(--accent); }

/* ── Drawer icon buttons (undo / redo) ───────────────────────────────────── */
.drawer-icon-btn {
  height: 32px; width: 32px; padding: 0; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.drawer-icon-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Manually-reviewed badge ─────────────────────────────────────────────── */
.reviewed-badge {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--green-bg); color: var(--green);
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: var(--r-xl);
}

/* ── Edit history timeline ───────────────────────────────────────────────── */
.history-empty { font-size: 13px; color: var(--text-faint); text-align: center; padding: 24px 0; }
.history-entry {
  display: flex; gap: 12px; padding: 12px 0;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.history-entry:last-child { border-bottom: none; }
.history-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); flex-shrink: 0; margin-top: 4px;
}
.history-content { flex: 1; min-width: 0; }
.history-meta { font-size: 11px; color: var(--text-faint); margin-top: 3px; }
.history-field { font-weight: 600; color: var(--text); }
.history-op { display: inline-block; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); background: var(--accent-bg); padding: 1px 6px; border-radius: var(--r-xl); }
.history-revert { display: inline-flex; align-items: center; gap: 4px; margin-left: 8px; height: 22px; padding: 0 8px; font-size: 11px; font-weight: 500; color: var(--text-muted); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm, 5px); cursor: pointer; }
.history-revert:hover { color: var(--red, #c0392b); border-color: var(--red, #c0392b); background: var(--surface); }
.history-diff {
  display: flex; align-items: center; gap: 6px;
  margin-top: 4px; font-size: 12px;
}
.history-old { color: var(--red); text-decoration: line-through; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-new { color: var(--green); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Live edit indicator (SSE) ───────────────────────────────────────────── */
.live-edit-badge {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--green-bg); color: var(--green);
  font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: var(--r-xl); animation: fade-in 300ms ease;
}
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.drawer-head h3 { margin: 0; font-size: 15px; font-weight: 500; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-close { background: none; border: none; font-size: 20px; color: var(--text-muted); padding: 4px; border-radius: var(--r-sm); }
.drawer-close:hover { background: var(--bg-subtle); }
.drawer-tabs { display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.drawer-tab { padding: 10px 16px; background: none; border: none; font-size: 13px; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; }
.drawer-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; }
.drawer-panel { display: none; }
.drawer-panel.active { display: block; }
.field-row { margin-bottom: 14px; }
.field-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.field-value { font-size: 14px; color: var(--text); display: flex; align-items: center; gap: 8px; }
.copy-btn { background: none; border: none; font-size: 14px; color: var(--text-faint); padding: 2px 4px; border-radius: var(--r-sm); cursor: pointer; }
.copy-btn:hover { color: var(--accent); background: var(--accent-bg); }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 20px; border-radius: var(--r-md);
  font-size: 13px; font-weight: 500; box-shadow: var(--shadow-md);
  animation: slide-up 200ms ease;
}
.toast-info { background: #202124; color: #fff; }
.toast-success { background: var(--green); color: #fff; }
.toast-error { background: var(--red); color: #fff; }

/* ── Utilities ───────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.meta { font-size: 12px; color: var(--text-faint); margin-bottom: 12px; }
.code { font-family: monospace; background: var(--bg-subtle); padding: 2px 6px; border-radius: var(--r-sm); font-size: 12px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slide-up { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }


/* ── App shell: collapsible sidebar ─────────────────────────────────────── */
body.has-sidebar { padding-left: var(--sidebar-w); transition: padding-left 200ms ease; }
body.has-sidebar.sidebar-collapsed { padding-left: var(--sidebar-w-collapsed); }

.app-sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 150;
  width: var(--sidebar-w);
  display: flex; flex-direction: column;
  background: #fff; border-right: 1px solid var(--border);
  transition: width 200ms ease;
}
.sidebar-collapsed .app-sidebar { width: var(--sidebar-w-collapsed); }

.sb-head {
  height: 64px; flex-shrink: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 0 20px; border-bottom: 1px solid var(--border);
  text-decoration: none; color: var(--text);
}
/* The logo is wide; when collapsed only the clover mark (left 28%) shows. */
.sb-logo { height: 28px; width: 100px; overflow: hidden; flex-shrink: 0; transition: width 200ms ease; }
.sb-logo img { height: 28px; width: auto; display: block; max-width: none; }
.sidebar-collapsed .sb-logo { width: 28px; }
.sb-product { font-size: 13px; font-weight: 600; color: var(--text-muted); padding-left: 10px; border-left: 1px solid var(--border); white-space: nowrap; }
.sidebar-collapsed .sb-product { display: none; }

.sb-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 8px 12px 12px; }
.sb-section {
  font-size: 11px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase;
  color: var(--text-faint); padding: 18px 10px 8px; white-space: nowrap;
}
.sidebar-collapsed .sb-section {
  height: 1px; padding: 0; margin: 14px 10px; background: var(--border); font-size: 0;
}
.sb-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 9px 12px; margin-bottom: 2px;
  border: none; border-radius: var(--r-md); background: none;
  font-size: 14px; font-weight: 500; color: var(--text-muted);
  text-decoration: none; text-align: left; white-space: nowrap;
  cursor: pointer; transition: background 100ms, color 100ms;
}
.sb-item i { font-size: 19px; flex-shrink: 0; width: 20px; text-align: center; }
.sb-item:hover { background: var(--bg-subtle); color: var(--text); }
.sb-item.active { background: var(--accent-bg); color: var(--accent-hover); }
.sb-item.active i { color: var(--accent); }
.sb-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.sb-item.hidden { display: none; }
.sidebar-collapsed .sb-item { justify-content: center; padding: 10px 0; }
.sidebar-collapsed .sb-label { display: none; }

.sb-foot { flex-shrink: 0; padding: 12px; border-top: 1px solid var(--border); }
.sb-collapse i { transition: transform 200ms; }
.sidebar-collapsed .sb-collapse i { transform: rotate(180deg); }

/* Topbar: sidebar toggle + breadcrumb */
.sb-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: var(--r-md);
  border: 1px solid transparent; background: none; color: var(--text-muted); font-size: 20px;
}
.sb-toggle:hover { background: var(--bg-subtle); color: var(--text); }
.crumb { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-muted); }
.crumb b { color: var(--text); font-weight: 600; }
.crumb i { font-size: 13px; color: var(--text-faint); }

@media (max-width: 900px) {
  body.has-sidebar { padding-left: var(--sidebar-w-collapsed); }
  .crumb .crumb-root, .crumb .crumb-root + i, .refresh-info, .brand-sub { display: none; }
  .topbar { padding: 0 12px; }
  /* Narrow screens always use the icon rail, whatever the saved preference. */
  .app-sidebar { width: var(--sidebar-w-collapsed); }
  .app-sidebar .sb-logo { width: 28px; }
  .app-sidebar .sb-product, .app-sidebar .sb-label { display: none; }
  .app-sidebar .sb-section { height: 1px; padding: 0; margin: 14px 10px; background: var(--border); font-size: 0; }
  .app-sidebar .sb-item { justify-content: center; padding: 10px 0; }
  .sb-toggle, .sb-collapse { display: none; }
}

/* ── Dashboard (super admin sales report) + country switcher ─────────────── */
.country-switch { display: none; position: relative; }
body[data-view="dashboard"] .country-switch { display: block; }
.country-btn {
  display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: var(--r-xl); background: var(--bg);
  color: var(--text); font-size: 13px; font-weight: 500;
}
.country-btn:hover { border-color: var(--accent); background: var(--accent-bg); }
.country-btn img, .country-opt img { border-radius: 2px; box-shadow: 0 0 0 1px rgba(0,0,0,.12); object-fit: cover; }
.country-menu {
  display: none; position: absolute; right: 0; top: 38px; min-width: 190px; z-index: 50;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-md);
  box-shadow: var(--shadow-md); padding: 4px;
}
.country-menu.open { display: block; }
.country-opt {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px;
  border: 0; background: none; border-radius: var(--r-sm); font-size: 13px; color: var(--text); text-align: left;
}
.country-opt:hover { background: var(--accent-bg); }
.country-opt.active { font-weight: 600; background: var(--bg-subtle); }
.country-all { width: 20px; text-align: center; color: var(--text-muted); }

.dash-head { display: flex; align-items: baseline; gap: 12px; margin: 0 0 14px; }
.dash-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.snap-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.snap { border: 1px solid var(--border); border-radius: var(--r-md); padding: 14px 16px; background: var(--bg); }
.snap .n { font-size: 28px; font-weight: 600; line-height: 1.1; }
.snap .l { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.snap.warn { border-color: var(--red); background: var(--red-bg); }
.snap.warn .n { color: var(--red); }
.snap.good .n { color: var(--green); }
.team + .team { border-top: 1px solid var(--border); }
.team-head {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 14px 20px;
  background: var(--bg-subtle);
}
.team-head .who { font-weight: 600; font-size: 14px; min-width: 180px; }
.team-head .who small { display: block; font-weight: 400; color: var(--text-faint); font-size: 12px; }
.team-stats { display: flex; gap: 22px; margin-left: auto; flex-wrap: wrap; }
.team-stats div { text-align: right; font-size: 12px; color: var(--text-muted); }
.team-stats b { display: block; font-size: 16px; color: var(--text); }
.team .data-table tbody tr { cursor: default; }
.team .data-table tbody tr:hover { background: transparent; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mini-bar { height: 6px; background: var(--bg-subtle); border-radius: 3px; overflow: hidden; margin-top: 4px; min-width: 70px; }
.mini-bar > i { display: block; height: 100%; background: var(--accent); }

/* ── Right-hand slide-over panels (reuse the modal markup) ───────────────── */
.modal-backdrop.side { justify-content: flex-end; align-items: stretch; }
.modal-backdrop.side .modal {
  max-width: 560px; width: 100%; max-height: none; height: 100%; border-radius: 0;
  animation: side-in 180ms ease-out;
}
@keyframes side-in { from { transform: translateX(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.person-chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.person-chips .chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 10px;
  border: 1px solid var(--border); border-radius: var(--r-xl); background: var(--bg-subtle); }
.person-sec { margin: 22px 0 8px; font-size: 13px; font-weight: 600; }
.person-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.person-list .row { display: flex; gap: 10px; justify-content: space-between; align-items: center;
  padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.person-list .row:last-child { border-bottom: 0; }
.person-list .row.link { cursor: pointer; }
.person-list .row.link:hover { background: var(--accent-bg); }
.team-head, .team .data-table tbody tr[data-email] { cursor: pointer; }
.team .data-table tbody tr[data-email]:hover { background: var(--accent-bg); }

/* Docked right-hand pane: sits beside the page (which makes room), no dimming backdrop. */
:root { --pane-w: 600px; }
.modal-backdrop.side {
  background: transparent; pointer-events: none; inset: 0 0 0 auto; width: var(--pane-w); z-index: 160;
}
.modal-backdrop.side .modal {
  pointer-events: auto; max-width: none !important; width: 100%; border-left: 1px solid var(--border);
  box-shadow: -6px 0 24px rgba(17,17,16,.08); overflow-y: auto;
}
.modal-backdrop.side#person-panel { z-index: 165; }
body.pane-open { padding-right: var(--pane-w); transition: padding-right 200ms ease; }
body.pane-open .users-table { font-size: 12px; }
#users-table-wrap { overflow-x: auto; }
@media (max-width: 900px) {
  :root { --pane-w: 100vw; }
  body.pane-open { padding-right: 0; }
}

/* ── Users page ──────────────────────────────────────────────────────────── */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 4px 0 18px; }
.page-head h2 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -.01em; }
.page-head p { margin: 2px 0 0; font-size: 13px; color: var(--text-muted); }
.page-tools { display: flex; align-items: center; gap: 12px; }
.count-chip { font-size: 12px; color: var(--text-muted); background: var(--bg-subtle); border: 1px solid var(--border); border-radius: var(--r-xl); padding: 4px 10px; }
.search-box { display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px; width: 240px;
  border: 1px solid var(--border); border-radius: var(--r-md); background: var(--bg); color: var(--text-faint); }
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(17,17,16,.08); }
.search-box input { border: 0; outline: 0; background: none; font: inherit; font-size: 13px; color: var(--text); width: 100%; }

.card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: 0 1px 2px rgba(17,17,16,.04); }
.users-card { overflow-x: auto; margin-bottom: 20px; }
.card-title { font-size: 14px; font-weight: 600; margin-bottom: 14px; }

.users-card .users-table { font-size: 13px; }
.users-card .users-table th { padding: 12px 20px; background: var(--bg-subtle); font-size: 11px; white-space: nowrap; }
.users-card .users-table td { padding: 12px 20px; vertical-align: middle; }
.users-card .users-table tbody tr:hover { background: var(--bg-subtle); }
.users-table th.act, .users-table td.act { width: 1%; text-align: right; }

.u-cell { display: flex; align-items: center; gap: 12px; min-width: 200px; }
.u-name { font-weight: 600; text-transform: none; }
a.u-name.link { color: var(--text); text-decoration: none; }
a.u-name.link:hover { color: var(--accent); text-decoration: underline; }
.u-email { font-size: 12px; color: var(--text-faint); }
.you-tag { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted);
  background: var(--bg-subtle); border: 1px solid var(--border); border-radius: var(--r-xl); padding: 1px 6px; margin-left: 4px; vertical-align: 1px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  font-size: 13px; font-weight: 600; background: var(--bg-subtle); color: var(--text-muted); border: 1px solid var(--border); }
.avatar.super_admin { background: #1f1147; color: #fff; border-color: #1f1147; }
.avatar.admin { background: #fce8e6; color: var(--red); border-color: transparent; }
.avatar.sales_manager, .avatar.sales { background: #e6f4ea; color: #1a7f4b; border-color: transparent; }
.avatar.analyst { background: var(--accent-bg); color: var(--accent); border-color: transparent; }
.dash { color: var(--text-faint); }
.country-tag { display: inline-flex; align-items: center; gap: 6px; }

.sel-sm { height: 32px; padding: 0 28px 0 10px; font: inherit; font-size: 13px; color: var(--text); background-color: var(--bg);
  border: 1px solid var(--border); border-radius: var(--r-md); max-width: 190px; cursor: pointer; }
.sel-sm:hover:not(:disabled) { border-color: var(--text-faint); }
.sel-sm:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(17,17,16,.08); }

.row-actions { display: inline-flex; gap: 4px; }
.icon-btn { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid transparent; border-radius: var(--r-md);
  background: none; color: var(--text-muted); font-size: 16px; cursor: pointer; }
.icon-btn:hover:not(:disabled) { background: var(--bg-subtle); border-color: var(--border); color: var(--text); }
.icon-btn.danger:hover:not(:disabled) { background: var(--red-bg); border-color: transparent; color: var(--red); }
.icon-btn:disabled { opacity: .3; cursor: not-allowed; }

.add-user-card { padding: 20px 24px 22px; }
.add-user-grid { display: grid; grid-template-columns: 1.4fr 1.2fr 1fr 1fr auto; gap: 14px; align-items: end; }
.add-user-grid .form-input, .add-user-grid .form-select { width: 100%; height: 40px; }
.add-user-grid .btn { height: 40px; padding: 0 20px; white-space: nowrap; }
@media (max-width: 1100px) { .add-user-grid { grid-template-columns: 1fr 1fr; } .add-user-grid .btn { grid-column: 1 / -1; } }
@media (max-width: 600px) { .search-box { width: 100%; } .page-tools { width: 100%; } }
