/* ==========================================================================
   KLIO.IM - MÓDULO AMIGOS, RED MÉDICA Y REFERIDOS (SUB-PESTAÑAS PROFESIONALES)
   ========================================================================== */

.friends-workspace {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 100%;
  flex: 1 1 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.friends-intro {
  margin-bottom: 0;
  flex-shrink: 0;
}

.friends-intro h2 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  color: var(--ink);
}

.friends-intro p {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
  line-height: 1.35;
}

/* ==========================================================================
   SUB-PESTAÑAS (SEGMENTED CONTROL)
   ========================================================================== */
.friends-subtabs-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--tint-subtle, #f1f8f7);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg, 12px);
  padding: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}

.friends-subtabs-bar::-webkit-scrollbar {
  display: none;
}

.friends-subtab-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md, 8px);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.16s ease;
  line-height: 1.25;
}

.friends-subtab-btn:hover {
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
}

.friends-subtab-btn.is-active {
  background: #ffffff;
  color: var(--primary-dark);
  border-color: color-mix(in srgb, var(--primary) 24%, var(--line));
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  font-weight: 700;
}

.friends-subtab-btn .icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.friends-subtab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 6px;
  border-radius: var(--radius-pill, 999px);
  font-size: 10.5px;
  font-weight: 700;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary-dark);
}

.friends-subtab-btn.is-active .friends-subtab-count {
  background: var(--primary);
  color: #ffffff;
}

/* ==========================================================================
   SUBTAB PANELS (ELÁSTICOS ANCLADOS AL VIEWPORT)
   ========================================================================== */
.friends-panel-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1 1 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

/* Top bar inside subtab */
.friends-panel-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 0;
  flex-wrap: wrap;
  flex-shrink: 0;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg, 12px);
  padding: 10px 16px;
}

.friends-panel-topbar-left h3 {
  font-size: 14.5px;
  font-weight: 700;
  margin: 0 0 2px;
  color: var(--ink);
}

.friends-panel-topbar-left p {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
}

.friends-scroll-pane {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.friends-scroll-pane::-webkit-scrollbar {
  width: 6px;
}

.friends-scroll-pane::-webkit-scrollbar-thumb {
  background: rgba(18, 56, 53, 0.16);
  border-radius: 6px;
}

/* ==========================================================================
   CARDS & DOCTOR ITEMS
   ========================================================================== */
.friends-doctor-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg, 12px);
  padding: 12px 16px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
  flex-wrap: wrap;
  transition: all 0.16s ease;
  flex-shrink: 0;
}

.friends-doctor-card:hover {
  border-color: color-mix(in srgb, var(--primary) 32%, var(--line));
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
}

.friends-doctor-info {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 240px;
  flex: 1;
}

.friends-doctor-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--tint);
  color: var(--primary);
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--primary) 35%, var(--line));
  flex-shrink: 0;
}

.friends-doctor-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.friends-doctor-avatar > .icon {
  width: 22px;
  height: 22px;
}

.friends-doctor-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.friends-doctor-meta h4 {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
  color: var(--ink);
  line-height: 1.3;
}

.friends-doctor-meta-sub {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.friends-id-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: color-mix(in srgb, var(--primary) 8%, #ffffff);
  border: 1px solid color-mix(in srgb, var(--primary) 22%, var(--line));
  border-radius: var(--radius-pill, 999px);
  padding: 1px 7px;
  font-size: 10.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--ink);
  font-weight: 700;
}

.friends-id-chip .chip-label {
  font-size: 9px;
  color: var(--primary);
  font-weight: 700;
}

.friends-id-chip-copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.friends-id-chip-copy-btn:hover {
  color: var(--primary);
  transform: scale(1.15);
}

.friends-doctor-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Badges for shared clinics */
.shared-clinic-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--radius-pill, 999px);
  font-size: 11px;
  font-weight: 600;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

.shared-clinic-badge.is-owner {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e40af;
}

/* ==========================================================================
   BUSCADOR CARD (ELÁSTICO)
   ========================================================================== */
.friends-search-box {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg, 12px);
  padding: 18px 20px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
}

.friends-search-form {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 10px;
  flex-shrink: 0;
}

.friends-search-results {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.friends-search-input-wrap {
  position: relative;
  flex: 1;
  min-width: 280px;
}

.friends-search-input-wrap input {
  width: 100%;
  height: 40px;
  padding: 8px 14px 8px 38px;
  border-radius: var(--radius-md, 8px);
  border: 1px solid var(--line);
  font-size: 13px;
  background: #ffffff;
  transition: all 0.16s ease;
}

.friends-search-input-wrap input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
  outline: none;
}

.friends-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
  width: 16px;
  height: 16px;
}

/* ==========================================================================
   REFERRALS SECTION (2 COLUMNAS ELÁSTICAS EN ESCRITORIO)
   ========================================================================== */
.friends-referrals-split {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 12px;
  flex: 1 1 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.friends-referrals-left {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
}

.friends-referrals-right {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  margin-bottom: 0 !important;
}

.friends-referrals-right .card-header {
  flex-shrink: 0;
  padding: 12px 16px;
}

.friends-referrals-right .card-body {
  flex: 1 1 0;
  min-height: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.friends-referrals-right .table-wrap {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.friends-referrals-right .table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fbfb;
  box-shadow: inset 0 -1px 0 var(--line);
}

.referral-hero-card {
  background: linear-gradient(135deg, color-mix(in srgb, var(--primary) 7%, #ffffff) 0%, #ffffff 100%);
  border: 1px solid color-mix(in srgb, var(--primary) 22%, var(--line));
  border-radius: var(--radius-lg, 12px);
  padding: 14px 18px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  flex-shrink: 0;
}

.referral-link-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 8px;
}

.referral-link-input {
  flex: 1;
  min-width: 200px;
  height: 36px;
  background: #ffffff !important;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  color: var(--ink);
  font-weight: 600;
  border: 1px solid var(--line);
  border-radius: var(--radius-md, 8px);
  padding: 6px 12px;
}

.referral-stats-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.referral-stat-card {
  background: var(--tint);
  border: 1px solid color-mix(in srgb, var(--primary) 20%, var(--line));
  border-radius: var(--radius-md, 8px);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.referral-stat-card .stat-val {
  font-size: 18px;
  font-weight: 800;
  color: var(--primary-dark);
  line-height: 1.1;
}

.referral-stat-card .stat-lbl {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}

/* Equipo Interno Card Elástica */
.friends-team-card {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  margin-bottom: 0 !important;
}

.friends-team-card .card-header {
  flex-shrink: 0;
  padding: 12px 18px;
}

.friends-team-card .card-body {
  flex: 1 1 0;
  min-height: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.friends-team-card .table-wrap {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.friends-team-card .table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fbfb;
  box-shadow: inset 0 -1px 0 var(--line);
}

/* ==========================================================================
   EMPTY STATE
   ========================================================================== */
.friends-empty-state {
  text-align: center;
  padding: 32px 20px;
  background: #ffffff;
  border: 1px dashed var(--line);
  border-radius: var(--radius-lg, 12px);
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1 1 0;
  min-height: 180px;
}

.friends-empty-state .icon {
  width: 38px;
  height: 38px;
  color: color-mix(in srgb, var(--primary) 40%, var(--line));
  margin-bottom: 10px;
}

.friends-empty-state h4 {
  font-size: 15px;
  color: var(--ink);
  margin: 0 0 6px;
  font-weight: 700;
}

.friends-empty-state p {
  font-size: 12.5px;
  margin: 0 0 12px;
  line-height: 1.5;
  max-width: 440px;
  margin-inline: auto;
}

@media (max-width: 960px) {
  .friends-referrals-split {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
}

@media (max-width: 760px) {
  .friends-workspace,
  .friends-panel-container,
  .friends-scroll-pane,
  .friends-referrals-split {
    overflow: visible;
    height: auto;
  }
}


@media (max-width: 760px) {
  .friends-search-input-wrap {
    min-width: 0 !important;
    width: 100% !important;
  }
  .referral-stats-row {
    grid-template-columns: 1fr !important;
  }
  .friends-referrals-right,
  .friends-team-card {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }
}
