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

:root {
  --bg:           #F6F6F4;
  --surface:      #FFFFFF;
  --border:       #E8E8E4;
  --text-1:       #1A1A1A;
  --text-2:       #6B6B6B;
  --text-3:       #ABABAB;
  --accent:       #E8580A;
  --accent-bg:    #FEF3EE;
  --accent-hover: #CC4600;
  --danger:       #DC2626;
  --sidebar-w:    220px;
  --radius:       8px;
  --shadow:       0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-1);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ─── Login ──────────────────────────────────────────────────────────────── */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-wrap {
  width: 100%;
  max-width: 380px;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  box-shadow: var(--shadow);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--text-1);
  margin-bottom: 6px;
}

.logo-mark {
  width: 10px;
  height: 10px;
  background: var(--accent);
  border-radius: 2px;
  flex-shrink: 0;
}

.login-sub {
  font-size: 13px;
  color: var(--text-3);
  margin-bottom: 32px;
}

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-group input,
.form-group select {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text-1);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
}

.form-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B6B6B' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 36px;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(232,88,10,0.12);
}

.form-group input::placeholder {
  color: var(--text-3);
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn-primary {
  height: 40px;
  padding: 0 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.btn-primary:hover  { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-secondary {
  height: 40px;
  padding: 0 18px;
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

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

.btn-full {
  width: 100%;
  justify-content: center;
  margin-top: 8px;
}

/* ─── Error / Info Messages ──────────────────────────────────────────────── */
.error-msg {
  font-size: 13px;
  color: var(--danger);
  padding: 9px 12px;
  background: #FEF2F2;
  border: 1px solid #FECACA;
  border-radius: var(--radius);
  margin-bottom: 14px;
}

/* ─── App Layout ─────────────────────────────────────────────────────────── */
.app-body {
  height: 100vh;
  overflow: hidden;
}

.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ─── App Switcher ────────────────────────────────────────────────────────── */
.app-switcher {
  width: 52px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 20;
  overflow: visible;
}

.switcher-brand {
  width: 100%;
  flex-shrink: 0;
  height: 57px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border);
}

.switcher-brand .logo-mark {
  width: 10px;
  height: 10px;
  background: var(--accent);
  border-radius: 2px;
  display: block;
}

.switcher-icons {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0;
  gap: 2px;
  width: 100%;
}

.app-icon {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-3);
  background: none;
  border: none;
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
}

.app-icon svg { width: 17px; height: 17px; }

.app-icon:hover {
  background: var(--bg);
  color: var(--text-2);
}

.app-icon.active {
  background: var(--accent-bg);
  color: var(--accent);
}

/* Indicador derecho: pastilla naranja entre el switcher y el sidebar */
.app-icon.active::after {
  content: '';
  position: absolute;
  right: -10px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 22px;
  background: var(--accent);
  border-radius: 2px 0 0 2px;
  pointer-events: none;
}

/* ─── App Panels ──────────────────────────────────────────────────────────── */
.app-panel {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.app-panel.hidden {
  display: none !important;
}

/* ─── Switcher separator ──────────────────────────────────────────────────── */
.switcher-sep {
  width: 24px;
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

/* ─── Contact Center iframe panel ────────────────────────────────────────── */
.cc-frame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* ─── Map placeholder ─────────────────────────────────────────────────────── */
.map-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(100vh - 130px);
}

.map-placeholder-inner {
  text-align: center;
}

.map-placeholder-inner svg {
  width: 56px;
  height: 56px;
  color: var(--text-3);
  margin-bottom: 18px;
  opacity: 0.5;
}

.map-placeholder-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 8px;
}

.map-placeholder-sub {
  font-size: 13px;
  color: var(--text-3);
  line-height: 1.7;
}

/* ─── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  padding: 22px 20px 18px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--text-1);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-nav {
  flex: 1;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  color: var(--text-2);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  user-select: none;
}

.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg); color: var(--text-1); }
.nav-item.active { background: var(--accent-bg); color: var(--accent); }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-transform: uppercase;
}

.user-meta {
  flex: 1;
  min-width: 0;
}

.user-meta-name {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-meta-role {
  display: block;
  font-size: 11px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.logout-btn {
  width: 30px;
  height: 30px;
  border: none;
  background: none;
  color: var(--text-3);
  cursor: pointer;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.1s, background 0.1s;
}

.logout-btn:hover { color: var(--text-1); background: var(--bg); }
.logout-btn svg { width: 16px; height: 16px; }

/* ─── Main Content ────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
}

.section { padding: 32px; max-width: 1120px; }
.section.hidden { display: none !important; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.section-header h1 {
  font-size: 19px;
  font-weight: 600;
  color: var(--text-1);
}

.section-header .hint {
  font-size: 12px;
  color: var(--text-3);
}

/* ─── Metric Cards ────────────────────────────────────────────────────────── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}

.metric-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

.metric-value {
  font-size: 30px;
  font-weight: 600;
  color: var(--text-1);
  line-height: 1;
  margin-bottom: 14px;
  letter-spacing: -0.5px;
}

.metric-value.uptime { font-size: 20px; letter-spacing: 0; }

.metric-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 10px;
}

.metric-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.6s ease;
  width: 0%;
}

.metric-bar-fill.warn  { background: #F59E0B; }
.metric-bar-fill.crit  { background: var(--danger); }

.metric-detail {
  font-size: 12px;
  color: var(--text-3);
}

/* ─── Card / Table ────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 20px;
}

.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-1);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  padding: 9px 20px;
  text-align: left;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  white-space: nowrap;
}

.data-table td {
  padding: 11px 20px;
  font-size: 13px;
  color: var(--text-1);
  border-bottom: 1px solid var(--border);
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--accent-bg); }

.td-muted { color: var(--text-3); font-style: italic; }
.loading  { text-align: center; color: var(--text-3); padding: 28px !important; }

.table-actions { display: flex; gap: 6px; align-items: center; }

.btn-table {
  height: 26px;
  padding: 0 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  transition: background 0.1s, color 0.1s;
}

.btn-table:hover { background: var(--bg); color: var(--text-1); }
.btn-table.danger { color: var(--danger); border-color: transparent; }
.btn-table.danger:hover { background: #FEF2F2; }

/* ─── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}

.badge-admin { background: var(--accent-bg); color: var(--accent); }
.badge-user  { background: var(--bg); color: var(--text-2); }

/* ─── Status dots ─────────────────────────────────────────────────────────── */
.state-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 5px;
  background: var(--text-3);
  vertical-align: middle;
}

.state-dot.running { background: #22C55E; }
.state-dot.sleeping { background: var(--text-3); }

/* ─── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(3px);
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: 390px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.14);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-1);
}

.modal-close {
  width: 28px;
  height: 28px;
  background: none;
  border: none;
  font-size: 18px;
  line-height: 1;
  color: var(--text-3);
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.1s, background 0.1s;
}

.modal-close:hover { color: var(--text-1); background: var(--bg); }

.modal-hint {
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ─── Logs ────────────────────────────────────────────────────────────────── */
.log-success { color: #16A34A; font-weight: 500; }
.log-fail    { color: var(--danger); font-weight: 500; }

/* ─── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 960px) {
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
  .metrics-grid { grid-template-columns: 1fr; }
  .sidebar { width: 60px; }
  .sidebar-brand span, .nav-item span, .user-meta { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .sidebar-footer { justify-content: center; }
}

/* ─── Form row (2 columns) ───────────────────────────────────────────────────── */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* ─── Textarea ───────────────────────────────────────────────────────────────── */
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text-1);
  background: var(--surface);
  outline: none;
  resize: vertical;
  min-height: 72px;
  font-family: inherit;
  line-height: 1.5;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(232,88,10,0.12);
}

.form-group textarea::placeholder { color: var(--text-3); }

/* ─── Modal large / xl ───────────────────────────────────────────────────────── */
.modal-lg  { width: 540px; }
.modal-xl  { width: 640px; }

.modal-body-scroll {
  max-height: calc(100vh - 200px);
  overflow-y: auto;
  padding-right: 4px;
  margin-bottom: 16px;
}

.form-section-title {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  margin: 20px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.form-section-title:first-child { margin-top: 0; }

/* ─── Utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ─── CRM Sidebar ─────────────────────────────────────────────────────────── */
.sidebar-crm {
  width: 260px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.crm-add-btn {
  margin-left: auto;
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  background: none;
  border-radius: 6px;
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.1s, color 0.1s;
}
.crm-add-btn:hover { background: var(--bg); color: var(--text-1); }

.crm-search-wrap {
  position: relative;
  padding: 10px 10px 6px;
}
.crm-search-icon {
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}
.crm-search {
  width: 100%;
  height: 32px;
  padding: 0 10px 0 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-1);
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.crm-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(232,88,10,0.10);
  background: var(--surface);
}
.crm-search::placeholder { color: var(--text-3); }

.crm-nav { padding: 4px 8px 6px; }

.crm-nav-section {
  display: flex;
  align-items: center;
  padding: 12px 12px 4px;
  gap: 6px;
}
.crm-nav-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  letter-spacing: 0.08em;
  flex: 1;
}
.crm-nav-add {
  width: 20px;
  height: 20px;
  border: 1px solid var(--border);
  background: none;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
  color: var(--text-3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, color 0.1s;
}
.crm-nav-add:hover { background: var(--bg); color: var(--text-1); }

.crm-nav-count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  background: var(--bg);
  border-radius: 10px;
  padding: 0 6px;
  height: 18px;
  display: inline-flex;
  align-items: center;
}
.nav-item.active .crm-nav-count {
  background: rgba(232,88,10,0.15);
  color: var(--accent);
}

.lista-nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s, color 0.1s;
}
.lista-nav-item:hover { background: var(--bg); color: var(--text-1); }
.lista-nav-item.active { background: var(--accent-bg); color: var(--accent); }
.lista-nav-item .lista-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.lista-nav-item .lista-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lista-nav-item .lista-count { font-size: 11px; color: var(--text-3); }
.lista-nav-actions { display: none; gap: 2px; }
.lista-nav-item:hover .lista-nav-actions { display: flex; }
.lista-nav-btn {
  width: 18px;
  height: 18px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 4px;
  color: var(--text-3);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, color 0.1s;
}
.lista-nav-btn:hover { background: var(--border); color: var(--text-1); }
.lista-nav-btn.danger:hover { background: #FEF2F2; color: var(--danger); }

/* ─── CRM Company List ────────────────────────────────────────────────────── */
.crm-company-list {
  flex: 1;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  padding: 6px 0;
}

.crm-list-empty {
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
  padding: 24px 16px;
}

.crm-company-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  cursor: pointer;
  transition: background 0.1s;
  border-left: 3px solid transparent;
  position: relative;
}
.crm-company-item:hover { background: var(--bg); }
.crm-company-item.active {
  background: var(--accent-bg);
  border-left-color: var(--accent);
}

.crm-company-item-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-2);
  flex-shrink: 0;
  text-transform: uppercase;
  overflow: hidden;
}

.crm-company-item-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 7px;
}

.crm-company-item-info { flex: 1; min-width: 0; }
.crm-company-item-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.crm-company-item-sub {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.crm-company-item-fav {
  width: 22px;
  height: 22px;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  color: var(--text-3);
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.1s, color 0.1s;
  padding: 0;
}
.crm-company-item:hover .crm-company-item-fav { opacity: 1; }
.crm-company-item-fav.is-fav {
  opacity: 1;
  color: #F59E0B;
}
.crm-company-item-fav.is-fav svg { fill: #F59E0B; }
.crm-company-item-fav svg { width: 13px; height: 13px; }

/* ─── CRM Main Area ────────────────────────────────────────────────────────── */
.crm-main { padding: 0; display: flex; flex-direction: column; overflow-y: auto; }

.crm-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-3);
  padding: 48px;
}
.crm-empty-state svg { opacity: 0.3; }
.crm-empty-title { font-size: 16px; font-weight: 600; color: var(--text-2); }
.crm-empty-sub   { font-size: 13px; color: var(--text-3); }

/* ─── CRM Detail ──────────────────────────────────────────────────────────── */
.crm-detail { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.crm-detail-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 24px 32px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.crm-detail-avatar-wrap {
  position: relative;
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  cursor: pointer;
}

.crm-detail-avatar {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  overflow: hidden;
  transition: filter 0.15s;
}

.crm-detail-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.crm-avatar-overlay {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  opacity: 0;
  transition: opacity 0.15s;
}

.crm-detail-avatar-wrap:hover .crm-avatar-overlay { opacity: 1; }
.crm-detail-avatar-wrap:hover .crm-detail-avatar   { filter: brightness(0.7); }

.crm-detail-title { flex: 1; min-width: 0; }

.crm-detail-name-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.crm-detail-name-row h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-1);
  line-height: 1.2;
}

.crm-fav-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--text-3);
  flex-shrink: 0;
  transition: color 0.1s, background 0.1s;
  padding: 0;
}
.crm-fav-btn:hover { background: var(--bg); color: #F59E0B; }
.crm-fav-btn.is-fav { color: #F59E0B; }
.crm-fav-btn.is-fav svg { fill: #F59E0B; }

.crm-detail-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.crm-detail-badge {
  font-size: 11px;
  font-weight: 500;
  background: var(--bg);
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 8px;
  height: 20px;
  display: inline-flex;
  align-items: center;
}
.crm-detail-badge:empty { display: none; }
.crm-detail-link {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}
.crm-detail-link:empty { display: none; }
.crm-detail-link:hover { text-decoration: underline; }

.crm-detail-actions { display: flex; gap: 8px; flex-shrink: 0; }
.crm-lista-btn { display: flex; align-items: center; gap: 6px; }

/* ─── CRM Tabs ────────────────────────────────────────────────────────────── */
.crm-tabs {
  display: flex;
  gap: 0;
  padding: 0 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.crm-tab {
  height: 42px;
  padding: 0 16px;
  border: none;
  background: none;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.1s, border-color 0.1s;
  margin-bottom: -1px;
  white-space: nowrap;
}
.crm-tab:hover { color: var(--text-1); }
.crm-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ─── CRM Tab Body ────────────────────────────────────────────────────────── */
.crm-tab-body {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  background: var(--bg);
}

.crm-summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
.crm-summary-col { display: flex; flex-direction: column; gap: 20px; }

.crm-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.crm-card-header {
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-1);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.crm-card-action {
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.crm-card-action:hover { text-decoration: underline; }
.crm-card-action:disabled { color: var(--text-3); cursor: not-allowed; text-decoration: none; }

.crm-fields { padding: 4px 0; }
.crm-field {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 18px;
  border-bottom: 1px solid var(--border);
}
.crm-field:last-child { border-bottom: none; }
.crm-field-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  min-width: 100px;
  flex-shrink: 0;
}
.crm-field-value {
  font-size: 13px;
  color: var(--text-1);
  word-break: break-all;
}
.crm-field-value.empty { color: var(--text-3); font-style: italic; }
.crm-field-value a { color: var(--accent); text-decoration: none; }
.crm-field-value a:hover { text-decoration: underline; }

.crm-contacts-empty {
  padding: 32px 18px;
  text-align: center;
  color: var(--text-3);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.crm-contacts-empty svg { opacity: 0.3; }
.crm-contacts-empty p { font-size: 13px; font-weight: 500; color: var(--text-2); }
.crm-contacts-empty span { font-size: 12px; }

.crm-detail-fields { padding: 4px 0; }
.crm-detail-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 14px 18px 6px;
}

/* ─── Color picker ─────────────────────────────────────────────────────────── */
.color-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 4px 0;
}
.color-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
  padding: 0;
}
.color-dot:hover { transform: scale(1.15); }
.color-dot.active { border-color: var(--text-1); transform: scale(1.1); }

.crm-avatar-circle,
.crm-avatar-circle img { border-radius: 50% !important; }

/* ─── CRM List View ──────────────────────────────────────────────────────────*/
.crm-list-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.crm-lv-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 32px 14px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.crm-lv-title-block { flex-shrink: 0; }

.crm-lv-search-wrap {
  flex: 1;
  position: relative;
}
.crm-lv-search-wrap .crm-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}
.crm-lv-search {
  width: 100%;
  height: 34px;
  padding: 0 12px 0 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: 13px;
  color: var(--text-1);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.crm-lv-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.08);
}
.crm-lv-search::placeholder { color: var(--text-3); }

.crm-lv-header h2 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-1);
  margin-bottom: 2px;
}

.crm-lv-count {
  font-size: 12px;
  color: var(--text-3);
  display: block;
}

.crm-lv-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 24px 24px;
  background: var(--bg);
}

.crm-lv-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.1s, box-shadow 0.1s;
  background: var(--surface);
  border: 1px solid var(--border);
  margin-bottom: 6px;
}

.crm-lv-row:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(232,88,10,0.08);
}

.crm-lv-avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  text-transform: uppercase;
}
.crm-lv-avatar.circle   { border-radius: 50%; }
.crm-lv-avatar img      { width: 100%; height: 100%; object-fit: contain; border-radius: inherit; }
.crm-lv-avatar.circle img { object-fit: cover; }

.crm-lv-main  { flex: 1; min-width: 0; }
.crm-lv-name  {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.crm-lv-sub   {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.crm-lv-col {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.crm-lv-col.w140 { width: 140px; }
.crm-lv-col.w180 { width: 180px; }

.crm-lv-pill {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  background: var(--bg);
  color: var(--text-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.crm-lv-arrow { color: var(--text-3); flex-shrink: 0; }

.crm-lv-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-3);
  font-size: 13px;
}

/* ─── Contact items inside company detail ─────────────────────────────────── */
.company-contact-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
  text-decoration: none;
}
.company-contact-item:last-child { border-bottom: none; }
.company-contact-item:hover { background: var(--accent-bg); }

.company-contact-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
  flex-shrink: 0;
  overflow: hidden;
  text-transform: uppercase;
}
.company-contact-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

.company-contact-info { flex: 1; min-width: 0; }
.company-contact-name {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.company-contact-item:hover .company-contact-name { text-decoration: underline; }
.company-contact-cargo {
  display: block;
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.company-contact-arrow { color: var(--text-3); flex-shrink: 0; }

.crm-contacts-badge {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  background: var(--bg);
  border-radius: 10px;
  padding: 0 6px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  margin-left: 4px;
  vertical-align: middle;
}

.crm-empresa-badge {
  background: #EFF6FF;
  color: #2563EB;
  border-color: #BFDBFE;
}

.btn-danger-soft {
  color: var(--danger) !important;
  border-color: transparent !important;
}
.btn-danger-soft:hover { background: #FEF2F2 !important; }

.crm-empresa-card-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.crm-empresa-card-logo {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-2);
  flex-shrink: 0;
  overflow: hidden;
  text-transform: uppercase;
}
.crm-empresa-card-logo img { width: 100%; height: 100%; object-fit: contain; }
.crm-empresa-card-name { font-size: 14px; font-weight: 600; color: var(--text-1); }
.crm-empresa-card-sub  { font-size: 12px; color: var(--text-3); margin-top: 2px; }

@media (max-width: 960px) {
  .crm-summary-grid { grid-template-columns: 1fr; }
  .sidebar-crm { width: 220px; }
}

/* ─── Map Panel ────────────────────────────────────────────────────────────── */
.sidebar-map {
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
}
.sidebar-map .crm-search-wrap { padding: 0 12px; margin-bottom: 4px; }

/* Stats bar */
.map-stats-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px 4px;
  font-size: 12px;
}
.map-stat-item { display: flex; align-items: baseline; gap: 4px; }
.map-stat-num  { font-size: 16px; font-weight: 700; color: var(--text-1); }
.map-stat-num.map-stat-warn { color: #D97706; }
.map-stat-lbl  { color: var(--text-3); }
.map-stat-sep  { color: var(--border); }

/* Tipo filter pills */
.map-tipo-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px 12px 8px;
}
.map-tipo-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: all .15s;
}
.map-tipo-pill:hover { border-color: var(--accent); color: var(--accent); }
.map-tipo-pill.active {
  background: var(--pill-color, var(--accent));
  border-color: var(--pill-color, var(--accent));
  color: #fff;
}
.map-tipo-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.map-tipo-pill.active .map-tipo-dot { background: rgba(255,255,255,0.7) !important; }

/* Company list */
.map-company-list {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 8px;
}
.map-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background .15s;
}
.map-list-item:hover { background: var(--bg); }
.map-list-item.selected { background: #EFF6FF; }
.map-list-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.6);
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.map-list-item-nocoords .map-list-dot { opacity: .35; box-shadow: none; }
.map-list-info { flex: 1; min-width: 0; }
.map-list-name { font-size: 13px; font-weight: 500; color: var(--text-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.map-list-sub  { font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.map-no-coords-header {
  padding: 8px 12px 4px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

/* Map main area */
.map-main {
  flex: 1;
  position: relative;
  overflow: hidden;
}
#leafletMap {
  width: 100%;
  height: 100%;
  background: #e8eaed;
}

/* Overlay controls */
.map-overlay-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 1000;
}
.map-ctrl-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
  transition: all .15s;
}
.map-ctrl-btn svg { width: 15px; height: 15px; }
.map-ctrl-btn:hover { background: var(--bg); color: var(--accent); border-color: var(--accent); }

/* Empty notice overlay */
.map-empty-notice {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--text-2);
  z-index: 500;
  background: rgba(255,255,255,0.92);
  padding: 32px 40px;
  border-radius: 16px;
  box-shadow: 0 2px 16px rgba(0,0,0,.1);
  pointer-events: none;
}
.map-empty-notice p { margin: 8px 0 0; font-size: 14px; }

/* Leaflet popup overrides */
.map-popup { min-width: 200px; }
.map-popup-name { font-size: 15px; font-weight: 700; color: var(--text-1); margin-bottom: 4px; }
.map-popup-tipo {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  margin-bottom: 6px;
  border: 1px solid transparent;
}
.map-popup-row { font-size: 12px; color: var(--text-2); margin: 3px 0; line-height: 1.4; }
.map-popup-row a { color: var(--accent); text-decoration: none; }
.map-popup-footer { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--border); }
.map-popup-btn {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.map-popup-btn:hover { text-decoration: underline; }

/* Leaflet marker custom */
.map-pin-wrap { background: none !important; border: none !important; }
.map-pin {
  display: block;
  border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,0.85);
  box-shadow: 0 1px 5px rgba(0,0,0,.35);
  transition: transform .15s, box-shadow .15s;
}

/* ── Org Chart ──────────────────────────────────────────────────────────────── */
.org-chart-scroll {
  overflow: auto;
  padding: 32px 24px 40px;
}

.org-chart-inner {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  position: relative;
  min-width: 100%;
}

.org-chart-svg {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  overflow: visible;
}

.org-roots {
  display: flex;
  gap: 32px;
  flex-wrap: nowrap;
  align-items: flex-start;
  position: relative;
  z-index: 1;
}

.org-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.org-node-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px 12px;
  min-width: 140px;
  max-width: 180px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  position: relative;
  z-index: 2;
  flex-shrink: 0;
}
.org-node-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.org-node-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 8px;
  overflow: hidden;
  flex-shrink: 0;
}

.org-node-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 148px;
}

.org-node-cargo {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 148px;
}

.org-node-children {
  display: flex;
  gap: 24px;
  padding-top: 48px;
  flex-wrap: nowrap;
  align-items: flex-start;
  position: relative;
  z-index: 1;
}

.org-orphans-section {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px dashed var(--border);
}

.org-orphans-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  margin-bottom: 16px;
  padding-left: 2px;
}
.map-pin:hover { transform: scale(1.3); box-shadow: 0 2px 8px rgba(0,0,0,.45); }
